import * as React from 'react'; import * as ButtonBase from '@tesseract-design/web-base-button'; import * as CheckControlBase from '@tesseract-design/web-base-checkcontrol'; export type CheckboxProps = Omit, 'size' | 'type' | 'style'> & { /** * Size of the component. */ size?: ButtonBase.ButtonSize, /** * Variant of the component. */ variant?: ButtonBase.ButtonVariant, /** * Should the component display a border? */ border?: boolean, /** * Should the component occupy the whole width of its parent? */ block?: boolean, /** * Style of the component. */ style?: ButtonBase.ButtonStyle, /** * Does the component need to conserve space? */ compact?: boolean, /** * Complementary content of the component. */ subtext?: React.ReactNode, /** * Short complementary content displayed at the edge of the component. */ badge?: React.ReactNode, /** * Appearance of the component. */ appearance?: CheckControlBase.CheckControlAppearance, /** * Does the component have indeterminate check state? */ indeterminate?: boolean, } /** * Component for performing an action upon activation (e.g. when clicked). * * This component functions as a regular button. */ export const Checkbox = React.forwardRef( ( { size = ButtonBase.ButtonSize.MEDIUM, variant = ButtonBase.ButtonVariant.OUTLINE, border = false, children, block = false, style = ButtonBase.ButtonStyle.DEFAULT, disabled = false, compact = false, subtext, badge, appearance = CheckControlBase.CheckControlAppearance.DEFAULT, indeterminate = false, className: _className, as: _as, ...etcProps }: CheckboxProps, ref, ) => { const styleProps = React.useMemo(() => ({ size, block, variant, border, style, compact, menuItem: false, disabled, appearance, type: 'checkbox', }), [size, block, variant, border, style, compact, disabled, appearance]); const defaultRef = React.useRef(null); const theRef = (ref ?? defaultRef) as React.MutableRefObject; React.useEffect(() => { if (!(indeterminate && theRef.current)) { return; } theRef.current.indeterminate = indeterminate; }, [theRef, indeterminate]); const checkIndicatorCommon = ( ) return (
); }, ); Checkbox.displayName = 'ActionButton';