UNPKG

@yamada-ui/react

Version:

React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion

81 lines (77 loc) 2.06 kB
"use client"; import { Group } from "../group/group.js"; import { CheckboxGroupContext, useCheckboxGroup } from "./use-checkbox-group.js"; import { Checkbox, CheckboxPropsContext, component, useRootComponentProps } from "./checkbox.js"; import { useMemo } from "react"; import { jsx } from "react/jsx-runtime"; //#region src/components/checkbox/checkbox-group.tsx /** * `CheckboxGroup` is a component that groups `Checkbox` components. * * @see https://yamada-ui.com/docs/components/checkbox */ const CheckboxGroupRoot = component((props) => { const [, { colorScheme, size, variant, checkedIcon, children, disabled, errorBorderColor, focusBorderColor, invalid, items = [], readOnly, shape,...rest }] = useRootComponentProps(props, "group", { transferProps: [ "variant", "colorScheme", "size", "shape" ] }); const { max, value, getInputProps, getLabelProps, getRootProps, onChange } = useCheckboxGroup(rest); const computedChildren = useMemo(() => { if (children) return children; return items.map(({ label, value: value$1,...rest$1 }, index) => /* @__PURE__ */ jsx(Checkbox, { value: value$1, ...rest$1, children: label }, value$1 ?? index)); }, [items, children]); return /* @__PURE__ */ jsx(CheckboxPropsContext, { value: useMemo(() => ({ colorScheme, size, variant, checkedIcon, disabled, errorBorderColor, focusBorderColor, invalid, readOnly, shape }), [ variant, size, colorScheme, shape, disabled, invalid, readOnly, errorBorderColor, focusBorderColor, checkedIcon ]), children: /* @__PURE__ */ jsx(CheckboxGroupContext, { value: useMemo(() => ({ max, value, getInputProps, getLabelProps, onChange }), [ max, value, getInputProps, getLabelProps, onChange ]), children: /* @__PURE__ */ jsx(Group, { orientation: "vertical", ...getRootProps(), children: computedChildren }) }) }); }, "group")(); //#endregion export { CheckboxGroupRoot }; //# sourceMappingURL=checkbox-group.js.map