@tamagui/group 1.88.13 → 1.89.0-1706308641099

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Nate Wienert
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,190 @@
1
+ import { getConfig, getTokens, getVariableValue, isTamaguiElement, mergeProps, spacedChildren, styled, useProps } from "@tamagui/core";
2
+ import { createContextScope } from "@tamagui/create-context";
3
+ import { withStaticProperties } from "@tamagui/helpers";
4
+ import { ThemeableStack } from "@tamagui/stacks";
5
+ import { useControllableState } from "@tamagui/use-controllable-state";
6
+ import React, { Children, forwardRef, isValidElement } from "react";
7
+ import { ScrollView } from "react-native-web";
8
+ import { useIndex, useIndexedChildren } from "reforest";
9
+ import { jsx } from "react/jsx-runtime";
10
+ const GROUP_NAME = "Group",
11
+ [createGroupContext, createGroupScope] = createContextScope(GROUP_NAME),
12
+ [GroupProvider, useGroupContext] = createGroupContext(GROUP_NAME),
13
+ GroupFrame = styled(ThemeableStack, {
14
+ name: "GroupFrame",
15
+ variants: {
16
+ unstyled: {
17
+ false: {
18
+ size: "$true"
19
+ }
20
+ },
21
+ size: (val, {
22
+ tokens
23
+ }) => ({
24
+ borderRadius: tokens.radius[val] ?? val ?? tokens.radius.$true
25
+ })
26
+ },
27
+ defaultVariants: {
28
+ unstyled: process.env.TAMAGUI_HEADLESS === "1"
29
+ }
30
+ });
31
+ function createGroup(verticalDefault) {
32
+ return withStaticProperties(forwardRef((props, ref) => {
33
+ const activeProps = useProps(props),
34
+ {
35
+ __scopeGroup,
36
+ children: childrenProp,
37
+ space,
38
+ size = "$true",
39
+ spaceDirection,
40
+ separator,
41
+ scrollable,
42
+ axis = verticalDefault ? "vertical" : "horizontal",
43
+ orientation = axis,
44
+ disabled: disabledProp,
45
+ disablePassBorderRadius: disablePassBorderRadiusProp,
46
+ borderRadius,
47
+ forceUseItem,
48
+ ...restProps
49
+ } = activeProps,
50
+ vertical = orientation === "vertical",
51
+ [itemChildrenCount, setItemChildrenCount] = useControllableState({
52
+ defaultProp: forceUseItem ? 1 : 0
53
+ }),
54
+ isUsingItems = itemChildrenCount > 0,
55
+ radius = borderRadius ?? (size ? getVariableValue(getTokens().radius[size]) - 1 : void 0),
56
+ disablePassBorderRadius = disablePassBorderRadiusProp ?? !(radius !== void 0),
57
+ childrenArray = Children.toArray(childrenProp),
58
+ children = isUsingItems ? Children.toArray(childrenProp).filter(isValidElement) : childrenArray.map((child, i) => {
59
+ if (!isValidElement(child)) return child;
60
+ const disabled = child.props.disabled ?? disabledProp,
61
+ isFirst = i === 0,
62
+ isLast = i === childrenArray.length - 1,
63
+ radiusStyles = disablePassBorderRadius === !0 ? null : getBorderRadius({
64
+ isFirst,
65
+ isLast,
66
+ radius,
67
+ vertical,
68
+ disable: disablePassBorderRadius
69
+ }),
70
+ props2 = {
71
+ disabled,
72
+ ...(isTamaguiElement(child) ? radiusStyles : {
73
+ style: radiusStyles
74
+ })
75
+ };
76
+ return cloneElementWithPropOrder(child, props2);
77
+ }),
78
+ indexedChildren = useIndexedChildren(spacedChildren({
79
+ direction: spaceDirection,
80
+ separator,
81
+ // @ts-ignore
82
+ space,
83
+ children
84
+ })),
85
+ onItemMount = React.useCallback(() => setItemChildrenCount(prev => prev + 1), []),
86
+ onItemUnmount = React.useCallback(() => setItemChildrenCount(prev => prev - 1), []);
87
+ return /* @__PURE__ */jsx(GroupProvider, {
88
+ disablePassBorderRadius,
89
+ vertical: orientation === "vertical",
90
+ radius,
91
+ disabled: disabledProp,
92
+ onItemMount,
93
+ onItemUnmount,
94
+ scope: __scopeGroup,
95
+ children: /* @__PURE__ */jsx(GroupFrame, {
96
+ ref,
97
+ size,
98
+ flexDirection: orientation === "horizontal" ? "row" : "column",
99
+ borderRadius,
100
+ ...restProps,
101
+ children: wrapScroll({
102
+ ...activeProps,
103
+ orientation
104
+ }, indexedChildren)
105
+ })
106
+ });
107
+ }), {
108
+ Item: GroupItem
109
+ });
110
+ }
111
+ const GroupItem = props => {
112
+ const {
113
+ __scopeGroup,
114
+ children,
115
+ forcePlacement
116
+ } = props,
117
+ groupItemProps = useGroupItem({
118
+ disabled: isValidElement(children) ? children.props.disabled : void 0
119
+ }, forcePlacement, __scopeGroup);
120
+ return isValidElement(children) ? isTamaguiElement(children) ? React.cloneElement(children, groupItemProps) : React.cloneElement(children, {
121
+ style: {
122
+ // @ts-ignore
123
+ ...children.props?.style,
124
+ ...groupItemProps
125
+ }
126
+ }) : children;
127
+ },
128
+ useGroupItem = (childrenProps, forcePlacement, __scopeGroup) => {
129
+ const treeIndex = useIndex(),
130
+ context = useGroupContext("GroupItem", __scopeGroup);
131
+ if (React.useEffect(() => (context.onItemMount(), () => {
132
+ context.onItemUnmount();
133
+ }), []), !treeIndex) throw Error("<Group.Item/> should only be used within a <Group/>");
134
+ const isFirst = forcePlacement === "first" || forcePlacement !== "last" && treeIndex.index === 0,
135
+ isLast = forcePlacement === "last" || forcePlacement !== "first" && treeIndex.index === treeIndex.maxIndex;
136
+ let propsToPass = {
137
+ disabled: childrenProps.disabled ?? context.disabled
138
+ };
139
+ if (context.disablePassBorderRadius !== !0) {
140
+ const borderRadius = getBorderRadius({
141
+ radius: context.radius,
142
+ isFirst,
143
+ isLast,
144
+ vertical: context.vertical,
145
+ disable: context.disablePassBorderRadius
146
+ });
147
+ return {
148
+ ...propsToPass,
149
+ ...borderRadius
150
+ };
151
+ }
152
+ return propsToPass;
153
+ },
154
+ Group = createGroup(!0),
155
+ YGroup = Group,
156
+ XGroup = createGroup(!1),
157
+ wrapScroll = ({
158
+ scrollable,
159
+ orientation,
160
+ showScrollIndicator = !1
161
+ }, children) => scrollable ? /* @__PURE__ */jsx(ScrollView, {
162
+ ...(orientation === "vertical" && {
163
+ showsVerticalScrollIndicator: showScrollIndicator
164
+ }),
165
+ ...(orientation === "horizontal" && {
166
+ horizontal: !0,
167
+ showsHorizontalScrollIndicator: showScrollIndicator
168
+ }),
169
+ children
170
+ }) : children,
171
+ getBorderRadius = ({
172
+ isFirst,
173
+ isLast,
174
+ radius,
175
+ vertical,
176
+ disable
177
+ }) => ({
178
+ borderTopLeftRadius: isFirst && disable !== "top" && disable !== "start" ? radius : 0,
179
+ borderTopRightRadius: disable !== "top" && disable !== "end" && (vertical && isFirst || !vertical && isLast) ? radius : 0,
180
+ borderBottomLeftRadius: disable !== "bottom" && disable !== "start" && (vertical && isLast || !vertical && isFirst) ? radius : 0,
181
+ borderBottomRightRadius: isLast && disable !== "bottom" && disable !== "end" ? radius : 0
182
+ }),
183
+ cloneElementWithPropOrder = (child, props) => {
184
+ const next = mergeProps(child.props, props, getConfig().shorthands);
185
+ return React.cloneElement({
186
+ ...child,
187
+ props: null
188
+ }, next);
189
+ };
190
+ export { Group, GroupFrame, XGroup, YGroup, useGroupItem };
@@ -0,0 +1 @@
1
+ export * from "./Group.mjs";
@@ -0,0 +1,190 @@
1
+ import { getConfig, getTokens, getVariableValue, isTamaguiElement, mergeProps, spacedChildren, styled, useProps } from "@tamagui/core";
2
+ import { createContextScope } from "@tamagui/create-context";
3
+ import { withStaticProperties } from "@tamagui/helpers";
4
+ import { ThemeableStack } from "@tamagui/stacks";
5
+ import { useControllableState } from "@tamagui/use-controllable-state";
6
+ import React, { Children, forwardRef, isValidElement } from "react";
7
+ import { ScrollView } from "react-native-web";
8
+ import { useIndex, useIndexedChildren } from "reforest";
9
+ import { jsx } from "react/jsx-runtime";
10
+ const GROUP_NAME = "Group",
11
+ [createGroupContext, createGroupScope] = createContextScope(GROUP_NAME),
12
+ [GroupProvider, useGroupContext] = createGroupContext(GROUP_NAME),
13
+ GroupFrame = styled(ThemeableStack, {
14
+ name: "GroupFrame",
15
+ variants: {
16
+ unstyled: {
17
+ false: {
18
+ size: "$true"
19
+ }
20
+ },
21
+ size: (val, {
22
+ tokens
23
+ }) => ({
24
+ borderRadius: tokens.radius[val] ?? val ?? tokens.radius.$true
25
+ })
26
+ },
27
+ defaultVariants: {
28
+ unstyled: process.env.TAMAGUI_HEADLESS === "1"
29
+ }
30
+ });
31
+ function createGroup(verticalDefault) {
32
+ return withStaticProperties(forwardRef((props, ref) => {
33
+ const activeProps = useProps(props),
34
+ {
35
+ __scopeGroup,
36
+ children: childrenProp,
37
+ space,
38
+ size = "$true",
39
+ spaceDirection,
40
+ separator,
41
+ scrollable,
42
+ axis = verticalDefault ? "vertical" : "horizontal",
43
+ orientation = axis,
44
+ disabled: disabledProp,
45
+ disablePassBorderRadius: disablePassBorderRadiusProp,
46
+ borderRadius,
47
+ forceUseItem,
48
+ ...restProps
49
+ } = activeProps,
50
+ vertical = orientation === "vertical",
51
+ [itemChildrenCount, setItemChildrenCount] = useControllableState({
52
+ defaultProp: forceUseItem ? 1 : 0
53
+ }),
54
+ isUsingItems = itemChildrenCount > 0,
55
+ radius = borderRadius ?? (size ? getVariableValue(getTokens().radius[size]) - 1 : void 0),
56
+ disablePassBorderRadius = disablePassBorderRadiusProp ?? !(radius !== void 0),
57
+ childrenArray = Children.toArray(childrenProp),
58
+ children = isUsingItems ? Children.toArray(childrenProp).filter(isValidElement) : childrenArray.map((child, i) => {
59
+ if (!isValidElement(child)) return child;
60
+ const disabled = child.props.disabled ?? disabledProp,
61
+ isFirst = i === 0,
62
+ isLast = i === childrenArray.length - 1,
63
+ radiusStyles = disablePassBorderRadius === !0 ? null : getBorderRadius({
64
+ isFirst,
65
+ isLast,
66
+ radius,
67
+ vertical,
68
+ disable: disablePassBorderRadius
69
+ }),
70
+ props2 = {
71
+ disabled,
72
+ ...(isTamaguiElement(child) ? radiusStyles : {
73
+ style: radiusStyles
74
+ })
75
+ };
76
+ return cloneElementWithPropOrder(child, props2);
77
+ }),
78
+ indexedChildren = useIndexedChildren(spacedChildren({
79
+ direction: spaceDirection,
80
+ separator,
81
+ // @ts-ignore
82
+ space,
83
+ children
84
+ })),
85
+ onItemMount = React.useCallback(() => setItemChildrenCount(prev => prev + 1), []),
86
+ onItemUnmount = React.useCallback(() => setItemChildrenCount(prev => prev - 1), []);
87
+ return /* @__PURE__ */jsx(GroupProvider, {
88
+ disablePassBorderRadius,
89
+ vertical: orientation === "vertical",
90
+ radius,
91
+ disabled: disabledProp,
92
+ onItemMount,
93
+ onItemUnmount,
94
+ scope: __scopeGroup,
95
+ children: /* @__PURE__ */jsx(GroupFrame, {
96
+ ref,
97
+ size,
98
+ flexDirection: orientation === "horizontal" ? "row" : "column",
99
+ borderRadius,
100
+ ...restProps,
101
+ children: wrapScroll({
102
+ ...activeProps,
103
+ orientation
104
+ }, indexedChildren)
105
+ })
106
+ });
107
+ }), {
108
+ Item: GroupItem
109
+ });
110
+ }
111
+ const GroupItem = props => {
112
+ const {
113
+ __scopeGroup,
114
+ children,
115
+ forcePlacement
116
+ } = props,
117
+ groupItemProps = useGroupItem({
118
+ disabled: isValidElement(children) ? children.props.disabled : void 0
119
+ }, forcePlacement, __scopeGroup);
120
+ return isValidElement(children) ? isTamaguiElement(children) ? React.cloneElement(children, groupItemProps) : React.cloneElement(children, {
121
+ style: {
122
+ // @ts-ignore
123
+ ...children.props?.style,
124
+ ...groupItemProps
125
+ }
126
+ }) : children;
127
+ },
128
+ useGroupItem = (childrenProps, forcePlacement, __scopeGroup) => {
129
+ const treeIndex = useIndex(),
130
+ context = useGroupContext("GroupItem", __scopeGroup);
131
+ if (React.useEffect(() => (context.onItemMount(), () => {
132
+ context.onItemUnmount();
133
+ }), []), !treeIndex) throw Error("<Group.Item/> should only be used within a <Group/>");
134
+ const isFirst = forcePlacement === "first" || forcePlacement !== "last" && treeIndex.index === 0,
135
+ isLast = forcePlacement === "last" || forcePlacement !== "first" && treeIndex.index === treeIndex.maxIndex;
136
+ let propsToPass = {
137
+ disabled: childrenProps.disabled ?? context.disabled
138
+ };
139
+ if (context.disablePassBorderRadius !== !0) {
140
+ const borderRadius = getBorderRadius({
141
+ radius: context.radius,
142
+ isFirst,
143
+ isLast,
144
+ vertical: context.vertical,
145
+ disable: context.disablePassBorderRadius
146
+ });
147
+ return {
148
+ ...propsToPass,
149
+ ...borderRadius
150
+ };
151
+ }
152
+ return propsToPass;
153
+ },
154
+ Group = createGroup(!0),
155
+ YGroup = Group,
156
+ XGroup = createGroup(!1),
157
+ wrapScroll = ({
158
+ scrollable,
159
+ orientation,
160
+ showScrollIndicator = !1
161
+ }, children) => scrollable ? /* @__PURE__ */jsx(ScrollView, {
162
+ ...(orientation === "vertical" && {
163
+ showsVerticalScrollIndicator: showScrollIndicator
164
+ }),
165
+ ...(orientation === "horizontal" && {
166
+ horizontal: !0,
167
+ showsHorizontalScrollIndicator: showScrollIndicator
168
+ }),
169
+ children
170
+ }) : children,
171
+ getBorderRadius = ({
172
+ isFirst,
173
+ isLast,
174
+ radius,
175
+ vertical,
176
+ disable
177
+ }) => ({
178
+ borderTopLeftRadius: isFirst && disable !== "top" && disable !== "start" ? radius : 0,
179
+ borderTopRightRadius: disable !== "top" && disable !== "end" && (vertical && isFirst || !vertical && isLast) ? radius : 0,
180
+ borderBottomLeftRadius: disable !== "bottom" && disable !== "start" && (vertical && isLast || !vertical && isFirst) ? radius : 0,
181
+ borderBottomRightRadius: isLast && disable !== "bottom" && disable !== "end" ? radius : 0
182
+ }),
183
+ cloneElementWithPropOrder = (child, props) => {
184
+ const next = mergeProps(child.props, props, getConfig().shorthands);
185
+ return React.cloneElement({
186
+ ...child,
187
+ props: null
188
+ }, next);
189
+ };
190
+ export { Group, GroupFrame, XGroup, YGroup, useGroupItem };
@@ -0,0 +1 @@
1
+ export * from "./Group.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/group",
3
- "version": "1.88.13",
3
+ "version": "1.89.0-1706308641099",
4
4
  "sideEffects": [
5
5
  "*.css"
6
6
  ],
@@ -23,18 +23,18 @@
23
23
  "clean:build": "tamagui-build clean:build"
24
24
  },
25
25
  "dependencies": {
26
- "@tamagui/core": "1.88.13",
27
- "@tamagui/create-context": "1.88.13",
28
- "@tamagui/helpers": "1.88.13",
29
- "@tamagui/stacks": "1.88.13",
30
- "@tamagui/use-controllable-state": "1.88.13",
26
+ "@tamagui/core": "1.89.0-1706308641099",
27
+ "@tamagui/create-context": "1.89.0-1706308641099",
28
+ "@tamagui/helpers": "1.89.0-1706308641099",
29
+ "@tamagui/stacks": "1.89.0-1706308641099",
30
+ "@tamagui/use-controllable-state": "1.89.0-1706308641099",
31
31
  "reforest": "^0.13.0"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "react": "*"
35
35
  },
36
36
  "devDependencies": {
37
- "@tamagui/build": "1.88.13",
37
+ "@tamagui/build": "1.89.0-1706308641099",
38
38
  "react": "^18.2.0"
39
39
  },
40
40
  "publishConfig": {