UNPKG

@nafr/echo-ui

Version:

A UI library born for WAA

30 lines (29 loc) 1.21 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { forwardRef } from 'react'; import { cn } from '../../../lib/utils'; import { CheckboxGroupContextProvider } from './context'; import { checkboxGroupStyle } from './styles'; import { COLOR, SIZE } from './constants'; export const CheckboxGroup = forwardRef((props, ref) => { const { value = [], disabled = false, size = SIZE, color = COLOR, classNames, styles, onChange, ...restProps } = props; const handleGroupChange = (option) => { const newValue = option.value; const updatedValue = value.includes(newValue) ? value.filter((val) => val !== newValue) : [...value, newValue]; onChange?.({ value: updatedValue, nativeEvent: option.nativeEvent, }); }; const contextValue = { value, disabled, size, color, classNames, styles, onChange: handleGroupChange, }; return (_jsx(CheckboxGroupContextProvider, { value: contextValue, children: _jsx("div", { ...restProps, ref: ref, className: cn(checkboxGroupStyle(), restProps.className), style: restProps.style, children: restProps.children }) })); });