1- import PropTypes from 'prop-types' ;
21import React , { useContext } from 'react' ;
32import { withGlobalProps } from '../../providers/globalProps' ;
43import { classNames } from '../../utils/classNames' ;
@@ -10,23 +9,24 @@ import { resolveContextOrProp } from '../_helpers/resolveContextOrProp';
109import { ButtonGroupContext } from '../ButtonGroup' ;
1110import { InputGroupContext } from '../InputGroup/InputGroupContext' ;
1211import getRootLabelVisibilityClassName from './helpers/getRootLabelVisibilityClassName' ;
12+ import { ButtonProps } from './Button.types' ;
1313import styles from './Button.module.scss' ;
1414
15- export const Button = React . forwardRef ( ( props , ref ) => {
15+ export const Button = React . forwardRef < HTMLButtonElement , ButtonProps > ( ( props , ref ) => {
1616 const {
17- afterLabel,
18- beforeLabel,
19- block,
20- disabled,
21- endCorner,
22- feedbackIcon,
17+ afterLabel = null ,
18+ beforeLabel = null ,
19+ block = false ,
20+ disabled = false ,
21+ endCorner = null ,
22+ feedbackIcon = null ,
2323 id,
2424 label,
25- labelVisibility,
26- priority,
27- size,
28- startCorner,
29- color,
25+ labelVisibility = 'xs' ,
26+ priority = 'filled' ,
27+ size = 'medium' ,
28+ startCorner = null ,
29+ color = 'primary' ,
3030 ...restProps
3131 } = props ;
3232 const buttonGroupContext = useContext ( ButtonGroupContext ) ;
@@ -100,100 +100,6 @@ export const Button = React.forwardRef((props, ref) => {
100100 ) ;
101101} ) ;
102102
103- Button . defaultProps = {
104- afterLabel : null ,
105- beforeLabel : null ,
106- block : false ,
107- color : 'primary' ,
108- disabled : false ,
109- endCorner : null ,
110- feedbackIcon : null ,
111- id : undefined ,
112- labelVisibility : 'xs' ,
113- priority : 'filled' ,
114- size : 'medium' ,
115- startCorner : null ,
116- type : 'button' ,
117- } ;
118-
119- Button . propTypes = {
120- /**
121- * Element to be displayed after label, eg. an icon.
122- */
123- afterLabel : PropTypes . node ,
124- /**
125- * Element to be displayed before label, eg. an icon.
126- */
127- beforeLabel : PropTypes . node ,
128- /**
129- * If `true`, the button will span the full width of its parent.
130- *
131- * Ignored if the component is rendered within `ButtonGroup` component
132- * as the value is inherited in such case.
133- */
134- block : PropTypes . bool ,
135- /**
136- * Color variant to clarify importance and meaning of the alert. Implements
137- * [Action, Feedback and Neutral color collections](/docs/foundation/collections#colors).
138- */
139- color : PropTypes . oneOf (
140- [ 'primary' , 'secondary' , 'selected' , 'success' , 'warning' , 'danger' , 'help' , 'info' , 'note' , 'light' , 'dark' ] ,
141- ) ,
142- /**
143- * If `true`, the button will be disabled.
144- *
145- * Ignored if the component is rendered within `ButtonGroup` component
146- * as the value is inherited in such case.
147- */
148- disabled : PropTypes . bool ,
149- /**
150- * Element to be displayed in the top right corner.
151- */
152- endCorner : PropTypes . node ,
153- /**
154- * Element to be displayed as a feedback icon on top of button label. When defined, it implies the
155- * button is in feedback state.
156- */
157- feedbackIcon : PropTypes . node ,
158- /**
159- * ID of the root HTML element.
160- *
161- * Also serves as base for ids of nested elements:
162- * * `<ID>__labelText`
163- */
164- id : PropTypes . string ,
165- /**
166- * Button label.
167- */
168- label : PropTypes . string . isRequired ,
169- /**
170- * Defines minimum breakpoint from which the button label will be visible.
171- */
172- labelVisibility : PropTypes . oneOf ( [ 'xs' , 'sm' , 'md' , 'lg' , 'xl' , 'x2l' , 'x3l' , 'none' ] ) ,
173- /**
174- * Visual priority to highlight or suppress the button.
175- *
176- * Ignored if the component is rendered within `ButtonGroup` component
177- * as the value is inherited in such case.
178- */
179- priority : PropTypes . oneOf ( [ 'filled' , 'outline' , 'flat' ] ) ,
180- /**
181- * Size of the button.
182- *
183- * Ignored if the component is rendered within `ButtonGroup` or `InputGroup` component as the value is inherited in
184- * such case.
185- */
186- size : PropTypes . oneOf ( [ 'small' , 'medium' , 'large' ] ) ,
187- /**
188- * Element to be displayed in the top left corner.
189- */
190- startCorner : PropTypes . node ,
191- /**
192- * Set the HTML `type` attribute of the `button` element.
193- */
194- type : PropTypes . oneOf ( [ 'button' , 'submit' ] ) ,
195- } ;
196-
197103export const ButtonWithGlobalProps = withGlobalProps ( Button , 'Button' ) ;
198104
199105export default ButtonWithGlobalProps ;
0 commit comments