@@ -4,6 +4,7 @@ import styled from 'styled-components';
44import { Link } from 'react-router' ;
55
66import { remSize , prop } from '../theme' ;
7+ import Icon , { ValidIconNameType } from './Icon' ;
78
89// The '&&&' will increase the specificity of the
910// component's CSS so that it overrides the more
@@ -28,6 +29,10 @@ const StyledButton = styled.button`
2829 &:hover:not(:disabled) {
2930 color: ${ prop ( 'buttonHoverColor' ) } ;
3031 background-color: ${ prop ( 'buttonHoverColorBackground' ) } ;
32+
33+ svg * {
34+ fill: ${ prop ( 'buttonHoverColor' ) } ;
35+ }
3136 }
3237
3338 &:disabled {
@@ -46,27 +51,36 @@ const StyledButton = styled.button`
4651 * A Button performs an primary action
4752 */
4853const Button = ( {
49- children, href, label, to, type, ...props
54+ children, href, iconAfterName , iconBeforeName , label, to, type, ...props
5055} ) => {
56+ const iconAfter = iconAfterName && < Icon name = { iconAfterName } /> ;
57+ const iconBefore = iconBeforeName && < Icon name = { iconBeforeName } /> ;
58+
59+ const content = < > { iconBefore } < span > { children } </ span > { iconAfter } </ > ;
60+
5161 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 > ;
5363 }
5464
5565 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 > ;
5767 }
5868
59- return < StyledButton aria-label = { label } type = { type } { ...props } > { children } </ StyledButton > ;
69+ return < StyledButton aria-label = { label } type = { type } { ...props } > { content } </ StyledButton > ;
6070} ;
6171
6272Button . defaultProps = {
6373 disabled : false ,
74+ iconAfterName : null ,
75+ iconBeforeName : null ,
6476 href : null ,
6577 label : null ,
6678 to : null ,
6779 type : 'button' ,
6880} ;
6981
82+ Button . iconNames = Icon . names ;
83+
7084Button . propTypes = {
7185 /**
7286 * The visible part of the button, telling the user what
@@ -77,6 +91,15 @@ Button.propTypes = {
7791 If the button can be activated or not
7892 */
7993 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 ,
80103 /**
81104 * Specifying an href will use an <a> to link to the URL
82105 */
0 commit comments