diff --git a/packages/components/src/components/button/Button.tsx b/packages/components/src/components/button/Button.tsx index af02a9b0..8b614a8e 100644 --- a/packages/components/src/components/button/Button.tsx +++ b/packages/components/src/components/button/Button.tsx @@ -1,10 +1,11 @@ +/* eslint-disable react/prop-types */ import * as React from 'react'; -import * as PropTypes from 'prop-types'; import { clsx } from 'clsx'; const prefix = 'tk-button'; -export interface ButtonProps extends Omit, 'size'> { +export interface ButtonProps + extends Omit, 'size'> { /** If true, add an Icon component as children */ iconButton?: boolean; /** Content of the button*/ @@ -17,77 +18,79 @@ export interface ButtonProps extends Omit, 's type?: 'button' | 'reset' | 'submit'; onClick?: (event: React.MouseEvent) => void; /** Color variant of the button*/ - variant?: 'primary' | 'secondary' | 'tertiary' | 'destructive' | 'primary-destructive' | 'secondary-destructive' | 'tertiary-destructive' | 'tertiary-accent'; + variant?: + | 'primary' + | 'secondary' + | 'tertiary' + | 'destructive' + | 'primary-destructive' + | 'secondary-destructive' + | 'tertiary-destructive' + | 'tertiary-accent'; /** Size of the button */ size?: 'large' | 'small' | 'medium'; iconRight?: React.ReactNode; iconLeft?: React.ReactNode; } -export const Button = React.forwardRef(({ - children, - className, - iconButton, - variant, - loading, - disabled, - type, - size, - iconRight, - iconLeft, - ...rest -}: ButtonProps, ref?: React.Ref) => { - const classes = clsx( - className, - prefix, - `${prefix}--${variant}`, - `${prefix}--${size}`, - { [`${prefix}--icon`]: iconButton, 'loading': loading, [`${prefix}--icon-left`]: iconLeft, [`${prefix}--icon-right`]: iconRight }, - ); +export const Button: React.FC< + ButtonProps & React.RefAttributes +> = React.forwardRef( + ( + { + children, + className, + iconButton = false, + variant = 'primary', + loading = false, + disabled = false, + type = 'button', + size = 'medium', + iconRight, + iconLeft, + ...rest + }, + ref + ) => { + const classes = clsx( + className, + prefix, + `${prefix}--${variant}`, + `${prefix}--${size}`, + { + [`${prefix}--icon`]: iconButton, + loading: loading, + [`${prefix}--icon-left`]: iconLeft, + [`${prefix}--icon-right`]: iconRight, + } + ); - if (variant === 'destructive') { - console.warn('The button variant: \'destructive\' will be deprecated.\n Please use: \'primary-destructive\' instead') - } - - return ( - - ); -}); + if (variant === 'destructive') { + console.warn( + "The button variant: 'destructive' will be deprecated.\n Please use: 'primary-destructive' instead" + ); + } -Button.defaultProps = { - iconButton: false, - className: '', - disabled: false, - loading: false, - type: 'button', - variant: 'primary', - size: 'medium', -}; + return ( + + ); + } +); -Button.propTypes = { - iconButton: PropTypes.bool, - children: PropTypes.any, - className: PropTypes.string, - disabled: PropTypes.bool, - loading: PropTypes.bool, - type: PropTypes.oneOf(['button', 'reset', 'submit']), - variant: PropTypes.oneOf(['primary', 'secondary', 'tertiary', 'destructive', 'primary-destructive', 'secondary-destructive', 'tertiary-destructive', 'tertiary-accent']), - onClick: PropTypes.func, - size: PropTypes.oneOf(['small', 'large', 'medium']), - iconLeft: PropTypes.node, - iconRight: PropTypes.node, -} Button.displayName = 'Button'; export default Button;