@@ -4,6 +4,7 @@ import styled from 'styled-components';
4
4
import { Link } from 'react-router' ;
5
5
6
6
import { remSize , prop } from '../theme' ;
7
+ import Icon , { ValidIconNameType } from './Icon' ;
7
8
8
9
// The '&&&' will increase the specificity of the
9
10
// component's CSS so that it overrides the more
@@ -28,6 +29,10 @@ const StyledButton = styled.button`
28
29
&:hover:not(:disabled) {
29
30
color: ${ prop ( 'buttonHoverColor' ) } ;
30
31
background-color: ${ prop ( 'buttonHoverColorBackground' ) } ;
32
+
33
+ svg * {
34
+ fill: ${ prop ( 'buttonHoverColor' ) } ;
35
+ }
31
36
}
32
37
33
38
&:disabled {
@@ -46,27 +51,36 @@ const StyledButton = styled.button`
46
51
* A Button performs an primary action
47
52
*/
48
53
const Button = ( {
49
- children, href, label, to, type, ...props
54
+ children, href, iconAfterName , iconBeforeName , label, to, type, ...props
50
55
} ) => {
56
+ const iconAfter = iconAfterName && < Icon name = { iconAfterName } /> ;
57
+ const iconBefore = iconBeforeName && < Icon name = { iconBeforeName } /> ;
58
+
59
+ const content = < > { iconBefore } < span > { children } </ span > { iconAfter } </ > ;
60
+
51
61
if ( href ) {
52
- return < StyledButton as = "a" aria-label = { label } href = { href } { ...props } > { children } </ StyledButton > ;
62
+ return < StyledButton as = "a" aria-label = { label } href = { href } { ...props } > { content } </ StyledButton > ;
53
63
}
54
64
55
65
if ( to ) {
56
- return < StyledButton as = { Link } aria-label = { label } to = { to } { ...props } > { children } </ StyledButton > ;
66
+ return < StyledButton as = { Link } aria-label = { label } to = { to } { ...props } > { content } </ StyledButton > ;
57
67
}
58
68
59
- return < StyledButton aria-label = { label } type = { type } { ...props } > { children } </ StyledButton > ;
69
+ return < StyledButton aria-label = { label } type = { type } { ...props } > { content } </ StyledButton > ;
60
70
} ;
61
71
62
72
Button . defaultProps = {
63
73
disabled : false ,
74
+ iconAfterName : null ,
75
+ iconBeforeName : null ,
64
76
href : null ,
65
77
label : null ,
66
78
to : null ,
67
79
type : 'button' ,
68
80
} ;
69
81
82
+ Button . iconNames = Icon . names ;
83
+
70
84
Button . propTypes = {
71
85
/**
72
86
* The visible part of the button, telling the user what
@@ -77,6 +91,15 @@ Button.propTypes = {
77
91
If the button can be activated or not
78
92
*/
79
93
disabled : PropTypes . bool ,
94
+ /**
95
+ * Name of icon to place before child content
96
+ */
97
+ iconAfterName : ValidIconNameType ,
98
+
99
+ /**
100
+ * Name of icon to place after child content
101
+ */
102
+ iconBeforeName : ValidIconNameType ,
80
103
/**
81
104
* Specifying an href will use an <a> to link to the URL
82
105
*/
0 commit comments