11import React , { ReactNode , SyntheticEvent } from 'react' ;
22import { css } from '@emotion/core' ;
3- import { transparentize } from 'polished' ;
43import theme from '../theme' ;
54import { classNames } from '../utils' ;
65import { Text } from '../content' ;
7- import {
8- Icon ,
9- InfoOutline ,
10- AlertTriangleOutline ,
11- AlertCircleOutline ,
12- CheckmarkCircleOutline ,
13- CloseOutline ,
14- } from '../icon' ;
15-
6+ import { Icon , CloseOutline } from '../icon' ;
7+ import { useSeverityStyle } from './useSeverityStyle' ;
8+ import { getSeverityIcon } from './getSeverityIcon' ;
9+ import { SeverityLevel } from '../types' ;
1610export interface AlertProps {
17- variant : 'warning' | 'info' | 'danger' | 'success' ;
11+ variant : SeverityLevel ;
1812 children ?: ReactNode ;
1913 /**
2014 * Title of the alert. Optional
@@ -49,30 +43,6 @@ export interface AlertProps {
4943 extra ?: ReactNode ;
5044}
5145
52- const warningCSS = css `
53- border : 1px solid ${ theme . colors . statusWarning } ;
54- background-color : ${ transparentize ( 0.85 , theme . colors . statusWarning ) } ;
55- color : ${ theme . colors . statusWarning } ;
56- ` ;
57-
58- const infoCSS = css `
59- border : 1px solid ${ theme . colors . statusInfo } ;
60- background-color : ${ transparentize ( 0.85 , theme . colors . statusInfo ) } ;
61- color : ${ theme . colors . statusInfo } ;
62- ` ;
63-
64- const dangerCSS = css `
65- border : 1px solid ${ theme . colors . statusDanger } ;
66- background-color : ${ transparentize ( 0.85 , theme . colors . statusDanger ) } ;
67- color : ${ theme . colors . statusDanger } ;
68- ` ;
69-
70- const successCSS = css `
71- border : 1px solid ${ theme . colors . statusSuccess } ;
72- background-color : ${ transparentize ( 0.85 , theme . colors . statusSuccess ) } ;
73- color : ${ theme . colors . statusSuccess } ;
74- ` ;
75-
7646export const Alert = ( {
7747 variant,
7848 title,
@@ -84,37 +54,10 @@ export const Alert = ({
8454 banner = false ,
8555 extra,
8656} : AlertProps ) => {
87- let variantStyle ;
88- switch ( variant ) {
89- case 'warning' :
90- variantStyle = warningCSS ;
91- break ;
92- case 'info' :
93- variantStyle = infoCSS ;
94- break ;
95- case 'danger' :
96- variantStyle = dangerCSS ;
97- break ;
98- case 'success' :
99- variantStyle = successCSS ;
100- break ;
101- }
57+ let variantStyle = useSeverityStyle ( variant ) ;
10258
10359 if ( ! icon && showIcon ) {
104- switch ( variant ) {
105- case 'warning' :
106- icon = < Icon svg = { < AlertTriangleOutline /> } /> ;
107- break ;
108- case 'info' :
109- icon = < Icon svg = { < InfoOutline /> } /> ;
110- break ;
111- case 'danger' :
112- icon = < Icon svg = { < AlertCircleOutline /> } /> ;
113- break ;
114- case 'success' :
115- icon = < Icon svg = { < CheckmarkCircleOutline /> } /> ;
116- break ;
117- }
60+ icon = getSeverityIcon ( variant ) ;
11861 }
11962 return (
12063 < div
0 commit comments