@hanzogui/toggle-group 7.0.0 → 7.3.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.
- package/LICENSE +40 -19
- package/dist/cjs/Toggle.cjs +150 -0
- package/dist/cjs/Toggle.native.js +159 -0
- package/dist/cjs/Toggle.native.js.map +1 -0
- package/dist/cjs/ToggleGroup.cjs +245 -0
- package/dist/cjs/ToggleGroup.native.js +262 -0
- package/dist/cjs/ToggleGroup.native.js.map +1 -0
- package/dist/cjs/context.cjs +36 -0
- package/dist/cjs/context.native.js +39 -0
- package/dist/cjs/context.native.js.map +1 -0
- package/dist/cjs/index.cjs +30 -0
- package/dist/cjs/index.native.js +33 -0
- package/dist/cjs/index.native.js.map +1 -0
- package/dist/cjs/types.cjs +18 -0
- package/dist/cjs/types.native.js +21 -0
- package/dist/cjs/types.native.js.map +1 -0
- package/dist/esm/Toggle.mjs +113 -0
- package/dist/esm/Toggle.mjs.map +1 -0
- package/dist/esm/Toggle.native.js +119 -0
- package/dist/esm/Toggle.native.js.map +1 -0
- package/dist/esm/ToggleGroup.mjs +209 -0
- package/dist/esm/ToggleGroup.mjs.map +1 -0
- package/dist/esm/ToggleGroup.native.js +223 -0
- package/dist/esm/ToggleGroup.native.js.map +1 -0
- package/dist/esm/context.mjs +10 -0
- package/dist/esm/context.mjs.map +1 -0
- package/dist/esm/context.native.js +10 -0
- package/dist/esm/context.native.js.map +1 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/index.mjs +4 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/index.native.js +4 -0
- package/dist/esm/index.native.js.map +1 -0
- package/dist/esm/types.mjs +2 -0
- package/dist/esm/types.mjs.map +1 -0
- package/dist/esm/types.native.js +2 -0
- package/dist/esm/types.native.js.map +1 -0
- package/dist/jsx/Toggle.mjs +113 -0
- package/dist/jsx/Toggle.mjs.map +1 -0
- package/dist/jsx/Toggle.native.js +159 -0
- package/dist/jsx/Toggle.native.js.map +1 -0
- package/dist/jsx/ToggleGroup.mjs +209 -0
- package/dist/jsx/ToggleGroup.mjs.map +1 -0
- package/dist/jsx/ToggleGroup.native.js +262 -0
- package/dist/jsx/ToggleGroup.native.js.map +1 -0
- package/dist/jsx/context.mjs +10 -0
- package/dist/jsx/context.mjs.map +1 -0
- package/dist/jsx/context.native.js +39 -0
- package/dist/jsx/context.native.js.map +1 -0
- package/dist/jsx/index.js +4 -0
- package/dist/jsx/index.js.map +1 -0
- package/dist/jsx/index.mjs +4 -0
- package/dist/jsx/index.mjs.map +1 -0
- package/dist/jsx/index.native.js +33 -0
- package/dist/jsx/index.native.js.map +1 -0
- package/dist/jsx/types.mjs +2 -0
- package/dist/jsx/types.mjs.map +1 -0
- package/dist/jsx/types.native.js +21 -0
- package/dist/jsx/types.native.js.map +1 -0
- package/package.json +23 -21
- package/src/Toggle.tsx +3 -3
- package/src/ToggleGroup.tsx +6 -6
- package/types/Toggle.d.ts +9 -9
- package/types/Toggle.d.ts.map +1 -0
- package/types/ToggleGroup.d.ts +19 -19
- package/types/ToggleGroup.d.ts.map +1 -0
- package/types/context.d.ts.map +1 -0
- package/types/index.d.ts.map +1 -0
- package/types/types.d.ts.map +1 -0
package/LICENSE
CHANGED
|
@@ -1,21 +1,42 @@
|
|
|
1
|
-
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026-present, Hanzo AI, Inc.
|
|
4
|
+
|
|
5
|
+
Portions of this software are derived from upstream code originally licensed under
|
|
6
|
+
the MIT License, with the following copyright notices retained per its terms:
|
|
2
7
|
|
|
3
8
|
Copyright (c) 2020 Nate Wienert
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
Copyright (c) 2015-present, Nicolas Gallagher.
|
|
10
|
+
Copyright (c) 2015-present, Facebook, Inc.
|
|
11
|
+
Copyright (c) 2021 Radix
|
|
12
|
+
Copyright (c) 2017 Carmelo Pullara
|
|
13
|
+
Copyright (c) 2018 Framer B.V.
|
|
14
|
+
Copyright (c) 2022 WorkOS
|
|
15
|
+
|
|
16
|
+
All rights reserved.
|
|
17
|
+
|
|
18
|
+
Redistribution and use in source and binary forms, with or without
|
|
19
|
+
modification, are permitted provided that the following conditions are met:
|
|
20
|
+
|
|
21
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
22
|
+
list of conditions and the following disclaimer.
|
|
23
|
+
|
|
24
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
25
|
+
this list of conditions and the following disclaimer in the documentation
|
|
26
|
+
and/or other materials provided with the distribution.
|
|
27
|
+
|
|
28
|
+
3. Neither the name of the copyright holder nor the names of its contributors
|
|
29
|
+
may be used to endorse or promote products derived from this software
|
|
30
|
+
without specific prior written permission.
|
|
31
|
+
|
|
32
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
33
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
34
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
35
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
36
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
37
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
38
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
39
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
40
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
41
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
42
|
+
POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -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.GUI_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.GUI_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","GUI_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":"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","ignoreList":[]}
|
|
@@ -0,0 +1,245 @@
|
|
|
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 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
|
+
});
|