@tamagui/group 1.114.4 → 1.115.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/Group.cjs +228 -0
- package/dist/cjs/index.cjs +18 -0
- package/dist/cjs/useIndexedChildren.cjs +78 -0
- package/package.json +9 -8
- package/dist/cjs/Group.js +0 -189
- package/dist/cjs/index.js +0 -15
- package/dist/cjs/useIndexedChildren.js +0 -70
- /package/dist/cjs/{Group.js.map → Group.cjs.map} +0 -0
- /package/dist/cjs/{index.js.map → index.cjs.map} +0 -0
- /package/dist/cjs/{useIndexedChildren.js.map → useIndexedChildren.cjs.map} +0 -0
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: !0
|
|
28
|
+
}) : target, mod)),
|
|
29
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
30
|
+
value: !0
|
|
31
|
+
}), mod);
|
|
32
|
+
var Group_exports = {};
|
|
33
|
+
__export(Group_exports, {
|
|
34
|
+
Group: () => Group,
|
|
35
|
+
GroupFrame: () => GroupFrame,
|
|
36
|
+
XGroup: () => XGroup,
|
|
37
|
+
YGroup: () => YGroup,
|
|
38
|
+
useGroupItem: () => useGroupItem
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(Group_exports);
|
|
41
|
+
var import_core = require("@tamagui/core"),
|
|
42
|
+
import_create_context = require("@tamagui/create-context"),
|
|
43
|
+
import_helpers = require("@tamagui/helpers"),
|
|
44
|
+
import_stacks = require("@tamagui/stacks"),
|
|
45
|
+
import_use_controllable_state = require("@tamagui/use-controllable-state"),
|
|
46
|
+
import_react = __toESM(require("react")),
|
|
47
|
+
import_react_native = require("react-native-web"),
|
|
48
|
+
import_useIndexedChildren = require("./useIndexedChildren.cjs"),
|
|
49
|
+
import_jsx_runtime = require("react/jsx-runtime");
|
|
50
|
+
const GROUP_NAME = "Group",
|
|
51
|
+
[createGroupContext, createGroupScope] = (0, import_create_context.createContextScope)(GROUP_NAME),
|
|
52
|
+
[GroupProvider, useGroupContext] = createGroupContext(GROUP_NAME),
|
|
53
|
+
GroupFrame = (0, import_core.styled)(import_stacks.ThemeableStack, {
|
|
54
|
+
name: "GroupFrame",
|
|
55
|
+
variants: {
|
|
56
|
+
unstyled: {
|
|
57
|
+
false: {
|
|
58
|
+
size: "$true"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
size: (val, {
|
|
62
|
+
tokens
|
|
63
|
+
}) => ({
|
|
64
|
+
borderRadius: tokens.radius[val] ?? val ?? tokens.radius.$true
|
|
65
|
+
})
|
|
66
|
+
},
|
|
67
|
+
defaultVariants: {
|
|
68
|
+
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
function createGroup(verticalDefault) {
|
|
72
|
+
return (0, import_helpers.withStaticProperties)(GroupFrame.styleable((props, ref) => {
|
|
73
|
+
const activeProps = (0, import_core.useProps)(props),
|
|
74
|
+
{
|
|
75
|
+
__scopeGroup,
|
|
76
|
+
children: childrenProp,
|
|
77
|
+
space,
|
|
78
|
+
size = "$true",
|
|
79
|
+
spaceDirection,
|
|
80
|
+
separator,
|
|
81
|
+
scrollable,
|
|
82
|
+
axis = verticalDefault ? "vertical" : "horizontal",
|
|
83
|
+
orientation = axis,
|
|
84
|
+
disabled: disabledProp,
|
|
85
|
+
disablePassBorderRadius: disablePassBorderRadiusProp,
|
|
86
|
+
borderRadius,
|
|
87
|
+
forceUseItem,
|
|
88
|
+
...restProps
|
|
89
|
+
} = activeProps,
|
|
90
|
+
vertical = orientation === "vertical",
|
|
91
|
+
[itemChildrenCount, setItemChildrenCount] = (0, import_use_controllable_state.useControllableState)({
|
|
92
|
+
defaultProp: forceUseItem ? 1 : 0
|
|
93
|
+
}),
|
|
94
|
+
isUsingItems = itemChildrenCount > 0,
|
|
95
|
+
radius = borderRadius ?? (size ? (0, import_core.getVariableValue)((0, import_core.getTokens)().radius[size]) - 1 : void 0),
|
|
96
|
+
disablePassBorderRadius = disablePassBorderRadiusProp ?? !(radius !== void 0),
|
|
97
|
+
childrenArray = import_react.default.Children.toArray(childrenProp),
|
|
98
|
+
children = isUsingItems ? import_react.default.Children.toArray(childrenProp).filter(import_react.default.isValidElement) : childrenArray.map((child, i) => {
|
|
99
|
+
if (!import_react.default.isValidElement(child) || child.type === import_react.default.Fragment) return child;
|
|
100
|
+
const disabled = child.props.disabled ?? disabledProp,
|
|
101
|
+
isFirst = i === 0,
|
|
102
|
+
isLast = i === childrenArray.length - 1,
|
|
103
|
+
radiusStyles = disablePassBorderRadius === !0 ? null : getBorderRadius({
|
|
104
|
+
isFirst,
|
|
105
|
+
isLast,
|
|
106
|
+
radius,
|
|
107
|
+
vertical,
|
|
108
|
+
disable: disablePassBorderRadius
|
|
109
|
+
}),
|
|
110
|
+
props2 = {
|
|
111
|
+
disabled,
|
|
112
|
+
...((0, import_core.isTamaguiElement)(child) ? radiusStyles : {
|
|
113
|
+
style: radiusStyles
|
|
114
|
+
})
|
|
115
|
+
};
|
|
116
|
+
return cloneElementWithPropOrder(child, props2);
|
|
117
|
+
}),
|
|
118
|
+
indexedChildren = (0, import_useIndexedChildren.useIndexedChildren)((0, import_core.spacedChildren)({
|
|
119
|
+
direction: spaceDirection,
|
|
120
|
+
separator,
|
|
121
|
+
space,
|
|
122
|
+
children
|
|
123
|
+
})),
|
|
124
|
+
onItemMount = import_react.default.useCallback(() => setItemChildrenCount(prev => prev + 1), []),
|
|
125
|
+
onItemUnmount = import_react.default.useCallback(() => setItemChildrenCount(prev => prev - 1), []);
|
|
126
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(GroupProvider, {
|
|
127
|
+
disablePassBorderRadius,
|
|
128
|
+
vertical: orientation === "vertical",
|
|
129
|
+
radius,
|
|
130
|
+
disabled: disabledProp,
|
|
131
|
+
onItemMount,
|
|
132
|
+
onItemUnmount,
|
|
133
|
+
scope: __scopeGroup,
|
|
134
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(GroupFrame, {
|
|
135
|
+
ref,
|
|
136
|
+
size,
|
|
137
|
+
flexDirection: orientation === "horizontal" ? "row" : "column",
|
|
138
|
+
borderRadius,
|
|
139
|
+
...restProps,
|
|
140
|
+
children: wrapScroll({
|
|
141
|
+
...activeProps,
|
|
142
|
+
orientation
|
|
143
|
+
}, indexedChildren)
|
|
144
|
+
})
|
|
145
|
+
});
|
|
146
|
+
}), {
|
|
147
|
+
Item: GroupItem
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
const GroupItem = import_react.default.forwardRef((props, _ref) => {
|
|
151
|
+
const {
|
|
152
|
+
__scopeGroup,
|
|
153
|
+
children,
|
|
154
|
+
forcePlacement
|
|
155
|
+
} = props,
|
|
156
|
+
groupItemProps = useGroupItem({
|
|
157
|
+
disabled: import_react.default.isValidElement(children) ? children.props.disabled : void 0
|
|
158
|
+
}, forcePlacement, __scopeGroup);
|
|
159
|
+
return !import_react.default.isValidElement(children) || children.type === import_react.default.Fragment ? children : (0, import_core.isTamaguiElement)(children) ? import_react.default.cloneElement(children, groupItemProps) : import_react.default.cloneElement(children, {
|
|
160
|
+
style: {
|
|
161
|
+
// @ts-ignore
|
|
162
|
+
...children.props?.style,
|
|
163
|
+
...groupItemProps
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}),
|
|
167
|
+
useGroupItem = (childrenProps, forcePlacement, __scopeGroup) => {
|
|
168
|
+
const treeIndex = (0, import_useIndexedChildren.useIndex)(),
|
|
169
|
+
context = useGroupContext("GroupItem", __scopeGroup);
|
|
170
|
+
if (import_react.default.useEffect(() => (context.onItemMount(), () => {
|
|
171
|
+
context.onItemUnmount();
|
|
172
|
+
}), []), !treeIndex) throw Error("<Group.Item/> should only be used within a <Group/>");
|
|
173
|
+
const isFirst = forcePlacement === "first" || forcePlacement !== "last" && treeIndex.index === 0,
|
|
174
|
+
isLast = forcePlacement === "last" || forcePlacement !== "first" && treeIndex.index === treeIndex.maxIndex;
|
|
175
|
+
let propsToPass = {
|
|
176
|
+
disabled: childrenProps.disabled ?? context.disabled
|
|
177
|
+
};
|
|
178
|
+
if (context.disablePassBorderRadius !== !0) {
|
|
179
|
+
const borderRadius = getBorderRadius({
|
|
180
|
+
radius: context.radius,
|
|
181
|
+
isFirst,
|
|
182
|
+
isLast,
|
|
183
|
+
vertical: context.vertical,
|
|
184
|
+
disable: context.disablePassBorderRadius
|
|
185
|
+
});
|
|
186
|
+
return {
|
|
187
|
+
...propsToPass,
|
|
188
|
+
...borderRadius
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
return propsToPass;
|
|
192
|
+
},
|
|
193
|
+
Group = createGroup(!0),
|
|
194
|
+
YGroup = Group,
|
|
195
|
+
XGroup = createGroup(!1),
|
|
196
|
+
wrapScroll = ({
|
|
197
|
+
scrollable,
|
|
198
|
+
orientation,
|
|
199
|
+
showScrollIndicator = !1
|
|
200
|
+
}, children) => scrollable ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react_native.ScrollView, {
|
|
201
|
+
...(orientation === "vertical" && {
|
|
202
|
+
showsVerticalScrollIndicator: showScrollIndicator
|
|
203
|
+
}),
|
|
204
|
+
...(orientation === "horizontal" && {
|
|
205
|
+
horizontal: !0,
|
|
206
|
+
showsHorizontalScrollIndicator: showScrollIndicator
|
|
207
|
+
}),
|
|
208
|
+
children
|
|
209
|
+
}) : children,
|
|
210
|
+
getBorderRadius = ({
|
|
211
|
+
isFirst,
|
|
212
|
+
isLast,
|
|
213
|
+
radius,
|
|
214
|
+
vertical,
|
|
215
|
+
disable
|
|
216
|
+
}) => ({
|
|
217
|
+
borderTopLeftRadius: isFirst && disable !== "top" && disable !== "start" ? radius : 0,
|
|
218
|
+
borderTopRightRadius: disable !== "top" && disable !== "end" && (vertical && isFirst || !vertical && isLast) ? radius : 0,
|
|
219
|
+
borderBottomLeftRadius: disable !== "bottom" && disable !== "start" && (vertical && isLast || !vertical && isFirst) ? radius : 0,
|
|
220
|
+
borderBottomRightRadius: isLast && disable !== "bottom" && disable !== "end" ? radius : 0
|
|
221
|
+
}),
|
|
222
|
+
cloneElementWithPropOrder = (child, props) => {
|
|
223
|
+
const next = (0, import_core.mergeProps)(child.props, props, (0, import_core.getConfig)().shorthands);
|
|
224
|
+
return import_react.default.cloneElement({
|
|
225
|
+
...child,
|
|
226
|
+
props: null
|
|
227
|
+
}, next);
|
|
228
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
7
|
+
get: () => from[key],
|
|
8
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
9
|
+
});
|
|
10
|
+
return to;
|
|
11
|
+
},
|
|
12
|
+
__reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
13
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
14
|
+
value: !0
|
|
15
|
+
}), mod);
|
|
16
|
+
var src_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(src_exports);
|
|
18
|
+
__reExport(src_exports, require("./Group.cjs"), module.exports);
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: !0
|
|
28
|
+
}) : target, mod)),
|
|
29
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
30
|
+
value: !0
|
|
31
|
+
}), mod);
|
|
32
|
+
var useIndexedChildren_exports = {};
|
|
33
|
+
__export(useIndexedChildren_exports, {
|
|
34
|
+
useIndex: () => useIndex,
|
|
35
|
+
useIndexedChildren: () => useIndexedChildren
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(useIndexedChildren_exports);
|
|
38
|
+
var React = __toESM(require("react")),
|
|
39
|
+
import_jsx_runtime = require("react/jsx-runtime");
|
|
40
|
+
const MaxIndexContext = React.createContext([]),
|
|
41
|
+
IndexContext = React.createContext(null);
|
|
42
|
+
function useIndex() {
|
|
43
|
+
const maxIndexPath = React.useContext(MaxIndexContext),
|
|
44
|
+
indexPathString = React.useContext(IndexContext);
|
|
45
|
+
return React.useMemo(() => {
|
|
46
|
+
if (indexPathString === null) return null;
|
|
47
|
+
const indexPath = parseIndexPath(indexPathString),
|
|
48
|
+
maxIndex = maxIndexPath[maxIndexPath.length - 1],
|
|
49
|
+
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]);
|
|
62
|
+
}
|
|
63
|
+
function useIndexedChildren(children) {
|
|
64
|
+
const parentMaxIndexPath = React.useContext(MaxIndexContext),
|
|
65
|
+
indexPathString = React.useContext(IndexContext),
|
|
66
|
+
childrenCount = React.Children.count(children),
|
|
67
|
+
maxIndexPath = React.useMemo(() => parentMaxIndexPath.concat(childrenCount - 1), [childrenCount]);
|
|
68
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(MaxIndexContext.Provider, {
|
|
69
|
+
value: maxIndexPath,
|
|
70
|
+
children: React.Children.map(children, (child, index) => React.isValidElement(child) ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(IndexContext.Provider, {
|
|
71
|
+
value: indexPathString ? `${indexPathString}.${index.toString()}` : index.toString(),
|
|
72
|
+
children: child
|
|
73
|
+
}, child.key) : child)
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
function parseIndexPath(indexPathString) {
|
|
77
|
+
return indexPathString.split(".").map(index => Number.parseInt(index, 10));
|
|
78
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/group",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.115.0",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"*.css"
|
|
6
6
|
],
|
|
@@ -29,18 +29,19 @@
|
|
|
29
29
|
"react-native": "./dist/cjs/index.native.js",
|
|
30
30
|
"types": "./types/index.d.ts",
|
|
31
31
|
"import": "./dist/esm/index.mjs",
|
|
32
|
-
"require": "./dist/cjs/index.
|
|
32
|
+
"require": "./dist/cjs/index.cjs",
|
|
33
|
+
"default": "./dist/cjs/index.native.js"
|
|
33
34
|
}
|
|
34
35
|
},
|
|
35
36
|
"dependencies": {
|
|
36
|
-
"@tamagui/core": "1.
|
|
37
|
-
"@tamagui/create-context": "1.
|
|
38
|
-
"@tamagui/helpers": "1.
|
|
39
|
-
"@tamagui/stacks": "1.
|
|
40
|
-
"@tamagui/use-controllable-state": "1.
|
|
37
|
+
"@tamagui/core": "1.115.0",
|
|
38
|
+
"@tamagui/create-context": "1.115.0",
|
|
39
|
+
"@tamagui/helpers": "1.115.0",
|
|
40
|
+
"@tamagui/stacks": "1.115.0",
|
|
41
|
+
"@tamagui/use-controllable-state": "1.115.0"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
|
-
"@tamagui/build": "1.
|
|
44
|
+
"@tamagui/build": "1.115.0",
|
|
44
45
|
"react": "^18.2.0 || ^19.0.0"
|
|
45
46
|
},
|
|
46
47
|
"publishConfig": {
|
package/dist/cjs/Group.js
DELETED
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
9
|
-
}, __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
-
return to;
|
|
14
|
-
};
|
|
15
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
21
|
-
mod
|
|
22
|
-
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
23
|
-
var Group_exports = {};
|
|
24
|
-
__export(Group_exports, {
|
|
25
|
-
Group: () => Group,
|
|
26
|
-
GroupFrame: () => GroupFrame,
|
|
27
|
-
XGroup: () => XGroup,
|
|
28
|
-
YGroup: () => YGroup,
|
|
29
|
-
useGroupItem: () => useGroupItem
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(Group_exports);
|
|
32
|
-
var import_core = require("@tamagui/core"), import_create_context = require("@tamagui/create-context"), import_helpers = require("@tamagui/helpers"), import_stacks = require("@tamagui/stacks"), import_use_controllable_state = require("@tamagui/use-controllable-state"), import_react = __toESM(require("react")), import_react_native = require("react-native-web"), import_useIndexedChildren = require("./useIndexedChildren"), import_jsx_runtime = require("react/jsx-runtime");
|
|
33
|
-
const GROUP_NAME = "Group", [createGroupContext, createGroupScope] = (0, import_create_context.createContextScope)(GROUP_NAME), [GroupProvider, useGroupContext] = createGroupContext(GROUP_NAME), GroupFrame = (0, import_core.styled)(import_stacks.ThemeableStack, {
|
|
34
|
-
name: "GroupFrame",
|
|
35
|
-
variants: {
|
|
36
|
-
unstyled: {
|
|
37
|
-
false: {
|
|
38
|
-
size: "$true"
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
size: (val, { tokens }) => ({
|
|
42
|
-
borderRadius: tokens.radius[val] ?? val ?? tokens.radius.$true
|
|
43
|
-
})
|
|
44
|
-
},
|
|
45
|
-
defaultVariants: {
|
|
46
|
-
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
function createGroup(verticalDefault) {
|
|
50
|
-
return (0, import_helpers.withStaticProperties)(
|
|
51
|
-
GroupFrame.styleable((props, ref) => {
|
|
52
|
-
const activeProps = (0, import_core.useProps)(props), {
|
|
53
|
-
__scopeGroup,
|
|
54
|
-
children: childrenProp,
|
|
55
|
-
space,
|
|
56
|
-
size = "$true",
|
|
57
|
-
spaceDirection,
|
|
58
|
-
separator,
|
|
59
|
-
scrollable,
|
|
60
|
-
axis = verticalDefault ? "vertical" : "horizontal",
|
|
61
|
-
orientation = axis,
|
|
62
|
-
disabled: disabledProp,
|
|
63
|
-
disablePassBorderRadius: disablePassBorderRadiusProp,
|
|
64
|
-
borderRadius,
|
|
65
|
-
forceUseItem,
|
|
66
|
-
...restProps
|
|
67
|
-
} = activeProps, vertical = orientation === "vertical", [itemChildrenCount, setItemChildrenCount] = (0, import_use_controllable_state.useControllableState)({
|
|
68
|
-
defaultProp: forceUseItem ? 1 : 0
|
|
69
|
-
}), isUsingItems = itemChildrenCount > 0, radius = borderRadius ?? (size ? (0, import_core.getVariableValue)((0, import_core.getTokens)().radius[size]) - 1 : void 0), disablePassBorderRadius = disablePassBorderRadiusProp ?? !(radius !== void 0), childrenArray = import_react.default.Children.toArray(childrenProp), children = isUsingItems ? import_react.default.Children.toArray(childrenProp).filter(import_react.default.isValidElement) : childrenArray.map((child, i) => {
|
|
70
|
-
if (!import_react.default.isValidElement(child) || child.type === import_react.default.Fragment)
|
|
71
|
-
return child;
|
|
72
|
-
const disabled = child.props.disabled ?? disabledProp, isFirst = i === 0, isLast = i === childrenArray.length - 1, radiusStyles = disablePassBorderRadius === !0 ? null : getBorderRadius({
|
|
73
|
-
isFirst,
|
|
74
|
-
isLast,
|
|
75
|
-
radius,
|
|
76
|
-
vertical,
|
|
77
|
-
disable: disablePassBorderRadius
|
|
78
|
-
}), props2 = {
|
|
79
|
-
disabled,
|
|
80
|
-
...(0, import_core.isTamaguiElement)(child) ? radiusStyles : { style: radiusStyles }
|
|
81
|
-
};
|
|
82
|
-
return cloneElementWithPropOrder(child, props2);
|
|
83
|
-
}), indexedChildren = (0, import_useIndexedChildren.useIndexedChildren)(
|
|
84
|
-
(0, import_core.spacedChildren)({
|
|
85
|
-
direction: spaceDirection,
|
|
86
|
-
separator,
|
|
87
|
-
space,
|
|
88
|
-
children
|
|
89
|
-
})
|
|
90
|
-
), onItemMount = import_react.default.useCallback(
|
|
91
|
-
() => setItemChildrenCount((prev) => prev + 1),
|
|
92
|
-
[]
|
|
93
|
-
), onItemUnmount = import_react.default.useCallback(
|
|
94
|
-
() => setItemChildrenCount((prev) => prev - 1),
|
|
95
|
-
[]
|
|
96
|
-
);
|
|
97
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
98
|
-
GroupProvider,
|
|
99
|
-
{
|
|
100
|
-
disablePassBorderRadius,
|
|
101
|
-
vertical: orientation === "vertical",
|
|
102
|
-
radius,
|
|
103
|
-
disabled: disabledProp,
|
|
104
|
-
onItemMount,
|
|
105
|
-
onItemUnmount,
|
|
106
|
-
scope: __scopeGroup,
|
|
107
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
108
|
-
GroupFrame,
|
|
109
|
-
{
|
|
110
|
-
ref,
|
|
111
|
-
size,
|
|
112
|
-
flexDirection: orientation === "horizontal" ? "row" : "column",
|
|
113
|
-
borderRadius,
|
|
114
|
-
...restProps,
|
|
115
|
-
children: wrapScroll({ ...activeProps, orientation }, indexedChildren)
|
|
116
|
-
}
|
|
117
|
-
)
|
|
118
|
-
}
|
|
119
|
-
);
|
|
120
|
-
}),
|
|
121
|
-
{
|
|
122
|
-
Item: GroupItem
|
|
123
|
-
}
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
const GroupItem = import_react.default.forwardRef(
|
|
127
|
-
(props, _ref) => {
|
|
128
|
-
const { __scopeGroup, children, forcePlacement } = props, groupItemProps = useGroupItem(
|
|
129
|
-
{ disabled: import_react.default.isValidElement(children) ? children.props.disabled : void 0 },
|
|
130
|
-
forcePlacement,
|
|
131
|
-
__scopeGroup
|
|
132
|
-
);
|
|
133
|
-
return !import_react.default.isValidElement(children) || children.type === import_react.default.Fragment ? children : (0, import_core.isTamaguiElement)(children) ? import_react.default.cloneElement(children, groupItemProps) : import_react.default.cloneElement(children, {
|
|
134
|
-
style: {
|
|
135
|
-
// @ts-ignore
|
|
136
|
-
...children.props?.style,
|
|
137
|
-
...groupItemProps
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
), useGroupItem = (childrenProps, forcePlacement, __scopeGroup) => {
|
|
142
|
-
const treeIndex = (0, import_useIndexedChildren.useIndex)(), context = useGroupContext("GroupItem", __scopeGroup);
|
|
143
|
-
if (import_react.default.useEffect(() => (context.onItemMount(), () => {
|
|
144
|
-
context.onItemUnmount();
|
|
145
|
-
}), []), !treeIndex)
|
|
146
|
-
throw Error("<Group.Item/> should only be used within a <Group/>");
|
|
147
|
-
const isFirst = forcePlacement === "first" || forcePlacement !== "last" && treeIndex.index === 0, isLast = forcePlacement === "last" || forcePlacement !== "first" && treeIndex.index === treeIndex.maxIndex;
|
|
148
|
-
let propsToPass = {
|
|
149
|
-
disabled: childrenProps.disabled ?? context.disabled
|
|
150
|
-
};
|
|
151
|
-
if (context.disablePassBorderRadius !== !0) {
|
|
152
|
-
const borderRadius = getBorderRadius({
|
|
153
|
-
radius: context.radius,
|
|
154
|
-
isFirst,
|
|
155
|
-
isLast,
|
|
156
|
-
vertical: context.vertical,
|
|
157
|
-
disable: context.disablePassBorderRadius
|
|
158
|
-
});
|
|
159
|
-
return { ...propsToPass, ...borderRadius };
|
|
160
|
-
}
|
|
161
|
-
return propsToPass;
|
|
162
|
-
}, Group = createGroup(!0), YGroup = Group, XGroup = createGroup(!1), wrapScroll = ({ scrollable, orientation, showScrollIndicator = !1 }, children) => scrollable ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
163
|
-
import_react_native.ScrollView,
|
|
164
|
-
{
|
|
165
|
-
...orientation === "vertical" && {
|
|
166
|
-
showsVerticalScrollIndicator: showScrollIndicator
|
|
167
|
-
},
|
|
168
|
-
...orientation === "horizontal" && {
|
|
169
|
-
horizontal: !0,
|
|
170
|
-
showsHorizontalScrollIndicator: showScrollIndicator
|
|
171
|
-
},
|
|
172
|
-
children
|
|
173
|
-
}
|
|
174
|
-
) : children, getBorderRadius = ({
|
|
175
|
-
isFirst,
|
|
176
|
-
isLast,
|
|
177
|
-
radius,
|
|
178
|
-
vertical,
|
|
179
|
-
disable
|
|
180
|
-
}) => ({
|
|
181
|
-
borderTopLeftRadius: isFirst && disable !== "top" && disable !== "start" ? radius : 0,
|
|
182
|
-
borderTopRightRadius: disable !== "top" && disable !== "end" && (vertical && isFirst || !vertical && isLast) ? radius : 0,
|
|
183
|
-
borderBottomLeftRadius: disable !== "bottom" && disable !== "start" && (vertical && isLast || !vertical && isFirst) ? radius : 0,
|
|
184
|
-
borderBottomRightRadius: isLast && disable !== "bottom" && disable !== "end" ? radius : 0
|
|
185
|
-
}), cloneElementWithPropOrder = (child, props) => {
|
|
186
|
-
const next = (0, import_core.mergeProps)(child.props, props, (0, import_core.getConfig)().shorthands);
|
|
187
|
-
return import_react.default.cloneElement({ ...child, props: null }, next);
|
|
188
|
-
};
|
|
189
|
-
//# sourceMappingURL=Group.js.map
|
package/dist/cjs/index.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
7
|
-
for (let key of __getOwnPropNames(from))
|
|
8
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
|
-
return to;
|
|
10
|
-
}, __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
11
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
12
|
-
var src_exports = {};
|
|
13
|
-
module.exports = __toCommonJS(src_exports);
|
|
14
|
-
__reExport(src_exports, require("./Group"), module.exports);
|
|
15
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
9
|
-
}, __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
-
return to;
|
|
14
|
-
};
|
|
15
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
21
|
-
mod
|
|
22
|
-
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
23
|
-
var useIndexedChildren_exports = {};
|
|
24
|
-
__export(useIndexedChildren_exports, {
|
|
25
|
-
useIndex: () => useIndex,
|
|
26
|
-
useIndexedChildren: () => useIndexedChildren
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(useIndexedChildren_exports);
|
|
29
|
-
var React = __toESM(require("react")), import_jsx_runtime = require("react/jsx-runtime");
|
|
30
|
-
const MaxIndexContext = React.createContext([]), IndexContext = React.createContext(null);
|
|
31
|
-
function useIndex() {
|
|
32
|
-
const maxIndexPath = React.useContext(MaxIndexContext), indexPathString = React.useContext(IndexContext);
|
|
33
|
-
return React.useMemo(() => {
|
|
34
|
-
if (indexPathString === null)
|
|
35
|
-
return null;
|
|
36
|
-
const indexPath = parseIndexPath(indexPathString), maxIndex = maxIndexPath[maxIndexPath.length - 1], index = indexPath[indexPath.length - 1];
|
|
37
|
-
return {
|
|
38
|
-
maxIndex,
|
|
39
|
-
maxIndexPath,
|
|
40
|
-
index,
|
|
41
|
-
indexPath,
|
|
42
|
-
indexPathString,
|
|
43
|
-
isFirst: index === 0,
|
|
44
|
-
isLast: index === maxIndex,
|
|
45
|
-
isEven: index % 2 === 0,
|
|
46
|
-
isOdd: Math.abs(index % 2) === 1
|
|
47
|
-
};
|
|
48
|
-
}, [maxIndexPath, indexPathString]);
|
|
49
|
-
}
|
|
50
|
-
function useIndexedChildren(children) {
|
|
51
|
-
const parentMaxIndexPath = React.useContext(MaxIndexContext), indexPathString = React.useContext(IndexContext), childrenCount = React.Children.count(children), maxIndexPath = React.useMemo(
|
|
52
|
-
() => parentMaxIndexPath.concat(childrenCount - 1),
|
|
53
|
-
[childrenCount]
|
|
54
|
-
);
|
|
55
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MaxIndexContext.Provider, { value: maxIndexPath, children: React.Children.map(
|
|
56
|
-
children,
|
|
57
|
-
(child, index) => React.isValidElement(child) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
58
|
-
IndexContext.Provider,
|
|
59
|
-
{
|
|
60
|
-
value: indexPathString ? `${indexPathString}.${index.toString()}` : index.toString(),
|
|
61
|
-
children: child
|
|
62
|
-
},
|
|
63
|
-
child.key
|
|
64
|
-
) : child
|
|
65
|
-
) });
|
|
66
|
-
}
|
|
67
|
-
function parseIndexPath(indexPathString) {
|
|
68
|
-
return indexPathString.split(".").map((index) => Number.parseInt(index, 10));
|
|
69
|
-
}
|
|
70
|
-
//# sourceMappingURL=useIndexedChildren.js.map
|
|
File without changes
|
|
File without changes
|
|
File without changes
|