@tamagui/toggle-group 2.7.7 → 3.0.0-beta.1091.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.
Files changed (78) hide show
  1. package/dist/cjs/Toggle.cjs +58 -130
  2. package/dist/cjs/Toggle.native.cjs +90 -0
  3. package/dist/cjs/Toggle.native.js +64 -135
  4. package/dist/cjs/Toggle.native.js.map +1 -1
  5. package/dist/cjs/ToggleGroup.cjs +157 -211
  6. package/dist/cjs/ToggleGroup.native.cjs +207 -0
  7. package/dist/cjs/ToggleGroup.native.js +172 -225
  8. package/dist/cjs/ToggleGroup.native.js.map +1 -1
  9. package/dist/cjs/context.cjs +18 -20
  10. package/dist/cjs/context.native.cjs +36 -0
  11. package/dist/cjs/context.native.js +19 -20
  12. package/dist/cjs/context.native.js.map +1 -1
  13. package/dist/cjs/index.cjs +14 -18
  14. package/dist/cjs/index.native.cjs +28 -0
  15. package/dist/cjs/index.native.js +14 -17
  16. package/dist/cjs/index.native.js.map +1 -1
  17. package/dist/cjs/types.cjs +9 -11
  18. package/dist/cjs/types.native.cjs +18 -0
  19. package/dist/cjs/types.native.js +9 -10
  20. package/dist/cjs/types.native.js.map +1 -1
  21. package/dist/esm/Toggle.mjs +46 -103
  22. package/dist/esm/Toggle.mjs.map +1 -1
  23. package/dist/esm/Toggle.native.js +51 -114
  24. package/dist/esm/Toggle.native.js.map +1 -1
  25. package/dist/esm/ToggleGroup.mjs +145 -188
  26. package/dist/esm/ToggleGroup.mjs.map +1 -1
  27. package/dist/esm/ToggleGroup.native.js +160 -203
  28. package/dist/esm/ToggleGroup.native.js.map +1 -1
  29. package/dist/esm/context.mjs +5 -3
  30. package/dist/esm/context.mjs.map +1 -1
  31. package/dist/esm/context.native.js +6 -4
  32. package/dist/esm/context.native.js.map +1 -1
  33. package/dist/esm/index.js +4 -3
  34. package/dist/esm/index.mjs +4 -3
  35. package/dist/esm/index.native.js +4 -3
  36. package/dist/esm/types.mjs +0 -2
  37. package/dist/esm/types.native.js +0 -2
  38. package/dist/jsx/Toggle.mjs +46 -103
  39. package/dist/jsx/Toggle.mjs.map +1 -1
  40. package/dist/jsx/Toggle.native.cjs +90 -0
  41. package/dist/jsx/Toggle.native.js +64 -135
  42. package/dist/jsx/Toggle.native.js.map +1 -1
  43. package/dist/jsx/ToggleGroup.mjs +145 -188
  44. package/dist/jsx/ToggleGroup.mjs.map +1 -1
  45. package/dist/jsx/ToggleGroup.native.cjs +207 -0
  46. package/dist/jsx/ToggleGroup.native.js +172 -225
  47. package/dist/jsx/ToggleGroup.native.js.map +1 -1
  48. package/dist/jsx/context.mjs +5 -3
  49. package/dist/jsx/context.mjs.map +1 -1
  50. package/dist/jsx/context.native.cjs +36 -0
  51. package/dist/jsx/context.native.js +19 -20
  52. package/dist/jsx/context.native.js.map +1 -1
  53. package/dist/jsx/index.js +4 -3
  54. package/dist/jsx/index.mjs +4 -3
  55. package/dist/jsx/index.native.cjs +28 -0
  56. package/dist/jsx/index.native.js +14 -17
  57. package/dist/jsx/index.native.js.map +1 -1
  58. package/dist/jsx/types.mjs +0 -2
  59. package/dist/jsx/types.native.cjs +18 -0
  60. package/dist/jsx/types.native.js +9 -10
  61. package/dist/jsx/types.native.js.map +1 -1
  62. package/package.json +18 -16
  63. package/src/Toggle.tsx +37 -89
  64. package/src/ToggleGroup.tsx +20 -11
  65. package/types/Toggle.d.ts +19 -59
  66. package/types/Toggle.d.ts.map +1 -1
  67. package/types/ToggleGroup.d.ts +31 -125
  68. package/types/ToggleGroup.d.ts.map +1 -1
  69. package/types/context.d.ts +1 -1
  70. package/types/context.d.ts.map +1 -1
  71. package/dist/esm/index.js.map +0 -1
  72. package/dist/esm/index.mjs.map +0 -1
  73. package/dist/esm/index.native.js.map +0 -1
  74. package/dist/esm/types.mjs.map +0 -1
  75. package/dist/esm/types.native.js.map +0 -1
  76. package/dist/jsx/index.js.map +0 -1
  77. package/dist/jsx/index.mjs.map +0 -1
  78. package/dist/jsx/types.mjs.map +0 -1
