@hanzogui/toggle-group 2.0.0

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 (71) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/Toggle.cjs +145 -0
  3. package/dist/cjs/Toggle.native.js +154 -0
  4. package/dist/cjs/Toggle.native.js.map +1 -0
  5. package/dist/cjs/ToggleGroup.cjs +229 -0
  6. package/dist/cjs/ToggleGroup.native.js +252 -0
  7. package/dist/cjs/ToggleGroup.native.js.map +1 -0
  8. package/dist/cjs/context.cjs +32 -0
  9. package/dist/cjs/context.native.js +37 -0
  10. package/dist/cjs/context.native.js.map +1 -0
  11. package/dist/cjs/index.cjs +28 -0
  12. package/dist/cjs/index.native.js +31 -0
  13. package/dist/cjs/index.native.js.map +1 -0
  14. package/dist/cjs/types.cjs +16 -0
  15. package/dist/cjs/types.native.js +19 -0
  16. package/dist/cjs/types.native.js.map +1 -0
  17. package/dist/esm/Toggle.mjs +110 -0
  18. package/dist/esm/Toggle.mjs.map +1 -0
  19. package/dist/esm/Toggle.native.js +116 -0
  20. package/dist/esm/Toggle.native.js.map +1 -0
  21. package/dist/esm/ToggleGroup.mjs +195 -0
  22. package/dist/esm/ToggleGroup.mjs.map +1 -0
  23. package/dist/esm/ToggleGroup.native.js +215 -0
  24. package/dist/esm/ToggleGroup.native.js.map +1 -0
  25. package/dist/esm/context.mjs +8 -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 +110 -0
  40. package/dist/jsx/Toggle.mjs.map +1 -0
  41. package/dist/jsx/Toggle.native.js +154 -0
  42. package/dist/jsx/Toggle.native.js.map +1 -0
  43. package/dist/jsx/ToggleGroup.mjs +195 -0
  44. package/dist/jsx/ToggleGroup.mjs.map +1 -0
  45. package/dist/jsx/ToggleGroup.native.js +252 -0
  46. package/dist/jsx/ToggleGroup.native.js.map +1 -0
  47. package/dist/jsx/context.mjs +8 -0
  48. package/dist/jsx/context.mjs.map +1 -0
  49. package/dist/jsx/context.native.js +37 -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 +31 -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 +19 -0
  60. package/dist/jsx/types.native.js.map +1 -0
  61. package/package.json +60 -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/ToggleGroup.d.ts +189 -0
  69. package/types/context.d.ts +9 -0
  70. package/types/index.d.ts +3 -0
  71. package/types/types.d.ts +5 -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,145 @@
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
+ __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: !0
11
+ });
12
+ },
13
+ __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
+ value: mod,
27
+ enumerable: !0
28
+ }) : target, mod)),
29
+ __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
30
+ value: !0
31
+ }), mod);
32
+ var Toggle_exports = {};
33
+ __export(Toggle_exports, {
34
+ Toggle: () => Toggle,
35
+ ToggleFrame: () => ToggleFrame
36
+ });
37
+ module.exports = __toCommonJS(Toggle_exports);
38
+ var import_gui_helpers = require("@hanzo/gui-helpers"),
39
+ import_gui_use_controllable_state = require("@hanzo/gui-use-controllable-state"),
40
+ import_gui_web = require("@hanzo/gui-web"),
41
+ React = __toESM(require("react"), 1),
42
+ import_context = require("./context.cjs"),
43
+ import_jsx_runtime = require("react/jsx-runtime");
44
+ const NAME = "Toggle",
45
+ ToggleFrame = (0, import_gui_web.styled)(import_gui_web.View, {
46
+ name: NAME,
47
+ render: "button",
48
+ context: import_context.context,
49
+ variants: {
50
+ unstyled: {
51
+ false: {
52
+ size: "$true",
53
+ alignItems: "center",
54
+ justifyContent: "center",
55
+ display: "flex",
56
+ backgroundColor: "$background",
57
+ borderColor: "$borderColor",
58
+ borderWidth: 1,
59
+ margin: -1,
60
+ hoverStyle: {
61
+ backgroundColor: "$backgroundHover",
62
+ borderColor: "$borderColorHover"
63
+ },
64
+ pressStyle: {
65
+ backgroundColor: "$backgroundPress",
66
+ borderColor: "$borderColorPress"
67
+ },
68
+ focusVisibleStyle: {
69
+ outlineColor: "$outlineColor",
70
+ outlineWidth: 2,
71
+ outlineStyle: "solid",
72
+ zIndex: 10
73
+ }
74
+ }
75
+ },
76
+ size: {
77
+ "...size": (val, {
78
+ tokens
79
+ }) => {
80
+ if (val) return {
81
+ width: tokens.size[val],
82
+ height: tokens.size[val]
83
+ };
84
+ },
85
+ ":number": val => ({
86
+ width: val,
87
+ height: val
88
+ })
89
+ },
90
+ defaultActiveStyle: {
91
+ true: {
92
+ backgroundColor: "$backgroundActive",
93
+ hoverStyle: {
94
+ backgroundColor: "$backgroundActive"
95
+ },
96
+ focusStyle: {
97
+ backgroundColor: "$backgroundActive"
98
+ }
99
+ }
100
+ }
101
+ },
102
+ defaultVariants: {
103
+ unstyled: process.env.HANZO_GUI_HEADLESS === "1"
104
+ }
105
+ }, {
106
+ accept: {
107
+ activeStyle: "style"
108
+ }
109
+ }),
110
+ Toggle = React.forwardRef(function (props, forwardedRef) {
111
+ const {
112
+ active: activeProp,
113
+ activeStyle,
114
+ defaultActive = !1,
115
+ onActiveChange,
116
+ activeTheme,
117
+ unstyled = !1,
118
+ ...buttonProps
119
+ } = props,
120
+ [active = !1, setActive] = (0, import_gui_use_controllable_state.useControllableState)({
121
+ prop: activeProp,
122
+ onChange: onActiveChange,
123
+ defaultProp: defaultActive
124
+ });
125
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToggleFrame, {
126
+ theme: activeTheme ?? null,
127
+ "aria-pressed": active,
128
+ "data-state": active ? "on" : "off",
129
+ "data-disabled": props.disabled ? "" : void 0,
130
+ unstyled,
131
+ ...(active && !activeStyle && !unstyled && {
132
+ defaultActiveStyle: !0
133
+ }),
134
+ ...(active && activeStyle && {
135
+ ...activeStyle,
136
+ hoverStyle: activeStyle,
137
+ focusStyle: activeStyle
138
+ }),
139
+ ...buttonProps,
140
+ ref: forwardedRef,
141
+ onPress: (0, import_gui_helpers.composeEventHandlers)(props.onPress ?? void 0, () => {
142
+ props.disabled || setActive(prev => !prev);
143
+ })
144
+ });
145
+ });
@@ -0,0 +1,154 @@
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
+ __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all) __defProp(target, name, {
11
+ get: all[name],
12
+ enumerable: !0
13
+ });
14
+ },
15
+ __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
17
+ get: () => from[key],
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
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: !0
30
+ }) : target, mod)),
31
+ __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
+ value: !0
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_jsx_runtime = require("react/jsx-runtime"),
41
+ import_gui_helpers = require("@hanzo/gui-helpers"),
42
+ import_gui_use_controllable_state = require("@hanzo/gui-use-controllable-state"),
43
+ import_gui_web = require("@hanzo/gui-web"),
44
+ React = __toESM(require("react"), 1),
45
+ import_context = require("./context.native.js"),
46
+ NAME = "Toggle",
47
+ ToggleFrame = (0, import_gui_web.styled)(import_gui_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": function (val, param) {
80
+ var {
81
+ tokens
82
+ } = param;
83
+ if (val) return {
84
+ width: tokens.size[val],
85
+ height: tokens.size[val]
86
+ };
87
+ },
88
+ ":number": function (val) {
89
+ return {
90
+ width: val,
91
+ height: val
92
+ };
93
+ }
94
+ },
95
+ defaultActiveStyle: {
96
+ true: {
97
+ backgroundColor: "$backgroundActive",
98
+ hoverStyle: {
99
+ backgroundColor: "$backgroundActive"
100
+ },
101
+ focusStyle: {
102
+ backgroundColor: "$backgroundActive"
103
+ }
104
+ }
105
+ }
106
+ },
107
+ defaultVariants: {
108
+ unstyled: process.env.HANZO_GUI_HEADLESS === "1"
109
+ }
110
+ }, {
111
+ accept: {
112
+ activeStyle: "style"
113
+ }
114
+ }),
115
+ Toggle = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
116
+ var {
117
+ active: activeProp,
118
+ activeStyle,
119
+ defaultActive = !1,
120
+ onActiveChange,
121
+ activeTheme,
122
+ unstyled = !1,
123
+ ...buttonProps
124
+ } = props,
125
+ [active = !1, setActive] = (0, import_gui_use_controllable_state.useControllableState)({
126
+ prop: activeProp,
127
+ onChange: onActiveChange,
128
+ defaultProp: defaultActive
129
+ }),
130
+ _props_onPress;
131
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToggleFrame, {
132
+ theme: activeTheme ?? null,
133
+ "aria-pressed": active,
134
+ "data-state": active ? "on" : "off",
135
+ "data-disabled": props.disabled ? "" : void 0,
136
+ unstyled,
137
+ ...(active && !activeStyle && !unstyled && {
138
+ defaultActiveStyle: !0
139
+ }),
140
+ ...(active && activeStyle && {
141
+ ...activeStyle,
142
+ hoverStyle: activeStyle,
143
+ focusStyle: activeStyle
144
+ }),
145
+ ...buttonProps,
146
+ ref: forwardedRef,
147
+ onPress: (0, import_gui_helpers.composeEventHandlers)((_props_onPress = props.onPress) !== null && _props_onPress !== void 0 ? _props_onPress : void 0, function () {
148
+ props.disabled || setActive(function (prev) {
149
+ return !prev;
150
+ });
151
+ })
152
+ });
153
+ });
154
+ //# 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_gui_helpers","import_gui_use_controllable_state","import_gui_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","HANZO_GUI_HEADLESS","accept","activeStyle","forwardRef","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":"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","ignoreList":[]}
@@ -0,0 +1,229 @@
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
+ __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: !0
11
+ });
12
+ },
13
+ __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
+ value: mod,
27
+ enumerable: !0
28
+ }) : target, mod)),
29
+ __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
30
+ value: !0
31
+ }), mod);
32
+ var ToggleGroup_exports = {};
33
+ __export(ToggleGroup_exports, {
34
+ ToggleGroup: () => ToggleGroup
35
+ });
36
+ module.exports = __toCommonJS(ToggleGroup_exports);
37
+ var import_gui_constants = require("@hanzo/gui-constants"),
38
+ import_gui_focusable = require("@hanzo/gui-focusable"),
39
+ import_gui_helpers = require("@hanzo/gui-helpers"),
40
+ import_gui_roving_focus = require("@hanzo/gui-roving-focus"),
41
+ import_gui_use_controllable_state = require("@hanzo/gui-use-controllable-state"),
42
+ import_gui_use_direction = require("@hanzo/gui-use-direction"),
43
+ import_gui_web = require("@hanzo/gui-web"),
44
+ import_react = __toESM(require("react"), 1),
45
+ import_Toggle = require("./Toggle.cjs"),
46
+ import_context = require("./context.cjs"),
47
+ import_jsx_runtime = require("react/jsx-runtime");
48
+ const TOGGLE_GROUP_NAME = "ToggleGroup",
49
+ TOGGLE_GROUP_ITEM_NAME = "ToggleGroupItem",
50
+ TOGGLE_GROUP_CONTEXT = "ToggleGroup",
51
+ {
52
+ Provider: ToggleGroupItemProvider
53
+ } = (0, import_gui_web.createStyledContext)(),
54
+ {
55
+ Provider: ToggleGroupContext,
56
+ useStyledContext: useToggleGroupContext
57
+ } = (0, import_gui_web.createStyledContext)({}),
58
+ ToggleGroupItem = import_Toggle.ToggleFrame.styleable((props, forwardedRef) => {
59
+ const valueContext = useToggleGroupValueContext(props.__scopeToggleGroup),
60
+ context = useToggleGroupContext(props.__scopeToggleGroup),
61
+ toggleContext = import_context.context.useStyledContext(props.__scopeToggleGroup),
62
+ active = valueContext?.value.includes(props.value),
63
+ color = props.color || toggleContext.color,
64
+ disabled = context.disabled || props.disabled || !1,
65
+ inner = /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToggleGroupItemImpl, {
66
+ ref: forwardedRef,
67
+ tabIndex: disabled ? -1 : 0,
68
+ ...props,
69
+ active,
70
+ disabled
71
+ });
72
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToggleGroupItemProvider, {
73
+ scope: props.__scopeToggleGroup,
74
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_context.context.Provider, {
75
+ color,
76
+ active,
77
+ children: context.rovingFocus ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_gui_roving_focus.RovingFocusGroup.Item, {
78
+ asChild: "except-style",
79
+ __scopeRovingFocusGroup: props.__scopeToggleGroup || TOGGLE_GROUP_CONTEXT,
80
+ focusable: !disabled,
81
+ active,
82
+ children: inner
83
+ }) : inner
84
+ })
85
+ });
86
+ });
87
+ ToggleGroupItem.displayName = TOGGLE_GROUP_ITEM_NAME;
88
+ const ToggleGroupItemImpl = import_react.default.forwardRef((props, forwardedRef) => {
89
+ const {
90
+ __scopeToggleGroup,
91
+ value,
92
+ ...itemProps
93
+ } = props,
94
+ valueContext = useToggleGroupValueContext(__scopeToggleGroup),
95
+ singleProps = {
96
+ "aria-pressed": void 0
97
+ },
98
+ typeProps = valueContext.type === "single" ? singleProps : void 0;
99
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Toggle.Toggle, {
100
+ ...typeProps,
101
+ ...itemProps,
102
+ ref: forwardedRef,
103
+ onActiveChange: pressed => {
104
+ pressed ? valueContext.onItemActivate(value) : valueContext.onItemDeactivate(value);
105
+ }
106
+ });
107
+ }),
108
+ ToggleGroup = (0, import_gui_helpers.withStaticProperties)(import_react.default.forwardRef((props, forwardedRef) => {
109
+ const {
110
+ type,
111
+ ...toggleGroupProps
112
+ } = props;
113
+ if (import_gui_constants.isWeb || import_react.default.useEffect(() => {
114
+ if (props.id) return (0, import_gui_focusable.registerFocusable)(props.id, {
115
+ focus: () => {}
116
+ });
117
+ }, [props.id]), type === "single") return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToggleGroupImplSingle, {
118
+ ...toggleGroupProps,
119
+ ref: forwardedRef
120
+ });
121
+ if (type === "multiple") return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToggleGroupImplMultiple, {
122
+ ...toggleGroupProps,
123
+ ref: forwardedRef
124
+ });
125
+ throw new Error(`Missing prop \`type\` expected on \`${TOGGLE_GROUP_NAME}\``);
126
+ }), {
127
+ Item: ToggleGroupItem
128
+ });
129
+ ToggleGroup.displayName = TOGGLE_GROUP_NAME;
130
+ const {
131
+ Provider: ToggleGroupValueProvider,
132
+ useStyledContext: useToggleGroupValueContext
133
+ } = (0, import_gui_web.createStyledContext)(),
134
+ ToggleGroupImplSingle = import_react.default.forwardRef((props, forwardedRef) => {
135
+ const {
136
+ value: valueProp,
137
+ defaultValue,
138
+ onValueChange = () => {},
139
+ disableDeactivation = !1,
140
+ children,
141
+ ...toggleGroupSingleProps
142
+ } = props,
143
+ [value, setValue] = (0, import_gui_use_controllable_state.useControllableState)({
144
+ prop: valueProp,
145
+ defaultProp: defaultValue,
146
+ onChange: onValueChange
147
+ });
148
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToggleGroupValueProvider, {
149
+ scope: props.__scopeToggleGroup,
150
+ type: "single",
151
+ value: value ? [value] : [],
152
+ defaultValue: value,
153
+ onItemActivate: setValue,
154
+ onItemDeactivate: import_react.default.useCallback(() => disableDeactivation ? null : setValue(""), [setValue, disableDeactivation]),
155
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToggleGroupImpl, {
156
+ ...toggleGroupSingleProps,
157
+ ref: forwardedRef,
158
+ children
159
+ })
160
+ });
161
+ }),
162
+ ToggleGroupImplMultiple = import_react.default.forwardRef((props, forwardedRef) => {
163
+ const {
164
+ value: valueProp,
165
+ defaultValue,
166
+ onValueChange = () => {},
167
+ disableDeactivation,
168
+ children,
169
+ ...toggleGroupMultipleProps
170
+ } = props,
171
+ [value = [], setValue] = (0, import_gui_use_controllable_state.useControllableState)({
172
+ prop: valueProp,
173
+ defaultProp: defaultValue,
174
+ onChange: onValueChange
175
+ }),
176
+ handleButtonActivate = import_react.default.useCallback(itemValue => setValue((prevValue = []) => [...prevValue, itemValue]), [setValue]),
177
+ handleButtonDeactivate = import_react.default.useCallback(itemValue => setValue((prevValue = []) => prevValue.filter(value2 => value2 !== itemValue)), [setValue]);
178
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToggleGroupValueProvider, {
179
+ scope: props.__scopeToggleGroup,
180
+ type: "multiple",
181
+ value,
182
+ defaultValue: value,
183
+ onItemActivate: handleButtonActivate,
184
+ onItemDeactivate: handleButtonDeactivate,
185
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToggleGroupImpl, {
186
+ ...toggleGroupMultipleProps,
187
+ ref: forwardedRef,
188
+ children
189
+ })
190
+ });
191
+ }),
192
+ ToggleGroupFrame = (0, import_gui_web.styled)(import_gui_web.View, {
193
+ name: TOGGLE_GROUP_NAME
194
+ }),
195
+ ToggleGroupImpl = ToggleGroupFrame.styleable((props, forwardedRef) => {
196
+ const {
197
+ __scopeToggleGroup,
198
+ disabled = !1,
199
+ orientation = "horizontal",
200
+ dir,
201
+ rovingFocus = !0,
202
+ loop = !0,
203
+ color,
204
+ ...toggleGroupProps
205
+ } = props,
206
+ direction = (0, import_gui_use_direction.useDirection)(dir),
207
+ content = /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToggleGroupFrame, {
208
+ role: "group",
209
+ ref: forwardedRef,
210
+ "data-disabled": disabled ? "" : void 0,
211
+ ...toggleGroupProps
212
+ });
213
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToggleGroupContext, {
214
+ scope: __scopeToggleGroup,
215
+ rovingFocus,
216
+ disabled,
217
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_context.context.Provider, {
218
+ color,
219
+ children: rovingFocus ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_gui_roving_focus.RovingFocusGroup, {
220
+ asChild: "except-style",
221
+ __scopeRovingFocusGroup: __scopeToggleGroup || TOGGLE_GROUP_CONTEXT,
222
+ orientation,
223
+ dir: direction,
224
+ loop,
225
+ children: content
226
+ }) : content
227
+ })
228
+ });
229
+ });