@tamagui/toggle-group 1.116.1 → 1.116.2

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.
@@ -0,0 +1,118 @@
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 Toggle_exports = {};
24
+ __export(Toggle_exports, {
25
+ Toggle: () => Toggle,
26
+ ToggleFrame: () => ToggleFrame
27
+ });
28
+ module.exports = __toCommonJS(Toggle_exports);
29
+ var import_helpers = require("@tamagui/helpers"), import_stacks = require("@tamagui/stacks"), import_use_controllable_state = require("@tamagui/use-controllable-state"), import_web = require("@tamagui/web"), React = __toESM(require("react")), import_jsx_runtime = require("react/jsx-runtime");
30
+ const NAME = "Toggle", ToggleFrame = (0, import_web.styled)(import_stacks.ThemeableStack, {
31
+ name: NAME,
32
+ tag: "button",
33
+ variants: {
34
+ unstyled: {
35
+ false: {
36
+ pressTheme: !0,
37
+ backgroundColor: "$background",
38
+ alignItems: "center",
39
+ justifyContent: "center",
40
+ display: "flex",
41
+ borderColor: "$borderColor",
42
+ borderWidth: 1,
43
+ margin: -1,
44
+ hoverStyle: {
45
+ backgroundColor: "$backgroundHover"
46
+ },
47
+ pressStyle: {
48
+ backgroundColor: "$backgroundPress"
49
+ },
50
+ focusStyle: {
51
+ borderColor: "$borderColorFocus"
52
+ },
53
+ focusVisibleStyle: {
54
+ outlineColor: "$outlineColor",
55
+ outlineWidth: 2,
56
+ outlineStyle: "solid"
57
+ }
58
+ }
59
+ },
60
+ active: {
61
+ true: {
62
+ zIndex: 1,
63
+ hoverStyle: {
64
+ backgroundColor: "$background"
65
+ },
66
+ focusStyle: {
67
+ borderColor: "$borderColor",
68
+ backgroundColor: "$background"
69
+ }
70
+ }
71
+ },
72
+ orientation: {
73
+ horizontal: {
74
+ flexDirection: "row",
75
+ spaceDirection: "horizontal"
76
+ },
77
+ vertical: {
78
+ flexDirection: "column",
79
+ spaceDirection: "vertical"
80
+ }
81
+ }
82
+ },
83
+ defaultVariants: {
84
+ unstyled: process.env.TAMAGUI_HEADLESS === "1"
85
+ }
86
+ }), Toggle = React.forwardRef(
87
+ function(props, forwardedRef) {
88
+ const {
89
+ pressed: pressedProp,
90
+ defaultPressed = !1,
91
+ onPressedChange,
92
+ ...buttonProps
93
+ } = props, [pressed = !1, setPressed] = (0, import_use_controllable_state.useControllableState)({
94
+ prop: pressedProp,
95
+ onChange: onPressedChange,
96
+ defaultProp: defaultPressed
97
+ });
98
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
99
+ ToggleFrame,
100
+ {
101
+ ...!props.unstyled && {
102
+ theme: pressed ? "active" : null,
103
+ themeShallow: !0
104
+ },
105
+ active: props.unstyled ? void 0 : pressed,
106
+ "aria-pressed": pressed,
107
+ "data-state": pressed ? "on" : "off",
108
+ "data-disabled": props.disabled ? "" : void 0,
109
+ ...buttonProps,
110
+ ref: forwardedRef,
111
+ onPress: (0, import_helpers.composeEventHandlers)(props.onPress ?? void 0, () => {
112
+ props.disabled || setPressed(!pressed);
113
+ })
114
+ }
115
+ );
116
+ }
117
+ );
118
+ //# sourceMappingURL=Toggle.js.map
@@ -0,0 +1,252 @@
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 ToggleGroup_exports = {};
24
+ __export(ToggleGroup_exports, {
25
+ ToggleGroup: () => ToggleGroup
26
+ });
27
+ module.exports = __toCommonJS(ToggleGroup_exports);
28
+ var import_constants = require("@tamagui/constants"), import_focusable = require("@tamagui/focusable"), import_font_size = require("@tamagui/font-size"), import_get_token = require("@tamagui/get-token"), import_group = require("@tamagui/group"), import_helpers = require("@tamagui/helpers"), import_helpers_tamagui = require("@tamagui/helpers-tamagui"), import_roving_focus = require("@tamagui/roving-focus"), import_use_controllable_state = require("@tamagui/use-controllable-state"), import_use_direction = require("@tamagui/use-direction"), import_web = require("@tamagui/web"), import_react = __toESM(require("react")), import_Toggle = require("./Toggle"), import_jsx_runtime = require("react/jsx-runtime");
29
+ const TOGGLE_GROUP_NAME = "ToggleGroup", TOGGLE_GROUP_ITEM_NAME = "ToggleGroupItem", TOGGLE_GROUP_CONTEXT = "ToggleGroup", { Provider: ToggleGroupItemProvider, useStyledContext: useToggleGroupItemContext } = (0, import_web.createStyledContext)(), { Provider: ToggleGroupContext, useStyledContext: useToggleGroupContext } = (0, import_web.createStyledContext)(), ToggleGroupItem = import_Toggle.ToggleFrame.extractable(
30
+ import_react.default.forwardRef(
31
+ (props, forwardedRef) => {
32
+ const { disablePassStyles, ...rest } = props, valueContext = useToggleGroupValueContext(props.__scopeToggleGroup), context = useToggleGroupContext(props.__scopeToggleGroup), pressed = valueContext?.value.includes(props.value), disabled = context.disabled || props.disabled || !1, groupItemProps = (0, import_group.useGroupItem)({ disabled }), size = props.size ?? context.size, sizeProps = props.unstyled ? {} : {
33
+ width: void 0,
34
+ height: void 0,
35
+ padding: (0, import_web.getVariableValue)(size) * 0.6
36
+ }, iconSize = (typeof size == "number" ? size * 0.7 : (0, import_font_size.getFontSize)(size)) * 1.2, theme = (0, import_web.useTheme)(), getThemedIcon = (0, import_helpers_tamagui.useGetThemedIcon)({ size: iconSize, color: theme.color }), children = import_react.default.Children.toArray(props.children).map((child) => props.disablePassStyles || !import_react.default.isValidElement(child) ? child : getThemedIcon(child)), commonProps = { pressed, disabled, ...sizeProps, ...rest, children }, inner = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
37
+ ToggleGroupItemImpl,
38
+ {
39
+ ...commonProps,
40
+ ref: forwardedRef,
41
+ focusable: !disabled,
42
+ disabled,
43
+ ...groupItemProps
44
+ }
45
+ );
46
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToggleGroupItemProvider, { scope: props.__scopeToggleGroup, children: context.rovingFocus ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
47
+ import_roving_focus.RovingFocusGroup.Item,
48
+ {
49
+ asChild: "except-style",
50
+ __scopeRovingFocusGroup: props.__scopeToggleGroup || TOGGLE_GROUP_CONTEXT,
51
+ focusable: !disabled,
52
+ active: pressed,
53
+ children: inner
54
+ }
55
+ ) : inner });
56
+ }
57
+ )
58
+ );
59
+ ToggleGroupItem.displayName = TOGGLE_GROUP_ITEM_NAME;
60
+ const ToggleGroupItemImpl = import_react.default.forwardRef((props, forwardedRef) => {
61
+ const { __scopeToggleGroup, value, ...itemProps } = props, valueContext = useToggleGroupValueContext(__scopeToggleGroup), singleProps = {
62
+ "aria-pressed": void 0
63
+ }, typeProps = valueContext.type === "single" ? singleProps : void 0;
64
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
65
+ import_Toggle.Toggle,
66
+ {
67
+ ...typeProps,
68
+ ...itemProps,
69
+ ref: forwardedRef,
70
+ onPressedChange: (pressed) => {
71
+ pressed ? valueContext.onItemActivate(value) : valueContext.onItemDeactivate(value);
72
+ }
73
+ }
74
+ );
75
+ }), ToggleGroup = (0, import_helpers.withStaticProperties)(
76
+ import_react.default.forwardRef(
77
+ (props, forwardedRef) => {
78
+ const { type, ...toggleGroupProps } = props;
79
+ if (import_constants.isWeb || import_react.default.useEffect(() => {
80
+ if (props.id)
81
+ return (0, import_focusable.registerFocusable)(props.id, {
82
+ // TODO: would be nice to focus on the first child later - could be done with reforest
83
+ // for now leaving it empty
84
+ focus: () => {
85
+ }
86
+ });
87
+ }, [props.id]), type === "single")
88
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToggleGroupImplSingle, { ...toggleGroupProps, ref: forwardedRef });
89
+ if (type === "multiple")
90
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToggleGroupImplMultiple, { ...toggleGroupProps, ref: forwardedRef });
91
+ throw new Error(`Missing prop \`type\` expected on \`${TOGGLE_GROUP_NAME}\``);
92
+ }
93
+ ),
94
+ {
95
+ Item: ToggleGroupItem
96
+ }
97
+ );
98
+ ToggleGroup.displayName = TOGGLE_GROUP_NAME;
99
+ const {
100
+ Provider: ToggleGroupValueProvider,
101
+ useStyledContext: useToggleGroupValueContext
102
+ } = (0, import_web.createStyledContext)(), ToggleGroupImplSingle = import_react.default.forwardRef((props, forwardedRef) => {
103
+ const {
104
+ value: valueProp,
105
+ defaultValue,
106
+ onValueChange = () => {
107
+ },
108
+ disableDeactivation = !1,
109
+ ...toggleGroupSingleProps
110
+ } = props, [value, setValue] = (0, import_use_controllable_state.useControllableState)({
111
+ prop: valueProp,
112
+ defaultProp: defaultValue,
113
+ onChange: onValueChange
114
+ });
115
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
116
+ ToggleGroupValueProvider,
117
+ {
118
+ scope: props.__scopeToggleGroup,
119
+ type: "single",
120
+ value: value ? [value] : [],
121
+ defaultValue: value,
122
+ onItemActivate: setValue,
123
+ onItemDeactivate: import_react.default.useCallback(
124
+ () => disableDeactivation ? null : setValue(""),
125
+ [setValue, disableDeactivation]
126
+ ),
127
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToggleGroupImpl, { ...toggleGroupSingleProps, ref: forwardedRef })
128
+ }
129
+ );
130
+ }), ToggleGroupImplMultiple = import_react.default.forwardRef((props, forwardedRef) => {
131
+ const {
132
+ value: valueProp,
133
+ defaultValue,
134
+ onValueChange = () => {
135
+ },
136
+ disableDeactivation,
137
+ ...toggleGroupMultipleProps
138
+ } = props, [value = [], setValue] = (0, import_use_controllable_state.useControllableState)({
139
+ prop: valueProp,
140
+ defaultProp: defaultValue,
141
+ onChange: onValueChange
142
+ }), handleButtonActivate = import_react.default.useCallback(
143
+ (itemValue) => setValue((prevValue = []) => [...prevValue, itemValue]),
144
+ [setValue]
145
+ ), handleButtonDeactivate = import_react.default.useCallback(
146
+ (itemValue) => setValue((prevValue = []) => prevValue.filter((value2) => value2 !== itemValue)),
147
+ [setValue]
148
+ );
149
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
150
+ ToggleGroupValueProvider,
151
+ {
152
+ scope: props.__scopeToggleGroup,
153
+ type: "multiple",
154
+ value,
155
+ defaultValue: value,
156
+ onItemActivate: handleButtonActivate,
157
+ onItemDeactivate: handleButtonDeactivate,
158
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToggleGroupImpl, { ...toggleGroupMultipleProps, ref: forwardedRef })
159
+ }
160
+ );
161
+ });
162
+ ToggleGroup.displayName = TOGGLE_GROUP_NAME;
163
+ const ToggleGroupImplElementFrame = (0, import_web.styled)(import_group.Group, {
164
+ name: TOGGLE_GROUP_NAME,
165
+ variants: {
166
+ unstyled: {
167
+ false: {
168
+ backgroundColor: "$background"
169
+ }
170
+ },
171
+ orientation: {
172
+ vertical: {
173
+ flexDirection: "column",
174
+ spaceDirection: "vertical"
175
+ },
176
+ horizontal: {
177
+ flexDirection: "row",
178
+ spaceDirection: "horizontal"
179
+ }
180
+ }
181
+ },
182
+ defaultVariants: {
183
+ unstyled: process.env.TAMAGUI_HEADLESS === "1"
184
+ }
185
+ }), ToggleGroupImpl = ToggleGroupImplElementFrame.extractable(
186
+ import_react.default.forwardRef(
187
+ (props, forwardedRef) => {
188
+ const {
189
+ __scopeToggleGroup,
190
+ disabled = !1,
191
+ orientation = "horizontal",
192
+ dir,
193
+ rovingFocus = !0,
194
+ loop = !0,
195
+ unstyled = !1,
196
+ size: sizeProp = "$true",
197
+ sizeAdjust = 0,
198
+ ...toggleGroupProps
199
+ } = props, direction = (0, import_use_direction.useDirection)(dir), commonProps = {
200
+ role: "group",
201
+ dir: direction,
202
+ ...toggleGroupProps
203
+ }, adjustedSize = (0, import_web.getVariableValue)(
204
+ (0, import_get_token.getSize)(sizeProp, {
205
+ shift: sizeAdjust
206
+ })
207
+ ), size = Math.round(adjustedSize * 0.45);
208
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
209
+ ToggleGroupContext,
210
+ {
211
+ scope: __scopeToggleGroup,
212
+ rovingFocus,
213
+ disabled,
214
+ size,
215
+ children: rovingFocus ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
216
+ import_roving_focus.RovingFocusGroup,
217
+ {
218
+ asChild: "except-style",
219
+ __scopeRovingFocusGroup: __scopeToggleGroup || TOGGLE_GROUP_CONTEXT,
220
+ orientation,
221
+ dir: direction,
222
+ loop,
223
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
224
+ ToggleGroupImplElementFrame,
225
+ {
226
+ "aria-orientation": orientation,
227
+ orientation,
228
+ axis: orientation,
229
+ ref: forwardedRef,
230
+ "data-disabled": disabled ? "" : void 0,
231
+ unstyled,
232
+ ...commonProps
233
+ }
234
+ )
235
+ }
236
+ ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
237
+ ToggleGroupImplElementFrame,
238
+ {
239
+ "aria-orientation": orientation,
240
+ ref: forwardedRef,
241
+ orientation,
242
+ "data-disabled": disabled ? "" : void 0,
243
+ unstyled,
244
+ ...commonProps
245
+ }
246
+ )
247
+ }
248
+ );
249
+ }
250
+ )
251
+ );
252
+ //# sourceMappingURL=ToggleGroup.js.map
@@ -0,0 +1,15 @@
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("./ToggleGroup"), module.exports);
15
+ //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/toggle-group",
3
- "version": "1.116.1",
3
+ "version": "1.116.2",
4
4
  "sideEffects": [
5
5
  "*.css"
6
6
  ],
