PromoCursed/node_modules/.cache/babel-loader/2274333460b9b2fe28394320a625d561e84e06fd7987938c28b998363cbbe3ac.json

1 line
14 KiB
JSON
Raw Normal View History

2024-08-20 23:25:37 +04:00
{"ast":null,"code":"\"use client\";\n\nimport _toConsumableArray from \"@babel/runtime/helpers/esm/toConsumableArray\";\nvar __rest = this && this.__rest || function (s, e) {\n var t = {};\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];\n }\n return t;\n};\nimport * as React from 'react';\nimport classNames from 'classnames';\nimport omit from \"rc-util/es/omit\";\nimport { ConfigContext } from '../config-provider';\nimport useCSSVarCls from '../config-provider/hooks/useCSSVarCls';\nimport Checkbox from './Checkbox';\nimport GroupContext from './GroupContext';\nimport useStyle from './style';\nconst CheckboxGroup = /*#__PURE__*/React.forwardRef((props, ref) => {\n const {\n defaultValue,\n children,\n options = [],\n prefixCls: customizePrefixCls,\n className,\n rootClassName,\n style,\n onChange\n } = props,\n restProps = __rest(props, [\"defaultValue\", \"children\", \"options\", \"prefixCls\", \"className\", \"rootClassName\", \"style\", \"onChange\"]);\n const {\n getPrefixCls,\n direction\n } = React.useContext(ConfigContext);\n const [value, setValue] = React.useState(restProps.value || defaultValue || []);\n const [registeredValues, setRegisteredValues] = React.useState([]);\n React.useEffect(() => {\n if ('value' in restProps) {\n setValue(restProps.value || []);\n }\n }, [restProps.value]);\n const memoOptions = React.useMemo(() => options.map(option => {\n if (typeof option === 'string' || typeof option === 'number') {\n return {\n label: option,\n value: option\n };\n }\n return option;\n }), [options]);\n const cancelValue = val => {\n setRegisteredValues(prevValues => prevValues.filter(v => v !== val));\n };\n const registerValue = val => {\n setRegisteredValues(prevValues => [].concat(_toConsumableArray(prevValues), [val]));\n };\n const toggleOption = option => {\n const optionIndex = value.indexOf(option.value);\n const newValue = _toConsumableArray(value);\n if (optionIndex === -1) {\n newValue.push(option.value);\n } else {\n newValue.splice(optionIndex, 1);\n }\n if (!('value' in restProps)) {\n setValue(newValue);\n }\n onChange === null || onChange === void 0 ? void 0 : onChange(newValue.filter(val => registeredValues.includes(val)).sort((a, b) => {\n const indexA = memoOptions.findIndex(opt => opt.value === a);\n const indexB = memoOptions.findIndex(opt => opt.value === b);\n return indexA - indexB;\n }));\n };\n const prefixCls = getPrefixCls('checkbox', customizePrefixCls);\n const groupPrefixCls = `${prefixCls}-group`;\n const rootCls = useCSSVarCls(prefixCls);\n const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls, rootCls);\n const domProps = omit(restProps, ['value', 'disabled']);\n const childrenNode = options.length ? memoOptions.map(option => ( /*#__PURE__*/React.createElement(Checkbox, {\n prefixCls: prefixCls,\n key: option.value.toString(),\n disabled: 'disabled' in option ? option.disabled : restProps.disabled,\n value: option.value,\n checked: value.includes(option.value),\n onChange: option.onChange,\n className: `${groupPrefixCls}-item`,\n style: option.style,\n title: option.title,\n id: option.id,\n required: option.required\n }, option.label))) : children;\n const context = {\n toggleOption,\n value,\n disabled: restProps.disabled,\n name: restProps.name,\n // https://github.com/ant-design/ant-design/issues/16376\n registerValue,\n cancelValue\n };\n const classString = classNames(groupPrefixCls, {\n [`${groupPrefixCls}-rtl`]: direction === 'rtl'\n }, className, rootClassName, cssVarCls, rootCls, hashId);\n return wrapCSSVar( /*#__PU