@@ -150,8 +150,10 @@ const StyledIconButton = styled.button`
150150 * A Button performs an primary action
151151 */
152152const Button = ( {
153- children, href, kind, 'aria-label' : ariaLabel , to, type, ...props
153+ children, href, kind, iconBefore , iconAfter , 'aria-label' : ariaLabel , to, type, ...props
154154} ) => {
155+ const hasChildren = React . Children . count ( children ) > 0 ;
156+ const content = < > { iconBefore } { hasChildren && < span > { children } </ span > } { iconAfter } </ > ;
155157 let StyledComponent = StyledButton ;
156158
157159 if ( kind === kinds . inline ) {
@@ -161,19 +163,31 @@ const Button = ({
161163 }
162164
163165 if ( href ) {
164- return < StyledComponent kind = { kind } as = "a" aria-label = { ariaLabel } href = { href } { ...props } > { children } </ StyledComponent > ;
166+ return (
167+ < StyledComponent
168+ kind = { kind }
169+ as = "a"
170+ aria-label = { ariaLabel }
171+ href = { href }
172+ { ...props }
173+ >
174+ { content }
175+ </ StyledComponent >
176+ ) ;
165177 }
166178
167179 if ( to ) {
168- return < StyledComponent kind = { kind } as = { Link } aria-label = { ariaLabel } to = { to } { ...props } > { children } </ StyledComponent > ;
180+ return < StyledComponent kind = { kind } as = { Link } aria-label = { ariaLabel } to = { to } { ...props } > { content } </ StyledComponent > ;
169181 }
170182
171- return < StyledComponent kind = { kind } aria-label = { ariaLabel } type = { type } { ...props } > { children } </ StyledComponent > ;
183+ return < StyledComponent kind = { kind } aria-label = { ariaLabel } type = { type } { ...props } > { content } </ StyledComponent > ;
172184} ;
173185
174186Button . defaultProps = {
175187 'children' : null ,
176188 'disabled' : false ,
189+ 'iconAfter' : null ,
190+ 'iconBefore' : null ,
177191 'kind' : kinds . block ,
178192 'href' : null ,
179193 'aria-label' : null ,
@@ -193,6 +207,14 @@ Button.propTypes = {
193207 If the button can be activated or not
194208 */
195209 'disabled' : PropTypes . bool ,
210+ /**
211+ * SVG icon to place after child content
212+ */
213+ 'iconAfter' : PropTypes . element ,
214+ /**
215+ * SVG icon to place before child content
216+ */
217+ 'iconBefore' : PropTypes . element ,
196218 /**
197219 * The kind of button - determines how it appears visually
198220 */
0 commit comments