@tamagui/collapsible 1.0.1-beta.99 → 1.0.1-rc.0
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 +4 -147
- package/dist/cjs/Collapsible.js.map +2 -2
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/Collapsible.js +2 -142
- package/dist/esm/Collapsible.js.map +2 -2
- package/dist/esm/index.js +0 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/jsx/Collapsible.js +2 -75
- package/dist/jsx/Collapsible.js.map +2 -2
- package/dist/jsx/index.js +0 -0
- package/dist/jsx/index.js.map +1 -1
- package/package.json +12 -16
- package/src/Collapsible.tsx +248 -254
- package/types/Collapsible.d.ts +1 -25
- package/types/index.d.ts +0 -0
- package/types/Collapsible.d.ts.map +0 -1
- package/types/index.d.ts.map +0 -1
package/dist/cjs/Collapsible.js
CHANGED
|
@@ -1,38 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
9
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
-
var __spreadValues = (a, b) => {
|
|
13
|
-
for (var prop in b || (b = {}))
|
|
14
|
-
if (__hasOwnProp.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
if (__getOwnPropSymbols)
|
|
17
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
-
if (__propIsEnum.call(b, prop))
|
|
19
|
-
__defNormalProp(a, prop, b[prop]);
|
|
20
|
-
}
|
|
21
|
-
return a;
|
|
22
|
-
};
|
|
23
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
-
var __objRest = (source, exclude) => {
|
|
25
|
-
var target = {};
|
|
26
|
-
for (var prop in source)
|
|
27
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
if (source != null && __getOwnPropSymbols)
|
|
30
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
31
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
32
|
-
target[prop] = source[prop];
|
|
33
|
-
}
|
|
34
|
-
return target;
|
|
35
|
-
};
|
|
36
6
|
var __export = (target, all) => {
|
|
37
7
|
for (var name in all)
|
|
38
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -45,128 +15,15 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
45
15
|
}
|
|
46
16
|
return to;
|
|
47
17
|
};
|
|
48
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
49
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
50
19
|
var Collapsible_exports = {};
|
|
51
20
|
__export(Collapsible_exports, {
|
|
52
|
-
Collapsible: () => Collapsible
|
|
53
|
-
CollapsibleContent: () => CollapsibleContent,
|
|
54
|
-
CollapsibleTrigger: () => CollapsibleTrigger,
|
|
55
|
-
Content: () => Content,
|
|
56
|
-
Root: () => Root,
|
|
57
|
-
Trigger: () => Trigger,
|
|
58
|
-
createCollapsibleScope: () => createCollapsibleScope
|
|
21
|
+
Collapsible: () => Collapsible
|
|
59
22
|
});
|
|
60
23
|
module.exports = __toCommonJS(Collapsible_exports);
|
|
61
|
-
|
|
62
|
-
var import_core = require("@tamagui/core");
|
|
63
|
-
var import_core2 = require("@tamagui/core");
|
|
64
|
-
var import_create_context = require("@tamagui/create-context");
|
|
65
|
-
var import_use_controllable_state = require("@tamagui/use-controllable-state");
|
|
66
|
-
var React = __toESM(require("react"));
|
|
67
|
-
const COLLAPSIBLE_NAME = "Collapsible";
|
|
68
|
-
const [createCollapsibleContext, createCollapsibleScope] = (0, import_create_context.createContextScope)(COLLAPSIBLE_NAME);
|
|
69
|
-
const [CollapsibleProvider, useCollapsibleContext] = createCollapsibleContext(COLLAPSIBLE_NAME);
|
|
70
|
-
const Collapsible = React.forwardRef((props, forwardedRef) => {
|
|
71
|
-
const _a = props, {
|
|
72
|
-
__scopeCollapsible,
|
|
73
|
-
open: openProp,
|
|
74
|
-
defaultOpen,
|
|
75
|
-
disabled,
|
|
76
|
-
onOpenChange
|
|
77
|
-
} = _a, collapsibleProps = __objRest(_a, [
|
|
78
|
-
"__scopeCollapsible",
|
|
79
|
-
"open",
|
|
80
|
-
"defaultOpen",
|
|
81
|
-
"disabled",
|
|
82
|
-
"onOpenChange"
|
|
83
|
-
]);
|
|
84
|
-
const [open, setOpen] = (0, import_use_controllable_state.useControllableState)({
|
|
85
|
-
prop: openProp,
|
|
86
|
-
defaultProp: defaultOpen || false,
|
|
87
|
-
onChange: onOpenChange
|
|
88
|
-
});
|
|
89
|
-
return /* @__PURE__ */ React.createElement(CollapsibleProvider, {
|
|
90
|
-
scope: __scopeCollapsible,
|
|
91
|
-
disabled,
|
|
92
|
-
contentId: (0, import_core2.useId)() || "",
|
|
93
|
-
open,
|
|
94
|
-
onOpenToggle: React.useCallback(() => setOpen((prevOpen) => !prevOpen), [setOpen])
|
|
95
|
-
}, /* @__PURE__ */ React.createElement(import_core.Stack, __spreadProps(__spreadValues({
|
|
96
|
-
"data-state": getState(open),
|
|
97
|
-
"data-disabled": disabled ? "" : void 0
|
|
98
|
-
}, collapsibleProps), {
|
|
99
|
-
ref: forwardedRef
|
|
100
|
-
})));
|
|
101
|
-
});
|
|
102
|
-
Collapsible.displayName = COLLAPSIBLE_NAME;
|
|
103
|
-
const TRIGGER_NAME = "CollapsibleTrigger";
|
|
104
|
-
const CollapsibleTrigger = React.forwardRef((props, forwardedRef) => {
|
|
105
|
-
const _a = props, { __scopeCollapsible } = _a, triggerProps = __objRest(_a, ["__scopeCollapsible"]);
|
|
106
|
-
const context = useCollapsibleContext(TRIGGER_NAME, __scopeCollapsible);
|
|
107
|
-
return /* @__PURE__ */ React.createElement(import_core.Stack, __spreadProps(__spreadValues({
|
|
108
|
-
type: "button",
|
|
109
|
-
"aria-controls": context.contentId,
|
|
110
|
-
"aria-expanded": context.open || false,
|
|
111
|
-
"data-state": getState(context.open),
|
|
112
|
-
"data-disabled": context.disabled ? "" : void 0,
|
|
113
|
-
disabled: context.disabled
|
|
114
|
-
}, triggerProps), {
|
|
115
|
-
ref: forwardedRef,
|
|
116
|
-
onPress: (0, import_core.composeEventHandlers)(props.onPress, context.onOpenToggle)
|
|
117
|
-
}));
|
|
118
|
-
});
|
|
119
|
-
CollapsibleTrigger.displayName = TRIGGER_NAME;
|
|
120
|
-
const CONTENT_NAME = "CollapsibleContent";
|
|
121
|
-
const CollapsibleContent = React.forwardRef((props, forwardedRef) => {
|
|
122
|
-
const _a = props, { forceMount } = _a, contentProps = __objRest(_a, ["forceMount"]);
|
|
123
|
-
const context = useCollapsibleContext(CONTENT_NAME, props.__scopeCollapsible);
|
|
124
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, ({ present }) => /* @__PURE__ */ React.createElement(CollapsibleContentImpl, __spreadProps(__spreadValues({}, contentProps), {
|
|
125
|
-
ref: forwardedRef,
|
|
126
|
-
present
|
|
127
|
-
})));
|
|
128
|
-
});
|
|
129
|
-
CollapsibleContent.displayName = CONTENT_NAME;
|
|
130
|
-
const CollapsibleContentImpl = React.forwardRef((props, forwardedRef) => {
|
|
131
|
-
const _a = props, { __scopeCollapsible, present, children } = _a, contentProps = __objRest(_a, ["__scopeCollapsible", "present", "children"]);
|
|
132
|
-
const context = useCollapsibleContext(CONTENT_NAME, __scopeCollapsible);
|
|
133
|
-
const [isPresent, setIsPresent] = React.useState(present);
|
|
134
|
-
const ref = React.useRef(null);
|
|
135
|
-
const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref);
|
|
136
|
-
const heightRef = React.useRef(0);
|
|
137
|
-
const height = heightRef.current;
|
|
138
|
-
const widthRef = React.useRef(0);
|
|
139
|
-
const width = widthRef.current;
|
|
140
|
-
const isOpen = context.open || isPresent;
|
|
141
|
-
const isMountAnimationPreventedRef = React.useRef(isOpen);
|
|
142
|
-
const originalStylesRef = React.useRef();
|
|
143
|
-
React.useEffect(() => {
|
|
144
|
-
const rAF = requestAnimationFrame(() => isMountAnimationPreventedRef.current = false);
|
|
145
|
-
return () => cancelAnimationFrame(rAF);
|
|
146
|
-
}, []);
|
|
147
|
-
return /* @__PURE__ */ React.createElement(import_core.Stack, __spreadProps(__spreadValues({
|
|
148
|
-
"data-state": getState(context.open),
|
|
149
|
-
"data-disabled": context.disabled ? "" : void 0,
|
|
150
|
-
id: context.contentId,
|
|
151
|
-
hidden: !isOpen
|
|
152
|
-
}, contentProps), {
|
|
153
|
-
ref: composedRefs
|
|
154
|
-
}), isOpen && children);
|
|
155
|
-
});
|
|
156
|
-
function getState(open) {
|
|
157
|
-
return open ? "open" : "closed";
|
|
158
|
-
}
|
|
159
|
-
const Root = Collapsible;
|
|
160
|
-
const Trigger = CollapsibleTrigger;
|
|
161
|
-
const Content = CollapsibleContent;
|
|
24
|
+
const Collapsible = {};
|
|
162
25
|
// Annotate the CommonJS export names for ESM import in node:
|
|
163
26
|
0 && (module.exports = {
|
|
164
|
-
Collapsible
|
|
165
|
-
CollapsibleContent,
|
|
166
|
-
CollapsibleTrigger,
|
|
167
|
-
Content,
|
|
168
|
-
Root,
|
|
169
|
-
Trigger,
|
|
170
|
-
createCollapsibleScope
|
|
27
|
+
Collapsible
|
|
171
28
|
});
|
|
172
29
|
//# sourceMappingURL=Collapsible.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Collapsible.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useComposedRefs } from '@tamagui/compose-refs'\
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["export const Collapsible = {}\n\n// import { useComposedRefs } from '@tamagui/compose-refs'\n// import { Stack, StackProps, TamaguiElement, composeEventHandlers, useId } from '@tamagui/core'\n// import type { Scope } from '@tamagui/create-context'\n// import { createContextScope } from '@tamagui/create-context'\n// // import { Presence } from '@tamagui/react-presence'\n// import { useControllableState } from '@tamagui/use-controllable-state'\n// import * as React from 'react'\n\n// /* -------------------------------------------------------------------------------------------------\n// * Collapsible\n// * -----------------------------------------------------------------------------------------------*/\n\n// const COLLAPSIBLE_NAME = 'Collapsible'\n\n// type ScopedProps<P> = P & { __scopeCollapsible?: Scope }\n// const [createCollapsibleContext, createCollapsibleScope] = createContextScope(COLLAPSIBLE_NAME)\n\n// type CollapsibleContextValue = {\n// contentId: string\n// disabled?: boolean\n// open: boolean\n// onOpenToggle(): void\n// }\n\n// const [CollapsibleProvider, useCollapsibleContext] =\n// createCollapsibleContext<CollapsibleContextValue>(COLLAPSIBLE_NAME)\n\n// type CollapsibleElement = TamaguiElement\n// interface CollapsibleProps extends StackProps {\n// defaultOpen?: boolean\n// open?: boolean\n// disabled?: boolean\n// onOpenChange?(open: boolean): void\n// }\n\n// const 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// ref={forwardedRef}\n// />\n// </CollapsibleProvider>\n// )\n// }\n// )\n\n// Collapsible.displayName = COLLAPSIBLE_NAME\n\n// /* -------------------------------------------------------------------------------------------------\n// * CollapsibleTrigger\n// * -----------------------------------------------------------------------------------------------*/\n\n// const TRIGGER_NAME = 'CollapsibleTrigger'\n\n// type CollapsibleTriggerElement = TamaguiElement\n// interface CollapsibleTriggerProps extends StackProps {}\n\n// const 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// ref={forwardedRef}\n// //\n// // onPress={composeEventHandlers(props.onPress, context.onOpenToggle)}\n// />\n// )\n// }\n// )\n\n// CollapsibleTrigger.displayName = TRIGGER_NAME\n\n// /* -------------------------------------------------------------------------------------------------\n// * CollapsibleContent\n// * -----------------------------------------------------------------------------------------------*/\n\n// const CONTENT_NAME = 'CollapsibleContent'\n\n// type CollapsibleContentElement = CollapsibleContentImplElement\n// interface 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\n// const 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\n// CollapsibleContent.displayName = CONTENT_NAME\n\n// /* -----------------------------------------------------------------------------------------------*/\n\n// type CollapsibleContentImplElement = TamaguiElement\n// interface CollapsibleContentImplProps extends StackProps {\n// present: boolean\n// }\n\n// const 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\n// function getState(open?: boolean) {\n// return open ? 'open' : 'closed'\n// }\n\n// const Root = Collapsible\n// const Trigger = CollapsibleTrigger\n// const Content = CollapsibleContent\n\n// export {\n// createCollapsibleScope,\n// //\n// Collapsible,\n// CollapsibleTrigger,\n// CollapsibleContent,\n// //\n// Root,\n// Trigger,\n// Content,\n// }\n// export type { CollapsibleProps, CollapsibleTriggerProps, CollapsibleContentProps }\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,cAAc,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/index.js
CHANGED
package/dist/cjs/index.js.map
CHANGED
package/dist/esm/Collapsible.js
CHANGED
|
@@ -1,145 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __objRest = (source, exclude) => {
|
|
21
|
-
var target = {};
|
|
22
|
-
for (var prop in source)
|
|
23
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
-
target[prop] = source[prop];
|
|
25
|
-
if (source != null && __getOwnPropSymbols)
|
|
26
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
}
|
|
30
|
-
return target;
|
|
31
|
-
};
|
|
32
|
-
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
33
|
-
import {
|
|
34
|
-
Stack,
|
|
35
|
-
composeEventHandlers
|
|
36
|
-
} from "@tamagui/core";
|
|
37
|
-
import { useId } from "@tamagui/core";
|
|
38
|
-
import { createContextScope } from "@tamagui/create-context";
|
|
39
|
-
import { useControllableState } from "@tamagui/use-controllable-state";
|
|
40
|
-
import * as React from "react";
|
|
41
|
-
const COLLAPSIBLE_NAME = "Collapsible";
|
|
42
|
-
const [createCollapsibleContext, createCollapsibleScope] = createContextScope(COLLAPSIBLE_NAME);
|
|
43
|
-
const [CollapsibleProvider, useCollapsibleContext] = createCollapsibleContext(COLLAPSIBLE_NAME);
|
|
44
|
-
const Collapsible = React.forwardRef((props, forwardedRef) => {
|
|
45
|
-
const _a = props, {
|
|
46
|
-
__scopeCollapsible,
|
|
47
|
-
open: openProp,
|
|
48
|
-
defaultOpen,
|
|
49
|
-
disabled,
|
|
50
|
-
onOpenChange
|
|
51
|
-
} = _a, collapsibleProps = __objRest(_a, [
|
|
52
|
-
"__scopeCollapsible",
|
|
53
|
-
"open",
|
|
54
|
-
"defaultOpen",
|
|
55
|
-
"disabled",
|
|
56
|
-
"onOpenChange"
|
|
57
|
-
]);
|
|
58
|
-
const [open, setOpen] = useControllableState({
|
|
59
|
-
prop: openProp,
|
|
60
|
-
defaultProp: defaultOpen || false,
|
|
61
|
-
onChange: onOpenChange
|
|
62
|
-
});
|
|
63
|
-
return /* @__PURE__ */ React.createElement(CollapsibleProvider, {
|
|
64
|
-
scope: __scopeCollapsible,
|
|
65
|
-
disabled,
|
|
66
|
-
contentId: useId() || "",
|
|
67
|
-
open,
|
|
68
|
-
onOpenToggle: React.useCallback(() => setOpen((prevOpen) => !prevOpen), [setOpen])
|
|
69
|
-
}, /* @__PURE__ */ React.createElement(Stack, __spreadProps(__spreadValues({
|
|
70
|
-
"data-state": getState(open),
|
|
71
|
-
"data-disabled": disabled ? "" : void 0
|
|
72
|
-
}, collapsibleProps), {
|
|
73
|
-
ref: forwardedRef
|
|
74
|
-
})));
|
|
75
|
-
});
|
|
76
|
-
Collapsible.displayName = COLLAPSIBLE_NAME;
|
|
77
|
-
const TRIGGER_NAME = "CollapsibleTrigger";
|
|
78
|
-
const CollapsibleTrigger = React.forwardRef((props, forwardedRef) => {
|
|
79
|
-
const _a = props, { __scopeCollapsible } = _a, triggerProps = __objRest(_a, ["__scopeCollapsible"]);
|
|
80
|
-
const context = useCollapsibleContext(TRIGGER_NAME, __scopeCollapsible);
|
|
81
|
-
return /* @__PURE__ */ React.createElement(Stack, __spreadProps(__spreadValues({
|
|
82
|
-
type: "button",
|
|
83
|
-
"aria-controls": context.contentId,
|
|
84
|
-
"aria-expanded": context.open || false,
|
|
85
|
-
"data-state": getState(context.open),
|
|
86
|
-
"data-disabled": context.disabled ? "" : void 0,
|
|
87
|
-
disabled: context.disabled
|
|
88
|
-
}, triggerProps), {
|
|
89
|
-
ref: forwardedRef,
|
|
90
|
-
onPress: composeEventHandlers(props.onPress, context.onOpenToggle)
|
|
91
|
-
}));
|
|
92
|
-
});
|
|
93
|
-
CollapsibleTrigger.displayName = TRIGGER_NAME;
|
|
94
|
-
const CONTENT_NAME = "CollapsibleContent";
|
|
95
|
-
const CollapsibleContent = React.forwardRef((props, forwardedRef) => {
|
|
96
|
-
const _a = props, { forceMount } = _a, contentProps = __objRest(_a, ["forceMount"]);
|
|
97
|
-
const context = useCollapsibleContext(CONTENT_NAME, props.__scopeCollapsible);
|
|
98
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, ({ present }) => /* @__PURE__ */ React.createElement(CollapsibleContentImpl, __spreadProps(__spreadValues({}, contentProps), {
|
|
99
|
-
ref: forwardedRef,
|
|
100
|
-
present
|
|
101
|
-
})));
|
|
102
|
-
});
|
|
103
|
-
CollapsibleContent.displayName = CONTENT_NAME;
|
|
104
|
-
const CollapsibleContentImpl = React.forwardRef((props, forwardedRef) => {
|
|
105
|
-
const _a = props, { __scopeCollapsible, present, children } = _a, contentProps = __objRest(_a, ["__scopeCollapsible", "present", "children"]);
|
|
106
|
-
const context = useCollapsibleContext(CONTENT_NAME, __scopeCollapsible);
|
|
107
|
-
const [isPresent, setIsPresent] = React.useState(present);
|
|
108
|
-
const ref = React.useRef(null);
|
|
109
|
-
const composedRefs = useComposedRefs(forwardedRef, ref);
|
|
110
|
-
const heightRef = React.useRef(0);
|
|
111
|
-
const height = heightRef.current;
|
|
112
|
-
const widthRef = React.useRef(0);
|
|
113
|
-
const width = widthRef.current;
|
|
114
|
-
const isOpen = context.open || isPresent;
|
|
115
|
-
const isMountAnimationPreventedRef = React.useRef(isOpen);
|
|
116
|
-
const originalStylesRef = React.useRef();
|
|
117
|
-
React.useEffect(() => {
|
|
118
|
-
const rAF = requestAnimationFrame(() => isMountAnimationPreventedRef.current = false);
|
|
119
|
-
return () => cancelAnimationFrame(rAF);
|
|
120
|
-
}, []);
|
|
121
|
-
return /* @__PURE__ */ React.createElement(Stack, __spreadProps(__spreadValues({
|
|
122
|
-
"data-state": getState(context.open),
|
|
123
|
-
"data-disabled": context.disabled ? "" : void 0,
|
|
124
|
-
id: context.contentId,
|
|
125
|
-
hidden: !isOpen
|
|
126
|
-
}, contentProps), {
|
|
127
|
-
ref: composedRefs
|
|
128
|
-
}), isOpen && children);
|
|
129
|
-
});
|
|
130
|
-
function getState(open) {
|
|
131
|
-
return open ? "open" : "closed";
|
|
132
|
-
}
|
|
133
|
-
const Root = Collapsible;
|
|
134
|
-
const Trigger = CollapsibleTrigger;
|
|
135
|
-
const Content = CollapsibleContent;
|
|
1
|
+
const Collapsible = {};
|
|
136
2
|
export {
|
|
137
|
-
Collapsible
|
|
138
|
-
CollapsibleContent,
|
|
139
|
-
CollapsibleTrigger,
|
|
140
|
-
Content,
|
|
141
|
-
Root,
|
|
142
|
-
Trigger,
|
|
143
|
-
createCollapsibleScope
|
|
3
|
+
Collapsible
|
|
144
4
|
};
|
|
145
5
|
//# sourceMappingURL=Collapsible.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Collapsible.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useComposedRefs } from '@tamagui/compose-refs'\
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["export const Collapsible = {}\n\n// import { useComposedRefs } from '@tamagui/compose-refs'\n// import { Stack, StackProps, TamaguiElement, composeEventHandlers, useId } from '@tamagui/core'\n// import type { Scope } from '@tamagui/create-context'\n// import { createContextScope } from '@tamagui/create-context'\n// // import { Presence } from '@tamagui/react-presence'\n// import { useControllableState } from '@tamagui/use-controllable-state'\n// import * as React from 'react'\n\n// /* -------------------------------------------------------------------------------------------------\n// * Collapsible\n// * -----------------------------------------------------------------------------------------------*/\n\n// const COLLAPSIBLE_NAME = 'Collapsible'\n\n// type ScopedProps<P> = P & { __scopeCollapsible?: Scope }\n// const [createCollapsibleContext, createCollapsibleScope] = createContextScope(COLLAPSIBLE_NAME)\n\n// type CollapsibleContextValue = {\n// contentId: string\n// disabled?: boolean\n// open: boolean\n// onOpenToggle(): void\n// }\n\n// const [CollapsibleProvider, useCollapsibleContext] =\n// createCollapsibleContext<CollapsibleContextValue>(COLLAPSIBLE_NAME)\n\n// type CollapsibleElement = TamaguiElement\n// interface CollapsibleProps extends StackProps {\n// defaultOpen?: boolean\n// open?: boolean\n// disabled?: boolean\n// onOpenChange?(open: boolean): void\n// }\n\n// const 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// ref={forwardedRef}\n// />\n// </CollapsibleProvider>\n// )\n// }\n// )\n\n// Collapsible.displayName = COLLAPSIBLE_NAME\n\n// /* -------------------------------------------------------------------------------------------------\n// * CollapsibleTrigger\n// * -----------------------------------------------------------------------------------------------*/\n\n// const TRIGGER_NAME = 'CollapsibleTrigger'\n\n// type CollapsibleTriggerElement = TamaguiElement\n// interface CollapsibleTriggerProps extends StackProps {}\n\n// const 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// ref={forwardedRef}\n// //\n// // onPress={composeEventHandlers(props.onPress, context.onOpenToggle)}\n// />\n// )\n// }\n// )\n\n// CollapsibleTrigger.displayName = TRIGGER_NAME\n\n// /* -------------------------------------------------------------------------------------------------\n// * CollapsibleContent\n// * -----------------------------------------------------------------------------------------------*/\n\n// const CONTENT_NAME = 'CollapsibleContent'\n\n// type CollapsibleContentElement = CollapsibleContentImplElement\n// interface 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\n// const 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\n// CollapsibleContent.displayName = CONTENT_NAME\n\n// /* -----------------------------------------------------------------------------------------------*/\n\n// type CollapsibleContentImplElement = TamaguiElement\n// interface CollapsibleContentImplProps extends StackProps {\n// present: boolean\n// }\n\n// const 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\n// function getState(open?: boolean) {\n// return open ? 'open' : 'closed'\n// }\n\n// const Root = Collapsible\n// const Trigger = CollapsibleTrigger\n// const Content = CollapsibleContent\n\n// export {\n// createCollapsibleScope,\n// //\n// Collapsible,\n// CollapsibleTrigger,\n// CollapsibleContent,\n// //\n// Root,\n// Trigger,\n// Content,\n// }\n// export type { CollapsibleProps, CollapsibleTriggerProps, CollapsibleContentProps }\n"],
|
|
5
|
+
"mappings": "AAAO,MAAM,cAAc,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/index.js
CHANGED
|
File without changes
|
package/dist/esm/index.js.map
CHANGED
package/dist/jsx/Collapsible.js
CHANGED
|
@@ -1,78 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
Stack,
|
|
4
|
-
composeEventHandlers
|
|
5
|
-
} from "@tamagui/core";
|
|
6
|
-
import { useId } from "@tamagui/core";
|
|
7
|
-
import { createContextScope } from "@tamagui/create-context";
|
|
8
|
-
import { useControllableState } from "@tamagui/use-controllable-state";
|
|
9
|
-
import * as React from "react";
|
|
10
|
-
const COLLAPSIBLE_NAME = "Collapsible";
|
|
11
|
-
const [createCollapsibleContext, createCollapsibleScope] = createContextScope(COLLAPSIBLE_NAME);
|
|
12
|
-
const [CollapsibleProvider, useCollapsibleContext] = createCollapsibleContext(COLLAPSIBLE_NAME);
|
|
13
|
-
const Collapsible = React.forwardRef((props, forwardedRef) => {
|
|
14
|
-
const {
|
|
15
|
-
__scopeCollapsible,
|
|
16
|
-
open: openProp,
|
|
17
|
-
defaultOpen,
|
|
18
|
-
disabled,
|
|
19
|
-
onOpenChange,
|
|
20
|
-
...collapsibleProps
|
|
21
|
-
} = props;
|
|
22
|
-
const [open, setOpen] = useControllableState({
|
|
23
|
-
prop: openProp,
|
|
24
|
-
defaultProp: defaultOpen || false,
|
|
25
|
-
onChange: onOpenChange
|
|
26
|
-
});
|
|
27
|
-
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>;
|
|
28
|
-
});
|
|
29
|
-
Collapsible.displayName = COLLAPSIBLE_NAME;
|
|
30
|
-
const TRIGGER_NAME = "CollapsibleTrigger";
|
|
31
|
-
const CollapsibleTrigger = React.forwardRef((props, forwardedRef) => {
|
|
32
|
-
const { __scopeCollapsible, ...triggerProps } = props;
|
|
33
|
-
const context = useCollapsibleContext(TRIGGER_NAME, __scopeCollapsible);
|
|
34
|
-
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)} />;
|
|
35
|
-
});
|
|
36
|
-
CollapsibleTrigger.displayName = TRIGGER_NAME;
|
|
37
|
-
const CONTENT_NAME = "CollapsibleContent";
|
|
38
|
-
const CollapsibleContent = React.forwardRef((props, forwardedRef) => {
|
|
39
|
-
const { forceMount, ...contentProps } = props;
|
|
40
|
-
const context = useCollapsibleContext(CONTENT_NAME, props.__scopeCollapsible);
|
|
41
|
-
return <>{({ present }) => <CollapsibleContentImpl {...contentProps} ref={forwardedRef} present={present} />}</>;
|
|
42
|
-
});
|
|
43
|
-
CollapsibleContent.displayName = CONTENT_NAME;
|
|
44
|
-
const CollapsibleContentImpl = React.forwardRef((props, forwardedRef) => {
|
|
45
|
-
const { __scopeCollapsible, present, children, ...contentProps } = props;
|
|
46
|
-
const context = useCollapsibleContext(CONTENT_NAME, __scopeCollapsible);
|
|
47
|
-
const [isPresent, setIsPresent] = React.useState(present);
|
|
48
|
-
const ref = React.useRef(null);
|
|
49
|
-
const composedRefs = useComposedRefs(forwardedRef, ref);
|
|
50
|
-
const heightRef = React.useRef(0);
|
|
51
|
-
const height = heightRef.current;
|
|
52
|
-
const widthRef = React.useRef(0);
|
|
53
|
-
const width = widthRef.current;
|
|
54
|
-
const isOpen = context.open || isPresent;
|
|
55
|
-
const isMountAnimationPreventedRef = React.useRef(isOpen);
|
|
56
|
-
const originalStylesRef = React.useRef();
|
|
57
|
-
React.useEffect(() => {
|
|
58
|
-
const rAF = requestAnimationFrame(() => isMountAnimationPreventedRef.current = false);
|
|
59
|
-
return () => cancelAnimationFrame(rAF);
|
|
60
|
-
}, []);
|
|
61
|
-
return <Stack data-state={getState(context.open)} data-disabled={context.disabled ? "" : void 0} id={context.contentId} hidden={!isOpen} {...contentProps} ref={composedRefs}>{isOpen && children}</Stack>;
|
|
62
|
-
});
|
|
63
|
-
function getState(open) {
|
|
64
|
-
return open ? "open" : "closed";
|
|
65
|
-
}
|
|
66
|
-
const Root = Collapsible;
|
|
67
|
-
const Trigger = CollapsibleTrigger;
|
|
68
|
-
const Content = CollapsibleContent;
|
|
1
|
+
const Collapsible = {};
|
|
69
2
|
export {
|
|
70
|
-
Collapsible
|
|
71
|
-
CollapsibleContent,
|
|
72
|
-
CollapsibleTrigger,
|
|
73
|
-
Content,
|
|
74
|
-
Root,
|
|
75
|
-
Trigger,
|
|
76
|
-
createCollapsibleScope
|
|
3
|
+
Collapsible
|
|
77
4
|
};
|
|
78
5
|
//# sourceMappingURL=Collapsible.js.map
|