@@ -4,7 +4,6 @@ import styled from 'styled-components';
44import { Link } from 'react-router' ;
55
66import { remSize , prop } from '../theme' ;
7- import Icon , { ValidIconNameType } from './Icon' ;
87
98const kinds = {
109 block : 'block' ,
@@ -151,14 +150,8 @@ const StyledIconButton = styled.button`
151150 * A Button performs an primary action
152151 */
153152const Button = ( {
154- children, href, iconAfterName , iconBeforeName , kind, label, to, type, ...props
153+ children, href, kind, 'aria- label' : ariaLabel , to, type, ...props
155154} ) => {
156- const IconAfter = Icon [ iconAfterName ] ;
157- const IconBefore = Icon [ iconBeforeName ] ;
158- const hasChildren = React . Children . count ( children ) > 0 ;
159-
160- const content = < > { IconBefore } { hasChildren && < span > { children } </ span > } { IconAfter } </ > ;
161-
162155 let StyledComponent = StyledButton ;
163156
164157 if ( kind === kinds . inline ) {
@@ -168,69 +161,58 @@ const Button = ({
168161 }
169162
170163 if ( href ) {
171- return < StyledComponent kind = { kind } as = "a" aria-label = { label } href = { href } { ...props } > { content } </ StyledComponent > ;
164+ return < StyledComponent kind = { kind } as = "a" aria-label = { ariaLabel } href = { href } { ...props } > { children } </ StyledComponent > ;
172165 }
173166
174167 if ( to ) {
175- return < StyledComponent kind = { kind } as = { Link } aria-label = { label } to = { to } { ...props } > { content } </ StyledComponent > ;
168+ return < StyledComponent kind = { kind } as = { Link } aria-label = { ariaLabel } to = { to } { ...props } > { children } </ StyledComponent > ;
176169 }
177170
178- return < StyledComponent kind = { kind } aria-label = { label } type = { type } { ...props } > { content } </ StyledComponent > ;
171+ return < StyledComponent kind = { kind } aria-label = { ariaLabel } type = { type } { ...props } > { children } </ StyledComponent > ;
179172} ;
180173
181174Button . defaultProps = {
182- children : null ,
183- disabled : false ,
184- iconAfterName : null ,
185- iconBeforeName : null ,
186- kind : kinds . block ,
187- href : null ,
188- label : null ,
189- to : null ,
190- type : 'button' ,
175+ 'children' : null ,
176+ 'disabled' : false ,
177+ 'kind' : kinds . block ,
178+ 'href' : null ,
179+ 'aria-label' : null ,
180+ 'to' : null ,
181+ 'type' : 'button' ,
191182} ;
192183
193- Button . iconNames = Object . keys ( Icon ) ;
194184Button . kinds = kinds ;
195185
196186Button . propTypes = {
197187 /**
198188 * The visible part of the button, telling the user what
199189 * the action is
200190 */
201- children : PropTypes . element ,
191+ ' children' : PropTypes . element ,
202192 /**
203193 If the button can be activated or not
204194 */
205- disabled : PropTypes . bool ,
206- /**
207- * Name of icon to place before child content
208- */
209- iconAfterName : ValidIconNameType ,
210- /**
211- * Name of icon to place after child content
212- */
213- iconBeforeName : ValidIconNameType ,
195+ 'disabled' : PropTypes . bool ,
214196 /**
215197 * The kind of button - determines how it appears visually
216198 */
217- kind : PropTypes . oneOf ( Object . values ( kinds ) ) ,
199+ ' kind' : PropTypes . oneOf ( Object . values ( kinds ) ) ,
218200 /**
219201 * Specifying an href will use an <a> to link to the URL
220202 */
221- href : PropTypes . string ,
203+ ' href' : PropTypes . string ,
222204 /*
223205 * An ARIA Label used for accessibility
224206 */
225- label : PropTypes . string ,
207+ 'aria- label' : PropTypes . string ,
226208 /**
227209 * Specifying a to URL will use a react-router Link
228210 */
229- to : PropTypes . string ,
211+ 'to' : PropTypes . string ,
230212 /**
231213 * If using a button, then type is defines the type of button
232214 */
233- type : PropTypes . oneOf ( [ 'button' , 'submit' ] ) ,
215+ ' type' : PropTypes . oneOf ( [ 'button' , 'submit' ] ) ,
234216} ;
235217
236218export default Button ;
0 commit comments