@workday/canvas-kit-react
Version:
The parent module that contains all Workday Canvas Kit React components
25 lines (24 loc) • 1.36 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import * as React from 'react';
import { createComponent, ErrorType, useUniqueId, useLocalRef, } from '@workday/canvas-kit-react/common';
import { CheckboxRipple } from './CheckboxRipple';
import { CheckboxContainer } from './CheckboxContainer';
import { CheckboxCheck } from './CheckboxCheck';
import { CheckboxInput } from './CheckboxInput';
export const Checkbox = createComponent('input')({
displayName: 'Checkbox',
Component: ({ id, label = '', ...elemProps }, ref, Element) => {
const { checked = false, disabled, error, indeterminate, variant } = elemProps;
const inputId = useUniqueId(id);
const { localRef, elementRef } = useLocalRef(ref);
React.useEffect(() => {
if (typeof indeterminate === 'boolean' && localRef.current) {
localRef.current.indeterminate = indeterminate;
}
}, [indeterminate, localRef]);
return (_jsxs(CheckboxContainer, { label: label, disabled: disabled, id: inputId, variant: variant, children: [_jsx(CheckboxInput, { as: Element, id: inputId, ref: elementRef, ...elemProps }), _jsx(CheckboxRipple, {}), _jsx(CheckboxCheck, { variant: variant, checked: checked, indeterminate: indeterminate, error: error })] }));
},
subComponents: {
ErrorType,
},
});