@@ -34,22 +34,22 @@
34
34
  }
35
35
  },
36
36
  "dependencies": {
37
- "@tamagui/constants": "1.116.1",
38
- "@tamagui/create-context": "1.116.1",
39
- "@tamagui/focusable": "1.116.1",
40
- "@tamagui/font-size": "1.116.1",
41
- "@tamagui/get-token": "1.116.1",
42
- "@tamagui/group": "1.116.1",
43
- "@tamagui/helpers": "1.116.1",
44
- "@tamagui/helpers-tamagui": "1.116.1",
45
- "@tamagui/roving-focus": "1.116.1",
46
- "@tamagui/stacks": "1.116.1",
47
- "@tamagui/use-controllable-state": "1.116.1",
48
- "@tamagui/use-direction": "1.116.1",
49
- "@tamagui/web": "1.116.1"
37
+ "@tamagui/constants": "1.116.2",
38
+ "@tamagui/create-context": "1.116.2",
39
+ "@tamagui/focusable": "1.116.2",
40
+ "@tamagui/font-size": "1.116.2",
41
+ "@tamagui/get-token": "1.116.2",
42
+ "@tamagui/group": "1.116.2",
43
+ "@tamagui/helpers": "1.116.2",
44
+ "@tamagui/helpers-tamagui": "1.116.2",
45
+ "@tamagui/roving-focus": "1.116.2",
46
+ "@tamagui/stacks": "1.116.2",
47
+ "@tamagui/use-controllable-state": "1.116.2",
48
+ "@tamagui/use-direction": "1.116.2",
49
+ "@tamagui/web": "1.116.2"
50
50
  },
51
51
  "devDependencies": {
52
- "@tamagui/build": "1.116.1",
52
+ "@tamagui/build": "1.116.2",
53
53
  "react": "^18.2.0 || ^19.0.0"
54
54
  },
55
55
  "publishConfig": {
File without changes
File without changes