@@ -5,37 +5,29 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: true
11
- });
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
12
  };
13
13
  var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
- get: () => from[key],
17
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
- });
19
- }
20
- return to;
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
21
  };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
- // If the importer is in node compatibility mode or this is not an ESM
24
- // file that has been converted to a CommonJS file using a Babel-
25
- // compatible transform (i.e. "__esModule" has not been set), then set
26
- // "default" to the CommonJS "module.exports" for node compatibility.
27
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
28
- value: mod,
29
- enumerable: true
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
30
25
  }) : target, mod));
31
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
- value: true
33
- }), mod);
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
27
  var ToggleGroup_exports = {};
35
- __export(ToggleGroup_exports, {
36
- ToggleGroup: () => ToggleGroup
37
- });
28
+ __export(ToggleGroup_exports, { ToggleGroup: () => ToggleGroup });
38
29
  module.exports = __toCommonJS(ToggleGroup_exports);
30
+ var import_compose_refs = require("@tamagui/compose-refs");
39
31
  var import_constants = require("@tamagui/constants");
40
32
  var import_focusable = require("@tamagui/focusable");
41
33
  var import_helpers = require("@tamagui/helpers");
@@ -50,196 +42,150 @@ var import_jsx_runtime = require("react/jsx-runtime");
50
42
  const TOGGLE_GROUP_NAME = "ToggleGroup";
51
43
  const TOGGLE_GROUP_ITEM_NAME = "ToggleGroupItem";
52
44
  const TOGGLE_GROUP_CONTEXT = "ToggleGroup";
53
- const {
54
- Provider: ToggleGroupItemProvider
55
- } = (0, import_web.createStyledContext)();
56
- const {
57
- Provider: ToggleGroupContext,
58
- useStyledContext: useToggleGroupContext
59
- } = (0, import_web.createStyledContext)({});
60
- const ToggleGroupItem = import_Toggle.ToggleFrame.styleable((props, forwardedRef) => {
61
- const valueContext = useToggleGroupValueContext(props.__scopeToggleGroup);
62
- const context = useToggleGroupContext(props.__scopeToggleGroup);
63
- const toggleContext = import_context.context.useStyledContext(props.__scopeToggleGroup);
64
- const active = valueContext?.value.includes(props.value);
65
- const color = props.color || toggleContext.color;
66
- const disabled = context.disabled || props.disabled || false;
67
- const inner = /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToggleGroupItemImpl, {
68
- ref: forwardedRef,
69
- tabIndex: disabled ? -1 : 0,
70
- ...props,
71
- active,
72
- disabled
73
- });
74
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToggleGroupItemProvider, {
75
- scope: props.__scopeToggleGroup,
76
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_context.context.Provider, {
77
- color,
78
- active,
79
- children: context.rovingFocus ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_roving_focus.RovingFocusGroup.Item, {
80
- asChild: "except-style",
81
- __scopeRovingFocusGroup: props.__scopeToggleGroup || TOGGLE_GROUP_CONTEXT,
82
- focusable: !disabled,
83
- active,
84
- children: inner
85
- }) : inner
86
- })
87
- });
45
+ const { Provider: ToggleGroupItemProvider } = (0, import_web.createStyledContext)();
46
+ const { Provider: ToggleGroupContext, useStyledContext: useToggleGroupContext } = (0, import_web.createStyledContext)({});
47
+ const ToggleGroupItem = (0, import_web.createStyledHOC)(import_Toggle.ToggleFrame, (props, forwardedRef) => {
48
+ const valueContext = useToggleGroupValueContext(props.__scopeToggleGroup);
49
+ const context = useToggleGroupContext(props.__scopeToggleGroup);
50
+ const toggleContext = import_context.context.useStyledContext(props.__scopeToggleGroup);
51
+ const active = valueContext?.value.includes(props.value);
52
+ const color = props.color || toggleContext.color;
53
+ const disabled = context.disabled || props.disabled || false;
54
+ const inner = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToggleGroupItemImpl, {
55
+ ref: forwardedRef,
56
+ ...context.rovingFocus ? null : { tabIndex: disabled ? -1 : 0 },
57
+ ...props,
58
+ active,
59
+ disabled
60
+ });
61
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToggleGroupItemProvider, {
62
+ scope: props.__scopeToggleGroup,
63
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_context.context.Provider, {
64
+ color,
65
+ active,
66
+ children: context.rovingFocus ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_roving_focus.RovingFocusGroup.Item, {
67
+ asChild: "except-style",
68
+ __scopeRovingFocusGroup: props.__scopeToggleGroup || TOGGLE_GROUP_CONTEXT,
69
+ tabIndex: disabled ? -1 : 0,
70
+ active,
71
+ children: inner
72
+ }) : inner
73
+ })
74
+ });
88
75
  });
