1 line
11 KiB
JSON
1 line
11 KiB
JSON
|
{"ast":null,"code":"\"use client\";\n\nimport * as React from 'react';\nimport classNames from 'classnames';\nimport useMergedState from \"rc-util/es/hooks/useMergedState\";\nimport pickAttrs from \"rc-util/es/pickAttrs\";\nimport { ConfigContext } from '../config-provider';\nimport useCSSVarCls from '../config-provider/hooks/useCSSVarCls';\nimport useSize from '../config-provider/hooks/useSize';\nimport { RadioGroupContextProvider } from './context';\nimport Radio from './radio';\nimport useStyle from './style';\nconst RadioGroup = /*#__PURE__*/React.forwardRef((props, ref) => {\n const {\n getPrefixCls,\n direction\n } = React.useContext(ConfigContext);\n const [value, setValue] = useMergedState(props.defaultValue, {\n value: props.value\n });\n const onRadioChange = ev => {\n const lastValue = value;\n const val = ev.target.value;\n if (!('value' in props)) {\n setValue(val);\n }\n const {\n onChange\n } = props;\n if (onChange && val !== lastValue) {\n onChange(ev);\n }\n };\n const {\n prefixCls: customizePrefixCls,\n className,\n rootClassName,\n options,\n buttonStyle = 'outline',\n disabled,\n children,\n size: customizeSize,\n style,\n id,\n onMouseEnter,\n onMouseLeave,\n onFocus,\n onBlur\n } = props;\n const prefixCls = getPrefixCls('radio', customizePrefixCls);\n const groupPrefixCls = `${prefixCls}-group`;\n // Style\n const rootCls = useCSSVarCls(prefixCls);\n const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls, rootCls);\n let childrenToRender = children;\n // 如果存在 options, 优先使用\n if (options && options.length > 0) {\n childrenToRender = options.map(option => {\n if (typeof option === 'string' || typeof option === 'number') {\n // 此处类型自动推导为 string\n return /*#__PURE__*/React.createElement(Radio, {\n key: option.toString(),\n prefixCls: prefixCls,\n disabled: disabled,\n value: option,\n checked: value === option\n }, option);\n }\n // 此处类型自动推导为 { label: string value: string }\n return /*#__PURE__*/React.createElement(Radio, {\n key: `radio-group-value-options-${option.value}`,\n prefixCls: prefixCls,\n disabled: option.disabled || disabled,\n value: option.value,\n checked: value === option.value,\n title: option.title,\n style: option.style,\n id: option.id,\n required: option.required\n }, option.label);\n });\n }\n const mergedSize = useSize(customizeSize);\n const classString = classNames(groupPrefixCls, `${groupPrefixCls}-${buttonStyle}`, {\n [`${groupPrefixCls}-${mergedSize}`]: mergedSize,\n [`${groupPrefixCls}-rtl`]: direction === 'rtl'\n }, className, rootClassName, hashId, cssVarCls, rootCls);\n return wrapCSSVar( /*#__PURE__*/React.createElement(\"div\", Object.assign({}, pickAttrs(props, {\n aria: true,\n data: true\n }), {\n className: classString,\n style: style,\n onMouseEnter: onMouseEnter,\n onMouseLeave: onMouseLeave,\n onFocus: onFocus,\n onBlur: onBlur,\n id: id,\n ref: ref\n }), /*#__PURE__*/React.createElement(RadioGroupContextProvider, {\n value: {\n onChange: onRadioChange,\n value,\n disabled: props.disabled,\n name: props.name,\n optionType: props.optionType\n }\n }, childrenToRender)));\n});\nexport default /*#__PURE__*/React.memo(RadioGroup);","map":{"version":3,"names":["React","classNames","useMergedState","pickAttrs","ConfigContext","useCSSVarCls","useSize","RadioGroupContextProvider","Radio","useStyle","RadioGroup","forwardRef","props","ref","getPrefixCls","direction","useContext","value","setValue","defaultValue","onRadioChange","ev","lastValue","val","target","onChange","prefixCls","customizePrefixCls","className","rootClassName","options","buttonStyle","disabled","children","size","customizeSize","style","id","onMouseEnter","onMouseLeave","onFocus","onBlur","groupPrefixCls","roo
|