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