89
76
  ToggleGroupItem.displayName = TOGGLE_GROUP_ITEM_NAME;
90
- const ToggleGroupItemImpl = import_react.default.forwardRef((props, forwardedRef) => {
91
- const {
92
- __scopeToggleGroup,
93
- value,
94
- ...itemProps
95
- } = props;
96
- const valueContext = useToggleGroupValueContext(__scopeToggleGroup);
97
- const singleProps = {
98
- "aria-pressed": void 0
99
- };
100
- const typeProps = valueContext.type === "single" ? singleProps : void 0;
101
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Toggle.Toggle, {
102
- ...typeProps,
103
- ...itemProps,
104
- ref: forwardedRef,
105
- onActiveChange: pressed => {
106
- if (pressed) {
107
- valueContext.onItemActivate(value);
108
- } else {
109
- valueContext.onItemDeactivate(value);
110
- }
111
- }
112
- });
113
- });
114
- const ToggleGroup = (0, import_helpers.withStaticProperties)(import_react.default.forwardRef((props, forwardedRef) => {
115
- const {
116
- type,
117
- ...toggleGroupProps
118
- } = props;
119
- if (!import_constants.isWeb) {
120
- import_react.default.useEffect(() => {
121
- if (!props.id) return;
122
- return (0, import_focusable.registerFocusable)(props.id, {
123
- focus: () => {}
124
- });
125
- }, [props.id]);
126
- }
127
- if (type === "single") {
128
- const singleProps = toggleGroupProps;
129
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToggleGroupImplSingle, {
130
- ...singleProps,
131
- ref: forwardedRef
132
- });
133
- }
134
- if (type === "multiple") {
135
- const multipleProps = toggleGroupProps;
136
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToggleGroupImplMultiple, {
137
- ...multipleProps,
138
- ref: forwardedRef
139
- });
140
- }
141
- throw new Error(`Missing prop \`type\` expected on \`${TOGGLE_GROUP_NAME}\``);
142
- }), {
143
- Item: ToggleGroupItem
77
+ const ToggleGroupItemImpl = (0, import_compose_refs.createRefComponent)((props, forwardedRef) => {
78
+ const { __scopeToggleGroup, value, ...itemProps } = props;
79
+ const valueContext = useToggleGroupValueContext(__scopeToggleGroup);
80
+ const singleProps = { "aria-pressed": void 0 };
81
+ const typeProps = valueContext.type === "single" ? singleProps : void 0;
82
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Toggle.Toggle, {
83
+ ...typeProps,
84
+ ...itemProps,
85
+ ref: forwardedRef,
86
+ onActiveChange: (pressed) => {
87
+ if (pressed) {
88
+ valueContext.onItemActivate(value);
89
+ } else {
90
+ valueContext.onItemDeactivate(value);
91
+ }
92
+ }
93
+ });
144
94
  });
