@hanzogui/toggle-group 2.0.0-rc.41-hanzoai.3

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 (76) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/Toggle.cjs +150 -0
  3. package/dist/cjs/Toggle.native.js +159 -0
  4. package/dist/cjs/Toggle.native.js.map +1 -0
  5. package/dist/cjs/ToggleGroup.cjs +245 -0
  6. package/dist/cjs/ToggleGroup.native.js +262 -0
  7. package/dist/cjs/ToggleGroup.native.js.map +1 -0
  8. package/dist/cjs/context.cjs +36 -0
  9. package/dist/cjs/context.native.js +39 -0
  10. package/dist/cjs/context.native.js.map +1 -0
  11. package/dist/cjs/index.cjs +30 -0
  12. package/dist/cjs/index.native.js +33 -0
  13. package/dist/cjs/index.native.js.map +1 -0
  14. package/dist/cjs/types.cjs +18 -0
  15. package/dist/cjs/types.native.js +21 -0
  16. package/dist/cjs/types.native.js.map +1 -0
  17. package/dist/esm/Toggle.mjs +113 -0
  18. package/dist/esm/Toggle.mjs.map +1 -0
  19. package/dist/esm/Toggle.native.js +119 -0
  20. package/dist/esm/Toggle.native.js.map +1 -0
  21. package/dist/esm/ToggleGroup.mjs +209 -0
  22. package/dist/esm/ToggleGroup.mjs.map +1 -0
  23. package/dist/esm/ToggleGroup.native.js +223 -0
  24. package/dist/esm/ToggleGroup.native.js.map +1 -0
  25. package/dist/esm/context.mjs +10 -0
  26. package/dist/esm/context.mjs.map +1 -0
  27. package/dist/esm/context.native.js +10 -0
  28. package/dist/esm/context.native.js.map +1 -0
  29. package/dist/esm/index.js +4 -0
  30. package/dist/esm/index.js.map +1 -0
  31. package/dist/esm/index.mjs +4 -0
  32. package/dist/esm/index.mjs.map +1 -0
  33. package/dist/esm/index.native.js +4 -0
  34. package/dist/esm/index.native.js.map +1 -0
  35. package/dist/esm/types.mjs +2 -0
  36. package/dist/esm/types.mjs.map +1 -0
  37. package/dist/esm/types.native.js +2 -0
  38. package/dist/esm/types.native.js.map +1 -0
  39. package/dist/jsx/Toggle.mjs +113 -0
  40. package/dist/jsx/Toggle.mjs.map +1 -0
  41. package/dist/jsx/Toggle.native.js +159 -0
  42. package/dist/jsx/Toggle.native.js.map +1 -0
  43. package/dist/jsx/ToggleGroup.mjs +209 -0
  44. package/dist/jsx/ToggleGroup.mjs.map +1 -0
  45. package/dist/jsx/ToggleGroup.native.js +262 -0
  46. package/dist/jsx/ToggleGroup.native.js.map +1 -0
  47. package/dist/jsx/context.mjs +10 -0
  48. package/dist/jsx/context.mjs.map +1 -0
  49. package/dist/jsx/context.native.js +39 -0
  50. package/dist/jsx/context.native.js.map +1 -0
  51. package/dist/jsx/index.js +4 -0
  52. package/dist/jsx/index.js.map +1 -0
  53. package/dist/jsx/index.mjs +4 -0
  54. package/dist/jsx/index.mjs.map +1 -0
  55. package/dist/jsx/index.native.js +33 -0
  56. package/dist/jsx/index.native.js.map +1 -0
  57. package/dist/jsx/types.mjs +2 -0
  58. package/dist/jsx/types.mjs.map +1 -0
  59. package/dist/jsx/types.native.js +21 -0
  60. package/dist/jsx/types.native.js.map +1 -0
  61. package/package.json +61 -0
  62. package/src/Toggle.tsx +150 -0
  63. package/src/ToggleGroup.tsx +355 -0
  64. package/src/context.tsx +10 -0
  65. package/src/index.ts +2 -0
  66. package/src/types.tsx +3 -0
  67. package/types/Toggle.d.ts +74 -0
  68. package/types/Toggle.d.ts.map +1 -0
  69. package/types/ToggleGroup.d.ts +189 -0
  70. package/types/ToggleGroup.d.ts.map +1 -0
  71. package/types/context.d.ts +9 -0
  72. package/types/context.d.ts.map +1 -0
  73. package/types/index.d.ts +3 -0
  74. package/types/index.d.ts.map +1 -0
  75. package/types/types.d.ts +5 -0
  76. package/types/types.d.ts.map +1 -0
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,150 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ };
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;
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
30
+ }) : target, mod));
31
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
+ value: true
33
+ }), mod);
34
+ var Toggle_exports = {};
35
+ __export(Toggle_exports, {
36
+ Toggle: () => Toggle,
37
+ ToggleFrame: () => ToggleFrame
38
+ });
39
+ module.exports = __toCommonJS(Toggle_exports);
40
+ var import_helpers = require("@hanzogui/helpers");
41
+ var import_use_controllable_state = require("@hanzogui/use-controllable-state");
42
+ var import_web = require("@hanzogui/web");
43
+ var React = __toESM(require("react"), 1);
44
+ var import_context = require("./context.cjs");
45
+ var import_jsx_runtime = require("react/jsx-runtime");
46
+ const NAME = "Toggle";
47
+ const ToggleFrame = (0, import_web.styled)(import_web.View, {
48
+ name: NAME,
49
+ render: "button",
50
+ context: import_context.context,
51
+ variants: {
52
+ unstyled: {
53
+ false: {
54
+ size: "$true",
55
+ alignItems: "center",
56
+ justifyContent: "center",
57
+ display: "flex",
58
+ backgroundColor: "$background",
59
+ borderColor: "$borderColor",
60
+ borderWidth: 1,
61
+ margin: -1,
62
+ hoverStyle: {
63
+ backgroundColor: "$backgroundHover",
64
+ borderColor: "$borderColorHover"
65
+ },
66
+ pressStyle: {
67
+ backgroundColor: "$backgroundPress",
68
+ borderColor: "$borderColorPress"
69
+ },
70
+ focusVisibleStyle: {
71
+ outlineColor: "$outlineColor",
72
+ outlineWidth: 2,
73
+ outlineStyle: "solid",
74
+ zIndex: 10
75
+ }
76
+ }
77
+ },
78
+ size: {
79
+ "...size": (val, {
80
+ tokens
81
+ }) => {
82
+ if (!val) return;
83
+ return {
84
+ width: tokens.size[val],
85
+ height: tokens.size[val]
86
+ };
87
+ },
88
+ ":number": val => ({
89
+ width: val,
90
+ height: val
91
+ })
92
+ },
93
+ defaultActiveStyle: {
94
+ true: {
95
+ backgroundColor: "$backgroundActive",
96
+ hoverStyle: {
97
+ backgroundColor: "$backgroundActive"
98
+ },
99
+ focusStyle: {
100
+ backgroundColor: "$backgroundActive"
101
+ }
102
+ }
103
+ }
104
+ },
105
+ defaultVariants: {
106
+ unstyled: process.env.HANZOGUI_HEADLESS === "1"
107
+ }
108
+ }, {
109
+ accept: {
110
+ activeStyle: "style"
111
+ }
112
+ });
113
+ const Toggle = React.forwardRef(function Toggle2(props, forwardedRef) {
114
+ const {
115
+ active: activeProp,
116
+ activeStyle,
117
+ defaultActive = false,
118
+ onActiveChange,
119
+ activeTheme,
120
+ unstyled = false,
121
+ ...buttonProps
122
+ } = props;
123
+ const [active = false, setActive] = (0, import_use_controllable_state.useControllableState)({
124
+ prop: activeProp,
125
+ onChange: onActiveChange,
126
+ defaultProp: defaultActive
127
+ });
128
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToggleFrame, {
129
+ theme: activeTheme ?? null,
130
+ "aria-pressed": active,
131
+ "data-state": active ? "on" : "off",
132
+ "data-disabled": props.disabled ? "" : void 0,
133
+ unstyled,
134
+ ...(active && !activeStyle && !unstyled && {
135
+ defaultActiveStyle: true
136
+ }),
137
+ ...(active && activeStyle && {
138
+ ...activeStyle,
139
+ hoverStyle: activeStyle,
140
+ focusStyle: activeStyle
141
+ }),
142
+ ...buttonProps,
143
+ ref: forwardedRef,
144
+ onPress: (0, import_helpers.composeEventHandlers)(props.onPress ?? void 0, () => {
145
+ if (!props.disabled) {
146
+ setActive(prev => !prev);
147
+ }
148
+ })
149
+ });
150
+ });
@@ -0,0 +1,159 @@
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(
25
+ // If the importer is in node compatibility mode or this is not an ESM
26
+ // file that has been converted to a CommonJS file using a Babel-
27
+ // compatible transform (i.e. "__esModule" has not been set), then set
28
+ // "default" to the CommonJS "module.exports" for node compatibility.
29
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
30
+ value: mod,
31
+ enumerable: true
32
+ }) : target, mod));
33
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
34
+ value: true
35
+ }), mod);
36
+ var Toggle_exports = {};
37
+ __export(Toggle_exports, {
38
+ Toggle: () => Toggle,
39
+ ToggleFrame: () => ToggleFrame
40
+ });
41
+ module.exports = __toCommonJS(Toggle_exports);
42
+ var import_jsx_runtime = require("react/jsx-runtime");
43
+ var import_helpers = require("@hanzogui/helpers");
44
+ var import_use_controllable_state = require("@hanzogui/use-controllable-state");
45
+ var import_web = require("@hanzogui/web");
46
+ var React = __toESM(require("react"), 1);
47
+ var import_context = require("./context.native.js");
48
+ var NAME = "Toggle";
49
+ var ToggleFrame = (0, import_web.styled)(import_web.View, {
50
+ name: NAME,
51
+ render: "button",
52
+ context: import_context.context,
53
+ variants: {
54
+ unstyled: {
55
+ false: {
56
+ size: "$true",
57
+ alignItems: "center",
58
+ justifyContent: "center",
59
+ display: "flex",
60
+ backgroundColor: "$background",
61
+ borderColor: "$borderColor",
62
+ borderWidth: 1,
63
+ margin: -1,
64
+ hoverStyle: {
65
+ backgroundColor: "$backgroundHover",
66
+ borderColor: "$borderColorHover"
67
+ },
68
+ pressStyle: {
69
+ backgroundColor: "$backgroundPress",
70
+ borderColor: "$borderColorPress"
71
+ },
72
+ focusVisibleStyle: {
73
+ outlineColor: "$outlineColor",
74
+ outlineWidth: 2,
75
+ outlineStyle: "solid",
76
+ zIndex: 10
77
+ }
78
+ }
79
+ },
80
+ size: {
81
+ "...size": function (val, param) {
82
+ var {
83
+ tokens
84
+ } = param;
85
+ if (!val) return;
86
+ return {
87
+ width: tokens.size[val],
88
+ height: tokens.size[val]
89
+ };
90
+ },
91
+ ":number": function (val) {
92
+ return {
93
+ width: val,
94
+ height: val
95
+ };
96
+ }
97
+ },
98
+ defaultActiveStyle: {
99
+ true: {
100
+ backgroundColor: "$backgroundActive",
101
+ hoverStyle: {
102
+ backgroundColor: "$backgroundActive"
103
+ },
104
+ focusStyle: {
105
+ backgroundColor: "$backgroundActive"
106
+ }
107
+ }
108
+ }
109
+ },
110
+ defaultVariants: {
111
+ unstyled: process.env.HANZOGUI_HEADLESS === "1"
112
+ }
113
+ }, {
114
+ accept: {
115
+ activeStyle: "style"
116
+ }
117
+ });
118
+ var Toggle = /* @__PURE__ */React.forwardRef(function Toggle2(props, forwardedRef) {
119
+ var {
120
+ active: activeProp,
121
+ activeStyle,
122
+ defaultActive = false,
123
+ onActiveChange,
124
+ activeTheme,
125
+ unstyled = false,
126
+ ...buttonProps
127
+ } = props;
128
+ var [active = false, setActive] = (0, import_use_controllable_state.useControllableState)({
129
+ prop: activeProp,
130
+ onChange: onActiveChange,
131
+ defaultProp: defaultActive
132
+ });
133
+ var _props_onPress;
134
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToggleFrame, {
135
+ theme: activeTheme !== null && activeTheme !== void 0 ? activeTheme : null,
136
+ "aria-pressed": active,
137
+ "data-state": active ? "on" : "off",
138
+ "data-disabled": props.disabled ? "" : void 0,
139
+ unstyled,
140
+ ...(active && !activeStyle && !unstyled && {
141
+ defaultActiveStyle: true
142
+ }),
143
+ ...(active && activeStyle && {
144
+ ...activeStyle,
145
+ hoverStyle: activeStyle,
146
+ focusStyle: activeStyle
147
+ }),
148
+ ...buttonProps,
149
+ ref: forwardedRef,
150
+ onPress: (0, import_helpers.composeEventHandlers)((_props_onPress = props.onPress) !== null && _props_onPress !== void 0 ? _props_onPress : void 0, function () {
151
+ if (!props.disabled) {
152
+ setActive(function (prev) {
153
+ return !prev;
154
+ });
155
+ }
156
+ })
157
+ });
158
+ });
159
+ //# sourceMappingURL=Toggle.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","Toggle_exports","__export","Toggle","ToggleFrame","module","exports","import_jsx_runtime","require","import_helpers","import_use_controllable_state","import_web","React","__toESM","import_context","NAME","styled","View","name","render","context","variants","unstyled","false","size","alignItems","justifyContent","display","backgroundColor","borderColor","borderWidth","margin","hoverStyle","pressStyle","focusVisibleStyle","outlineColor","outlineWidth","outlineStyle","zIndex","...size","val","param","tokens","width","height",":number","defaultActiveStyle","true","focusStyle","defaultVariants","process","env","HANZOGUI_HEADLESS","accept","activeStyle","forwardRef","Toggle2","props","forwardedRef","active","activeProp","defaultActive","onActiveChange","activeTheme","buttonProps","setActive","useControllableState","prop","onChange","defaultProp","_props_onPress","jsx","theme","disabled","ref","onPress","composeEventHandlers","prev"],"sources":["../../src/Toggle.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,cAAA;AAAAC,QAAA,CAAAD,cAAA;EAAAE,MAAA,EAAAA,CAAA,KAAAA,MAAA;EAAAC,WAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAV,YAAqC,CAAAK,cAAA;AACrC,IAAAM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= Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ };
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;
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
30
+ }) : target, mod));
31
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
+ value: true
33
+ }), mod);
34
+ var ToggleGroup_exports = {};
35
+ __export(ToggleGroup_exports, {
36
+ ToggleGroup: () => ToggleGroup
37
+ });
38
+ module.exports = __toCommonJS(ToggleGroup_exports);
39
+ var import_constants = require("@hanzogui/constants");
40
+ var import_focusable = require("@hanzogui/focusable");
41
+ var import_helpers = require("@hanzogui/helpers");
42
+ var import_roving_focus = require("@hanzogui/roving-focus");
43
+ var import_use_controllable_state = require("@hanzogui/use-controllable-state");
44
+ var import_use_direction = require("@hanzogui/use-direction");
45
+ var import_web = require("@hanzogui/web");
46
+ var import_react = __toESM(require("react"), 1);
47
+ var import_Toggle = require("./Toggle.cjs");
48
+ var import_context = require("./context.cjs");
49
+ var import_jsx_runtime = require("react/jsx-runtime");
50
+ const TOGGLE_GROUP_NAME = "ToggleGroup";
51
+ const TOGGLE_GROUP_ITEM_NAME = "ToggleGroupItem";
52
+ 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
+ });
88
+ });
89
+ 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
144
+ });
145
+ 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
+ });
177
+ });
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
+ });
207
+ });
208
+ const ToggleGroupFrame = (0, import_web.styled)(import_web.View, {
209
+ name: TOGGLE_GROUP_NAME
210
+ });
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
+ });