@tamagui/collapsible 1.0.1-beta.150 → 1.0.1-beta.153
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.
- package/dist/cjs/Collapsible.js +69 -55
- package/dist/cjs/Collapsible.js.map +2 -2
- package/dist/esm/Collapsible.js +65 -54
- package/dist/esm/Collapsible.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/jsx/Collapsible.js +32 -26
- package/dist/jsx/Collapsible.js.map +1 -1
- package/dist/jsx/index.js.map +1 -1
- package/package.json +8 -8
package/dist/cjs/Collapsible.js
CHANGED
|
@@ -17,7 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
21
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
25
|
var Collapsible_exports = {};
|
|
23
26
|
__export(Collapsible_exports, {
|
|
@@ -30,6 +33,7 @@ __export(Collapsible_exports, {
|
|
|
30
33
|
createCollapsibleScope: () => createCollapsibleScope
|
|
31
34
|
});
|
|
32
35
|
module.exports = __toCommonJS(Collapsible_exports);
|
|
36
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
33
37
|
var import_compose_refs = require("@tamagui/compose-refs");
|
|
34
38
|
var import_core = require("@tamagui/core");
|
|
35
39
|
var import_core2 = require("@tamagui/core");
|
|
@@ -39,61 +43,70 @@ var React = __toESM(require("react"));
|
|
|
39
43
|
const COLLAPSIBLE_NAME = "Collapsible";
|
|
40
44
|
const [createCollapsibleContext, createCollapsibleScope] = (0, import_create_context.createContextScope)(COLLAPSIBLE_NAME);
|
|
41
45
|
const [CollapsibleProvider, useCollapsibleContext] = createCollapsibleContext(COLLAPSIBLE_NAME);
|
|
42
|
-
const Collapsible = React.forwardRef(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
})
|
|
46
|
+
const Collapsible = React.forwardRef(
|
|
47
|
+
(props, forwardedRef) => {
|
|
48
|
+
const {
|
|
49
|
+
__scopeCollapsible,
|
|
50
|
+
open: openProp,
|
|
51
|
+
defaultOpen,
|
|
52
|
+
disabled,
|
|
53
|
+
onOpenChange,
|
|
54
|
+
...collapsibleProps
|
|
55
|
+
} = props;
|
|
56
|
+
const [open, setOpen] = (0, import_use_controllable_state.useControllableState)({
|
|
57
|
+
prop: openProp,
|
|
58
|
+
defaultProp: defaultOpen || false,
|
|
59
|
+
onChange: onOpenChange
|
|
60
|
+
});
|
|
61
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CollapsibleProvider, {
|
|
62
|
+
scope: __scopeCollapsible,
|
|
63
|
+
disabled,
|
|
64
|
+
contentId: (0, import_core2.useId)() || "",
|
|
65
|
+
open,
|
|
66
|
+
onOpenToggle: React.useCallback(() => setOpen((prevOpen) => !prevOpen), [setOpen]),
|
|
67
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Stack, {
|
|
68
|
+
"data-state": getState(open),
|
|
69
|
+
"data-disabled": disabled ? "" : void 0,
|
|
70
|
+
...collapsibleProps,
|
|
71
|
+
ref: forwardedRef
|
|
72
|
+
})
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
);
|
|
69
76
|
Collapsible.displayName = COLLAPSIBLE_NAME;
|
|
70
77
|
const TRIGGER_NAME = "CollapsibleTrigger";
|
|
71
|
-
const CollapsibleTrigger = React.forwardRef(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
});
|
|
78
|
+
const CollapsibleTrigger = React.forwardRef(
|
|
79
|
+
(props, forwardedRef) => {
|
|
80
|
+
const { __scopeCollapsible, ...triggerProps } = props;
|
|
81
|
+
const context = useCollapsibleContext(TRIGGER_NAME, __scopeCollapsible);
|
|
82
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Stack, {
|
|
83
|
+
type: "button",
|
|
84
|
+
"aria-controls": context.contentId,
|
|
85
|
+
"aria-expanded": context.open || false,
|
|
86
|
+
"data-state": getState(context.open),
|
|
87
|
+
"data-disabled": context.disabled ? "" : void 0,
|
|
88
|
+
disabled: context.disabled,
|
|
89
|
+
...triggerProps,
|
|
90
|
+
ref: forwardedRef,
|
|
91
|
+
onPress: (0, import_core.composeEventHandlers)(props.onPress, context.onOpenToggle)
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
);
|
|
86
95
|
CollapsibleTrigger.displayName = TRIGGER_NAME;
|
|
87
96
|
const CONTENT_NAME = "CollapsibleContent";
|
|
88
|
-
const CollapsibleContent = React.forwardRef(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
+
const CollapsibleContent = React.forwardRef(
|
|
98
|
+
(props, forwardedRef) => {
|
|
99
|
+
const { forceMount, ...contentProps } = props;
|
|
100
|
+
const context = useCollapsibleContext(CONTENT_NAME, props.__scopeCollapsible);
|
|
101
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
|
|
102
|
+
children: ({ present }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CollapsibleContentImpl, {
|
|
103
|
+
...contentProps,
|
|
104
|
+
ref: forwardedRef,
|
|
105
|
+
present
|
|
106
|
+
})
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
);
|
|
97
110
|
CollapsibleContent.displayName = CONTENT_NAME;
|
|
98
111
|
const CollapsibleContentImpl = React.forwardRef((props, forwardedRef) => {
|
|
99
112
|
const { __scopeCollapsible, present, children, ...contentProps } = props;
|
|
@@ -112,14 +125,15 @@ const CollapsibleContentImpl = React.forwardRef((props, forwardedRef) => {
|
|
|
112
125
|
const rAF = requestAnimationFrame(() => isMountAnimationPreventedRef.current = false);
|
|
113
126
|
return () => cancelAnimationFrame(rAF);
|
|
114
127
|
}, []);
|
|
115
|
-
return /* @__PURE__ */
|
|
128
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Stack, {
|
|
116
129
|
"data-state": getState(context.open),
|
|
117
130
|
"data-disabled": context.disabled ? "" : void 0,
|
|
118
131
|
id: context.contentId,
|
|
119
132
|
hidden: !isOpen,
|
|
120
133
|
...contentProps,
|
|
121
|
-
ref: composedRefs
|
|
122
|
-
|
|
134
|
+
ref: composedRefs,
|
|
135
|
+
children: isOpen && children
|
|
136
|
+
});
|
|
123
137
|
});
|
|
124
138
|
function getState(open) {
|
|
125
139
|
return open ? "open" : "closed";
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Collapsible.tsx"],
|
|
4
4
|
"sourcesContent": ["import { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n Stack,\n StackProps,\n TamaguiElement,\n composeEventHandlers,\n useIsomorphicLayoutEffect,\n} from '@tamagui/core'\nimport { useId } from '@tamagui/core'\nimport { createContextScope } from '@tamagui/create-context'\nimport type { Scope } from '@tamagui/create-context'\n// import { Presence } from '@tamagui/react-presence'\nimport { useControllableState } from '@tamagui/use-controllable-state'\nimport * as React from 'react'\n\n/* -------------------------------------------------------------------------------------------------\n * Collapsible\n * -----------------------------------------------------------------------------------------------*/\n\nconst COLLAPSIBLE_NAME = 'Collapsible'\n\ntype ScopedProps<P> = P & { __scopeCollapsible?: Scope }\nconst [createCollapsibleContext, createCollapsibleScope] = createContextScope(COLLAPSIBLE_NAME)\n\ntype CollapsibleContextValue = {\n contentId: string\n disabled?: boolean\n open: boolean\n onOpenToggle(): void\n}\n\nconst [CollapsibleProvider, useCollapsibleContext] =\n createCollapsibleContext<CollapsibleContextValue>(COLLAPSIBLE_NAME)\n\ntype CollapsibleElement = TamaguiElement\ninterface CollapsibleProps extends StackProps {\n defaultOpen?: boolean\n open?: boolean\n disabled?: boolean\n onOpenChange?(open: boolean): void\n}\n\nconst Collapsible = React.forwardRef<CollapsibleElement, CollapsibleProps>(\n (props: ScopedProps<CollapsibleProps>, forwardedRef) => {\n const {\n __scopeCollapsible,\n open: openProp,\n defaultOpen,\n disabled,\n onOpenChange,\n ...collapsibleProps\n } = props\n\n const [open, setOpen] = useControllableState({\n prop: openProp,\n defaultProp: defaultOpen || false,\n onChange: onOpenChange,\n })\n\n return (\n <CollapsibleProvider\n scope={__scopeCollapsible}\n disabled={disabled}\n contentId={useId() || ''}\n open={open}\n onOpenToggle={React.useCallback(() => setOpen((prevOpen) => !prevOpen), [setOpen])}\n >\n <Stack\n data-state={getState(open)}\n data-disabled={disabled ? '' : undefined}\n {...collapsibleProps}\n // @ts-expect-error\n ref={forwardedRef}\n />\n </CollapsibleProvider>\n )\n }\n)\n\nCollapsible.displayName = COLLAPSIBLE_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * CollapsibleTrigger\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRIGGER_NAME = 'CollapsibleTrigger'\n\ntype CollapsibleTriggerElement = TamaguiElement\ninterface CollapsibleTriggerProps extends StackProps {}\n\nconst CollapsibleTrigger = React.forwardRef<CollapsibleTriggerElement, CollapsibleTriggerProps>(\n (props: ScopedProps<CollapsibleTriggerProps>, forwardedRef) => {\n const { __scopeCollapsible, ...triggerProps } = props\n const context = useCollapsibleContext(TRIGGER_NAME, __scopeCollapsible)\n return (\n <Stack\n type=\"button\"\n aria-controls={context.contentId}\n aria-expanded={context.open || false}\n data-state={getState(context.open)}\n data-disabled={context.disabled ? '' : undefined}\n disabled={context.disabled}\n {...triggerProps}\n // @ts-expect-error\n ref={forwardedRef}\n onPress={composeEventHandlers(props.onPress, context.onOpenToggle)}\n />\n )\n }\n)\n\nCollapsibleTrigger.displayName = TRIGGER_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * CollapsibleContent\n * -----------------------------------------------------------------------------------------------*/\n\nconst CONTENT_NAME = 'CollapsibleContent'\n\ntype CollapsibleContentElement = CollapsibleContentImplElement\ninterface CollapsibleContentProps extends Omit<CollapsibleContentImplProps, 'present'> {\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true\n}\n\nconst CollapsibleContent = React.forwardRef<CollapsibleContentElement, CollapsibleContentProps>(\n (props: ScopedProps<CollapsibleContentProps>, forwardedRef) => {\n const { forceMount, ...contentProps } = props\n const context = useCollapsibleContext(CONTENT_NAME, props.__scopeCollapsible)\n return (\n // <Presence present={forceMount || context.open}>\n <>\n {({ present }) => (\n <CollapsibleContentImpl {...contentProps} ref={forwardedRef} present={present} />\n )}\n </>\n // </Presence>\n )\n }\n)\n\nCollapsibleContent.displayName = CONTENT_NAME\n\n/* -----------------------------------------------------------------------------------------------*/\n\ntype CollapsibleContentImplElement = TamaguiElement\ninterface CollapsibleContentImplProps extends StackProps {\n present: boolean\n}\n\nconst CollapsibleContentImpl = React.forwardRef<\n CollapsibleContentImplElement,\n CollapsibleContentImplProps\n>((props: ScopedProps<CollapsibleContentImplProps>, forwardedRef) => {\n const { __scopeCollapsible, present, children, ...contentProps } = props\n const context = useCollapsibleContext(CONTENT_NAME, __scopeCollapsible)\n const [isPresent, setIsPresent] = React.useState(present)\n const ref = React.useRef<CollapsibleContentImplElement>(null)\n const composedRefs = useComposedRefs(forwardedRef, ref)\n const heightRef = React.useRef<number | undefined>(0)\n const height = heightRef.current\n const widthRef = React.useRef<number | undefined>(0)\n const width = widthRef.current\n // when opening we want it to immediately open to retrieve dimensions\n // when closing we delay `present` to retrieve dimensions before closing\n const isOpen = context.open || isPresent\n const isMountAnimationPreventedRef = React.useRef(isOpen)\n const originalStylesRef = React.useRef<Record<string, string>>()\n\n React.useEffect(() => {\n const rAF = requestAnimationFrame(() => (isMountAnimationPreventedRef.current = false))\n return () => cancelAnimationFrame(rAF)\n }, [])\n\n // useIsomorphicLayoutEffect(() => {\n // const node = ref.current\n // if (node) {\n // originalStylesRef.current = originalStylesRef.current || {\n // transitionDuration: node.style.transitionDuration,\n // animationDuration: node.style.animationDuration,\n // animationFillMode: node.style.animationFillMode,\n // }\n // // block any animations/transitions so the element renders at its full dimensions\n // node.style.transitionDuration = '0s'\n // node.style.animationDuration = '0s'\n // node.style.animationFillMode = 'none'\n\n // // get width and height from full dimensions\n // const rect = node.getBoundingClientRect()\n // heightRef.current = rect.height\n // widthRef.current = rect.width\n\n // // kick off any animations/transitions that were originally set up if it isn't the initial mount\n // if (!isMountAnimationPreventedRef.current) {\n // node.style.transitionDuration = originalStylesRef.current.transitionDuration\n // node.style.animationDuration = originalStylesRef.current.animationDuration\n // node.style.animationFillMode = originalStylesRef.current.animationFillMode\n // }\n\n // setIsPresent(present)\n // }\n // /**\n // * depends on `context.open` because it will change to `false`\n // * when a close is triggered but `present` will be `false` on\n // * animation end (so when close finishes). This allows us to\n // * retrieve the dimensions *before* closing.\n // */\n // }, [context.open, present])\n\n return (\n <Stack\n data-state={getState(context.open)}\n data-disabled={context.disabled ? '' : undefined}\n id={context.contentId}\n hidden={!isOpen}\n {...contentProps}\n // @ts-expect-error\n ref={composedRefs}\n // style={{\n // [`--radix-collapsible-content-height` as any]: height ? `${height}px` : undefined,\n // [`--radix-collapsible-content-width` as any]: width ? `${width}px` : undefined,\n // ...props.style,\n // }}\n >\n {isOpen && children}\n </Stack>\n )\n})\n\n/* -----------------------------------------------------------------------------------------------*/\n\nfunction getState(open?: boolean) {\n return open ? 'open' : 'closed'\n}\n\nconst Root = Collapsible\nconst Trigger = CollapsibleTrigger\nconst Content = CollapsibleContent\n\nexport {\n createCollapsibleScope,\n //\n Collapsible,\n CollapsibleTrigger,\n CollapsibleContent,\n //\n Root,\n Trigger,\n Content,\n}\nexport type { CollapsibleProps, CollapsibleTriggerProps, CollapsibleContentProps }\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmEQ;AAnER,0BAAgC;AAChC,kBAMO;AACP,IAAAA,eAAsB;AACtB,4BAAmC;AAGnC,oCAAqC;AACrC,YAAuB;AAMvB,MAAM,mBAAmB;AAGzB,MAAM,CAAC,0BAA0B,sBAAsB,QAAI,0CAAmB,gBAAgB;AAS9F,MAAM,CAAC,qBAAqB,qBAAqB,IAC/C,yBAAkD,gBAAgB;AAUpE,MAAM,cAAc,MAAM;AAAA,EACxB,CAAC,OAAsC,iBAAiB;AACtD,UAAM;AAAA,MACJ;AAAA,MACA,MAAM;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,SACG;AAAA,IACL,IAAI;AAEJ,UAAM,CAAC,MAAM,OAAO,QAAI,oDAAqB;AAAA,MAC3C,MAAM;AAAA,MACN,aAAa,eAAe;AAAA,MAC5B,UAAU;AAAA,IACZ,CAAC;AAED,WACE,4CAAC;AAAA,MACC,OAAO;AAAA,MACP;AAAA,MACA,eAAW,oBAAM,KAAK;AAAA,MACtB;AAAA,MACA,cAAc,MAA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,QAAM,CAAC,WAAW,YAAY,IAAI,MAAM,SAAS,OAAO;AACxD,QAAM,MAAM,MAAM,OAAsC,IAAI;AAC5D,QAAM,mBAAe,qCAAgB,cAAc,GAAG;AACtD,QAAM,YAAY,MAAM,OAA2B,CAAC;AACpD,QAAM,SAAS,UAAU;AACzB,QAAM,WAAW,MAAM,OAA2B,CAAC;AACnD,QAAM,QAAQ,SAAS;AAGvB,QAAM,SAAS,QAAQ,QAAQ;AAC/B,QAAM,+BAA+B,MAAM,OAAO,MAAM;AACxD,QAAM,oBAAoB,MAAM,OAA+B;AAE/D,QAAM,UAAU,MAAM;AACpB,UAAM,MAAM,sBAAsB,MAAO,6BAA6B,UAAU,KAAM;AACtF,WAAO,MAAM,qBAAqB,GAAG;AAAA,EACvC,GAAG,CAAC,CAAC;AAqCL,SACE,4CAAC;AAAA,IACC,cAAY,SAAS,QAAQ,IAAI;AAAA,IACjC,iBAAe,QAAQ,WAAW,KAAK;AAAA,IACvC,IAAI,QAAQ;AAAA,IACZ,QAAQ,CAAC;AAAA,IACR,GAAG;AAAA,IAEJ,KAAK;AAAA,IAOJ,oBAAU;AAAA,GACb;AAEJ,CAAC;AAID,SAAS,SAAS,MAAgB;AAChC,SAAO,OAAO,SAAS;AACzB;AAEA,MAAM,OAAO;AACb,MAAM,UAAU;AAChB,MAAM,UAAU;",
|
|
6
|
+
"names": ["import_core"]
|
|
7
7
|
}
|
package/dist/esm/Collapsible.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
1
2
|
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
2
3
|
import {
|
|
3
4
|
Stack,
|
|
@@ -10,61 +11,70 @@ import * as React from "react";
|
|
|
10
11
|
const COLLAPSIBLE_NAME = "Collapsible";
|
|
11
12
|
const [createCollapsibleContext, createCollapsibleScope] = createContextScope(COLLAPSIBLE_NAME);
|
|
12
13
|
const [CollapsibleProvider, useCollapsibleContext] = createCollapsibleContext(COLLAPSIBLE_NAME);
|
|
13
|
-
const Collapsible = React.forwardRef(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
})
|
|
14
|
+
const Collapsible = React.forwardRef(
|
|
15
|
+
(props, forwardedRef) => {
|
|
16
|
+
const {
|
|
17
|
+
__scopeCollapsible,
|
|
18
|
+
open: openProp,
|
|
19
|
+
defaultOpen,
|
|
20
|
+
disabled,
|
|
21
|
+
onOpenChange,
|
|
22
|
+
...collapsibleProps
|
|
23
|
+
} = props;
|
|
24
|
+
const [open, setOpen] = useControllableState({
|
|
25
|
+
prop: openProp,
|
|
26
|
+
defaultProp: defaultOpen || false,
|
|
27
|
+
onChange: onOpenChange
|
|
28
|
+
});
|
|
29
|
+
return /* @__PURE__ */ jsx(CollapsibleProvider, {
|
|
30
|
+
scope: __scopeCollapsible,
|
|
31
|
+
disabled,
|
|
32
|
+
contentId: useId() || "",
|
|
33
|
+
open,
|
|
34
|
+
onOpenToggle: React.useCallback(() => setOpen((prevOpen) => !prevOpen), [setOpen]),
|
|
35
|
+
children: /* @__PURE__ */ jsx(Stack, {
|
|
36
|
+
"data-state": getState(open),
|
|
37
|
+
"data-disabled": disabled ? "" : void 0,
|
|
38
|
+
...collapsibleProps,
|
|
39
|
+
ref: forwardedRef
|
|
40
|
+
})
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
);
|
|
40
44
|
Collapsible.displayName = COLLAPSIBLE_NAME;
|
|
41
45
|
const TRIGGER_NAME = "CollapsibleTrigger";
|
|
42
|
-
const CollapsibleTrigger = React.forwardRef(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
});
|
|
46
|
+
const CollapsibleTrigger = React.forwardRef(
|
|
47
|
+
(props, forwardedRef) => {
|
|
48
|
+
const { __scopeCollapsible, ...triggerProps } = props;
|
|
49
|
+
const context = useCollapsibleContext(TRIGGER_NAME, __scopeCollapsible);
|
|
50
|
+
return /* @__PURE__ */ jsx(Stack, {
|
|
51
|
+
type: "button",
|
|
52
|
+
"aria-controls": context.contentId,
|
|
53
|
+
"aria-expanded": context.open || false,
|
|
54
|
+
"data-state": getState(context.open),
|
|
55
|
+
"data-disabled": context.disabled ? "" : void 0,
|
|
56
|
+
disabled: context.disabled,
|
|
57
|
+
...triggerProps,
|
|
58
|
+
ref: forwardedRef,
|
|
59
|
+
onPress: composeEventHandlers(props.onPress, context.onOpenToggle)
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
);
|
|
57
63
|
CollapsibleTrigger.displayName = TRIGGER_NAME;
|
|
58
64
|
const CONTENT_NAME = "CollapsibleContent";
|
|
59
|
-
const CollapsibleContent = React.forwardRef(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
const CollapsibleContent = React.forwardRef(
|
|
66
|
+
(props, forwardedRef) => {
|
|
67
|
+
const { forceMount, ...contentProps } = props;
|
|
68
|
+
const context = useCollapsibleContext(CONTENT_NAME, props.__scopeCollapsible);
|
|
69
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
70
|
+
children: ({ present }) => /* @__PURE__ */ jsx(CollapsibleContentImpl, {
|
|
71
|
+
...contentProps,
|
|
72
|
+
ref: forwardedRef,
|
|
73
|
+
present
|
|
74
|
+
})
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
);
|
|
68
78
|
CollapsibleContent.displayName = CONTENT_NAME;
|
|
69
79
|
const CollapsibleContentImpl = React.forwardRef((props, forwardedRef) => {
|
|
70
80
|
const { __scopeCollapsible, present, children, ...contentProps } = props;
|
|
@@ -83,14 +93,15 @@ const CollapsibleContentImpl = React.forwardRef((props, forwardedRef) => {
|
|
|
83
93
|
const rAF = requestAnimationFrame(() => isMountAnimationPreventedRef.current = false);
|
|
84
94
|
return () => cancelAnimationFrame(rAF);
|
|
85
95
|
}, []);
|
|
86
|
-
return /* @__PURE__ */
|
|
96
|
+
return /* @__PURE__ */ jsx(Stack, {
|
|
87
97
|
"data-state": getState(context.open),
|
|
88
98
|
"data-disabled": context.disabled ? "" : void 0,
|
|
89
99
|
id: context.contentId,
|
|
90
100
|
hidden: !isOpen,
|
|
91
101
|
...contentProps,
|
|
92
|
-
ref: composedRefs
|
|
93
|
-
|
|
102
|
+
ref: composedRefs,
|
|
103
|
+
children: isOpen && children
|
|
104
|
+
});
|
|
94
105
|
});
|
|
95
106
|
function getState(open) {
|
|
96
107
|
return open ? "open" : "closed";
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Collapsible.tsx"],
|
|
4
4
|
"sourcesContent": ["import { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n Stack,\n StackProps,\n TamaguiElement,\n composeEventHandlers,\n useIsomorphicLayoutEffect,\n} from '@tamagui/core'\nimport { useId } from '@tamagui/core'\nimport { createContextScope } from '@tamagui/create-context'\nimport type { Scope } from '@tamagui/create-context'\n// import { Presence } from '@tamagui/react-presence'\nimport { useControllableState } from '@tamagui/use-controllable-state'\nimport * as React from 'react'\n\n/* -------------------------------------------------------------------------------------------------\n * Collapsible\n * -----------------------------------------------------------------------------------------------*/\n\nconst COLLAPSIBLE_NAME = 'Collapsible'\n\ntype ScopedProps<P> = P & { __scopeCollapsible?: Scope }\nconst [createCollapsibleContext, createCollapsibleScope] = createContextScope(COLLAPSIBLE_NAME)\n\ntype CollapsibleContextValue = {\n contentId: string\n disabled?: boolean\n open: boolean\n onOpenToggle(): void\n}\n\nconst [CollapsibleProvider, useCollapsibleContext] =\n createCollapsibleContext<CollapsibleContextValue>(COLLAPSIBLE_NAME)\n\ntype CollapsibleElement = TamaguiElement\ninterface CollapsibleProps extends StackProps {\n defaultOpen?: boolean\n open?: boolean\n disabled?: boolean\n onOpenChange?(open: boolean): void\n}\n\nconst Collapsible = React.forwardRef<CollapsibleElement, CollapsibleProps>(\n (props: ScopedProps<CollapsibleProps>, forwardedRef) => {\n const {\n __scopeCollapsible,\n open: openProp,\n defaultOpen,\n disabled,\n onOpenChange,\n ...collapsibleProps\n } = props\n\n const [open, setOpen] = useControllableState({\n prop: openProp,\n defaultProp: defaultOpen || false,\n onChange: onOpenChange,\n })\n\n return (\n <CollapsibleProvider\n scope={__scopeCollapsible}\n disabled={disabled}\n contentId={useId() || ''}\n open={open}\n onOpenToggle={React.useCallback(() => setOpen((prevOpen) => !prevOpen), [setOpen])}\n >\n <Stack\n data-state={getState(open)}\n data-disabled={disabled ? '' : undefined}\n {...collapsibleProps}\n // @ts-expect-error\n ref={forwardedRef}\n />\n </CollapsibleProvider>\n )\n }\n)\n\nCollapsible.displayName = COLLAPSIBLE_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * CollapsibleTrigger\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRIGGER_NAME = 'CollapsibleTrigger'\n\ntype CollapsibleTriggerElement = TamaguiElement\ninterface CollapsibleTriggerProps extends StackProps {}\n\nconst CollapsibleTrigger = React.forwardRef<CollapsibleTriggerElement, CollapsibleTriggerProps>(\n (props: ScopedProps<CollapsibleTriggerProps>, forwardedRef) => {\n const { __scopeCollapsible, ...triggerProps } = props\n const context = useCollapsibleContext(TRIGGER_NAME, __scopeCollapsible)\n return (\n <Stack\n type=\"button\"\n aria-controls={context.contentId}\n aria-expanded={context.open || false}\n data-state={getState(context.open)}\n data-disabled={context.disabled ? '' : undefined}\n disabled={context.disabled}\n {...triggerProps}\n // @ts-expect-error\n ref={forwardedRef}\n onPress={composeEventHandlers(props.onPress, context.onOpenToggle)}\n />\n )\n }\n)\n\nCollapsibleTrigger.displayName = TRIGGER_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * CollapsibleContent\n * -----------------------------------------------------------------------------------------------*/\n\nconst CONTENT_NAME = 'CollapsibleContent'\n\ntype CollapsibleContentElement = CollapsibleContentImplElement\ninterface CollapsibleContentProps extends Omit<CollapsibleContentImplProps, 'present'> {\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true\n}\n\nconst CollapsibleContent = React.forwardRef<CollapsibleContentElement, CollapsibleContentProps>(\n (props: ScopedProps<CollapsibleContentProps>, forwardedRef) => {\n const { forceMount, ...contentProps } = props\n const context = useCollapsibleContext(CONTENT_NAME, props.__scopeCollapsible)\n return (\n // <Presence present={forceMount || context.open}>\n <>\n {({ present }) => (\n <CollapsibleContentImpl {...contentProps} ref={forwardedRef} present={present} />\n )}\n </>\n // </Presence>\n )\n }\n)\n\nCollapsibleContent.displayName = CONTENT_NAME\n\n/* -----------------------------------------------------------------------------------------------*/\n\ntype CollapsibleContentImplElement = TamaguiElement\ninterface CollapsibleContentImplProps extends StackProps {\n present: boolean\n}\n\nconst CollapsibleContentImpl = React.forwardRef<\n CollapsibleContentImplElement,\n CollapsibleContentImplProps\n>((props: ScopedProps<CollapsibleContentImplProps>, forwardedRef) => {\n const { __scopeCollapsible, present, children, ...contentProps } = props\n const context = useCollapsibleContext(CONTENT_NAME, __scopeCollapsible)\n const [isPresent, setIsPresent] = React.useState(present)\n const ref = React.useRef<CollapsibleContentImplElement>(null)\n const composedRefs = useComposedRefs(forwardedRef, ref)\n const heightRef = React.useRef<number | undefined>(0)\n const height = heightRef.current\n const widthRef = React.useRef<number | undefined>(0)\n const width = widthRef.current\n // when opening we want it to immediately open to retrieve dimensions\n // when closing we delay `present` to retrieve dimensions before closing\n const isOpen = context.open || isPresent\n const isMountAnimationPreventedRef = React.useRef(isOpen)\n const originalStylesRef = React.useRef<Record<string, string>>()\n\n React.useEffect(() => {\n const rAF = requestAnimationFrame(() => (isMountAnimationPreventedRef.current = false))\n return () => cancelAnimationFrame(rAF)\n }, [])\n\n // useIsomorphicLayoutEffect(() => {\n // const node = ref.current\n // if (node) {\n // originalStylesRef.current = originalStylesRef.current || {\n // transitionDuration: node.style.transitionDuration,\n // animationDuration: node.style.animationDuration,\n // animationFillMode: node.style.animationFillMode,\n // }\n // // block any animations/transitions so the element renders at its full dimensions\n // node.style.transitionDuration = '0s'\n // node.style.animationDuration = '0s'\n // node.style.animationFillMode = 'none'\n\n // // get width and height from full dimensions\n // const rect = node.getBoundingClientRect()\n // heightRef.current = rect.height\n // widthRef.current = rect.width\n\n // // kick off any animations/transitions that were originally set up if it isn't the initial mount\n // if (!isMountAnimationPreventedRef.current) {\n // node.style.transitionDuration = originalStylesRef.current.transitionDuration\n // node.style.animationDuration = originalStylesRef.current.animationDuration\n // node.style.animationFillMode = originalStylesRef.current.animationFillMode\n // }\n\n // setIsPresent(present)\n // }\n // /**\n // * depends on `context.open` because it will change to `false`\n // * when a close is triggered but `present` will be `false` on\n // * animation end (so when close finishes). This allows us to\n // * retrieve the dimensions *before* closing.\n // */\n // }, [context.open, present])\n\n return (\n <Stack\n data-state={getState(context.open)}\n data-disabled={context.disabled ? '' : undefined}\n id={context.contentId}\n hidden={!isOpen}\n {...contentProps}\n // @ts-expect-error\n ref={composedRefs}\n // style={{\n // [`--radix-collapsible-content-height` as any]: height ? `${height}px` : undefined,\n // [`--radix-collapsible-content-width` as any]: width ? `${width}px` : undefined,\n // ...props.style,\n // }}\n >\n {isOpen && children}\n </Stack>\n )\n})\n\n/* -----------------------------------------------------------------------------------------------*/\n\nfunction getState(open?: boolean) {\n return open ? 'open' : 'closed'\n}\n\nconst Root = Collapsible\nconst Trigger = CollapsibleTrigger\nconst Content = CollapsibleContent\n\nexport {\n createCollapsibleScope,\n //\n Collapsible,\n CollapsibleTrigger,\n CollapsibleContent,\n //\n Root,\n Trigger,\n Content,\n}\nexport type { CollapsibleProps, CollapsibleTriggerProps, CollapsibleContentProps }\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": "AAmEQ,SAmEF,UAnEE;AAnER,SAAS,uBAAuB;AAChC;AAAA,EACE;AAAA,EAGA;AAAA,OAEK;AACP,SAAS,aAAa;AACtB,SAAS,0BAA0B;AAGnC,SAAS,4BAA4B;AACrC,YAAY,WAAW;AAMvB,MAAM,mBAAmB;AAGzB,MAAM,CAAC,0BAA0B,sBAAsB,IAAI,mBAAmB,gBAAgB;AAS9F,MAAM,CAAC,qBAAqB,qBAAqB,IAC/C,yBAAkD,gBAAgB;AAUpE,MAAM,cAAc,MAAM;AAAA,EACxB,CAAC,OAAsC,iBAAiB;AACtD,UAAM;AAAA,MACJ;AAAA,MACA,MAAM;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,SACG;AAAA,IACL,IAAI;AAEJ,UAAM,CAAC,MAAM,OAAO,IAAI,qBAAqB;AAAA,MAC3C,MAAM;AAAA,MACN,aAAa,eAAe;AAAA,MAC5B,UAAU;AAAA,IACZ,CAAC;AAED,WACE,oBAAC;AAAA,MACC,OAAO;AAAA,MACP;AAAA,MACA,WAAW,MAAM,KAAK;AAAA,MACtB;AAAA,MACA,cAAc,MAAM,YAAY,MAAM,QAAQ,CAAC,aAAa,CAAC,QAAQ,GAAG,CAAC,OAAO,CAAC;AAAA,MAEjF,8BAAC;AAAA,QACC,cAAY,SAAS,IAAI;AAAA,QACzB,iBAAe,WAAW,KAAK;AAAA,QAC9B,GAAG;AAAA,QAEJ,KAAK;AAAA,OACP;AAAA,KACF;AAAA,EAEJ;AACF;AAEA,YAAY,cAAc;AAM1B,MAAM,eAAe;AAKrB,MAAM,qBAAqB,MAAM;AAAA,EAC/B,CAAC,OAA6C,iBAAiB;AAC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M,oBAAoB,MAAM,OAA+B;AAE/D,QAAM,UAAU,MAAM;AACpB,UAAM,MAAM,sBAAsB,MAAO,6BAA6B,UAAU,KAAM;AACtF,WAAO,MAAM,qBAAqB,GAAG;AAAA,EACvC,GAAG,CAAC,CAAC;AAqCL,SACE,oBAAC;AAAA,IACC,cAAY,SAAS,QAAQ,IAAI;AAAA,IACjC,iBAAe,QAAQ,WAAW,KAAK;AAAA,IACvC,IAAI,QAAQ;AAAA,IACZ,QAAQ,CAAC;AAAA,IACR,GAAG;AAAA,IAEJ,KAAK;AAAA,IAOJ,oBAAU;AAAA,GACb;AAEJ,CAAC;AAID,SAAS,SAAS,MAAgB;AAChC,SAAO,OAAO,SAAS;AACzB;AAEA,MAAM,OAAO;AACb,MAAM,UAAU;AAChB,MAAM,UAAU;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/index.js.map
CHANGED
package/dist/jsx/Collapsible.js
CHANGED
|
@@ -10,36 +10,42 @@ import * as React from "react";
|
|
|
10
10
|
const COLLAPSIBLE_NAME = "Collapsible";
|
|
11
11
|
const [createCollapsibleContext, createCollapsibleScope] = createContextScope(COLLAPSIBLE_NAME);
|
|
12
12
|
const [CollapsibleProvider, useCollapsibleContext] = createCollapsibleContext(COLLAPSIBLE_NAME);
|
|
13
|
-
const Collapsible = React.forwardRef(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
})
|
|
13
|
+
const Collapsible = React.forwardRef(
|
|
14
|
+
(props, forwardedRef) => {
|
|
15
|
+
const {
|
|
16
|
+
__scopeCollapsible,
|
|
17
|
+
open: openProp,
|
|
18
|
+
defaultOpen,
|
|
19
|
+
disabled,
|
|
20
|
+
onOpenChange,
|
|
21
|
+
...collapsibleProps
|
|
22
|
+
} = props;
|
|
23
|
+
const [open, setOpen] = useControllableState({
|
|
24
|
+
prop: openProp,
|
|
25
|
+
defaultProp: defaultOpen || false,
|
|
26
|
+
onChange: onOpenChange
|
|
27
|
+
});
|
|
28
|
+
return <CollapsibleProvider scope={__scopeCollapsible} disabled={disabled} contentId={useId() || ""} open={open} onOpenToggle={React.useCallback(() => setOpen((prevOpen) => !prevOpen), [setOpen])}><Stack data-state={getState(open)} data-disabled={disabled ? "" : void 0} {...collapsibleProps} ref={forwardedRef} /></CollapsibleProvider>;
|
|
29
|
+
}
|
|
30
|
+
);
|
|
29
31
|
Collapsible.displayName = COLLAPSIBLE_NAME;
|
|
30
32
|
const TRIGGER_NAME = "CollapsibleTrigger";
|
|
31
|
-
const CollapsibleTrigger = React.forwardRef(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
})
|
|
33
|
+
const CollapsibleTrigger = React.forwardRef(
|
|
34
|
+
(props, forwardedRef) => {
|
|
35
|
+
const { __scopeCollapsible, ...triggerProps } = props;
|
|
36
|
+
const context = useCollapsibleContext(TRIGGER_NAME, __scopeCollapsible);
|
|
37
|
+
return <Stack type="button" aria-controls={context.contentId} aria-expanded={context.open || false} data-state={getState(context.open)} data-disabled={context.disabled ? "" : void 0} disabled={context.disabled} {...triggerProps} ref={forwardedRef} onPress={composeEventHandlers(props.onPress, context.onOpenToggle)} />;
|
|
38
|
+
}
|
|
39
|
+
);
|
|
36
40
|
CollapsibleTrigger.displayName = TRIGGER_NAME;
|
|
37
41
|
const CONTENT_NAME = "CollapsibleContent";
|
|
38
|
-
const CollapsibleContent = React.forwardRef(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
})
|
|
42
|
+
const CollapsibleContent = React.forwardRef(
|
|
43
|
+
(props, forwardedRef) => {
|
|
44
|
+
const { forceMount, ...contentProps } = props;
|
|
45
|
+
const context = useCollapsibleContext(CONTENT_NAME, props.__scopeCollapsible);
|
|
46
|
+
return <>{({ present }) => <CollapsibleContentImpl {...contentProps} ref={forwardedRef} present={present} />}</>;
|
|
47
|
+
}
|
|
48
|
+
);
|
|
43
49
|
CollapsibleContent.displayName = CONTENT_NAME;
|
|
44
50
|
const CollapsibleContentImpl = React.forwardRef((props, forwardedRef) => {
|
|
45
51
|
const { __scopeCollapsible, present, children, ...contentProps } = props;
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Collapsible.tsx"],
|
|
4
4
|
"sourcesContent": ["import { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n Stack,\n StackProps,\n TamaguiElement,\n composeEventHandlers,\n useIsomorphicLayoutEffect,\n} from '@tamagui/core'\nimport { useId } from '@tamagui/core'\nimport { createContextScope } from '@tamagui/create-context'\nimport type { Scope } from '@tamagui/create-context'\n// import { Presence } from '@tamagui/react-presence'\nimport { useControllableState } from '@tamagui/use-controllable-state'\nimport * as React from 'react'\n\n/* -------------------------------------------------------------------------------------------------\n * Collapsible\n * -----------------------------------------------------------------------------------------------*/\n\nconst COLLAPSIBLE_NAME = 'Collapsible'\n\ntype ScopedProps<P> = P & { __scopeCollapsible?: Scope }\nconst [createCollapsibleContext, createCollapsibleScope] = createContextScope(COLLAPSIBLE_NAME)\n\ntype CollapsibleContextValue = {\n contentId: string\n disabled?: boolean\n open: boolean\n onOpenToggle(): void\n}\n\nconst [CollapsibleProvider, useCollapsibleContext] =\n createCollapsibleContext<CollapsibleContextValue>(COLLAPSIBLE_NAME)\n\ntype CollapsibleElement = TamaguiElement\ninterface CollapsibleProps extends StackProps {\n defaultOpen?: boolean\n open?: boolean\n disabled?: boolean\n onOpenChange?(open: boolean): void\n}\n\nconst Collapsible = React.forwardRef<CollapsibleElement, CollapsibleProps>(\n (props: ScopedProps<CollapsibleProps>, forwardedRef) => {\n const {\n __scopeCollapsible,\n open: openProp,\n defaultOpen,\n disabled,\n onOpenChange,\n ...collapsibleProps\n } = props\n\n const [open, setOpen] = useControllableState({\n prop: openProp,\n defaultProp: defaultOpen || false,\n onChange: onOpenChange,\n })\n\n return (\n <CollapsibleProvider\n scope={__scopeCollapsible}\n disabled={disabled}\n contentId={useId() || ''}\n open={open}\n onOpenToggle={React.useCallback(() => setOpen((prevOpen) => !prevOpen), [setOpen])}\n >\n <Stack\n data-state={getState(open)}\n data-disabled={disabled ? '' : undefined}\n {...collapsibleProps}\n // @ts-expect-error\n ref={forwardedRef}\n />\n </CollapsibleProvider>\n )\n }\n)\n\nCollapsible.displayName = COLLAPSIBLE_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * CollapsibleTrigger\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRIGGER_NAME = 'CollapsibleTrigger'\n\ntype CollapsibleTriggerElement = TamaguiElement\ninterface CollapsibleTriggerProps extends StackProps {}\n\nconst CollapsibleTrigger = React.forwardRef<CollapsibleTriggerElement, CollapsibleTriggerProps>(\n (props: ScopedProps<CollapsibleTriggerProps>, forwardedRef) => {\n const { __scopeCollapsible, ...triggerProps } = props\n const context = useCollapsibleContext(TRIGGER_NAME, __scopeCollapsible)\n return (\n <Stack\n type=\"button\"\n aria-controls={context.contentId}\n aria-expanded={context.open || false}\n data-state={getState(context.open)}\n data-disabled={context.disabled ? '' : undefined}\n disabled={context.disabled}\n {...triggerProps}\n // @ts-expect-error\n ref={forwardedRef}\n onPress={composeEventHandlers(props.onPress, context.onOpenToggle)}\n />\n )\n }\n)\n\nCollapsibleTrigger.displayName = TRIGGER_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * CollapsibleContent\n * -----------------------------------------------------------------------------------------------*/\n\nconst CONTENT_NAME = 'CollapsibleContent'\n\ntype CollapsibleContentElement = CollapsibleContentImplElement\ninterface CollapsibleContentProps extends Omit<CollapsibleContentImplProps, 'present'> {\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true\n}\n\nconst CollapsibleContent = React.forwardRef<CollapsibleContentElement, CollapsibleContentProps>(\n (props: ScopedProps<CollapsibleContentProps>, forwardedRef) => {\n const { forceMount, ...contentProps } = props\n const context = useCollapsibleContext(CONTENT_NAME, props.__scopeCollapsible)\n return (\n // <Presence present={forceMount || context.open}>\n <>\n {({ present }) => (\n <CollapsibleContentImpl {...contentProps} ref={forwardedRef} present={present} />\n )}\n </>\n // </Presence>\n )\n }\n)\n\nCollapsibleContent.displayName = CONTENT_NAME\n\n/* -----------------------------------------------------------------------------------------------*/\n\ntype CollapsibleContentImplElement = TamaguiElement\ninterface CollapsibleContentImplProps extends StackProps {\n present: boolean\n}\n\nconst CollapsibleContentImpl = React.forwardRef<\n CollapsibleContentImplElement,\n CollapsibleContentImplProps\n>((props: ScopedProps<CollapsibleContentImplProps>, forwardedRef) => {\n const { __scopeCollapsible, present, children, ...contentProps } = props\n const context = useCollapsibleContext(CONTENT_NAME, __scopeCollapsible)\n const [isPresent, setIsPresent] = React.useState(present)\n const ref = React.useRef<CollapsibleContentImplElement>(null)\n const composedRefs = useComposedRefs(forwardedRef, ref)\n const heightRef = React.useRef<number | undefined>(0)\n const height = heightRef.current\n const widthRef = React.useRef<number | undefined>(0)\n const width = widthRef.current\n // when opening we want it to immediately open to retrieve dimensions\n // when closing we delay `present` to retrieve dimensions before closing\n const isOpen = context.open || isPresent\n const isMountAnimationPreventedRef = React.useRef(isOpen)\n const originalStylesRef = React.useRef<Record<string, string>>()\n\n React.useEffect(() => {\n const rAF = requestAnimationFrame(() => (isMountAnimationPreventedRef.current = false))\n return () => cancelAnimationFrame(rAF)\n }, [])\n\n // useIsomorphicLayoutEffect(() => {\n // const node = ref.current\n // if (node) {\n // originalStylesRef.current = originalStylesRef.current || {\n // transitionDuration: node.style.transitionDuration,\n // animationDuration: node.style.animationDuration,\n // animationFillMode: node.style.animationFillMode,\n // }\n // // block any animations/transitions so the element renders at its full dimensions\n // node.style.transitionDuration = '0s'\n // node.style.animationDuration = '0s'\n // node.style.animationFillMode = 'none'\n\n // // get width and height from full dimensions\n // const rect = node.getBoundingClientRect()\n // heightRef.current = rect.height\n // widthRef.current = rect.width\n\n // // kick off any animations/transitions that were originally set up if it isn't the initial mount\n // if (!isMountAnimationPreventedRef.current) {\n // node.style.transitionDuration = originalStylesRef.current.transitionDuration\n // node.style.animationDuration = originalStylesRef.current.animationDuration\n // node.style.animationFillMode = originalStylesRef.current.animationFillMode\n // }\n\n // setIsPresent(present)\n // }\n // /**\n // * depends on `context.open` because it will change to `false`\n // * when a close is triggered but `present` will be `false` on\n // * animation end (so when close finishes). This allows us to\n // * retrieve the dimensions *before* closing.\n // */\n // }, [context.open, present])\n\n return (\n <Stack\n data-state={getState(context.open)}\n data-disabled={context.disabled ? '' : undefined}\n id={context.contentId}\n hidden={!isOpen}\n {...contentProps}\n // @ts-expect-error\n ref={composedRefs}\n // style={{\n // [`--radix-collapsible-content-height` as any]: height ? `${height}px` : undefined,\n // [`--radix-collapsible-content-width` as any]: width ? `${width}px` : undefined,\n // ...props.style,\n // }}\n >\n {isOpen && children}\n </Stack>\n )\n})\n\n/* -----------------------------------------------------------------------------------------------*/\n\nfunction getState(open?: boolean) {\n return open ? 'open' : 'closed'\n}\n\nconst Root = Collapsible\nconst Trigger = CollapsibleTrigger\nconst Content = CollapsibleContent\n\nexport {\n createCollapsibleScope,\n //\n Collapsible,\n CollapsibleTrigger,\n CollapsibleContent,\n //\n Root,\n Trigger,\n Content,\n}\nexport type { CollapsibleProps, CollapsibleTriggerProps, CollapsibleContentProps }\n"],
|
|
5
|
-
"mappings": "AAAA;
|
|
5
|
+
"mappings": "AAAA,SAAS,uBAAuB;AAChC;AAAA,EACE;AAAA,EAGA;AAAA,OAEK;AACP,SAAS,aAAa;AACtB,SAAS,0BAA0B;AAGnC,SAAS,4BAA4B;AACrC,YAAY,WAAW;AAMvB,MAAM,mBAAmB;AAGzB,MAAM,CAAC,0BAA0B,sBAAsB,IAAI,mBAAmB,gBAAgB;AAS9F,MAAM,CAAC,qBAAqB,qBAAqB,IAC/C,yBAAkD,gBAAgB;AAUpE,MAAM,c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AS,SAAS,GAEnF;AAAA,EAGJ;AACF;AAEA,mBAAmB,cAAc;AASjC,MAAM,yBAAyB,MAAM,WAGnC,CAAC,OAAiD,iBAAiB;AACnE,QAAM,EAAE,oBAAoB,SAAS,aAAa,aAAa,IAAI;AACnE,QAAM,UAAU,sBAAsB,cAAc,kBAAkB;AACtE,QAAM,CAAC,WAAW,YAAY,IAAI,MAAM,SAAS,OAAO;AACxD,QAAM,MAAM,MAAM,OAAsC,IAAI;AAC5D,QAAM,eAAe,gBAAgB,cAAc,GAAG;AACtD,QAAM,YAAY,MAAM,OAA2B,CAAC;AACpD,QAAM,SAAS,UAAU;AACzB,QAAM,WAAW,MAAM,OAA2B,CAAC;AACnD,QAAM,QAAQ,SAAS;AAGvB,QAAM,SAAS,QAAQ,QAAQ;AAC/B,QAAM,+BAA+B,MAAM,OAAO,MAAM;AACxD,QAAM,oBAAoB,MAAM,OAA+B;AAE/D,QAAM,UAAU,MAAM;AACpB,UAAM,MAAM,sBAAsB,MAAO,6BAA6B,UAAU,KAAM;AACtF,WAAO,MAAM,qBAAqB,GAAG;AAAA,EACvC,GAAG,CAAC,CAAC;AAqCL,SACE,CAAC,MACC,YAAY,SAAS,QAAQ,IAAI,GACjC,eAAe,QAAQ,WAAW,KAAK,QACvC,IAAI,QAAQ,WACZ,QAAQ,CAAC,YACL,cAEJ,KAAK,eAOJ,UAAU,SACb,EAfC;AAiBL,CAAC;AAID,SAAS,SAAS,MAAgB;AAChC,SAAO,OAAO,SAAS;AACzB;AAEA,MAAM,OAAO;AACb,MAAM,UAAU;AAChB,MAAM,UAAU;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/jsx/index.js.map
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/collapsible",
|
|
3
|
-
"version": "1.0.1-beta.
|
|
3
|
+
"version": "1.0.1-beta.153",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
@@ -17,19 +17,19 @@
|
|
|
17
17
|
"watch": "tamagui-build --watch"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@tamagui/compose-refs": "^1.0.1-beta.
|
|
21
|
-
"@tamagui/core": "^1.0.1-beta.
|
|
22
|
-
"@tamagui/create-context": "^1.0.1-beta.
|
|
23
|
-
"@tamagui/polyfill-dev": "^1.0.1-beta.
|
|
24
|
-
"@tamagui/stacks": "^1.0.1-beta.
|
|
25
|
-
"@tamagui/use-controllable-state": "^1.0.1-beta.
|
|
20
|
+
"@tamagui/compose-refs": "^1.0.1-beta.153",
|
|
21
|
+
"@tamagui/core": "^1.0.1-beta.153",
|
|
22
|
+
"@tamagui/create-context": "^1.0.1-beta.153",
|
|
23
|
+
"@tamagui/polyfill-dev": "^1.0.1-beta.153",
|
|
24
|
+
"@tamagui/stacks": "^1.0.1-beta.153",
|
|
25
|
+
"@tamagui/use-controllable-state": "^1.0.1-beta.153"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"react": "*",
|
|
29
29
|
"react-dom": "*"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@tamagui/build": "^1.0.1-beta.
|
|
32
|
+
"@tamagui/build": "^1.0.1-beta.153",
|
|
33
33
|
"react": "*",
|
|
34
34
|
"react-dom": "*"
|
|
35
35
|
},
|