95
+ const ToggleGroup = (0, import_helpers.withStaticProperties)((0, import_compose_refs.createRefComponent)((props, forwardedRef) => {
96
+ const { type, ...toggleGroupProps } = props;
97
+ if (!import_constants.isWeb) {
98
+ import_react.default.useEffect(() => {
99
+ if (!props.id) return;
100
+ return (0, import_focusable.registerFocusable)(props.id, { focus: () => {} });
101
+ }, [props.id]);
102
+ }
103
+ if (type === "single") {
104
+ const singleProps = toggleGroupProps;
105
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToggleGroupImplSingle, {
106
+ ...singleProps,
107
+ ref: forwardedRef
108
+ });
109
+ }
110
+ if (type === "multiple") {
111
+ const multipleProps = toggleGroupProps;
112
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToggleGroupImplMultiple, {
113
+ ...multipleProps,
114
+ ref: forwardedRef
115
+ });
116
+ }
117
+ throw new Error(`Missing prop \`type\` expected on \`${TOGGLE_GROUP_NAME}\``);
118
+ }), { Item: ToggleGroupItem });
145
119
  ToggleGroup.displayName = TOGGLE_GROUP_NAME;
146
- const {
147
- Provider: ToggleGroupValueProvider,
148
- useStyledContext: useToggleGroupValueContext
149
- } = (0, import_web.createStyledContext)();
150
- const ToggleGroupImplSingle = import_react.default.forwardRef((props, forwardedRef) => {
151
- const {
152
- value: valueProp,
153
- defaultValue,
154
- onValueChange = () => {},
155
- disableDeactivation = false,
156
- children,
157
- ...toggleGroupSingleProps
158
- } = props;
159
- const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
160
- prop: valueProp,
161
- defaultProp: defaultValue,
162
- onChange: onValueChange
163
- });
164
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToggleGroupValueProvider, {
165
- scope: props.__scopeToggleGroup,
166
- type: "single",
167
- value: value ? [value] : [],
168
- defaultValue: value,
169
- onItemActivate: setValue,
170
- onItemDeactivate: import_react.default.useCallback(() => disableDeactivation ? null : setValue(""), [setValue, disableDeactivation]),
171
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToggleGroupImpl, {
172
- ...toggleGroupSingleProps,
173
- ref: forwardedRef,
174
- children
175
- })
176
- });
120
+ const { Provider: ToggleGroupValueProvider, useStyledContext: useToggleGroupValueContext } = (0, import_web.createStyledContext)();
121
+ const ToggleGroupImplSingle = (0, import_compose_refs.createRefComponent)((props, forwardedRef) => {
122
+ const { value: valueProp, defaultValue, onValueChange = () => {}, disableDeactivation = false, children, ...toggleGroupSingleProps } = props;
123
+ const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
124
+ prop: valueProp,
125
+ defaultProp: defaultValue,
126
+ onChange: onValueChange
127
+ });
128
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToggleGroupValueProvider, {
129
+ scope: props.__scopeToggleGroup,
130
+ type: "single",
131
+ value: value ? [value] : [],
132
+ defaultValue: value,
133
+ onItemActivate: setValue,
134
+ onItemDeactivate: import_react.default.useCallback(() => disableDeactivation ? null : setValue(""), [setValue, disableDeactivation]),
135
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToggleGroupImpl, {
136
+ ...toggleGroupSingleProps,
137
+ ref: forwardedRef,
138
+ children
139
+ })
140
+ });
177
141
  });
178
- const ToggleGroupImplMultiple = import_react.default.forwardRef((props, forwardedRef) => {
179
- const {
180
- value: valueProp,
181
- defaultValue,
182
- onValueChange = () => {},
183
- disableDeactivation,
184
- children,
185
- ...toggleGroupMultipleProps
186
- } = props;
187
- const [value = [], setValue] = (0, import_use_controllable_state.useControllableState)({
188
- prop: valueProp,
189
- defaultProp: defaultValue,
190
- onChange: onValueChange
191
- });
192
- const handleButtonActivate = import_react.default.useCallback(itemValue => setValue((prevValue = []) => [...prevValue, itemValue]), [setValue]);
193
- const handleButtonDeactivate = import_react.default.useCallback(itemValue => setValue((prevValue = []) => prevValue.filter(value2 => value2 !== itemValue)), [setValue]);
194
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToggleGroupValueProvider, {
195
- scope: props.__scopeToggleGroup,
196
- type: "multiple",
197
- value,
198
- defaultValue: value,
199
- onItemActivate: handleButtonActivate,
200
- onItemDeactivate: handleButtonDeactivate,
201
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToggleGroupImpl, {
202
- ...toggleGroupMultipleProps,
203
- ref: forwardedRef,
204
- children
205
- })
206
- });
142
+ const ToggleGroupImplMultiple = (0, import_compose_refs.createRefComponent)((props, forwardedRef) => {
143
+ const { value: valueProp, defaultValue, onValueChange = () => {}, disableDeactivation, children, ...toggleGroupMultipleProps } = props;
144
+ const [value = [], setValue] = (0, import_use_controllable_state.useControllableState)({
145
+ prop: valueProp,
146
+ defaultProp: defaultValue,
147
+ onChange: onValueChange
148
+ });
149
+ const handleButtonActivate = import_react.default.useCallback((itemValue) => setValue((prevValue = []) => [...prevValue, itemValue]), [setValue]);
150
+ const handleButtonDeactivate = import_react.default.useCallback((itemValue) => setValue((prevValue = []) => prevValue.filter((value2) => value2 !== itemValue)), [setValue]);
151
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToggleGroupValueProvider, {
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, {
159
+ ...toggleGroupMultipleProps,
160
+ ref: forwardedRef,
161
+ children
162
+ })
163
+ });
207
164
  });
