1 line
29 KiB
JSON
1 line
29 KiB
JSON
|
{"ast":null,"code":"\"use client\";\n\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 { useMemo, useRef } from 'react';\nimport classnames from 'classnames';\nimport CSSMotion from 'rc-motion';\nimport { isPresetColor } from '../_util/colors';\nimport { cloneElement } from '../_util/reactNode';\nimport { ConfigContext } from '../config-provider';\nimport Ribbon from './Ribbon';\nimport ScrollNumber from './ScrollNumber';\nimport useStyle from './style';\nconst InternalBadge = /*#__PURE__*/React.forwardRef((props, ref) => {\n var _a, _b, _c, _d, _e;\n const {\n prefixCls: customizePrefixCls,\n scrollNumberPrefixCls: customizeScrollNumberPrefixCls,\n children,\n status,\n text,\n color,\n count = null,\n overflowCount = 99,\n dot = false,\n size = 'default',\n title,\n offset,\n style,\n className,\n rootClassName,\n classNames,\n styles,\n showZero = false\n } = props,\n restProps = __rest(props, [\"prefixCls\", \"scrollNumberPrefixCls\", \"children\", \"status\", \"text\", \"color\", \"count\", \"overflowCount\", \"dot\", \"size\", \"title\", \"offset\", \"style\", \"className\", \"rootClassName\", \"classNames\", \"styles\", \"showZero\"]);\n const {\n getPrefixCls,\n direction,\n badge\n } = React.useContext(ConfigContext);\n const prefixCls = getPrefixCls('badge', customizePrefixCls);\n const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls);\n // ================================ Misc ================================\n const numberedDisplayCount = count > overflowCount ? `${overflowCount}+` : count;\n const isZero = numberedDisplayCount === '0' || numberedDisplayCount === 0;\n const ignoreCount = count === null || isZero && !showZero;\n const hasStatus = (status !== null && status !== undefined || color !== null && color !== undefined) && ignoreCount;\n const showAsDot = dot && !isZero;\n const mergedCount = showAsDot ? '' : numberedDisplayCount;\n const isHidden = useMemo(() => {\n const isEmpty = mergedCount === null || mergedCount === undefined || mergedCount === '';\n return (isEmpty || isZero && !showZero) && !showAsDot;\n }, [mergedCount, isZero, showZero, showAsDot]);\n // Count should be cache in case hidden change it\n const countRef = useRef(count);\n if (!isHidden) {\n countRef.current = count;\n }\n const livingCount = countRef.current;\n // We need cache count since remove motion should not change count display\n const displayCountRef = useRef(mergedCount);\n if (!isHidden) {\n displayCountRef.current = mergedCount;\n }\n const displayCount = displayCountRef.current;\n // We will cache the dot status to avoid shaking on leaved motion\n const isDotRef = useRef(showAsDot);\n if (!isHidden) {\n isDotRef.current = showAsDot;\n }\n // =============================== Styles ===============================\n const mergedStyle = useMemo(() => {\n if (!offset) {\n return Object.assign(Object.assign({}, badge === null || badge === void 0 ? void 0 : badge.style), style);\n }\n const offsetStyle = {\n marginTop: offset[1]\n };\n if (direction === 'rtl') {\n offsetStyle.left = parseInt(offset[0], 10);\n } else {\n offsetStyle.right = -parseInt(offset[0], 10);\n }\n return Object.assign(Object.assign(Object.assign({}, offsetStyle), badge === null || badge === void 0 ? void 0 : badge.style), style);\n }, [direction, offset, style, badge === null || badge === void 0 ? void 0 : badge.style]);\n // =============================== Render ===============================\n // >>> Title\n const ti
|