1
1
import React from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
3
import { css } from '@emotion/core' ;
4
- import withMouseOverState from '../../../hocs/with-mouse-over-state ' ;
4
+ import styled from '@emotion/styled ' ;
5
5
import filterAriaAttributes from '../../../utils/filter-aria-attributes' ;
6
6
import filterDataAttributes from '../../../utils/filter-data-attributes' ;
7
+ import vars from '../../../../materials/custom-properties' ;
7
8
import AccessibleButton from '../accessible-button' ;
8
9
10
+ const hoverStyle = props => {
11
+ const overwrittenVars = {
12
+ ...vars ,
13
+ ...props . theme ,
14
+ } ;
15
+
16
+ return css `
17
+ &:hover {
18
+ svg * {
19
+ fill: ${ overwrittenVars . colorPrimary } ;
20
+ }
21
+ }
22
+ ` ;
23
+ } ;
24
+
25
+ const fillStyle = props => {
26
+ const overwrittenVars = {
27
+ ...vars ,
28
+ ...props . theme ,
29
+ } ;
30
+ return css `
31
+ svg * {
32
+ fill: ${ props . isDisabled
33
+ ? overwrittenVars . colorNeutral60
34
+ : overwrittenVars . colorSolid } ;
35
+ }
36
+ ` ;
37
+ } ;
38
+
39
+ const IconContainer = styled . div `
40
+ display: flex;
41
+ align-items: center;
42
+ justify-content: center;
43
+
44
+ ${ fillStyle }
45
+
46
+ ${ props => ! props . isDisabled && hoverStyle }
47
+ ` ;
48
+
9
49
export const SecondaryIconButton = props => {
10
50
const buttonAttributes = {
11
51
'data-track-component' : 'SecondaryIconButton' ,
12
52
...filterAriaAttributes ( props ) ,
13
53
...filterDataAttributes ( props ) ,
14
54
} ;
15
- let iconTheme = 'black' ;
16
- if ( props . isDisabled ) iconTheme = 'grey' ;
17
- else if ( props . isMouseOver ) iconTheme = 'green' ;
18
55
return (
19
- < div
20
- onMouseOver = { props . handleMouseOver }
21
- onMouseOut = { props . handleMouseOut }
22
- css = { css `
23
- display : inline-flex;
24
- align-items : center;
25
- border : none;
26
- background : none;
27
- padding : 0 ;
28
- min-height : initial;
29
- cursor : pointer;
30
- ` }
56
+ < AccessibleButton
57
+ type = { props . type }
58
+ buttonAttributes = { buttonAttributes }
59
+ label = { props . label }
60
+ onClick = { props . onClick }
61
+ isDisabled = { props . isDisabled }
31
62
>
32
- < AccessibleButton
33
- type = { props . type }
34
- buttonAttributes = { buttonAttributes }
35
- label = { props . label }
36
- onClick = { props . onClick }
37
- isDisabled = { props . isDisabled }
38
- >
39
- < div
40
- css = { css `
41
- display : flex;
42
- align-items : center;
43
- justify-content : center;
44
- ` }
45
- >
46
- { React . cloneElement ( props . icon , { theme : iconTheme } ) }
47
- </ div >
48
- </ AccessibleButton >
49
- </ div >
63
+ < IconContainer isDisabled = { props . isDisabled } >
64
+ { React . cloneElement ( props . icon ) }
65
+ </ IconContainer >
66
+ </ AccessibleButton >
50
67
) ;
51
68
} ;
52
69
@@ -57,15 +74,11 @@ SecondaryIconButton.propTypes = {
57
74
icon : PropTypes . element . isRequired ,
58
75
isDisabled : PropTypes . bool ,
59
76
onClick : PropTypes . func . isRequired ,
60
-
61
- // HoC
62
- isMouseOver : PropTypes . bool . isRequired ,
63
- handleMouseOver : PropTypes . func . isRequired ,
64
- handleMouseOut : PropTypes . func . isRequired ,
65
77
} ;
78
+
66
79
SecondaryIconButton . defaultProps = {
67
80
type : 'button' ,
68
81
isDisabled : false ,
69
82
} ;
70
83
71
- export default withMouseOverState ( SecondaryIconButton ) ;
84
+ export default SecondaryIconButton ;
0 commit comments