208
- const ToggleGroupFrame = (0, import_web.styled)(import_web.View, {
209
- name: TOGGLE_GROUP_NAME
165
+ const ToggleGroupFrame = (0, import_web.styled)(import_web.View, { displayName: TOGGLE_GROUP_NAME });
166
+ const ToggleGroupImpl = (0, import_web.createStyledHOC)(ToggleGroupFrame, (props, forwardedRef) => {
167
+ const { __scopeToggleGroup, disabled = false, orientation = "horizontal", dir, rovingFocus = true, loop = true, color, ...toggleGroupProps } = props;
168
+ const direction = (0, import_use_direction.useDirection)(dir);
169
+ const content = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToggleGroupFrame, {
170
+ role: "group",
171
+ ref: forwardedRef,
172
+ "data-disabled": disabled ? "" : void 0,
173
+ ...toggleGroupProps
174
+ });
175
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToggleGroupContext, {
176
+ scope: __scopeToggleGroup,
177
+ rovingFocus,
178
+ disabled,
179
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_context.context.Provider, {
180
+ color,
181
+ children: rovingFocus ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_roving_focus.RovingFocusGroup, {
182
+ asChild: "except-style",
183
+ __scopeRovingFocusGroup: __scopeToggleGroup || TOGGLE_GROUP_CONTEXT,
184
+ orientation,
185
+ dir: direction,
186
+ loop,
187
+ children: content
188
+ }) : content
189
+ })
190
+ });
210
191
  });
