@lobehub/ui 5.10.0 → 5.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { AccordionConfigContext, AccordionItemStateProvider } from "./context.mjs";
|
|
3
3
|
import { styles } from "./style.mjs";
|
|
4
|
-
import { Children, Fragment, isValidElement, memo, useCallback } from "react";
|
|
4
|
+
import { Children, Fragment, isValidElement, memo, useCallback, useMemo, useRef } from "react";
|
|
5
5
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
6
6
|
import { Divider } from "antd";
|
|
7
7
|
import { cx } from "antd-style";
|
|
@@ -15,37 +15,61 @@ const Accordion = memo(({ children, className: userClassName, style: userStyle,
|
|
|
15
15
|
onChange: onExpandedChange,
|
|
16
16
|
value: expandedKeysProp
|
|
17
17
|
});
|
|
18
|
+
const expandedKeysRef = useRef(expandedKeys);
|
|
19
|
+
expandedKeysRef.current = expandedKeys;
|
|
20
|
+
const setExpandedKeysRef = useRef(setExpandedKeys);
|
|
21
|
+
setExpandedKeysRef.current = setExpandedKeys;
|
|
22
|
+
const isOpenKey = useCallback((key) => expandedKeysRef.current.includes(key), []);
|
|
18
23
|
const toggleExpand = useCallback((key) => {
|
|
19
|
-
const prev =
|
|
24
|
+
const prev = expandedKeysRef.current;
|
|
20
25
|
let newKeys;
|
|
21
26
|
if (accordion) newKeys = prev.includes(key) ? [] : [key];
|
|
22
27
|
else newKeys = prev.includes(key) ? prev.filter((k) => k !== key) : [...prev, key];
|
|
23
|
-
|
|
24
|
-
}, [
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
setExpandedKeysRef.current(newKeys);
|
|
29
|
+
}, [accordion]);
|
|
30
|
+
const toggleExpandKeys = useCallback((keys, preferredKey) => {
|
|
31
|
+
const prev = expandedKeysRef.current;
|
|
32
|
+
const isOpen = keys.some((key) => prev.includes(key));
|
|
33
|
+
let newKeys;
|
|
34
|
+
if (accordion) newKeys = isOpen ? [] : [preferredKey];
|
|
35
|
+
else newKeys = isOpen ? prev.filter((key) => !keys.includes(key)) : [...prev, preferredKey];
|
|
36
|
+
setExpandedKeysRef.current(newKeys);
|
|
37
|
+
}, [accordion]);
|
|
38
|
+
const configValue = useMemo(() => ({
|
|
39
|
+
disableAnimation,
|
|
40
|
+
hideIndicator,
|
|
41
|
+
indicatorPlacement,
|
|
42
|
+
keepContentMounted,
|
|
43
|
+
motionProps,
|
|
44
|
+
showDivider,
|
|
45
|
+
variant
|
|
46
|
+
}), [
|
|
30
47
|
disableAnimation,
|
|
31
|
-
expandedKeys,
|
|
32
48
|
hideIndicator,
|
|
33
49
|
indicatorPlacement,
|
|
34
|
-
isExpanded: useCallback((key) => {
|
|
35
|
-
return expandedKeys.includes(key);
|
|
36
|
-
}, [expandedKeys]),
|
|
37
50
|
keepContentMounted,
|
|
38
51
|
motionProps,
|
|
39
|
-
onToggle: toggleExpand,
|
|
40
52
|
showDivider,
|
|
41
53
|
variant
|
|
42
|
-
|
|
54
|
+
]);
|
|
55
|
+
const hasExplicitExpandedKeys = expandedKeysProp !== void 0 || defaultExpandedKeys !== void 0;
|
|
43
56
|
const content = /* @__PURE__ */ jsx(Fragment$1, { children: validChildren.map((child, index) => {
|
|
44
|
-
const
|
|
45
|
-
|
|
57
|
+
const hasChildItemKey = child.props.itemKey !== void 0;
|
|
58
|
+
const childKey = hasChildItemKey ? child.props.itemKey : index;
|
|
59
|
+
const itemIsOpen = expandedKeys.includes(childKey);
|
|
60
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(AccordionItemStateProvider, {
|
|
61
|
+
expandedKeys: hasChildItemKey ? void 0 : expandedKeys,
|
|
62
|
+
isOpen: itemIsOpen,
|
|
63
|
+
isOpenKey,
|
|
64
|
+
itemKey: childKey,
|
|
65
|
+
preferProviderKeyForNestedItems: !hasExplicitExpandedKeys,
|
|
66
|
+
onToggleKey: toggleExpand,
|
|
67
|
+
onToggleKeys: toggleExpandKeys,
|
|
68
|
+
children: child
|
|
69
|
+
}), showDivider && index < validChildren.length - 1 && /* @__PURE__ */ jsx(Divider, { className: styles.divider })] }, childKey);
|
|
46
70
|
}) });
|
|
47
|
-
return /* @__PURE__ */ jsx(
|
|
48
|
-
value:
|
|
71
|
+
return /* @__PURE__ */ jsx(AccordionConfigContext, {
|
|
72
|
+
value: configValue,
|
|
49
73
|
children: /* @__PURE__ */ jsx("div", {
|
|
50
74
|
className: cx(styles.base, classNames?.base, userClassName),
|
|
51
75
|
ref,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Accordion.mjs","names":[],"sources":["../../src/Accordion/Accordion.tsx"],"sourcesContent":["'use client';\n\nimport { Divider } from 'antd';\nimport { cx } from 'antd-style';\nimport { LayoutGroup } from 'motion/react';\nimport { type Key } from 'react';\nimport { Children, Fragment, isValidElement, memo, useCallback } from 'react';\nimport useMergeState from 'use-merge-value';\n\nimport {
|
|
1
|
+
{"version":3,"file":"Accordion.mjs","names":[],"sources":["../../src/Accordion/Accordion.tsx"],"sourcesContent":["'use client';\n\nimport { Divider } from 'antd';\nimport { cx } from 'antd-style';\nimport { LayoutGroup } from 'motion/react';\nimport { type Key } from 'react';\nimport { Children, Fragment, isValidElement, memo, useCallback, useMemo, useRef } from 'react';\nimport useMergeState from 'use-merge-value';\n\nimport { AccordionConfigContext, AccordionItemStateProvider } from './context';\nimport { styles } from './style';\nimport { type AccordionProps } from './type';\n\nconst Accordion = memo<AccordionProps>(\n ({\n children,\n className: userClassName,\n style: userStyle,\n accordion = false,\n defaultExpandedKeys,\n expandedKeys: expandedKeysProp,\n onExpandedChange,\n variant = 'borderless',\n gap,\n showDivider = false,\n disableAnimation = false,\n hideIndicator = false,\n indicatorPlacement = 'start',\n keepContentMounted = true,\n classNames,\n styles: customStyles,\n motionProps,\n ref,\n ...rest\n }) => {\n // Convert children to array and filter valid elements\n const validChildren = Children.toArray(children).filter(isValidElement);\n\n // Collect all item keys\n const allItemKeys = validChildren.map((child, index) => (child.props as any).itemKey || index);\n\n // If defaultExpandedKeys or expandedKeys is undefined, expand all items by default\n const initialExpandedKeys = defaultExpandedKeys ?? allItemKeys;\n\n const [expandedKeys, setExpandedKeys] = useMergeState<Key[]>(initialExpandedKeys, {\n onChange: onExpandedChange,\n value: expandedKeysProp,\n });\n\n // Hold expandedKeys and setExpandedKeys via refs so toggleExpand can stay\n // reference-stable. use-merge-value's setter is recreated on every render,\n // so depending on it would force AccordionItemStateProvider's memoized\n // value to change identity each render — even when nothing toggled —\n // re-rendering every nested AccordionItem via \"context changed\".\n const expandedKeysRef = useRef(expandedKeys);\n expandedKeysRef.current = expandedKeys;\n const setExpandedKeysRef = useRef(setExpandedKeys);\n setExpandedKeysRef.current = setExpandedKeys;\n\n const isOpenKey = useCallback((key: Key) => expandedKeysRef.current.includes(key), []);\n\n const toggleExpand = useCallback(\n (key: Key) => {\n const prev = expandedKeysRef.current;\n let newKeys: Key[];\n\n if (accordion) {\n newKeys = prev.includes(key) ? [] : [key];\n } else {\n newKeys = prev.includes(key) ? prev.filter((k: Key) => k !== key) : [...prev, key];\n }\n\n setExpandedKeysRef.current(newKeys);\n },\n [accordion],\n );\n\n const toggleExpandKeys = useCallback(\n (keys: Key[], preferredKey: Key) => {\n const prev = expandedKeysRef.current;\n const isOpen = keys.some((key) => prev.includes(key));\n let newKeys: Key[];\n\n if (accordion) {\n newKeys = isOpen ? [] : [preferredKey];\n } else {\n newKeys = isOpen\n ? prev.filter((key: Key) => !keys.includes(key))\n : [...prev, preferredKey];\n }\n\n setExpandedKeysRef.current(newKeys);\n },\n [accordion],\n );\n\n const configValue = useMemo(\n () => ({\n disableAnimation,\n hideIndicator,\n indicatorPlacement,\n keepContentMounted,\n motionProps,\n showDivider,\n variant,\n }),\n [\n disableAnimation,\n hideIndicator,\n indicatorPlacement,\n keepContentMounted,\n motionProps,\n showDivider,\n variant,\n ],\n );\n\n const hasExplicitExpandedKeys =\n expandedKeysProp !== undefined || defaultExpandedKeys !== undefined;\n\n const content = (\n <>\n {validChildren.map((child, index) => {\n const hasChildItemKey = (child.props as any).itemKey !== undefined;\n const childKey = hasChildItemKey ? (child.props as any).itemKey : index;\n const itemIsOpen = expandedKeys.includes(childKey);\n return (\n <Fragment key={childKey}>\n <AccordionItemStateProvider\n expandedKeys={hasChildItemKey ? undefined : expandedKeys}\n isOpen={itemIsOpen}\n isOpenKey={isOpenKey}\n itemKey={childKey}\n preferProviderKeyForNestedItems={!hasExplicitExpandedKeys}\n onToggleKey={toggleExpand}\n onToggleKeys={toggleExpandKeys}\n >\n {child}\n </AccordionItemStateProvider>\n {showDivider && index < validChildren.length - 1 && (\n <Divider className={styles.divider} />\n )}\n </Fragment>\n );\n })}\n </>\n );\n\n return (\n <AccordionConfigContext value={configValue}>\n <div\n className={cx(styles.base, classNames?.base, userClassName)}\n ref={ref}\n style={{\n gap: gap,\n ...customStyles?.base,\n ...userStyle,\n }}\n {...rest}\n >\n {disableAnimation ? content : <LayoutGroup>{content}</LayoutGroup>}\n </div>\n </AccordionConfigContext>\n );\n },\n);\n\nAccordion.displayName = 'Accordion';\n\nexport default Accordion;\n"],"mappings":";;;;;;;;;;AAaA,MAAM,YAAY,MACf,EACC,UACA,WAAW,eACX,OAAO,WACP,YAAY,OACZ,qBACA,cAAc,kBACd,kBACA,UAAU,cACV,KACA,cAAc,OACd,mBAAmB,OACnB,gBAAgB,OAChB,qBAAqB,SACrB,qBAAqB,MACrB,YACA,QAAQ,cACR,aACA,KACA,GAAG,WACC;CAEJ,MAAM,gBAAgB,SAAS,QAAQ,SAAS,CAAC,OAAO,eAAe;CAGvE,MAAM,cAAc,cAAc,KAAK,OAAO,UAAW,MAAM,MAAc,WAAW,MAAM;CAK9F,MAAM,CAAC,cAAc,mBAAmB,cAFZ,uBAAuB,aAE+B;EAChF,UAAU;EACV,OAA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A,CACE,oBAAC,4BAAD;GACE,cAAc,kBAAkB,KAAA,IAAY;GAC5C,QAAQ;GACG;GACX,SAAS;GACT,iCAAiC,CAAC;GAClC,aAAa;GACb,cAAc;aAEb;GAC0B,CAAA,EAC5B,eAAe,QAAQ,cAAc,SAAS,KAC7C,oBAAC,SAAD,EAAS,WAAW,OAAO,SAAW,CAAA,CAE/B,EAAA,EAfI,SAeJ;GAEb,EACD,CAAA;AAGL,QACE,oBAAC,wBAAD;EAAwB,OAAO;YAC7B,oBAAC,OAAD;GACE,WAAW,GAAG,OAAO,MAAM,YAAY,MAAM,cAAc;GACtD;GACL,OAAO;IACA;IACL,GAAG,cAAc;IACjB,GAAG;IACJ;GACD,GAAI;aAEH,mBAAmB,UAAU,oBAAC,aAAD,EAAA,UAAc,SAAsB,CAAA;GAC9D,CAAA;EACiB,CAAA;EAG9B;AAED,UAAU,cAAc"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useMotionComponent } from "../MotionProvider/index.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { useAccordionConfig, useAccordionItemState } from "./context.mjs";
|
|
4
4
|
import { styles } from "./style.mjs";
|
|
5
5
|
import FlexBasic_default from "../Flex/FlexBasic.mjs";
|
|
6
6
|
import Block from "../Block/Block.mjs";
|
|
@@ -114,35 +114,45 @@ const AccordionItemContent = memo(({ disableAnimation, isOpen, keepContentMounte
|
|
|
114
114
|
});
|
|
115
115
|
AccordionItemContent.displayName = "AccordionItemContent";
|
|
116
116
|
const AccordionItem = memo(({ itemKey, title, children, action, alwaysShowAction = false, disabled = false, allowExpand = true, hideIndicator: itemHideIndicator, indicatorPlacement: itemIndicatorPlacement, indicator: customIndicator, classNames, paddingInline = 16, paddingBlock = 8, padding, ref, variant: customVariant, styles: customStyles, headerWrapper, defaultExpand, expand, onExpandChange }) => {
|
|
117
|
-
const
|
|
117
|
+
const itemStateContext = useAccordionItemState();
|
|
118
|
+
const configContext = useAccordionConfig();
|
|
118
119
|
const isStandalone = expand !== void 0 || defaultExpand !== void 0;
|
|
119
120
|
const [isExpandedStandalone, setIsExpandedStandalone] = useMergeState(defaultExpand ?? false, {
|
|
120
121
|
onChange: onExpandChange,
|
|
121
122
|
value: expand
|
|
122
123
|
});
|
|
123
|
-
const
|
|
124
|
-
const
|
|
125
|
-
const
|
|
126
|
-
const
|
|
127
|
-
const
|
|
128
|
-
const
|
|
129
|
-
const contextMotionProps = context?.motionProps;
|
|
130
|
-
const contextVariant = context?.variant ?? "borderless";
|
|
124
|
+
const contextHideIndicator = configContext?.hideIndicator;
|
|
125
|
+
const contextIndicatorPlacement = configContext?.indicatorPlacement;
|
|
126
|
+
const contextKeepContentMounted = configContext?.keepContentMounted;
|
|
127
|
+
const contextDisableAnimation = configContext?.disableAnimation;
|
|
128
|
+
const contextMotionProps = configContext?.motionProps;
|
|
129
|
+
const contextVariant = configContext?.variant ?? "borderless";
|
|
131
130
|
const isInitialRenderRef = useRef(true);
|
|
132
131
|
useEffect(() => {
|
|
133
132
|
isInitialRenderRef.current = false;
|
|
134
133
|
}, []);
|
|
135
|
-
const
|
|
134
|
+
const isDirectContextItem = itemStateContext?.itemKey === itemKey;
|
|
135
|
+
let isOpen = false;
|
|
136
|
+
if (isStandalone) isOpen = isExpandedStandalone;
|
|
137
|
+
else if (itemStateContext) isOpen = isDirectContextItem ? itemStateContext.isOpen : itemStateContext.isOpen || itemStateContext.isOpenKey(itemKey);
|
|
136
138
|
const hideIndicatorFinal = itemHideIndicator ?? contextHideIndicator ?? false;
|
|
137
139
|
const indicatorPlacementFinal = itemIndicatorPlacement ?? contextIndicatorPlacement ?? "start";
|
|
138
140
|
const keepContentMounted = contextKeepContentMounted ?? true;
|
|
139
141
|
const disableAnimation = contextDisableAnimation ?? false;
|
|
140
142
|
const variant = customVariant || contextVariant;
|
|
143
|
+
const contextOnToggle = useCallback(() => {
|
|
144
|
+
if (!itemStateContext) return;
|
|
145
|
+
if (itemStateContext.itemKey === itemKey) {
|
|
146
|
+
itemStateContext.onToggle();
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
itemStateContext.onToggleNestedKey(itemKey);
|
|
150
|
+
}, [itemStateContext, itemKey]);
|
|
141
151
|
const handleToggle = useCallback(() => {
|
|
142
152
|
if (!allowExpand) return;
|
|
143
153
|
if (!disabled) {
|
|
144
154
|
if (isStandalone) setIsExpandedStandalone(!isExpandedStandalone);
|
|
145
|
-
else if (contextOnToggle) contextOnToggle(
|
|
155
|
+
else if (contextOnToggle) contextOnToggle();
|
|
146
156
|
}
|
|
147
157
|
}, [
|
|
148
158
|
allowExpand,
|
|
@@ -150,8 +160,7 @@ const AccordionItem = memo(({ itemKey, title, children, action, alwaysShowAction
|
|
|
150
160
|
isStandalone,
|
|
151
161
|
setIsExpandedStandalone,
|
|
152
162
|
isExpandedStandalone,
|
|
153
|
-
contextOnToggle
|
|
154
|
-
itemKey
|
|
163
|
+
contextOnToggle
|
|
155
164
|
]);
|
|
156
165
|
const handleKeyDown = useCallback((e) => {
|
|
157
166
|
if (!allowExpand || disabled) return;
|
|
@@ -228,8 +237,6 @@ const AccordionItem = memo(({ itemKey, title, children, action, alwaysShowAction
|
|
|
228
237
|
}), [
|
|
229
238
|
action,
|
|
230
239
|
alwaysShowAction,
|
|
231
|
-
cx,
|
|
232
|
-
styles,
|
|
233
240
|
classNames?.action,
|
|
234
241
|
customStyles?.action
|
|
235
242
|
]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccordionItem.mjs","names":["Flexbox"],"sources":["../../src/Accordion/AccordionItem.tsx"],"sourcesContent":["'use client';\n\nimport { cx } from 'antd-style';\nimport { AnimatePresence } from 'motion/react';\nimport {\n type ComponentPropsWithoutRef,\n type CSSProperties,\n type KeyboardEvent,\n memo,\n type ReactNode,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n} from 'react';\nimport useMergeState from 'use-merge-value';\n\nimport Block from '@/Block';\nimport { Flexbox } from '@/Flex';\nimport { type MotionComponentType, useMotionComponent } from '@/MotionProvider';\nimport Text from '@/Text';\nimport { stopPropagation } from '@/utils/dom';\n\nimport ArrowIcon from './ArrowIcon';\nimport { useAccordionContext } from './context';\nimport { styles } from './style';\nimport { type AccordionItemProps } from './type';\n\ntype AccordionContentBaseProps = {\n children?: ReactNode;\n className?: string;\n contentInnerClassName: string;\n style?: CSSProperties;\n};\n\ntype AccordionStaticContentProps = AccordionContentBaseProps & {\n isOpen: boolean;\n keepContentMounted: boolean;\n};\n\ntype MotionDivProps = ComponentPropsWithoutRef<MotionComponentType['div']>;\n\ntype AccordionMotionContentProps = AccordionContentBaseProps & {\n contextMotionProps?: MotionDivProps;\n isOpen: boolean;\n skipInitialAnimation: boolean;\n};\n\ntype AccordionItemContentProps = AccordionContentBaseProps & {\n contextMotionProps?: MotionDivProps;\n disableAnimation: boolean;\n isOpen: boolean;\n keepContentMounted: boolean;\n skipInitialAnimation: boolean;\n};\n\nconst motionContainerStyle: CSSProperties = { overflow: 'hidden' };\n\nconst AccordionStaticContent = memo<AccordionStaticContentProps>(\n ({ className, style, children, contentInnerClassName, isOpen, keepContentMounted }) => {\n if (keepContentMounted) {\n return (\n <div\n className={className}\n role=\"region\"\n style={{\n display: isOpen ? 'block' : 'none',\n ...style,\n }}\n >\n <div className={contentInnerClassName}>{children}</div>\n </div>\n );\n }\n\n if (!isOpen) return null;\n\n return (\n <div className={className} role=\"region\" style={style}>\n <div className={contentInnerClassName}>{children}</div>\n </div>\n );\n },\n);\n\nAccordionStaticContent.displayName = 'AccordionStaticContent';\n\nconst AccordionMotionContent = memo<AccordionMotionContentProps>(\n ({\n contextMotionProps,\n className,\n style,\n children,\n contentInnerClassName,\n isOpen,\n skipInitialAnimation,\n }) => {\n const Motion = useMotionComponent();\n\n const motionProps = useMemo(\n () => ({\n animate: 'enter',\n exit: 'exit',\n initial: skipInitialAnimation ? false : 'exit',\n variants: {\n enter: {\n height: 'auto',\n opacity: 1,\n transition: {\n duration: 0.2,\n ease: [0.4, 0, 0.2, 1],\n },\n },\n exit: {\n height: 0,\n opacity: 0,\n transition: {\n duration: 0.2,\n ease: [0.4, 0, 0.2, 1],\n },\n },\n },\n ...contextMotionProps,\n }),\n [contextMotionProps, skipInitialAnimation],\n );\n\n return (\n <AnimatePresence initial={false}>\n {isOpen ? (\n <Motion.div {...(motionProps as any)} style={motionContainerStyle}>\n <div className={className} role=\"region\" style={style}>\n <div className={contentInnerClassName}>{children}</div>\n </div>\n </Motion.div>\n ) : null}\n </AnimatePresence>\n );\n },\n);\n\nAccordionMotionContent.displayName = 'AccordionMotionContent';\n\nconst AccordionItemContent = memo<AccordionItemContentProps>(\n ({\n disableAnimation,\n isOpen,\n keepContentMounted,\n className,\n style,\n children,\n contentInnerClassName,\n contextMotionProps,\n skipInitialAnimation,\n }) => {\n if (disableAnimation || !keepContentMounted) {\n return (\n <AccordionStaticContent\n className={className}\n contentInnerClassName={contentInnerClassName}\n isOpen={isOpen}\n keepContentMounted={keepContentMounted}\n style={style}\n >\n {children}\n </AccordionStaticContent>\n );\n }\n\n return (\n <AccordionMotionContent\n className={className}\n contentInnerClassName={contentInnerClassName}\n contextMotionProps={contextMotionProps}\n isOpen={isOpen}\n skipInitialAnimation={skipInitialAnimation}\n style={style}\n >\n {children}\n </AccordionMotionContent>\n );\n },\n);\n\nAccordionItemContent.displayName = 'AccordionItemContent';\n\nconst AccordionItem = memo<AccordionItemProps>(\n ({\n itemKey,\n title,\n children,\n action,\n alwaysShowAction = false,\n disabled = false,\n allowExpand = true,\n hideIndicator: itemHideIndicator,\n indicatorPlacement: itemIndicatorPlacement,\n indicator: customIndicator,\n classNames,\n paddingInline = 16,\n paddingBlock = 8,\n padding,\n ref,\n variant: customVariant,\n styles: customStyles,\n headerWrapper,\n defaultExpand,\n expand,\n onExpandChange,\n }) => {\n const context = useAccordionContext();\n\n // Determine if using standalone mode (has expand or defaultExpand props)\n const isStandalone = expand !== undefined || defaultExpand !== undefined;\n\n // Standalone state management\n const [isExpandedStandalone, setIsExpandedStandalone] = useMergeState<boolean>(\n defaultExpand ?? false,\n {\n onChange: onExpandChange,\n value: expand,\n },\n );\n\n // Context values (may be null if used standalone)\n const contextIsExpanded = context?.isExpanded;\n const contextOnToggle = context?.onToggle;\n const contextHideIndicator = context?.hideIndicator;\n const contextIndicatorPlacement = context?.indicatorPlacement;\n const contextKeepContentMounted = context?.keepContentMounted;\n const contextDisableAnimation = context?.disableAnimation;\n const contextMotionProps = context?.motionProps;\n const contextVariant = context?.variant ?? 'borderless';\n\n const isInitialRenderRef = useRef(true);\n\n useEffect(() => {\n isInitialRenderRef.current = false;\n }, []);\n\n // Determine expanded state\n const isOpen = isStandalone\n ? isExpandedStandalone\n : contextIsExpanded\n ? contextIsExpanded(itemKey)\n : false;\n\n // Determine other props with fallbacks\n const hideIndicatorFinal = itemHideIndicator ?? contextHideIndicator ?? false;\n const indicatorPlacementFinal = itemIndicatorPlacement ?? contextIndicatorPlacement ?? 'start';\n const keepContentMounted = contextKeepContentMounted ?? true;\n const disableAnimation = contextDisableAnimation ?? false;\n const variant = customVariant || contextVariant;\n\n const handleToggle = useCallback(() => {\n // If allowExpand is false, only allow controlled expansion via expand prop\n if (!allowExpand) return;\n\n if (!disabled) {\n if (isStandalone) {\n setIsExpandedStandalone(!isExpandedStandalone);\n } else if (contextOnToggle) {\n contextOnToggle(itemKey);\n }\n }\n }, [\n allowExpand,\n disabled,\n isStandalone,\n setIsExpandedStandalone,\n isExpandedStandalone,\n contextOnToggle,\n itemKey,\n ]);\n\n const handleKeyDown = useCallback(\n (e: KeyboardEvent) => {\n // If allowExpand is false, disable keyboard toggle\n if (!allowExpand || disabled) return;\n\n switch (e.key) {\n case 'Enter':\n case ' ': {\n e.preventDefault();\n handleToggle();\n break;\n }\n }\n },\n [allowExpand, disabled, handleToggle],\n );\n\n const preventTitleTextSelection = useCallback((e: any) => {\n // Prevent browser from creating a selection range on double/multi click,\n // which can accidentally select the content region.\n if (e?.detail > 1) e.preventDefault();\n }, []);\n\n // Build indicator\n const indicator = useMemo(() => {\n if (!allowExpand || hideIndicatorFinal) return null;\n\n if (customIndicator) {\n if (typeof customIndicator === 'function') {\n return (\n <span\n aria-hidden=\"true\"\n className={cx(styles.indicator, classNames?.indicator)}\n style={customStyles?.indicator}\n >\n {customIndicator({ isDisabled: disabled, isOpen })}\n </span>\n );\n }\n return (\n <span\n aria-hidden=\"true\"\n className={cx(styles.indicator, classNames?.indicator)}\n style={customStyles?.indicator}\n >\n {customIndicator}\n </span>\n );\n }\n\n return (\n <span\n aria-hidden=\"true\"\n className={cx(styles.indicator, classNames?.indicator)}\n style={customStyles?.indicator}\n >\n <ArrowIcon className={cx(styles.icon, isOpen && styles.iconRotate)} />\n </span>\n );\n }, [\n allowExpand,\n hideIndicatorFinal,\n customIndicator,\n disabled,\n isOpen,\n classNames,\n customStyles,\n ]);\n\n const skipInitialAnimation = isInitialRenderRef.current && isOpen;\n\n const contentClassName = useMemo(\n () => cx('accordion-content', styles.content, classNames?.content),\n [classNames?.content],\n );\n\n const titleNode = useMemo(\n () =>\n typeof title === 'string' ? (\n <Text ellipsis className={classNames?.title} style={customStyles?.title}>\n {title}\n </Text>\n ) : (\n title\n ),\n [title, classNames?.title, customStyles?.title],\n );\n\n const actionNode = useMemo(\n () =>\n action && (\n <Flexbox\n horizontal\n align={'center'}\n flex={'none'}\n gap={4}\n style={customStyles?.action}\n className={cx(\n 'accordion-action',\n styles.action,\n alwaysShowAction && styles.actionVisible,\n classNames?.action,\n )}\n onClick={stopPropagation}\n >\n {action}\n </Flexbox>\n ),\n [action, alwaysShowAction, cx, styles, classNames?.action, customStyles?.action],\n );\n\n const headerElement = useMemo(() => {\n const header = (\n <Block\n horizontal\n className={cx('accordion-header', styles.header, classNames?.header)}\n clickable={!disabled && allowExpand}\n gap={4}\n justify={'space-between'}\n padding={padding}\n paddingBlock={paddingBlock}\n paddingInline={paddingInline}\n ref={ref}\n variant={customVariant || variant}\n style={{\n alignItems: 'center',\n cursor: disabled ? 'not-allowed' : allowExpand ? 'pointer' : 'default',\n opacity: disabled ? 0.5 : undefined,\n overflow: 'hidden',\n width: '100%',\n ...customStyles?.header,\n }}\n onClick={handleToggle}\n onKeyDown={handleKeyDown}\n >\n {indicatorPlacementFinal === 'start' ? (\n <>\n <Flexbox\n horizontal\n align={'center'}\n className={styles.titleWrapper}\n flex={1}\n gap={2}\n style={{\n overflow: 'hidden',\n }}\n onDoubleClick={preventTitleTextSelection}\n onMouseDown={preventTitleTextSelection}\n >\n {titleNode}\n {indicator}\n </Flexbox>\n <Flexbox horizontal align={'center'} flex={'none'} gap={4}>\n {actionNode}\n </Flexbox>\n </>\n ) : (\n <>\n <Flexbox\n horizontal\n align={'center'}\n className={styles.titleWrapper}\n flex={1}\n gap={2}\n style={{\n overflow: 'hidden',\n }}\n onDoubleClick={preventTitleTextSelection}\n onMouseDown={preventTitleTextSelection}\n >\n {titleNode}\n </Flexbox>\n <Flexbox horizontal align={'center'} flex={'none'} gap={4}>\n {actionNode}\n {indicator}\n </Flexbox>\n </>\n )}\n </Block>\n );\n if (headerWrapper) {\n return headerWrapper(header);\n }\n return header;\n }, [\n classNames?.header,\n disabled,\n allowExpand,\n padding,\n paddingBlock,\n paddingInline,\n ref,\n customVariant,\n variant,\n customStyles?.header,\n handleToggle,\n handleKeyDown,\n indicatorPlacementFinal,\n preventTitleTextSelection,\n titleNode,\n indicator,\n actionNode,\n headerWrapper,\n ]);\n\n return (\n <div\n className={cx('accordion-item', styles.item, classNames?.base)}\n style={customStyles?.base}\n >\n {headerElement}\n <AccordionItemContent\n className={contentClassName}\n contentInnerClassName={styles.contentInner}\n contextMotionProps={contextMotionProps}\n disableAnimation={!!disableAnimation}\n isOpen={isOpen}\n keepContentMounted={!!keepContentMounted}\n skipInitialAnimation={skipInitialAnimation}\n style={customStyles?.content}\n >\n {children}\n </AccordionItemContent>\n </div>\n );\n },\n);\n\nAccordionItem.displayName = 'AccordionItem';\n\nexport default AccordionItem;\n"],"mappings":";;;;;;;;;;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G,YACA,UACO;MACT,EAAA,CAAA;GAEC,CAAA;AAEV,MAAI,cACF,QAAO,cAAc,OAAO;AAE9B,SAAO;IACN;EACD,YAAY;EACZ;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,cAAc;EACd;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAAC;AAEF,QACE,qBAAC,OAAD;EACE,WAAW,GAAG,kBAAkB,OAAO,MAAM,YAAY,KAAK;EAC9D,OAAO,cAAc;YAFvB,CAIG,eACD,oBAAC,sBAAD;GACE,WAAW;GACX,uBAAuB,OAAO;GACV;GACpB,kBAAkB,CAAC,CAAC;GACZ;GACR,oBAAoB,CAAC,CAAC;GACA;GACtB,OAAO,cAAc;GAEpB;GACoB,CAAA,CACnB;;EAGX;AAED,cAAc,cAAc"}
|
|
1
|
+
{"version":3,"file":"AccordionItem.mjs","names":["Flexbox"],"sources":["../../src/Accordion/AccordionItem.tsx"],"sourcesContent":["'use client';\n\nimport { cx } from 'antd-style';\nimport { AnimatePresence } from 'motion/react';\nimport {\n type ComponentPropsWithoutRef,\n type CSSProperties,\n type KeyboardEvent,\n memo,\n type ReactNode,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n} from 'react';\nimport useMergeState from 'use-merge-value';\n\nimport Block from '@/Block';\nimport { Flexbox } from '@/Flex';\nimport { type MotionComponentType, useMotionComponent } from '@/MotionProvider';\nimport Text from '@/Text';\nimport { stopPropagation } from '@/utils/dom';\n\nimport ArrowIcon from './ArrowIcon';\nimport { useAccordionConfig, useAccordionItemState } from './context';\nimport { styles } from './style';\nimport { type AccordionItemProps } from './type';\n\ntype AccordionContentBaseProps = {\n children?: ReactNode;\n className?: string;\n contentInnerClassName: string;\n style?: CSSProperties;\n};\n\ntype AccordionStaticContentProps = AccordionContentBaseProps & {\n isOpen: boolean;\n keepContentMounted: boolean;\n};\n\ntype MotionDivProps = ComponentPropsWithoutRef<MotionComponentType['div']>;\n\ntype AccordionMotionContentProps = AccordionContentBaseProps & {\n contextMotionProps?: MotionDivProps;\n isOpen: boolean;\n skipInitialAnimation: boolean;\n};\n\ntype AccordionItemContentProps = AccordionContentBaseProps & {\n contextMotionProps?: MotionDivProps;\n disableAnimation: boolean;\n isOpen: boolean;\n keepContentMounted: boolean;\n skipInitialAnimation: boolean;\n};\n\nconst motionContainerStyle: CSSProperties = { overflow: 'hidden' };\n\nconst AccordionStaticContent = memo<AccordionStaticContentProps>(\n ({ className, style, children, contentInnerClassName, isOpen, keepContentMounted }) => {\n if (keepContentMounted) {\n return (\n <div\n className={className}\n role=\"region\"\n style={{\n display: isOpen ? 'block' : 'none',\n ...style,\n }}\n >\n <div className={contentInnerClassName}>{children}</div>\n </div>\n );\n }\n\n if (!isOpen) return null;\n\n return (\n <div className={className} role=\"region\" style={style}>\n <div className={contentInnerClassName}>{children}</div>\n </div>\n );\n },\n);\n\nAccordionStaticContent.displayName = 'AccordionStaticContent';\n\nconst AccordionMotionContent = memo<AccordionMotionContentProps>(\n ({\n contextMotionProps,\n className,\n style,\n children,\n contentInnerClassName,\n isOpen,\n skipInitialAnimation,\n }) => {\n const Motion = useMotionComponent();\n\n const motionProps = useMemo(\n () => ({\n animate: 'enter',\n exit: 'exit',\n initial: skipInitialAnimation ? false : 'exit',\n variants: {\n enter: {\n height: 'auto',\n opacity: 1,\n transition: {\n duration: 0.2,\n ease: [0.4, 0, 0.2, 1],\n },\n },\n exit: {\n height: 0,\n opacity: 0,\n transition: {\n duration: 0.2,\n ease: [0.4, 0, 0.2, 1],\n },\n },\n },\n ...contextMotionProps,\n }),\n [contextMotionProps, skipInitialAnimation],\n );\n\n return (\n <AnimatePresence initial={false}>\n {isOpen ? (\n <Motion.div {...(motionProps as any)} style={motionContainerStyle}>\n <div className={className} role=\"region\" style={style}>\n <div className={contentInnerClassName}>{children}</div>\n </div>\n </Motion.div>\n ) : null}\n </AnimatePresence>\n );\n },\n);\n\nAccordionMotionContent.displayName = 'AccordionMotionContent';\n\nconst AccordionItemContent = memo<AccordionItemContentProps>(\n ({\n disableAnimation,\n isOpen,\n keepContentMounted,\n className,\n style,\n children,\n contentInnerClassName,\n contextMotionProps,\n skipInitialAnimation,\n }) => {\n if (disableAnimation || !keepContentMounted) {\n return (\n <AccordionStaticContent\n className={className}\n contentInnerClassName={contentInnerClassName}\n isOpen={isOpen}\n keepContentMounted={keepContentMounted}\n style={style}\n >\n {children}\n </AccordionStaticContent>\n );\n }\n\n return (\n <AccordionMotionContent\n className={className}\n contentInnerClassName={contentInnerClassName}\n contextMotionProps={contextMotionProps}\n isOpen={isOpen}\n skipInitialAnimation={skipInitialAnimation}\n style={style}\n >\n {children}\n </AccordionMotionContent>\n );\n },\n);\n\nAccordionItemContent.displayName = 'AccordionItemContent';\n\nconst AccordionItem = memo<AccordionItemProps>(\n ({\n itemKey,\n title,\n children,\n action,\n alwaysShowAction = false,\n disabled = false,\n allowExpand = true,\n hideIndicator: itemHideIndicator,\n indicatorPlacement: itemIndicatorPlacement,\n indicator: customIndicator,\n classNames,\n paddingInline = 16,\n paddingBlock = 8,\n padding,\n ref,\n variant: customVariant,\n styles: customStyles,\n headerWrapper,\n defaultExpand,\n expand,\n onExpandChange,\n }) => {\n // Per-item state context: only this item's provider re-emits when its\n // own isOpen flips, so siblings stay stable across toggles.\n const itemStateContext = useAccordionItemState();\n const configContext = useAccordionConfig();\n\n // Determine if using standalone mode (has expand or defaultExpand props)\n const isStandalone = expand !== undefined || defaultExpand !== undefined;\n\n // Standalone state management\n const [isExpandedStandalone, setIsExpandedStandalone] = useMergeState<boolean>(\n defaultExpand ?? false,\n {\n onChange: onExpandChange,\n value: expand,\n },\n );\n\n const contextHideIndicator = configContext?.hideIndicator;\n const contextIndicatorPlacement = configContext?.indicatorPlacement;\n const contextKeepContentMounted = configContext?.keepContentMounted;\n const contextDisableAnimation = configContext?.disableAnimation;\n const contextMotionProps = configContext?.motionProps;\n const contextVariant = configContext?.variant ?? 'borderless';\n\n const isInitialRenderRef = useRef(true);\n\n useEffect(() => {\n isInitialRenderRef.current = false;\n }, []);\n\n const isDirectContextItem = itemStateContext?.itemKey === itemKey;\n\n // Determine expanded state\n let isOpen = false;\n if (isStandalone) {\n isOpen = isExpandedStandalone;\n } else if (itemStateContext) {\n isOpen = isDirectContextItem\n ? itemStateContext.isOpen\n : itemStateContext.isOpen || itemStateContext.isOpenKey(itemKey);\n }\n\n // Determine other props with fallbacks\n const hideIndicatorFinal = itemHideIndicator ?? contextHideIndicator ?? false;\n const indicatorPlacementFinal = itemIndicatorPlacement ?? contextIndicatorPlacement ?? 'start';\n const keepContentMounted = contextKeepContentMounted ?? true;\n const disableAnimation = contextDisableAnimation ?? false;\n const variant = customVariant || contextVariant;\n\n const contextOnToggle = useCallback(() => {\n if (!itemStateContext) return;\n if (itemStateContext.itemKey === itemKey) {\n itemStateContext.onToggle();\n return;\n }\n itemStateContext.onToggleNestedKey(itemKey);\n }, [itemStateContext, itemKey]);\n\n const handleToggle = useCallback(() => {\n // If allowExpand is false, only allow controlled expansion via expand prop\n if (!allowExpand) return;\n\n if (!disabled) {\n if (isStandalone) {\n setIsExpandedStandalone(!isExpandedStandalone);\n } else if (contextOnToggle) {\n contextOnToggle();\n }\n }\n }, [\n allowExpand,\n disabled,\n isStandalone,\n setIsExpandedStandalone,\n isExpandedStandalone,\n contextOnToggle,\n ]);\n\n const handleKeyDown = useCallback(\n (e: KeyboardEvent) => {\n // If allowExpand is false, disable keyboard toggle\n if (!allowExpand || disabled) return;\n\n switch (e.key) {\n case 'Enter':\n case ' ': {\n e.preventDefault();\n handleToggle();\n break;\n }\n }\n },\n [allowExpand, disabled, handleToggle],\n );\n\n const preventTitleTextSelection = useCallback((e: any) => {\n // Prevent browser from creating a selection range on double/multi click,\n // which can accidentally select the content region.\n if (e?.detail > 1) e.preventDefault();\n }, []);\n\n // Build indicator\n const indicator = useMemo(() => {\n if (!allowExpand || hideIndicatorFinal) return null;\n\n if (customIndicator) {\n if (typeof customIndicator === 'function') {\n return (\n <span\n aria-hidden=\"true\"\n className={cx(styles.indicator, classNames?.indicator)}\n style={customStyles?.indicator}\n >\n {customIndicator({ isDisabled: disabled, isOpen })}\n </span>\n );\n }\n return (\n <span\n aria-hidden=\"true\"\n className={cx(styles.indicator, classNames?.indicator)}\n style={customStyles?.indicator}\n >\n {customIndicator}\n </span>\n );\n }\n\n return (\n <span\n aria-hidden=\"true\"\n className={cx(styles.indicator, classNames?.indicator)}\n style={customStyles?.indicator}\n >\n <ArrowIcon className={cx(styles.icon, isOpen && styles.iconRotate)} />\n </span>\n );\n }, [\n allowExpand,\n hideIndicatorFinal,\n customIndicator,\n disabled,\n isOpen,\n classNames,\n customStyles,\n ]);\n\n const skipInitialAnimation = isInitialRenderRef.current && isOpen;\n\n const contentClassName = useMemo(\n () => cx('accordion-content', styles.content, classNames?.content),\n [classNames?.content],\n );\n\n const titleNode = useMemo(\n () =>\n typeof title === 'string' ? (\n <Text ellipsis className={classNames?.title} style={customStyles?.title}>\n {title}\n </Text>\n ) : (\n title\n ),\n [title, classNames?.title, customStyles?.title],\n );\n\n const actionNode = useMemo(\n () =>\n action && (\n <Flexbox\n horizontal\n align={'center'}\n flex={'none'}\n gap={4}\n style={customStyles?.action}\n className={cx(\n 'accordion-action',\n styles.action,\n alwaysShowAction && styles.actionVisible,\n classNames?.action,\n )}\n onClick={stopPropagation}\n >\n {action}\n </Flexbox>\n ),\n [action, alwaysShowAction, classNames?.action, customStyles?.action],\n );\n\n const headerElement = useMemo(() => {\n const header = (\n <Block\n horizontal\n className={cx('accordion-header', styles.header, classNames?.header)}\n clickable={!disabled && allowExpand}\n gap={4}\n justify={'space-between'}\n padding={padding}\n paddingBlock={paddingBlock}\n paddingInline={paddingInline}\n ref={ref}\n variant={customVariant || variant}\n style={{\n alignItems: 'center',\n cursor: disabled ? 'not-allowed' : allowExpand ? 'pointer' : 'default',\n opacity: disabled ? 0.5 : undefined,\n overflow: 'hidden',\n width: '100%',\n ...customStyles?.header,\n }}\n onClick={handleToggle}\n onKeyDown={handleKeyDown}\n >\n {indicatorPlacementFinal === 'start' ? (\n <>\n <Flexbox\n horizontal\n align={'center'}\n className={styles.titleWrapper}\n flex={1}\n gap={2}\n style={{\n overflow: 'hidden',\n }}\n onDoubleClick={preventTitleTextSelection}\n onMouseDown={preventTitleTextSelection}\n >\n {titleNode}\n {indicator}\n </Flexbox>\n <Flexbox horizontal align={'center'} flex={'none'} gap={4}>\n {actionNode}\n </Flexbox>\n </>\n ) : (\n <>\n <Flexbox\n horizontal\n align={'center'}\n className={styles.titleWrapper}\n flex={1}\n gap={2}\n style={{\n overflow: 'hidden',\n }}\n onDoubleClick={preventTitleTextSelection}\n onMouseDown={preventTitleTextSelection}\n >\n {titleNode}\n </Flexbox>\n <Flexbox horizontal align={'center'} flex={'none'} gap={4}>\n {actionNode}\n {indicator}\n </Flexbox>\n </>\n )}\n </Block>\n );\n if (headerWrapper) {\n return headerWrapper(header);\n }\n return header;\n }, [\n classNames?.header,\n disabled,\n allowExpand,\n padding,\n paddingBlock,\n paddingInline,\n ref,\n customVariant,\n variant,\n customStyles?.header,\n handleToggle,\n handleKeyDown,\n indicatorPlacementFinal,\n preventTitleTextSelection,\n titleNode,\n indicator,\n actionNode,\n headerWrapper,\n ]);\n\n return (\n <div\n className={cx('accordion-item', styles.item, classNames?.base)}\n style={customStyles?.base}\n >\n {headerElement}\n <AccordionItemContent\n className={contentClassName}\n contentInnerClassName={styles.contentInner}\n contextMotionProps={contextMotionProps}\n disableAnimation={!!disableAnimation}\n isOpen={isOpen}\n keepContentMounted={!!keepContentMounted}\n skipInitialAnimation={skipInitialAnimation}\n style={customStyles?.content}\n >\n {children}\n </AccordionItemContent>\n </div>\n );\n },\n);\n\nAccordionItem.displayName = 'AccordionItem';\n\nexport default AccordionItem;\n"],"mappings":";;;;;;;;;;;;;;;AAwDA,MAAM,uBAAsC,EAAE,UAAU,UAAU;AAElE,MAAM,yBAAyB,MAC5B,EAAE,WAAW,OAAO,UAAU,uBAAuB,QAAQ,yBAAyB;AACrF,KAAI,mBAC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Z;IACO,CAAA,EACV,qBAACA,mBAAD;IAAS,YAAA;IAAW,OAAO;IAAU,MAAM;IAAQ,KAAK;cAAxD,CACG,YACA,UACO;MACT,EAAA,CAAA;GAEC,CAAA;AAEV,MAAI,cACF,QAAO,cAAc,OAAO;AAE9B,SAAO;IACN;EACD,YAAY;EACZ;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,cAAc;EACd;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAAC;AAEF,QACE,qBAAC,OAAD;EACE,WAAW,GAAG,kBAAkB,OAAO,MAAM,YAAY,KAAK;EAC9D,OAAO,cAAc;YAFvB,CAIG,eACD,oBAAC,sBAAD;GACE,WAAW;GACX,uBAAuB,OAAO;GACV;GACpB,kBAAkB,CAAC,CAAC;GACZ;GACR,oBAAoB,CAAC,CAAC;GACA;GACtB,OAAO,cAAc;GAEpB;GACoB,CAAA,CACnB;;EAGX;AAED,cAAc,cAAc"}
|
package/es/Accordion/context.mjs
CHANGED
|
@@ -1,10 +1,42 @@
|
|
|
1
|
-
import { createContext, use } from "react";
|
|
1
|
+
import { createContext, memo, use, useMemo } from "react";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
3
|
//#region src/Accordion/context.tsx
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Per-item context: each AccordionItem gets its own provider, so a toggle
|
|
6
|
+
* only invalidates the value seen by that single item. Sibling items keep
|
|
7
|
+
* the same context value identity and skip re-render.
|
|
8
|
+
*/
|
|
9
|
+
const AccordionItemStateContext = createContext(null);
|
|
10
|
+
/**
|
|
11
|
+
* Static config shared by all items. Identity changes only when the user
|
|
12
|
+
* changes config props on <Accordion>, which is rare.
|
|
13
|
+
*/
|
|
14
|
+
const AccordionConfigContext = createContext(null);
|
|
15
|
+
const useAccordionItemState = () => use(AccordionItemStateContext);
|
|
16
|
+
const useAccordionConfig = () => use(AccordionConfigContext);
|
|
17
|
+
const AccordionItemStateProvider = memo(({ children, expandedKeys, isOpenKey, isOpen, itemKey, onToggleKey, onToggleKeys, preferProviderKeyForNestedItems }) => {
|
|
18
|
+
return /* @__PURE__ */ jsx(AccordionItemStateContext, {
|
|
19
|
+
value: useMemo(() => ({
|
|
20
|
+
isOpenKey,
|
|
21
|
+
isOpen,
|
|
22
|
+
itemKey,
|
|
23
|
+
onToggle: () => onToggleKey(itemKey),
|
|
24
|
+
onToggleKey,
|
|
25
|
+
onToggleNestedKey: (key) => onToggleKeys([itemKey, key], preferProviderKeyForNestedItems ? itemKey : key)
|
|
26
|
+
}), [
|
|
27
|
+
expandedKeys,
|
|
28
|
+
isOpenKey,
|
|
29
|
+
isOpen,
|
|
30
|
+
itemKey,
|
|
31
|
+
onToggleKey,
|
|
32
|
+
onToggleKeys,
|
|
33
|
+
preferProviderKeyForNestedItems
|
|
34
|
+
]),
|
|
35
|
+
children
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
AccordionItemStateProvider.displayName = "AccordionItemStateProvider";
|
|
7
39
|
//#endregion
|
|
8
|
-
export {
|
|
40
|
+
export { AccordionConfigContext, AccordionItemStateProvider, useAccordionConfig, useAccordionItemState };
|
|
9
41
|
|
|
10
42
|
//# sourceMappingURL=context.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.mjs","names":[],"sources":["../../src/Accordion/context.tsx"],"sourcesContent":["import type { Key } from 'react';\nimport { createContext, use } from 'react';\n\ninterface
|
|
1
|
+
{"version":3,"file":"context.mjs","names":[],"sources":["../../src/Accordion/context.tsx"],"sourcesContent":["import type { Key, ReactNode } from 'react';\nimport { createContext, memo, use, useMemo } from 'react';\n\ninterface AccordionItemStateValue {\n isOpen: boolean;\n isOpenKey: (key: Key) => boolean;\n itemKey: Key;\n onToggle: () => void;\n onToggleKey: (key: Key) => void;\n onToggleNestedKey: (key: Key) => void;\n}\n\ninterface AccordionConfigValue {\n disableAnimation?: boolean;\n hideIndicator?: boolean;\n indicatorPlacement?: 'end' | 'start';\n keepContentMounted?: boolean;\n motionProps?: any;\n showDivider?: boolean;\n variant?: 'filled' | 'outlined' | 'borderless';\n}\n\n/**\n * Per-item context: each AccordionItem gets its own provider, so a toggle\n * only invalidates the value seen by that single item. Sibling items keep\n * the same context value identity and skip re-render.\n */\nexport const AccordionItemStateContext = createContext<AccordionItemStateValue | null>(null);\n\n/**\n * Static config shared by all items. Identity changes only when the user\n * changes config props on <Accordion>, which is rare.\n */\nexport const AccordionConfigContext = createContext<AccordionConfigValue | null>(null);\n\nexport const useAccordionItemState = () => use(AccordionItemStateContext);\nexport const useAccordionConfig = () => use(AccordionConfigContext);\n\ninterface AccordionItemStateProviderProps {\n children: ReactNode;\n // Used only to refresh the memoized context for wrapper children when\n // controlled expanded keys change; direct children use `isOpen`.\n expandedKeys?: Key[];\n isOpen: boolean;\n isOpenKey: (key: Key) => boolean;\n itemKey: Key;\n onToggleKey: (key: Key) => void;\n onToggleKeys: (keys: Key[], preferredKey: Key) => void;\n preferProviderKeyForNestedItems: boolean;\n}\n\nexport const AccordionItemStateProvider = memo<AccordionItemStateProviderProps>(\n ({\n children,\n expandedKeys,\n isOpenKey,\n isOpen,\n itemKey,\n onToggleKey,\n onToggleKeys,\n preferProviderKeyForNestedItems,\n }) => {\n const value = useMemo(\n () => ({\n isOpenKey,\n isOpen,\n itemKey,\n onToggle: () => onToggleKey(itemKey),\n onToggleKey,\n onToggleNestedKey: (key: Key) =>\n onToggleKeys([itemKey, key], preferProviderKeyForNestedItems ? itemKey : key),\n }),\n [\n expandedKeys,\n isOpenKey,\n isOpen,\n itemKey,\n onToggleKey,\n onToggleKeys,\n preferProviderKeyForNestedItems,\n ],\n );\n return <AccordionItemStateContext value={value}>{children}</AccordionItemStateContext>;\n },\n);\n\nAccordionItemStateProvider.displayName = 'AccordionItemStateProvider';\n"],"mappings":";;;;;;;;AA2BA,MAAa,4BAA4B,cAA8C,KAAK;;;;;AAM5F,MAAa,yBAAyB,cAA2C,KAAK;AAEtF,MAAa,8BAA8B,IAAI,0BAA0B;AACzE,MAAa,2BAA2B,IAAI,uBAAuB;AAenE,MAAa,6BAA6B,MACvC,EACC,UACA,cACA,WACA,QACA,SACA,aACA,cACA,sCACI;AAqBJ,QAAO,oBAAC,2BAAD;EAA2B,OApBpB,eACL;GACL;GACA;GACA;GACA,gBAAgB,YAAY,QAAQ;GACpC;GACA,oBAAoB,QAClB,aAAa,CAAC,SAAS,IAAI,EAAE,kCAAkC,UAAU,IAAI;GAChF,GACD;GACE;GACA;GACA;GACA;GACA;GACA;GACA;GACD,CAE2C;EAAG;EAAqC,CAAA;EAEzF;AAED,2BAA2B,cAAc"}
|