import React, { forwardRef } from 'react'; import { CustomButton } from './Button.styled'; import type { ButtonType, ButtonProps, GhostButtonProps, OutlinedButtonProps, ContainedButtonProps, } from './Button.types'; const GhostButton = forwardRef( (props, ref) => { const { size = 'small', icon, className, children, startIcon, hasIconOnly, // eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars variant: _variant, ...restProps } = props; return ( {!hasIconOnly && <>{children}} ); }, ); const OutlinedButton = forwardRef< HTMLButtonElement, OutlinedButtonProps & { hasIconOnly: boolean } >((props, ref) => { const { size = 'small', icon, className, children, startIcon, hasIconOnly, // eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars variant: _variant, ...restProps } = props; return ( {!hasIconOnly && <>{children}} ); }); const ContainedButton = forwardRef< HTMLButtonElement, ContainedButtonProps & { hasIconOnly: boolean } >((props, ref) => { const { size = 'small', icon, className, children, startIcon, hasIconOnly, // eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars variant: _variant, ...restProps } = props; return ( {!hasIconOnly && <>{children}} ); }); const Button = forwardRef((props, ref) => { const { kind, variant, icon, children, startIcon } = props; const hasIconOnly = Boolean((startIcon || icon) && !children); if (kind === 'outlined' || variant === 'outlined') { return ; } if (kind === 'ghost' || variant === 'text' || variant === 'ghost') { return ; } return ( ); /** * There is an issue between React 18, Mui's OverridableComponent type and the * type coercion to temporarily fix it. * https://github.com/lunit-io/design-system/pull/143#issuecomment-1831127232 */ }) as ButtonType; export default Button;