UNPKG

@trellixio/roaster-coffee

Version:
34 lines (31 loc) 1.31 kB
import * as React from 'react'; import { classNames } from '../../../utils/classNames/index.js'; import { useUncontrolled } from '../../../utils/useUncontrolled/index.js'; import '@floating-ui/react'; import { CheckboxGroupProvider } from './CheckboxGroup.context.js'; const CheckboxGroup = React.forwardRef((props, ref) => { const { title, children, className, value, defaultValue, onChange, orientation = "vertical" } = props; const [internalValue, setInternalValue] = useUncontrolled({ value, defaultValue, finalValue: [], onChange }); const handleChange = (event) => { const itemValue = event.currentTarget.value; setInternalValue( internalValue.includes(itemValue) ? internalValue.filter((item) => item !== itemValue) : [...internalValue, itemValue] ); }; return /* @__PURE__ */ React.createElement(CheckboxGroupProvider, { value: { value: internalValue, onChange: handleChange } }, /* @__PURE__ */ React.createElement("p", null, title), /* @__PURE__ */ React.createElement( "div", { ref, className: classNames("option-list checkbox", { "items-group": orientation === "horizontal" }, className) }, children )); }); CheckboxGroup.displayName = "CheckboxGroup"; export { CheckboxGroup }; //# sourceMappingURL=CheckboxGroup.js.map