1
1
import { useState } from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
- import styled from 'styled-components ' ;
3
+ import classNames from 'classnames ' ;
4
4
import Button from '../Button' ;
5
5
import Icon from '../Icon' ;
6
- import {
7
- components ,
8
- spacing ,
9
- colors ,
10
- baseFontSize as defaultBaseFontSize ,
11
- breakpoints ,
12
- } from '../shared/theme' ;
13
-
14
- const Content = styled . div `
15
- align-items: start;
16
- display: flex;
17
-
18
- & > span {
19
- flex: 1;
20
- }
21
- ` ;
22
-
23
- const AlertIcon = styled ( Icon ) `
24
- width: ${ defaultBaseFontSize * 1.5 } px;
25
- ` ;
26
-
27
- const CloseButton = styled ( Button . Icon ) . attrs ( {
28
- icon : 'close' ,
29
- } ) `
30
- height: auto;
31
- opacity: 0.8;
32
- padding: 0;
33
- transition: opacity 0.4s ease;
34
- width: auto;
35
-
36
- &:hover {
37
- background: none;
38
- opacity: 1;
39
- }
40
- ` ;
41
-
42
- CloseButton . displayName = 'CloseButton' ;
43
-
44
- const Wrapper = styled . div `
45
- border-radius: 8px;
46
- box-sizing: border-box;
47
-
48
- ${ ( {
49
- skin,
50
- theme : {
51
- baseFontSize,
52
- spacing : { small, medium } ,
53
- components : {
54
- alert : {
55
- skins : {
56
- [ skin ] : { background, icon, text } ,
57
- } ,
58
- } ,
59
- } ,
60
- } ,
61
- } ) => `
62
- font-size: ${ baseFontSize } px;
63
- background-color: ${ background } ;
64
- border: 1.5px solid ${ icon } ;
65
- color: ${ text } ;
66
- padding: ${ small } px ${ medium } px;
67
-
68
- ${ Content } ${ AlertIcon } {
69
- color: ${ icon } ;
70
- margin-right: ${ medium } px;
71
- }
72
-
73
- ${ Content } > ${ CloseButton } {
74
- color: ${ icon } ;
75
- margin: 0 0 0 ${ medium } px !important;
76
- min-height: 0;
77
- opacity: 1;
78
- }
79
- ` }
80
- ` ;
6
+ import styles from './Alert.module.css' ;
81
7
82
8
const Alert = ( {
83
9
icon = null ,
84
10
skin = 'neutral' ,
85
11
children,
86
- theme = {
87
- colors,
88
- baseFontSize : defaultBaseFontSize ,
89
- spacing,
90
- breakpoints,
91
- components : {
92
- alert : components . alert ,
93
- } ,
94
- } ,
95
12
onClose = undefined ,
13
+ className,
96
14
...rest
97
15
} ) => {
98
16
const [ show , setShow ] = useState ( true ) ;
17
+ const contentClass = classNames ( styles . content , className ) ;
18
+ const alertClass = classNames ( styles [ 'alert-icon' ] , styles [ `icon-${ skin } ` ] ) ;
19
+ const closeButtonClass = classNames (
20
+ styles [ 'close-button' ] ,
21
+ styles [ `icon-${ skin } ` ] ,
22
+ ) ;
23
+ const wrapperClass = classNames ( styles . wrapper , styles [ `wrapper-${ skin } ` ] ) ;
99
24
100
25
const handleClose = ( ) => {
101
26
setShow ( false ) ;
@@ -104,13 +29,19 @@ const Alert = ({
104
29
105
30
return (
106
31
show && (
107
- < Wrapper theme = { theme } skin = { skin } { ...rest } role = "alert" >
108
- < Content >
109
- { icon && < AlertIcon name = { icon } /> }
32
+ < div className = { wrapperClass } { ...rest } role = "alert" >
33
+ < div className = { contentClass } >
34
+ { icon && < Icon name = { icon } className = { alertClass } /> }
110
35
{ children && < span > { children } </ span > }
111
- { onClose && < CloseButton theme = { theme } onClick = { handleClose } /> }
112
- </ Content >
113
- </ Wrapper >
36
+ { onClose && (
37
+ < Button . Icon
38
+ onClick = { handleClose }
39
+ icon = "close"
40
+ className = { closeButtonClass }
41
+ />
42
+ ) }
43
+ </ div >
44
+ </ div >
114
45
)
115
46
) ;
116
47
} ;
@@ -124,14 +55,6 @@ Alert.propTypes = {
124
55
/** You must pass a callback that is called when close button is clicked */
125
56
onClose : PropTypes . func ,
126
57
skin : PropTypes . oneOf ( [ 'primary' , 'success' , 'error' , 'neutral' , 'warning' ] ) ,
127
- theme : PropTypes . shape ( {
128
- baseFontSize : PropTypes . number ,
129
- colors : PropTypes . object ,
130
- spacing : PropTypes . object ,
131
- components : PropTypes . shape ( {
132
- alert : PropTypes . object ,
133
- } ) ,
134
- } ) ,
135
58
} ;
136
59
137
60
export default Alert ;
0 commit comments