1 line
13 KiB
JSON
1 line
13 KiB
JSON
|
{"ast":null,"code":"\"use client\";\n\nimport React from 'react';\nimport CloseOutlined from \"@ant-design/icons/es/icons/CloseOutlined\";\nimport pickAttrs from \"rc-util/es/pickAttrs\";\nexport function pickClosable(context) {\n if (!context) {\n return undefined;\n }\n return {\n closable: context.closable,\n closeIcon: context.closeIcon\n };\n}\n/** Convert `closable` and `closeIcon` to config object */\nfunction useClosableConfig(closableCollection) {\n const {\n closable,\n closeIcon\n } = closableCollection || {};\n return React.useMemo(() => {\n if (\n // If `closable`, whatever rest be should be true\n !closable && (closable === false || closeIcon === false || closeIcon === null)) {\n return false;\n }\n if (closable === undefined && closeIcon === undefined) {\n return null;\n }\n let closableConfig = {\n closeIcon: typeof closeIcon !== 'boolean' && closeIcon !== null ? closeIcon : undefined\n };\n if (closable && typeof closable === 'object') {\n closableConfig = Object.assign(Object.assign({}, closableConfig), closable);\n }\n return closableConfig;\n }, [closable, closeIcon]);\n}\n/**\n * Assign object without `undefined` field. Will skip if is `false`.\n * This helps to handle both closableConfig or false\n */\nfunction assignWithoutUndefined() {\n const target = {};\n for (var _len = arguments.length, objList = new Array(_len), _key = 0; _key < _len; _key++) {\n objList[_key] = arguments[_key];\n }\n objList.forEach(obj => {\n if (obj) {\n Object.keys(obj).forEach(key => {\n if (obj[key] !== undefined) {\n target[key] = obj[key];\n }\n });\n }\n });\n return target;\n}\n/** Use same object to support `useMemo` optimization */\nconst EmptyFallbackCloseCollection = {};\nexport default function useClosable(propCloseCollection, contextCloseCollection) {\n let fallbackCloseCollection = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : EmptyFallbackCloseCollection;\n // Align the `props`, `context` `fallback` to config object first\n const propCloseConfig = useClosableConfig(propCloseCollection);\n const contextCloseConfig = useClosableConfig(contextCloseCollection);\n const mergedFallbackCloseCollection = React.useMemo(() => Object.assign({\n closeIcon: /*#__PURE__*/React.createElement(CloseOutlined, null)\n }, fallbackCloseCollection), [fallbackCloseCollection]);\n // Use fallback logic to fill the config\n const mergedClosableConfig = React.useMemo(() => {\n // ================ Props First ================\n // Skip if prop is disabled\n if (propCloseConfig === false) {\n return false;\n }\n if (propCloseConfig) {\n return assignWithoutUndefined(mergedFallbackCloseCollection, contextCloseConfig, propCloseConfig);\n }\n // =============== Context Second ==============\n // Skip if context is disabled\n if (contextCloseConfig === false) {\n return false;\n }\n if (contextCloseConfig) {\n return assignWithoutUndefined(mergedFallbackCloseCollection, contextCloseConfig);\n }\n // ============= Fallback Default ==============\n return !mergedFallbackCloseCollection.closable ? false : mergedFallbackCloseCollection;\n }, [propCloseConfig, contextCloseConfig, mergedFallbackCloseCollection]);\n // Calculate the final closeIcon\n return React.useMemo(() => {\n if (mergedClosableConfig === false) {\n return [false, null];\n }\n const {\n closeIconRender\n } = mergedFallbackCloseCollection;\n const {\n closeIcon\n } = mergedClosableConfig;\n let mergedCloseIcon = closeIcon;\n if (mergedCloseIcon !== null && mergedCloseIcon !== undefined) {\n // Wrap the closeIcon if needed\n if (closeIconRender) {\n mergedCloseIcon = closeIconRender(closeIcon);\n }\n // Wrap the closeIcon with aria props\n const ariaProps = pickAttrs(mergedClosableConfig, true);\n if (Object.keys(ariaProps).length) {\n mergedCloseIcon = /*#__PURE__*/React.isVa
|