@tamagui/group 2.7.7 → 3.0.0-beta.1093.1
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/Group.cjs +99 -132
- package/dist/cjs/Group.native.cjs +140 -0
- package/dist/cjs/Group.native.js +102 -136
- package/dist/cjs/Group.native.js.map +1 -1
- package/dist/cjs/index.cjs +9 -11
- package/dist/cjs/index.native.cjs +20 -0
- package/dist/cjs/index.native.js +9 -10
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/useIndexedChildren.cjs +51 -58
- package/dist/cjs/useIndexedChildren.native.cjs +83 -0
- package/dist/cjs/useIndexedChildren.native.js +59 -65
- package/dist/cjs/useIndexedChildren.native.js.map +1 -1
- package/dist/esm/Group.mjs +80 -104
- package/dist/esm/Group.mjs.map +1 -1
- package/dist/esm/Group.native.js +84 -110
- package/dist/esm/Group.native.js.map +1 -1
- package/dist/esm/index.js +1 -2
- package/dist/esm/index.mjs +1 -2
- package/dist/esm/index.native.js +1 -2
- package/dist/esm/useIndexedChildren.mjs +35 -33
- package/dist/esm/useIndexedChildren.mjs.map +1 -1
- package/dist/esm/useIndexedChildren.native.js +44 -42
- package/dist/esm/useIndexedChildren.native.js.map +1 -1
- package/dist/jsx/Group.mjs +80 -104
- package/dist/jsx/Group.mjs.map +1 -1
- package/dist/jsx/Group.native.cjs +140 -0
- package/dist/jsx/Group.native.js +102 -136
- package/dist/jsx/Group.native.js.map +1 -1
- package/dist/jsx/index.js +1 -2
- package/dist/jsx/index.mjs +1 -2
- package/dist/jsx/index.native.cjs +20 -0
- package/dist/jsx/index.native.js +9 -10
- package/dist/jsx/index.native.js.map +1 -1
- package/dist/jsx/useIndexedChildren.mjs +35 -33
- package/dist/jsx/useIndexedChildren.mjs.map +1 -1
- package/dist/jsx/useIndexedChildren.native.cjs +83 -0
- package/dist/jsx/useIndexedChildren.native.js +59 -65
- package/dist/jsx/useIndexedChildren.native.js.map +1 -1
- package/package.json +11 -10
- package/src/Group.tsx +11 -19
- package/types/Group.d.ts +107 -78
- package/types/Group.d.ts.map +1 -1
- package/types/useIndexedChildren.d.ts +1 -1
- package/types/useIndexedChildren.d.ts.map +1 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js.map +0 -1
- package/dist/jsx/index.js.map +0 -1
- package/dist/jsx/index.mjs.map +0 -1
package/dist/jsx/Group.mjs
CHANGED
|
@@ -1,128 +1,104 @@
|
|
|
1
|
-
import { mergeSlotStyleProps, styled } from "@tamagui/core";
|
|
1
|
+
import { createStyledHOC, mergeSlotStyleProps, resolveSize, styled } from "@tamagui/core";
|
|
2
2
|
import { createContextScope } from "@tamagui/create-context";
|
|
3
3
|
import { withStaticProperties } from "@tamagui/helpers";
|
|
4
4
|
import { YStack } from "@tamagui/stacks";
|
|
5
5
|
import React from "react";
|
|
6
6
|
import { useIndex, useIndexedChildren } from "./useIndexedChildren.mjs";
|
|
7
7
|
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
|
|
8
9
|
const GROUP_NAME = "Group";
|
|
9
10
|
const [createGroupContext, createGroupScope] = createContextScope(GROUP_NAME);
|
|
10
11
|
const [GroupProvider, useGroupContext] = createGroupContext(GROUP_NAME);
|
|
12
|
+
const groupSizeVariant = styled.dynamic((val, env) => {
|
|
13
|
+
return { borderRadius: resolveSize(val, env).frame.borderRadius };
|
|
14
|
+
});
|
|
11
15
|
const GroupFrame = styled(YStack, {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
false: {
|
|
16
|
-
size: "$true"
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
size: (val, {
|
|
20
|
-
tokens
|
|
21
|
-
}) => {
|
|
22
|
-
const borderRadius = tokens.radius[val] ?? val ?? tokens.radius["$true"];
|
|
23
|
-
return {
|
|
24
|
-
borderRadius
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
defaultVariants: {
|
|
29
|
-
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
30
|
-
}
|
|
16
|
+
displayName: "GroupFrame",
|
|
17
|
+
size: true,
|
|
18
|
+
variants: { size: groupSizeVariant }
|
|
31
19
|
});
|
|
32
20
|
function createGroup(verticalDefault) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
flexDirection: vertical ? "column" : "row",
|
|
50
|
-
...restProps,
|
|
51
|
-
children: indexedChildren
|
|
52
|
-
})
|
|
53
|
-
});
|
|
54
|
-
}), {
|
|
55
|
-
Item: GroupItem
|
|
56
|
-
});
|
|
21
|
+
return withStaticProperties(createStyledHOC(GroupFrame, (props, ref) => {
|
|
22
|
+
const { __scopeGroup, children: childrenProp, orientation = verticalDefault ? "vertical" : "horizontal", disabled, ...restProps } = props;
|
|
23
|
+
const vertical = orientation === "vertical";
|
|
24
|
+
const indexedChildren = useIndexedChildren(React.Children.toArray(childrenProp));
|
|
25
|
+
return /* @__PURE__ */ jsx(GroupProvider, {
|
|
26
|
+
vertical,
|
|
27
|
+
disabled,
|
|
28
|
+
scope: __scopeGroup,
|
|
29
|
+
children: /* @__PURE__ */ jsx(GroupFrame, {
|
|
30
|
+
ref,
|
|
31
|
+
flexDirection: vertical ? "column" : "row",
|
|
32
|
+
...restProps,
|
|
33
|
+
children: indexedChildren
|
|
34
|
+
})
|
|
35
|
+
});
|
|
36
|
+
}), { Item: GroupItem });
|
|
57
37
|
}
|
|
58
38
|
function GroupItem(props) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (context.disabled != null) {
|
|
81
|
-
groupProps.disabled = children.props.disabled ?? context.disabled;
|
|
82
|
-
}
|
|
83
|
-
const mergedProps = mergeSlotStyleProps(groupProps, children.props);
|
|
84
|
-
return React.cloneElement(children, mergedProps);
|
|
39
|
+
const { __scopeGroup, children, forcePlacement, ...forwardedProps } = props;
|
|
40
|
+
const context = useGroupContext("GroupItem", __scopeGroup);
|
|
41
|
+
const treeIndex = useIndex();
|
|
42
|
+
if (!treeIndex) {
|
|
43
|
+
throw Error("<Group.Item/> should only be used within a <Group/>");
|
|
44
|
+
}
|
|
45
|
+
if (!React.isValidElement(children)) {
|
|
46
|
+
return children;
|
|
47
|
+
}
|
|
48
|
+
const isFirst = forcePlacement === "first" || forcePlacement !== "last" && treeIndex.index === 0;
|
|
49
|
+
const isLast = forcePlacement === "last" || forcePlacement !== "first" && treeIndex.index === treeIndex.maxIndex;
|
|
50
|
+
const radiusStyles = getZeroedRadius(isFirst, isLast, context.vertical);
|
|
51
|
+
const groupProps = {
|
|
52
|
+
...forwardedProps,
|
|
53
|
+
...radiusStyles
|
|
54
|
+
};
|
|
55
|
+
if (context.disabled != null) {
|
|
56
|
+
groupProps.disabled = children.props.disabled ?? context.disabled;
|
|
57
|
+
}
|
|
58
|
+
const mergedProps = mergeSlotStyleProps(groupProps, children.props);
|
|
59
|
+
return React.cloneElement(children, mergedProps);
|
|
85
60
|
}
|
|
86
61
|
const useGroupItem = (childrenProps, forcePlacement, __scopeGroup) => {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
62
|
+
const treeIndex = useIndex();
|
|
63
|
+
const context = useGroupContext("GroupItem", __scopeGroup);
|
|
64
|
+
if (!treeIndex) {
|
|
65
|
+
throw Error("useGroupItem should only be used within a <Group/>");
|
|
66
|
+
}
|
|
67
|
+
const isFirst = forcePlacement === "first" || forcePlacement !== "last" && treeIndex.index === 0;
|
|
68
|
+
const isLast = forcePlacement === "last" || forcePlacement !== "first" && treeIndex.index === treeIndex.maxIndex;
|
|
69
|
+
const radiusStyles = getZeroedRadius(isFirst, isLast, context.vertical);
|
|
70
|
+
return {
|
|
71
|
+
disabled: childrenProps.disabled ?? context.disabled,
|
|
72
|
+
...radiusStyles
|
|
73
|
+
};
|
|
99
74
|
};
|
|
100
75
|
const Group = createGroup(true);
|
|
101
76
|
const YGroup = Group;
|
|
102
77
|
const XGroup = createGroup(false);
|
|
103
78
|
function getZeroedRadius(isFirst, isLast, vertical) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
79
|
+
if (vertical) {
|
|
80
|
+
return {
|
|
81
|
+
...isFirst ? null : {
|
|
82
|
+
borderTopLeftRadius: 0,
|
|
83
|
+
borderTopRightRadius: 0
|
|
84
|
+
},
|
|
85
|
+
...isLast ? null : {
|
|
86
|
+
borderBottomLeftRadius: 0,
|
|
87
|
+
borderBottomRightRadius: 0
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
...isFirst ? null : {
|
|
93
|
+
borderTopLeftRadius: 0,
|
|
94
|
+
borderBottomLeftRadius: 0
|
|
95
|
+
},
|
|
96
|
+
...isLast ? null : {
|
|
97
|
+
borderTopRightRadius: 0,
|
|
98
|
+
borderBottomRightRadius: 0
|
|
99
|
+
}
|
|
100
|
+
};
|
|
126
101
|
}
|
|
102
|
+
|
|
127
103
|
export { Group, GroupFrame, XGroup, YGroup, createGroupScope, useGroupItem };
|
|
128
104
|
//# sourceMappingURL=Group.mjs.map
|
package/dist/jsx/Group.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"file":"Group.js","names":[],"sources":["jsx/Group.js"],"sourcesContent":["import { createStyledHOC, mergeSlotStyleProps, resolveSize, styled } from \"@tamagui/core\";\nimport { createContextScope } from \"@tamagui/create-context\";\nimport { withStaticProperties } from \"@tamagui/helpers\";\nimport { YStack } from \"@tamagui/stacks\";\nimport React from \"react\";\nimport { useIndex, useIndexedChildren } from \"./useIndexedChildren\";\nimport { jsx } from \"react/jsx-runtime\";\nconst GROUP_NAME = \"Group\";\nconst [createGroupContext, createGroupScope] = createContextScope(GROUP_NAME);\nconst [GroupProvider, useGroupContext] = createGroupContext(GROUP_NAME);\nconst groupSizeVariant = styled.dynamic((val, env) => {\n return {\n borderRadius: resolveSize(val, env).frame.borderRadius\n };\n});\nconst GroupFrame = styled(YStack, {\n displayName: \"GroupFrame\",\n size: true,\n variants: {\n size: groupSizeVariant\n }\n});\nfunction createGroup(verticalDefault) {\n return withStaticProperties(\n createStyledHOC(GroupFrame, (props, ref) => {\n const {\n __scopeGroup,\n children: childrenProp,\n orientation = verticalDefault ? \"vertical\" : \"horizontal\",\n disabled,\n ...restProps\n } = props;\n const vertical = orientation === \"vertical\";\n const indexedChildren = useIndexedChildren(React.Children.toArray(childrenProp));\n return /* @__PURE__ */ jsx(GroupProvider, { vertical, disabled, scope: __scopeGroup, children: /* @__PURE__ */ jsx(\n GroupFrame,\n {\n ref,\n flexDirection: vertical ? \"column\" : \"row\",\n ...restProps,\n children: indexedChildren\n }\n ) });\n }),\n {\n Item: GroupItem\n }\n );\n}\nfunction GroupItem(props) {\n const { __scopeGroup, children, forcePlacement, ...forwardedProps } = props;\n const context = useGroupContext(\"GroupItem\", __scopeGroup);\n const treeIndex = useIndex();\n if (!treeIndex) {\n throw Error(\"<Group.Item/> should only be used within a <Group/>\");\n }\n if (!React.isValidElement(children)) {\n return children;\n }\n const isFirst = forcePlacement === \"first\" || forcePlacement !== \"last\" && treeIndex.index === 0;\n const isLast = forcePlacement === \"last\" || forcePlacement !== \"first\" && treeIndex.index === treeIndex.maxIndex;\n const radiusStyles = getZeroedRadius(isFirst, isLast, context.vertical);\n const groupProps = {\n ...forwardedProps,\n ...radiusStyles\n };\n if (context.disabled != null) {\n groupProps.disabled = children.props.disabled ?? context.disabled;\n }\n const mergedProps = mergeSlotStyleProps(groupProps, children.props);\n return React.cloneElement(children, mergedProps);\n}\nconst useGroupItem = (childrenProps, forcePlacement, __scopeGroup) => {\n const treeIndex = useIndex();\n const context = useGroupContext(\"GroupItem\", __scopeGroup);\n if (!treeIndex) {\n throw Error(\"useGroupItem should only be used within a <Group/>\");\n }\n const isFirst = forcePlacement === \"first\" || forcePlacement !== \"last\" && treeIndex.index === 0;\n const isLast = forcePlacement === \"last\" || forcePlacement !== \"first\" && treeIndex.index === treeIndex.maxIndex;\n const radiusStyles = getZeroedRadius(isFirst, isLast, context.vertical);\n return {\n disabled: childrenProps.disabled ?? context.disabled,\n ...radiusStyles\n };\n};\nconst Group = createGroup(true);\nconst YGroup = Group;\nconst XGroup = createGroup(false);\nfunction getZeroedRadius(isFirst, isLast, vertical) {\n if (vertical) {\n return {\n ...isFirst ? null : { borderTopLeftRadius: 0, borderTopRightRadius: 0 },\n ...isLast ? null : { borderBottomLeftRadius: 0, borderBottomRightRadius: 0 }\n };\n }\n return {\n ...isFirst ? null : { borderTopLeftRadius: 0, borderBottomLeftRadius: 0 },\n ...isLast ? null : { borderTopRightRadius: 0, borderBottomRightRadius: 0 }\n };\n}\nexport {\n Group,\n GroupFrame,\n XGroup,\n YGroup,\n createGroupScope,\n useGroupItem\n};\n//# sourceMappingURL=Group.js.map\n"],"mappings":";;;;;;;;;AAOA,MAAM,aAAa;AACnB,MAAM,CAAC,oBAAoB,oBAAoB,mBAAmB,UAAU;AAC5E,MAAM,CAAC,eAAe,mBAAmB,mBAAmB,UAAU;AACtE,MAAM,mBAAmB,OAAO,SAAS,KAAK,QAAQ;CACpD,OAAO,EACL,cAAc,YAAY,KAAK,GAAG,CAAC,CAAC,MAAM,aAC5C;AACF,CAAC;AACD,MAAM,aAAa,OAAO,QAAQ;CAChC,aAAa;CACb,MAAM;CACN,UAAU,EACR,MAAM,iBACR;AACF,CAAC;AACD,SAAS,YAAY,iBAAiB;CACpC,OAAO,qBACL,gBAAgB,aAAa,OAAO,QAAQ;EAC1C,MAAM,EACJ,cACA,UAAU,cACV,cAAc,kBAAkB,aAAa,cAC7C,UACA,GAAG,cACD;EACJ,MAAM,WAAW,gBAAgB;EACjC,MAAM,kBAAkB,mBAAmB,MAAM,SAAS,QAAQ,YAAY,CAAC;EAC/E,OAAuB,oBAAI,eAAe;GAAE;GAAU;GAAU,OAAO;GAAc,UAA0B,oBAC7G,YACA;IACE;IACA,eAAe,WAAW,WAAW;IACrC,GAAG;IACH,UAAU;GACZ,CACF;EAAE,CAAC;CACL,CAAC,GACD,EACE,MAAM,UACR,CACF;AACF;AACA,SAAS,UAAU,OAAO;CACxB,MAAM,EAAE,cAAc,UAAU,gBAAgB,GAAG,mBAAmB;CACtE,MAAM,UAAU,gBAAgB,aAAa,YAAY;CACzD,MAAM,YAAY,SAAS;CAC3B,IAAI,CAAC,WAAW;EACd,MAAM,MAAM,qDAAqD;CACnE;CACA,IAAI,CAAC,MAAM,eAAe,QAAQ,GAAG;EACnC,OAAO;CACT;CACA,MAAM,UAAU,mBAAmB,WAAW,mBAAmB,UAAU,UAAU,UAAU;CAC/F,MAAM,SAAS,mBAAmB,UAAU,mBAAmB,WAAW,UAAU,UAAU,UAAU;CACxG,MAAM,eAAe,gBAAgB,SAAS,QAAQ,QAAQ,QAAQ;CACtE,MAAM,aAAa;EACjB,GAAG;EACH,GAAG;CACL;CACA,IAAI,QAAQ,YAAY,MAAM;EAC5B,WAAW,WAAW,SAAS,MAAM,YAAY,QAAQ;CAC3D;CACA,MAAM,cAAc,oBAAoB,YAAY,SAAS,KAAK;CAClE,OAAO,MAAM,aAAa,UAAU,WAAW;AACjD;AACA,MAAM,gBAAgB,eAAe,gBAAgB,iBAAiB;CACpE,MAAM,YAAY,SAAS;CAC3B,MAAM,UAAU,gBAAgB,aAAa,YAAY;CACzD,IAAI,CAAC,WAAW;EACd,MAAM,MAAM,oDAAoD;CAClE;CACA,MAAM,UAAU,mBAAmB,WAAW,mBAAmB,UAAU,UAAU,UAAU;CAC/F,MAAM,SAAS,mBAAmB,UAAU,mBAAmB,WAAW,UAAU,UAAU,UAAU;CACxG,MAAM,eAAe,gBAAgB,SAAS,QAAQ,QAAQ,QAAQ;CACtE,OAAO;EACL,UAAU,cAAc,YAAY,QAAQ;EAC5C,GAAG;CACL;AACF;AACA,MAAM,QAAQ,YAAY,IAAI;AAC9B,MAAM,SAAS;AACf,MAAM,SAAS,YAAY,KAAK;AAChC,SAAS,gBAAgB,SAAS,QAAQ,UAAU;CAClD,IAAI,UAAU;EACZ,OAAO;GACL,GAAG,UAAU,OAAO;IAAE,qBAAqB;IAAG,sBAAsB;GAAE;GACtE,GAAG,SAAS,OAAO;IAAE,wBAAwB;IAAG,yBAAyB;GAAE;EAC7E;CACF;CACA,OAAO;EACL,GAAG,UAAU,OAAO;GAAE,qBAAqB;GAAG,wBAAwB;EAAE;EACxE,GAAG,SAAS,OAAO;GAAE,sBAAsB;GAAG,yBAAyB;EAAE;CAC3E;AACF"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all) __defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: true
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
18
|
+
get: () => from[key],
|
|
19
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
25
|
+
value: mod,
|
|
26
|
+
enumerable: true
|
|
27
|
+
}) : target, mod));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var Group_exports = {};
|
|
30
|
+
__export(Group_exports, {
|
|
31
|
+
Group: () => Group,
|
|
32
|
+
GroupFrame: () => GroupFrame,
|
|
33
|
+
XGroup: () => XGroup,
|
|
34
|
+
YGroup: () => YGroup,
|
|
35
|
+
createGroupScope: () => createGroupScope,
|
|
36
|
+
useGroupItem: () => useGroupItem
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(Group_exports);
|
|
39
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
40
|
+
var import_core = require("@tamagui/core");
|
|
41
|
+
var import_create_context = require("@tamagui/create-context");
|
|
42
|
+
var import_helpers = require("@tamagui/helpers");
|
|
43
|
+
var import_stacks = require("@tamagui/stacks");
|
|
44
|
+
var import_react = __toESM(require("react"), 1);
|
|
45
|
+
var import_useIndexedChildren = require("./useIndexedChildren.native.js");
|
|
46
|
+
var GROUP_NAME = "Group";
|
|
47
|
+
var [createGroupContext, createGroupScope] = (0, import_create_context.createContextScope)(GROUP_NAME);
|
|
48
|
+
var [GroupProvider, useGroupContext] = createGroupContext(GROUP_NAME);
|
|
49
|
+
var groupSizeVariant = import_core.styled.dynamic(function(val, env) {
|
|
50
|
+
return { borderRadius: (0, import_core.resolveSize)(val, env).frame.borderRadius };
|
|
51
|
+
});
|
|
52
|
+
var GroupFrame = (0, import_core.styled)(import_stacks.YStack, {
|
|
53
|
+
displayName: "GroupFrame",
|
|
54
|
+
size: true,
|
|
55
|
+
variants: { size: groupSizeVariant }
|
|
56
|
+
});
|
|
57
|
+
function createGroup(verticalDefault) {
|
|
58
|
+
return (0, import_helpers.withStaticProperties)((0, import_core.createStyledHOC)(GroupFrame, function(props, ref) {
|
|
59
|
+
var { __scopeGroup, children: childrenProp, orientation = verticalDefault ? "vertical" : "horizontal", disabled, ...restProps } = props;
|
|
60
|
+
var vertical = orientation === "vertical";
|
|
61
|
+
var indexedChildren = (0, import_useIndexedChildren.useIndexedChildren)(import_react.default.Children.toArray(childrenProp));
|
|
62
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(GroupProvider, {
|
|
63
|
+
vertical,
|
|
64
|
+
disabled,
|
|
65
|
+
scope: __scopeGroup,
|
|
66
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(GroupFrame, {
|
|
67
|
+
ref,
|
|
68
|
+
flexDirection: vertical ? "column" : "row",
|
|
69
|
+
...restProps,
|
|
70
|
+
children: indexedChildren
|
|
71
|
+
})
|
|
72
|
+
});
|
|
73
|
+
}), { Item: GroupItem });
|
|
74
|
+
}
|
|
75
|
+
function GroupItem(props) {
|
|
76
|
+
var { __scopeGroup, children, forcePlacement, ...forwardedProps } = props;
|
|
77
|
+
var context = useGroupContext("GroupItem", __scopeGroup);
|
|
78
|
+
var treeIndex = (0, import_useIndexedChildren.useIndex)();
|
|
79
|
+
if (!treeIndex) {
|
|
80
|
+
throw Error("<Group.Item/> should only be used within a <Group/>");
|
|
81
|
+
}
|
|
82
|
+
if (!/* @__PURE__ */ import_react.default.isValidElement(children)) {
|
|
83
|
+
return children;
|
|
84
|
+
}
|
|
85
|
+
var isFirst = forcePlacement === "first" || forcePlacement !== "last" && treeIndex.index === 0;
|
|
86
|
+
var isLast = forcePlacement === "last" || forcePlacement !== "first" && treeIndex.index === treeIndex.maxIndex;
|
|
87
|
+
var radiusStyles = getZeroedRadius(isFirst, isLast, context.vertical);
|
|
88
|
+
var groupProps = {
|
|
89
|
+
...forwardedProps,
|
|
90
|
+
...radiusStyles
|
|
91
|
+
};
|
|
92
|
+
if (context.disabled != null) {
|
|
93
|
+
var _children_props_disabled;
|
|
94
|
+
groupProps.disabled = (_children_props_disabled = children.props.disabled) !== null && _children_props_disabled !== void 0 ? _children_props_disabled : context.disabled;
|
|
95
|
+
}
|
|
96
|
+
var mergedProps = (0, import_core.mergeSlotStyleProps)(groupProps, children.props);
|
|
97
|
+
return /* @__PURE__ */ import_react.default.cloneElement(children, mergedProps);
|
|
98
|
+
}
|
|
99
|
+
var useGroupItem = function(childrenProps, forcePlacement, __scopeGroup) {
|
|
100
|
+
var treeIndex = (0, import_useIndexedChildren.useIndex)();
|
|
101
|
+
var context = useGroupContext("GroupItem", __scopeGroup);
|
|
102
|
+
if (!treeIndex) {
|
|
103
|
+
throw Error("useGroupItem should only be used within a <Group/>");
|
|
104
|
+
}
|
|
105
|
+
var isFirst = forcePlacement === "first" || forcePlacement !== "last" && treeIndex.index === 0;
|
|
106
|
+
var isLast = forcePlacement === "last" || forcePlacement !== "first" && treeIndex.index === treeIndex.maxIndex;
|
|
107
|
+
var radiusStyles = getZeroedRadius(isFirst, isLast, context.vertical);
|
|
108
|
+
var _childrenProps_disabled;
|
|
109
|
+
return {
|
|
110
|
+
disabled: (_childrenProps_disabled = childrenProps.disabled) !== null && _childrenProps_disabled !== void 0 ? _childrenProps_disabled : context.disabled,
|
|
111
|
+
...radiusStyles
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
var Group = createGroup(true);
|
|
115
|
+
var YGroup = Group;
|
|
116
|
+
var XGroup = createGroup(false);
|
|
117
|
+
function getZeroedRadius(isFirst, isLast, vertical) {
|
|
118
|
+
if (vertical) {
|
|
119
|
+
return {
|
|
120
|
+
...isFirst ? null : {
|
|
121
|
+
borderTopLeftRadius: 0,
|
|
122
|
+
borderTopRightRadius: 0
|
|
123
|
+
},
|
|
124
|
+
...isLast ? null : {
|
|
125
|
+
borderBottomLeftRadius: 0,
|
|
126
|
+
borderBottomRightRadius: 0
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
...isFirst ? null : {
|
|
132
|
+
borderTopLeftRadius: 0,
|
|
133
|
+
borderBottomLeftRadius: 0
|
|
134
|
+
},
|
|
135
|
+
...isLast ? null : {
|
|
136
|
+
borderTopRightRadius: 0,
|
|
137
|
+
borderBottomRightRadius: 0
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
}
|