UNPKG

@mantine/core

Version:

React components library focused on usability, accessibility and developer experience

36 lines (35 loc) 1.28 kB
"use client"; import { useProps } from "../../../core/MantineProvider/use-props/use-props.mjs"; import { genericFactory } from "../../../core/factory/factory.mjs"; import { createContext } from "react"; import { useUncontrolled } from "@mantine/hooks"; import { jsx } from "react/jsx-runtime"; //#region packages/@mantine/core/src/components/Chip/ChipGroup/ChipGroup.tsx const ChipGroup = genericFactory((props) => { const { value, defaultValue, onChange, multiple, children } = useProps("ChipGroup", null, props); const [_value, setValue] = useUncontrolled({ value, defaultValue, finalValue: multiple ? [] : null, onChange }); const isChipSelected = (val) => Array.isArray(_value) ? _value.includes(val) : val === _value; const handleChange = (event) => { const val = event.currentTarget.value; if (Array.isArray(_value)) setValue(_value.includes(val) ? _value.filter((v) => v !== val) : [..._value, val]); else setValue(val); }; return /* @__PURE__ */ jsx(ChipGroupContext, { value: { isChipSelected, onChange: handleChange, multiple }, children }); }); ChipGroup.displayName = "@mantine/core/ChipGroup"; const ChipGroupContext = createContext(null); //#endregion export { ChipGroup, ChipGroupContext }; //# sourceMappingURL=ChipGroup.mjs.map