@workday/canvas-kit-react
Version:
The parent module that contains all Workday Canvas Kit React components
27 lines (26 loc) • 1.38 kB
JavaScript
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 (React.createElement(CheckboxContainer, { label: label, disabled: disabled, id: inputId, variant: variant },
React.createElement(CheckboxInput, { as: Element, id: inputId, ref: elementRef, ...elemProps }),
React.createElement(CheckboxRipple, null),
React.createElement(CheckboxCheck, { variant: variant, checked: checked, indeterminate: indeterminate, error: error })));
},
subComponents: {
ErrorType,
},
});