@tamagui/group 2.7.7 → 3.0.0-beta.643.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 +104 -132
- package/dist/cjs/Group.native.cjs +147 -0
- package/dist/cjs/Group.native.js +109 -136
- package/dist/cjs/Group.native.js.map +1 -1
- package/dist/cjs/index.cjs +10 -11
- package/dist/cjs/index.native.cjs +21 -0
- package/dist/cjs/index.native.js +10 -10
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/useIndexedChildren.cjs +52 -58
- package/dist/cjs/useIndexedChildren.native.cjs +84 -0
- package/dist/cjs/useIndexedChildren.native.js +60 -65
- package/dist/cjs/useIndexedChildren.native.js.map +1 -1
- package/dist/esm/Group.mjs +84 -104
- package/dist/esm/Group.mjs.map +1 -1
- package/dist/esm/Group.native.js +90 -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 +84 -104
- package/dist/jsx/Group.mjs.map +1 -1
- package/dist/jsx/Group.native.cjs +147 -0
- package/dist/jsx/Group.native.js +109 -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 +21 -0
- package/dist/jsx/index.native.js +10 -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 +84 -0
- package/dist/jsx/useIndexedChildren.native.js +60 -65
- package/dist/jsx/useIndexedChildren.native.js.map +1 -1
- package/package.json +9 -9
- package/src/Group.tsx +20 -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
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
|
|
3
4
|
var __create = Object.create;
|
|
4
5
|
var __defProp = Object.defineProperty;
|
|
5
6
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -7,85 +8,79 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
7
8
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
9
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
10
|
var __export = (target, all) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
for (var name in all) __defProp(target, name, {
|
|
12
|
+
get: all[name],
|
|
13
|
+
enumerable: true
|
|
14
|
+
});
|
|
14
15
|
};
|
|
15
16
|
var __copyProps = (to, from, except, desc) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
19
|
+
get: () => from[key],
|
|
20
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
23
24
|
};
|
|
24
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
30
|
-
value: mod,
|
|
31
|
-
enumerable: true
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: true
|
|
32
28
|
}) : target, mod));
|
|
33
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
34
|
-
value: true
|
|
35
|
-
}), mod);
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
30
|
var useIndexedChildren_exports = {};
|
|
37
31
|
__export(useIndexedChildren_exports, {
|
|
38
|
-
|
|
39
|
-
|
|
32
|
+
useIndex: () => useIndex,
|
|
33
|
+
useIndexedChildren: () => useIndexedChildren
|
|
40
34
|
});
|
|
41
35
|
module.exports = __toCommonJS(useIndexedChildren_exports);
|
|
42
36
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
43
37
|
var React = __toESM(require("react"), 1);
|
|
44
|
-
var MaxIndexContext = /* @__PURE__ */React.createContext([]);
|
|
45
|
-
var IndexContext = /* @__PURE__ */React.createContext(null);
|
|
38
|
+
var MaxIndexContext = /* @__PURE__ */ React.createContext([]);
|
|
39
|
+
var IndexContext = /* @__PURE__ */ React.createContext(null);
|
|
46
40
|
function useIndex() {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
41
|
+
var maxIndexPath = React.useContext(MaxIndexContext);
|
|
42
|
+
var indexPathString = React.useContext(IndexContext);
|
|
43
|
+
return React.useMemo(function() {
|
|
44
|
+
if (indexPathString === null) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
var indexPath = parseIndexPath(indexPathString);
|
|
48
|
+
var maxIndex = maxIndexPath[maxIndexPath.length - 1];
|
|
49
|
+
var index = indexPath[indexPath.length - 1];
|
|
50
|
+
return {
|
|
51
|
+
maxIndex,
|
|
52
|
+
maxIndexPath,
|
|
53
|
+
index,
|
|
54
|
+
indexPath,
|
|
55
|
+
indexPathString,
|
|
56
|
+
isFirst: index === 0,
|
|
57
|
+
isLast: index === maxIndex,
|
|
58
|
+
isEven: index % 2 === 0,
|
|
59
|
+
isOdd: Math.abs(index % 2) === 1
|
|
60
|
+
};
|
|
61
|
+
}, [maxIndexPath, indexPathString]);
|
|
68
62
|
}
|
|
69
63
|
function useIndexedChildren(children) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
64
|
+
var parentMaxIndexPath = React.useContext(MaxIndexContext);
|
|
65
|
+
var indexPathString = React.useContext(IndexContext);
|
|
66
|
+
var childrenCount = React.Children.count(children);
|
|
67
|
+
var maxIndexPath = React.useMemo(function() {
|
|
68
|
+
return parentMaxIndexPath.concat(childrenCount - 1);
|
|
69
|
+
}, [childrenCount]);
|
|
70
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MaxIndexContext.Provider, {
|
|
71
|
+
value: maxIndexPath,
|
|
72
|
+
children: React.Children.map(children, function(child, index) {
|
|
73
|
+
return /* @__PURE__ */ React.isValidElement(child) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IndexContext.Provider, {
|
|
74
|
+
value: indexPathString ? `${indexPathString}.${index.toString()}` : index.toString(),
|
|
75
|
+
children: child
|
|
76
|
+
}, child.key) : child;
|
|
77
|
+
})
|
|
78
|
+
});
|
|
85
79
|
}
|
|
86
80
|
function parseIndexPath(indexPathString) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
81
|
+
return indexPathString.split(".").map(function(index) {
|
|
82
|
+
return Number.parseInt(index, 10);
|
|
83
|
+
});
|
|
90
84
|
}
|
|
85
|
+
|
|
91
86
|
//# sourceMappingURL=useIndexedChildren.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"useIndexedChildren.native.js","names":[],"sources":["cjs/useIndexedChildren.native.js"],"sourcesContent":["\"use strict\";\nvar __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar useIndexedChildren_exports = {};\n__export(useIndexedChildren_exports, {\n useIndex: () => useIndex,\n useIndexedChildren: () => useIndexedChildren\n});\nmodule.exports = __toCommonJS(useIndexedChildren_exports);\nvar import_jsx_runtime = require(\"react/jsx-runtime\");\nvar React = __toESM(require(\"react\"), 1);\nvar MaxIndexContext = /* @__PURE__ */ React.createContext([]);\nvar IndexContext = /* @__PURE__ */ React.createContext(null);\nfunction useIndex() {\n var maxIndexPath = React.useContext(MaxIndexContext);\n var indexPathString = React.useContext(IndexContext);\n return React.useMemo(function() {\n if (indexPathString === null) {\n return null;\n }\n var indexPath = parseIndexPath(indexPathString);\n var maxIndex = maxIndexPath[maxIndexPath.length - 1];\n var index = indexPath[indexPath.length - 1];\n return {\n maxIndex,\n maxIndexPath,\n index,\n indexPath,\n indexPathString,\n isFirst: index === 0,\n isLast: index === maxIndex,\n isEven: index % 2 === 0,\n isOdd: Math.abs(index % 2) === 1\n };\n }, [\n maxIndexPath,\n indexPathString\n ]);\n}\nfunction useIndexedChildren(children) {\n var parentMaxIndexPath = React.useContext(MaxIndexContext);\n var indexPathString = React.useContext(IndexContext);\n var childrenCount = React.Children.count(children);\n var maxIndexPath = React.useMemo(function() {\n return parentMaxIndexPath.concat(childrenCount - 1);\n }, [\n childrenCount\n ]);\n return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MaxIndexContext.Provider, {\n value: maxIndexPath,\n children: React.Children.map(children, function(child, index) {\n return /* @__PURE__ */ React.isValidElement(child) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IndexContext.Provider, {\n value: indexPathString ? `${indexPathString}.${index.toString()}` : index.toString(),\n children: child\n }, child.key) : child;\n })\n });\n}\nfunction parseIndexPath(indexPathString) {\n return indexPathString.split(\".\").map(function(index) {\n return Number.parseInt(index, 10);\n });\n}\n//# sourceMappingURL=useIndexedChildren.js.map\n"],"mappings":";;;;AACA,IAAI,WAAW,OAAO;AACtB,IAAI,YAAY,OAAO;AACvB,I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ledHOC, mergeSlotStyleProps, resolveSizeToken, 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 = (val, { tokens }) => {
|
|
13
|
+
const radiusToken = resolveSizeToken(val, "radius");
|
|
14
|
+
return { borderRadius: tokens.radius[radiusToken] ?? radiusToken };
|
|
15
|
+
};
|
|
11
16
|
const GroupFrame = styled(YStack, {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
}
|
|
17
|
+
displayName: "GroupFrame",
|
|
18
|
+
size: true,
|
|
19
|
+
variants: { size: {
|
|
20
|
+
true: groupSizeVariant,
|
|
21
|
+
any: groupSizeVariant
|
|
22
|
+
} }
|
|
31
23
|
});
|
|
32
24
|
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
|
-
});
|
|
25
|
+
return withStaticProperties(createStyledHOC(GroupFrame, (props, ref) => {
|
|
26
|
+
const { __scopeGroup, children: childrenProp, orientation = verticalDefault ? "vertical" : "horizontal", disabled, ...restProps } = props;
|
|
27
|
+
const vertical = orientation === "vertical";
|
|
28
|
+
const indexedChildren = useIndexedChildren(React.Children.toArray(childrenProp));
|
|
29
|
+
return /* @__PURE__ */ jsx(GroupProvider, {
|
|
30
|
+
vertical,
|
|
31
|
+
disabled,
|
|
32
|
+
scope: __scopeGroup,
|
|
33
|
+
children: /* @__PURE__ */ jsx(GroupFrame, {
|
|
34
|
+
ref,
|
|
35
|
+
flexDirection: vertical ? "column" : "row",
|
|
36
|
+
...restProps,
|
|
37
|
+
children: indexedChildren
|
|
38
|
+
})
|
|
39
|
+
});
|
|
40
|
+
}), { Item: GroupItem });
|
|
57
41
|
}
|
|
58
42
|
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);
|
|
43
|
+
const { __scopeGroup, children, forcePlacement, ...forwardedProps } = props;
|
|
44
|
+
const context = useGroupContext("GroupItem", __scopeGroup);
|
|
45
|
+
const treeIndex = useIndex();
|
|
46
|
+
if (!treeIndex) {
|
|
47
|
+
throw Error("<Group.Item/> should only be used within a <Group/>");
|
|
48
|
+
}
|
|
49
|
+
if (!React.isValidElement(children)) {
|
|
50
|
+
return children;
|
|
51
|
+
}
|
|
52
|
+
const isFirst = forcePlacement === "first" || forcePlacement !== "last" && treeIndex.index === 0;
|
|
53
|
+
const isLast = forcePlacement === "last" || forcePlacement !== "first" && treeIndex.index === treeIndex.maxIndex;
|
|
54
|
+
const radiusStyles = getZeroedRadius(isFirst, isLast, context.vertical);
|
|
55
|
+
const groupProps = {
|
|
56
|
+
...forwardedProps,
|
|
57
|
+
...radiusStyles
|
|
58
|
+
};
|
|
59
|
+
if (context.disabled != null) {
|
|
60
|
+
groupProps.disabled = children.props.disabled ?? context.disabled;
|
|
61
|
+
}
|
|
62
|
+
const mergedProps = mergeSlotStyleProps(groupProps, children.props);
|
|
63
|
+
return React.cloneElement(children, mergedProps);
|
|
85
64
|
}
|
|
86
65
|
const useGroupItem = (childrenProps, forcePlacement, __scopeGroup) => {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
66
|
+
const treeIndex = useIndex();
|
|
67
|
+
const context = useGroupContext("GroupItem", __scopeGroup);
|
|
68
|
+
if (!treeIndex) {
|
|
69
|
+
throw Error("useGroupItem should only be used within a <Group/>");
|
|
70
|
+
}
|
|
71
|
+
const isFirst = forcePlacement === "first" || forcePlacement !== "last" && treeIndex.index === 0;
|
|
72
|
+
const isLast = forcePlacement === "last" || forcePlacement !== "first" && treeIndex.index === treeIndex.maxIndex;
|
|
73
|
+
const radiusStyles = getZeroedRadius(isFirst, isLast, context.vertical);
|
|
74
|
+
return {
|
|
75
|
+
disabled: childrenProps.disabled ?? context.disabled,
|
|
76
|
+
...radiusStyles
|
|
77
|
+
};
|
|
99
78
|
};
|
|
100
79
|
const Group = createGroup(true);
|
|
101
80
|
const YGroup = Group;
|
|
102
81
|
const XGroup = createGroup(false);
|
|
103
82
|
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
|
-
|
|
83
|
+
if (vertical) {
|
|
84
|
+
return {
|
|
85
|
+
...isFirst ? null : {
|
|
86
|
+
borderTopLeftRadius: 0,
|
|
87
|
+
borderTopRightRadius: 0
|
|
88
|
+
},
|
|
89
|
+
...isLast ? null : {
|
|
90
|
+
borderBottomLeftRadius: 0,
|
|
91
|
+
borderBottomRightRadius: 0
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
...isFirst ? null : {
|
|
97
|
+
borderTopLeftRadius: 0,
|
|
98
|
+
borderBottomLeftRadius: 0
|
|
99
|
+
},
|
|
100
|
+
...isLast ? null : {
|
|
101
|
+
borderTopRightRadius: 0,
|
|
102
|
+
borderBottomRightRadius: 0
|
|
103
|
+
}
|
|
104
|
+
};
|
|
126
105
|
}
|
|
106
|
+
|
|
127
107
|
export { Group, GroupFrame, XGroup, YGroup, createGroupScope, useGroupItem };
|
|
128
108
|
//# sourceMappingURL=Group.mjs.map
|
package/dist/esm/Group.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"file":"Group.js","names":[],"sources":["esm/Group.js"],"sourcesContent":["import {\n createStyledHOC,\n mergeSlotStyleProps,\n resolveSizeToken,\n styled\n} 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 = (val, { tokens }) => {\n const radiusToken = resolveSizeToken(val, \"radius\");\n return {\n borderRadius: tokens.radius[radiusToken] ?? radiusToken\n };\n};\nconst GroupFrame = styled(YStack, {\n displayName: \"GroupFrame\",\n size: true,\n variants: {\n size: {\n true: groupSizeVariant,\n any: groupSizeVariant\n }\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":";;;;;;;;;AAYA,MAAM,aAAa;AACnB,MAAM,CAAC,oBAAoB,oBAAoB,mBAAmB,UAAU;AAC5E,MAAM,CAAC,eAAe,mBAAmB,mBAAmB,UAAU;AACtE,MAAM,oBAAoB,KAAK,EAAE,aAAa;CAC5C,MAAM,cAAc,iBAAiB,KAAK,QAAQ;CAClD,OAAO,EACL,cAA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