211
- const ToggleGroupImpl = ToggleGroupFrame.styleable((props, forwardedRef) => {
212
- const {
213
- __scopeToggleGroup,
214
- disabled = false,
215
- orientation = "horizontal",
216
- dir,
217
- rovingFocus = true,
218
- loop = true,
219
- color,
220
- ...toggleGroupProps
221
- } = props;
222
- const direction = (0, import_use_direction.useDirection)(dir);
223
- const content = /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToggleGroupFrame, {
224
- role: "group",
225
- ref: forwardedRef,
226
- "data-disabled": disabled ? "" : void 0,
227
- ...toggleGroupProps
228
- });
229
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToggleGroupContext, {
230
- scope: __scopeToggleGroup,
231
- rovingFocus,
232
- disabled,
233
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_context.context.Provider, {
234
- color,
235
- children: rovingFocus ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_roving_focus.RovingFocusGroup, {
236
- asChild: "except-style",
237
- __scopeRovingFocusGroup: __scopeToggleGroup || TOGGLE_GROUP_CONTEXT,
238
- orientation,
239
- dir: direction,
240
- loop,
241
- children: content
242
- }) : content
243
- })
244
- });
245
- });
@@ -0,0 +1,207 @@
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 ToggleGroup_exports = {};
30
+ __export(ToggleGroup_exports, { ToggleGroup: () => ToggleGroup });
31
+ module.exports = __toCommonJS(ToggleGroup_exports);
32
+ var import_jsx_runtime = require("react/jsx-runtime");
33
+ var import_compose_refs = require("@tamagui/compose-refs");
34
+ var import_constants = require("@tamagui/constants");
35
+ var import_focusable = require("@tamagui/focusable");
36
+ var import_helpers = require("@tamagui/helpers");
37
+ var import_roving_focus = require("@tamagui/roving-focus");
38
+ var import_use_controllable_state = require("@tamagui/use-controllable-state");
39
+ var import_use_direction = require("@tamagui/use-direction");
40
+ var import_web = require("@tamagui/web");
41
+ var import_react = __toESM(require("react"), 1);
42
+ var import_Toggle = require("./Toggle.native.js");
43
+ var import_context = require("./context.native.js");
44
+ var TOGGLE_GROUP_NAME = "ToggleGroup";
45
+ var TOGGLE_GROUP_ITEM_NAME = "ToggleGroupItem";
46
+ var TOGGLE_GROUP_CONTEXT = "ToggleGroup";
47
+ var { Provider: ToggleGroupItemProvider } = (0, import_web.createStyledContext)();
48
+ var { Provider: ToggleGroupContext, useStyledContext: useToggleGroupContext } = (0, import_web.createStyledContext)({});
49
+ var ToggleGroupItem = (0, import_web.createStyledHOC)(import_Toggle.ToggleFrame, function(props, forwardedRef) {
50
+ var valueContext = useToggleGroupValueContext(props.__scopeToggleGroup);
51
+ var context = useToggleGroupContext(props.__scopeToggleGroup);
52
+ var toggleContext = import_context.context.useStyledContext(props.__scopeToggleGroup);
53
+ var active = valueContext === null || valueContext === void 0 ? void 0 : valueContext.value.includes(props.value);
54
+ var color = props.color || toggleContext.color;
55
+ var disabled = context.disabled || props.disabled || false;
56
+ var inner = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToggleGroupItemImpl, {
57
+ ref: forwardedRef,
58
+ ...context.rovingFocus ? null : { tabIndex: disabled ? -1 : 0 },
59
+ ...props,
60
+ active,
61
+ disabled
62
+ });
63
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToggleGroupItemProvider, {
64
+ scope: props.__scopeToggleGroup,
65
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_context.context.Provider, {
66
+ color,
67
+ active,
68
+ children: context.rovingFocus ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_roving_focus.RovingFocusGroup.Item, {
69
+ asChild: "except-style",
70
+ __scopeRovingFocusGroup: props.__scopeToggleGroup || TOGGLE_GROUP_CONTEXT,
71
+ tabIndex: disabled ? -1 : 0,
72
+ active,
73
+ children: inner
74
+ }) : inner
75
+ })
76
+ });
77
+ });
78
+ ToggleGroupItem.displayName = TOGGLE_GROUP_ITEM_NAME;
79
+ var ToggleGroupItemImpl = (0, import_compose_refs.createRefComponent)(function(props, forwardedRef) {
80
+ var { __scopeToggleGroup, value, ...itemProps } = props;
81
+ var valueContext = useToggleGroupValueContext(__scopeToggleGroup);
82
+ var singleProps = { "aria-pressed": void 0 };
83
+ var typeProps = valueContext.type === "single" ? singleProps : void 0;
84
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Toggle.Toggle, {
85
+ ...typeProps,
86
+ ...itemProps,
87
+ ref: forwardedRef,
88
+ onActiveChange: function(pressed) {
89
+ if (pressed) {
90
+ valueContext.onItemActivate(value);
91
+ } else {
92
+ valueContext.onItemDeactivate(value);
93
+ }
94
+ }
95
+ });
96
+ });
97
+ var ToggleGroup = (0, import_helpers.withStaticProperties)((0, import_compose_refs.createRefComponent)(function(props, forwardedRef) {
98
+ var { type, ...toggleGroupProps } = props;
99
+ if (!import_constants.isWeb) {
100
+ import_react.default.useEffect(function() {
101
+ if (!props.id) return;
102
+ return (0, import_focusable.registerFocusable)(props.id, { focus: function() {} });
103
+ }, [props.id]);
104
+ }
105
+ if (type === "single") {
106
+ var singleProps = toggleGroupProps;
107
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToggleGroupImplSingle, {
108
+ ...singleProps,
109
+ ref: forwardedRef
110
+ });
111
+ }
112
+ if (type === "multiple") {
113
+ var multipleProps = toggleGroupProps;
114
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToggleGroupImplMultiple, {
115
+ ...multipleProps,
116
+ ref: forwardedRef
117
+ });
118
+ }
119
+ throw new Error(`Missing prop \`type\` expected on \`${TOGGLE_GROUP_NAME}\``);
120
+ }), { Item: ToggleGroupItem });
121
+ ToggleGroup.displayName = TOGGLE_GROUP_NAME;
122
+ var { Provider: ToggleGroupValueProvider, useStyledContext: useToggleGroupValueContext } = (0, import_web.createStyledContext)();
123
+ var ToggleGroupImplSingle = (0, import_compose_refs.createRefComponent)(function(props, forwardedRef) {
124
+ var { value: valueProp, defaultValue, onValueChange = function() {}, disableDeactivation = false, children, ...toggleGroupSingleProps } = props;
125
+ var [value, setValue] = (0, import_use_controllable_state.useControllableState)({
126
+ prop: valueProp,
127
+ defaultProp: defaultValue,
128
+ onChange: onValueChange
129
+ });
130
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToggleGroupValueProvider, {
131
+ scope: props.__scopeToggleGroup,
132
+ type: "single",
133
+ value: value ? [value] : [],
134
+ defaultValue: value,
135
+ onItemActivate: setValue,
136
+ onItemDeactivate: import_react.default.useCallback(function() {
137
+ return disableDeactivation ? null : setValue("");
138
+ }, [setValue, disableDeactivation]),
139
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToggleGroupImpl, {
140
+ ...toggleGroupSingleProps,
141
+ ref: forwardedRef,
142
+ children
143
+ })
144
+ });
145
+ });
146
+ var ToggleGroupImplMultiple = (0, import_compose_refs.createRefComponent)(function(props, forwardedRef) {
147
+ var { value: valueProp, defaultValue, onValueChange = function() {}, disableDeactivation, children, ...toggleGroupMultipleProps } = props;
148
+ var [value = [], setValue] = (0, import_use_controllable_state.useControllableState)({
149
+ prop: valueProp,
150
+ defaultProp: defaultValue,
151
+ onChange: onValueChange
152
+ });
153
+ var handleButtonActivate = import_react.default.useCallback(function(itemValue) {
154
+ return setValue(function() {
155
+ var prevValue = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
156
+ return [...prevValue, itemValue];
157
+ });
158
+ }, [setValue]);
159
+ var handleButtonDeactivate = import_react.default.useCallback(function(itemValue) {
160
+ return setValue(function() {
161
+ var prevValue = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
162
+ return prevValue.filter(function(value2) {
163
+ return value2 !== itemValue;
164
+ });
165
+ });
166
+ }, [setValue]);
167
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToggleGroupValueProvider, {
168
+ scope: props.__scopeToggleGroup,
169
+ type: "multiple",
170
+ value,
171
+ defaultValue: value,
172
+ onItemActivate: handleButtonActivate,
173
+ onItemDeactivate: handleButtonDeactivate,
174
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToggleGroupImpl, {
175
+ ...toggleGroupMultipleProps,
176
+ ref: forwardedRef,
177
+ children
178
+ })
179
+ });
180
+ });
181
+ var ToggleGroupFrame = (0, import_web.styled)(import_web.View, { displayName: TOGGLE_GROUP_NAME });
182
+ var ToggleGroupImpl = (0, import_web.createStyledHOC)(ToggleGroupFrame, function(props, forwardedRef) {
183
+ var { __scopeToggleGroup, disabled = false, orientation = "horizontal", dir, rovingFocus = true, loop = true, color, ...toggleGroupProps } = props;
184
+ var direction = (0, import_use_direction.useDirection)(dir);
185
+ var content = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToggleGroupFrame, {
186
+ role: "group",
187
+ ref: forwardedRef,
188
+ "data-disabled": disabled ? "" : void 0,
189
+ ...toggleGroupProps
190
+ });
191
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToggleGroupContext, {
192
+ scope: __scopeToggleGroup,
193
+ rovingFocus,
194
+ disabled,
195
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_context.context.Provider, {
196
+ color,
197
+ children: rovingFocus ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_roving_focus.RovingFocusGroup, {
198
+ asChild: "except-style",
199
+ __scopeRovingFocusGroup: __scopeToggleGroup || TOGGLE_GROUP_CONTEXT,
200
+ orientation,
201
+ dir: direction,
202
+ loop,
203
+ children: content
204
+ }) : content
205
+ })
206
+ });
207
+ });