UNPKG

@nex-ui/react

Version:

🎉 A beautiful, modern, and reliable React component library.

53 lines (49 loc) • 1.57 kB
"use client"; 'use strict'; var jsxRuntime = require('react/jsx-runtime'); var react = require('react'); var hooks = require('@nex-ui/hooks'); var CheckboxGroupContext = require('./CheckboxGroupContext.cjs'); const CheckboxGroup = (props)=>{ const { name, onValueChange, children, disabled, size, color, radius, defaultValue = [], value: valueProp } = props; const [values, setValues] = hooks.useControlledState(valueProp, defaultValue, onValueChange); const ctx = react.useMemo(()=>({ disabled, name, size, color, radius, toggleValue: (value)=>{ if (disabled) { return; } let newValues; if (values.includes(value)) { newValues = values.filter((existingValue)=>existingValue !== value); } else { newValues = [ ...values, value ]; } setValues(newValues); }, isChecked: (value)=>{ return value ? values.includes(value) : false; } }), [ color, disabled, name, radius, setValues, size, values ]); return /*#__PURE__*/ jsxRuntime.jsx(CheckboxGroupContext.CheckboxGroupProvider, { value: ctx, children: children }); }; CheckboxGroup.displayName = 'CheckboxGroup'; exports.CheckboxGroup = CheckboxGroup;