@xsolla/xui-toggle-button-group 0.101.0-pr166.1772004027
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/README.md +78 -0
- package/native/index.d.mts +58 -0
- package/native/index.d.ts +58 -0
- package/native/index.js +482 -0
- package/native/index.js.flow +117 -0
- package/native/index.js.map +1 -0
- package/native/index.mjs +449 -0
- package/native/index.mjs.map +1 -0
- package/package.json +49 -0
- package/web/index.d.mts +58 -0
- package/web/index.d.ts +58 -0
- package/web/index.js +480 -0
- package/web/index.js.flow +117 -0
- package/web/index.js.map +1 -0
- package/web/index.mjs +443 -0
- package/web/index.mjs.map +1 -0
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xsolla/xui-toggle-button-group",
|
|
3
|
+
"version": "0.101.0-pr166.1772004027",
|
|
4
|
+
"main": "./web/index.js",
|
|
5
|
+
"module": "./web/index.mjs",
|
|
6
|
+
"types": "./web/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "yarn build:web && yarn build:native",
|
|
9
|
+
"build:web": "PLATFORM=web tsup",
|
|
10
|
+
"build:native": "PLATFORM=native tsup"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@xsolla/xui-core": "0.101.0-pr166.1772004027",
|
|
14
|
+
"@xsolla/xui-primitives-core": "0.101.0-pr166.1772004027"
|
|
15
|
+
},
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"react": ">=16.8.0",
|
|
18
|
+
"styled-components": ">=4"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
22
|
+
"tsup": "^8.0.0",
|
|
23
|
+
"vitest": "^4.0.18"
|
|
24
|
+
},
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"react-native": "./native/index.js",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"react-native": {
|
|
31
|
+
"types": "./native/index.d.ts",
|
|
32
|
+
"import": "./native/index.mjs",
|
|
33
|
+
"require": "./native/index.js"
|
|
34
|
+
},
|
|
35
|
+
"import": {
|
|
36
|
+
"types": "./web/index.d.ts",
|
|
37
|
+
"default": "./web/index.mjs"
|
|
38
|
+
},
|
|
39
|
+
"require": {
|
|
40
|
+
"types": "./web/index.d.ts",
|
|
41
|
+
"default": "./web/index.js"
|
|
42
|
+
},
|
|
43
|
+
"default": {
|
|
44
|
+
"types": "./web/index.d.ts",
|
|
45
|
+
"default": "./web/index.js"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
package/web/index.d.mts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
type ToggleButtonGroupSize = "xl" | "lg" | "md" | "sm";
|
|
4
|
+
type ToggleButtonGroupAppearance = "separated" | "united";
|
|
5
|
+
interface ToggleButtonGroupItem {
|
|
6
|
+
/** Unique identifier for the item */
|
|
7
|
+
id: string;
|
|
8
|
+
/** Display label for the item */
|
|
9
|
+
label: string;
|
|
10
|
+
/** Optional icon to display on the left */
|
|
11
|
+
iconLeft?: React.ReactNode;
|
|
12
|
+
/** Optional icon to display on the right */
|
|
13
|
+
iconRight?: React.ReactNode;
|
|
14
|
+
/** Whether the item is disabled */
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
/** Accessible label for screen readers */
|
|
17
|
+
"aria-label"?: string;
|
|
18
|
+
}
|
|
19
|
+
interface ToggleButtonGroupProps {
|
|
20
|
+
/** Array of items */
|
|
21
|
+
items: ToggleButtonGroupItem[];
|
|
22
|
+
/** ID(s) of the currently active item(s). For single selection, pass a string. For multiple selection, pass an array. */
|
|
23
|
+
value?: string | string[];
|
|
24
|
+
/** Default value(s) for uncontrolled mode */
|
|
25
|
+
defaultValue?: string | string[];
|
|
26
|
+
/** Callback when selection changes. Returns string for single selection, string[] for multiple. */
|
|
27
|
+
onChange?: (value: string | string[]) => void;
|
|
28
|
+
/** Size variant */
|
|
29
|
+
size?: ToggleButtonGroupSize;
|
|
30
|
+
/** Visual appearance - separated has gaps, united has connected items */
|
|
31
|
+
appearance?: ToggleButtonGroupAppearance;
|
|
32
|
+
/** Whether multiple items can be selected */
|
|
33
|
+
multiple?: boolean;
|
|
34
|
+
/** HTML id attribute */
|
|
35
|
+
id?: string;
|
|
36
|
+
/** Test ID for testing frameworks */
|
|
37
|
+
testID?: string;
|
|
38
|
+
/** Accessible label for the group */
|
|
39
|
+
"aria-label"?: string;
|
|
40
|
+
/** ID of element that labels this group */
|
|
41
|
+
"aria-labelledby"?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* ToggleButtonGroup - A control for picking one or several options from a set
|
|
46
|
+
*
|
|
47
|
+
* Used to pick one or several options from a linear set of closely related options.
|
|
48
|
+
* Can be used to filter or to sort elements.
|
|
49
|
+
*
|
|
50
|
+
* ## Accessibility Features
|
|
51
|
+
*
|
|
52
|
+
* - **Role**: Uses `role="radiogroup"` for single selection, `role="group"` for multiple
|
|
53
|
+
* - **Keyboard Navigation**: Arrow keys to navigate, Enter/Space to select
|
|
54
|
+
* - **ARIA**: Proper aria-checked and aria-disabled states
|
|
55
|
+
*/
|
|
56
|
+
declare const ToggleButtonGroup: React.FC<ToggleButtonGroupProps>;
|
|
57
|
+
|
|
58
|
+
export { ToggleButtonGroup, type ToggleButtonGroupAppearance, type ToggleButtonGroupItem, type ToggleButtonGroupProps, type ToggleButtonGroupSize };
|
package/web/index.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
type ToggleButtonGroupSize = "xl" | "lg" | "md" | "sm";
|
|
4
|
+
type ToggleButtonGroupAppearance = "separated" | "united";
|
|
5
|
+
interface ToggleButtonGroupItem {
|
|
6
|
+
/** Unique identifier for the item */
|
|
7
|
+
id: string;
|
|
8
|
+
/** Display label for the item */
|
|
9
|
+
label: string;
|
|
10
|
+
/** Optional icon to display on the left */
|
|
11
|
+
iconLeft?: React.ReactNode;
|
|
12
|
+
/** Optional icon to display on the right */
|
|
13
|
+
iconRight?: React.ReactNode;
|
|
14
|
+
/** Whether the item is disabled */
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
/** Accessible label for screen readers */
|
|
17
|
+
"aria-label"?: string;
|
|
18
|
+
}
|
|
19
|
+
interface ToggleButtonGroupProps {
|
|
20
|
+
/** Array of items */
|
|
21
|
+
items: ToggleButtonGroupItem[];
|
|
22
|
+
/** ID(s) of the currently active item(s). For single selection, pass a string. For multiple selection, pass an array. */
|
|
23
|
+
value?: string | string[];
|
|
24
|
+
/** Default value(s) for uncontrolled mode */
|
|
25
|
+
defaultValue?: string | string[];
|
|
26
|
+
/** Callback when selection changes. Returns string for single selection, string[] for multiple. */
|
|
27
|
+
onChange?: (value: string | string[]) => void;
|
|
28
|
+
/** Size variant */
|
|
29
|
+
size?: ToggleButtonGroupSize;
|
|
30
|
+
/** Visual appearance - separated has gaps, united has connected items */
|
|
31
|
+
appearance?: ToggleButtonGroupAppearance;
|
|
32
|
+
/** Whether multiple items can be selected */
|
|
33
|
+
multiple?: boolean;
|
|
34
|
+
/** HTML id attribute */
|
|
35
|
+
id?: string;
|
|
36
|
+
/** Test ID for testing frameworks */
|
|
37
|
+
testID?: string;
|
|
38
|
+
/** Accessible label for the group */
|
|
39
|
+
"aria-label"?: string;
|
|
40
|
+
/** ID of element that labels this group */
|
|
41
|
+
"aria-labelledby"?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* ToggleButtonGroup - A control for picking one or several options from a set
|
|
46
|
+
*
|
|
47
|
+
* Used to pick one or several options from a linear set of closely related options.
|
|
48
|
+
* Can be used to filter or to sort elements.
|
|
49
|
+
*
|
|
50
|
+
* ## Accessibility Features
|
|
51
|
+
*
|
|
52
|
+
* - **Role**: Uses `role="radiogroup"` for single selection, `role="group"` for multiple
|
|
53
|
+
* - **Keyboard Navigation**: Arrow keys to navigate, Enter/Space to select
|
|
54
|
+
* - **ARIA**: Proper aria-checked and aria-disabled states
|
|
55
|
+
*/
|
|
56
|
+
declare const ToggleButtonGroup: React.FC<ToggleButtonGroupProps>;
|
|
57
|
+
|
|
58
|
+
export { ToggleButtonGroup, type ToggleButtonGroupAppearance, type ToggleButtonGroupItem, type ToggleButtonGroupProps, type ToggleButtonGroupSize };
|
package/web/index.js
ADDED
|
@@ -0,0 +1,480 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], 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", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.tsx
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
ToggleButtonGroup: () => ToggleButtonGroup
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
|
36
|
+
|
|
37
|
+
// src/ToggleButtonGroup.tsx
|
|
38
|
+
var import_react2 = require("react");
|
|
39
|
+
|
|
40
|
+
// ../primitives-web/src/Box.tsx
|
|
41
|
+
var import_react = __toESM(require("react"));
|
|
42
|
+
var import_styled_components = __toESM(require("styled-components"));
|
|
43
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
44
|
+
var StyledBox = import_styled_components.default.div`
|
|
45
|
+
display: flex;
|
|
46
|
+
box-sizing: border-box;
|
|
47
|
+
background-color: ${(props) => props.backgroundColor || "transparent"};
|
|
48
|
+
border-color: ${(props) => props.borderColor || "transparent"};
|
|
49
|
+
border-width: ${(props) => typeof props.borderWidth === "number" ? `${props.borderWidth}px` : props.borderWidth || 0};
|
|
50
|
+
|
|
51
|
+
${(props) => props.borderBottomWidth !== void 0 && `
|
|
52
|
+
border-bottom-width: ${typeof props.borderBottomWidth === "number" ? `${props.borderBottomWidth}px` : props.borderBottomWidth};
|
|
53
|
+
border-bottom-color: ${props.borderBottomColor || props.borderColor || "transparent"};
|
|
54
|
+
border-bottom-style: solid;
|
|
55
|
+
`}
|
|
56
|
+
${(props) => props.borderTopWidth !== void 0 && `
|
|
57
|
+
border-top-width: ${typeof props.borderTopWidth === "number" ? `${props.borderTopWidth}px` : props.borderTopWidth};
|
|
58
|
+
border-top-color: ${props.borderTopColor || props.borderColor || "transparent"};
|
|
59
|
+
border-top-style: solid;
|
|
60
|
+
`}
|
|
61
|
+
${(props) => props.borderLeftWidth !== void 0 && `
|
|
62
|
+
border-left-width: ${typeof props.borderLeftWidth === "number" ? `${props.borderLeftWidth}px` : props.borderLeftWidth};
|
|
63
|
+
border-left-color: ${props.borderLeftColor || props.borderColor || "transparent"};
|
|
64
|
+
border-left-style: solid;
|
|
65
|
+
`}
|
|
66
|
+
${(props) => props.borderRightWidth !== void 0 && `
|
|
67
|
+
border-right-width: ${typeof props.borderRightWidth === "number" ? `${props.borderRightWidth}px` : props.borderRightWidth};
|
|
68
|
+
border-right-color: ${props.borderRightColor || props.borderColor || "transparent"};
|
|
69
|
+
border-right-style: solid;
|
|
70
|
+
`}
|
|
71
|
+
|
|
72
|
+
border-style: ${(props) => props.borderStyle || (props.borderWidth || props.borderBottomWidth || props.borderTopWidth || props.borderLeftWidth || props.borderRightWidth ? "solid" : "none")};
|
|
73
|
+
border-radius: ${(props) => typeof props.borderRadius === "number" ? `${props.borderRadius}px` : props.borderRadius || 0};
|
|
74
|
+
height: ${(props) => typeof props.height === "number" ? `${props.height}px` : props.height || "auto"};
|
|
75
|
+
width: ${(props) => typeof props.width === "number" ? `${props.width}px` : props.width || "auto"};
|
|
76
|
+
min-width: ${(props) => typeof props.minWidth === "number" ? `${props.minWidth}px` : props.minWidth || "auto"};
|
|
77
|
+
min-height: ${(props) => typeof props.minHeight === "number" ? `${props.minHeight}px` : props.minHeight || "auto"};
|
|
78
|
+
|
|
79
|
+
padding: ${(props) => typeof props.padding === "number" ? `${props.padding}px` : props.padding || 0};
|
|
80
|
+
${(props) => props.paddingHorizontal && `
|
|
81
|
+
padding-left: ${typeof props.paddingHorizontal === "number" ? `${props.paddingHorizontal}px` : props.paddingHorizontal};
|
|
82
|
+
padding-right: ${typeof props.paddingHorizontal === "number" ? `${props.paddingHorizontal}px` : props.paddingHorizontal};
|
|
83
|
+
`}
|
|
84
|
+
${(props) => props.paddingVertical && `
|
|
85
|
+
padding-top: ${typeof props.paddingVertical === "number" ? `${props.paddingVertical}px` : props.paddingVertical};
|
|
86
|
+
padding-bottom: ${typeof props.paddingVertical === "number" ? `${props.paddingVertical}px` : props.paddingVertical};
|
|
87
|
+
`}
|
|
88
|
+
${(props) => props.paddingTop !== void 0 && `padding-top: ${typeof props.paddingTop === "number" ? `${props.paddingTop}px` : props.paddingTop};`}
|
|
89
|
+
${(props) => props.paddingBottom !== void 0 && `padding-bottom: ${typeof props.paddingBottom === "number" ? `${props.paddingBottom}px` : props.paddingBottom};`}
|
|
90
|
+
${(props) => props.paddingLeft !== void 0 && `padding-left: ${typeof props.paddingLeft === "number" ? `${props.paddingLeft}px` : props.paddingLeft};`}
|
|
91
|
+
${(props) => props.paddingRight !== void 0 && `padding-right: ${typeof props.paddingRight === "number" ? `${props.paddingRight}px` : props.paddingRight};`}
|
|
92
|
+
|
|
93
|
+
margin: ${(props) => typeof props.margin === "number" ? `${props.margin}px` : props.margin || 0};
|
|
94
|
+
${(props) => props.marginTop !== void 0 && `margin-top: ${typeof props.marginTop === "number" ? `${props.marginTop}px` : props.marginTop};`}
|
|
95
|
+
${(props) => props.marginBottom !== void 0 && `margin-bottom: ${typeof props.marginBottom === "number" ? `${props.marginBottom}px` : props.marginBottom};`}
|
|
96
|
+
${(props) => props.marginLeft !== void 0 && `margin-left: ${typeof props.marginLeft === "number" ? `${props.marginLeft}px` : props.marginLeft};`}
|
|
97
|
+
${(props) => props.marginRight !== void 0 && `margin-right: ${typeof props.marginRight === "number" ? `${props.marginRight}px` : props.marginRight};`}
|
|
98
|
+
|
|
99
|
+
flex-direction: ${(props) => props.flexDirection || "column"};
|
|
100
|
+
flex-wrap: ${(props) => props.flexWrap || "nowrap"};
|
|
101
|
+
align-items: ${(props) => props.alignItems || "stretch"};
|
|
102
|
+
justify-content: ${(props) => props.justifyContent || "flex-start"};
|
|
103
|
+
cursor: ${(props) => props.cursor ? props.cursor : props.onClick || props.onPress ? "pointer" : "inherit"};
|
|
104
|
+
position: ${(props) => props.position || "static"};
|
|
105
|
+
top: ${(props) => typeof props.top === "number" ? `${props.top}px` : props.top};
|
|
106
|
+
bottom: ${(props) => typeof props.bottom === "number" ? `${props.bottom}px` : props.bottom};
|
|
107
|
+
left: ${(props) => typeof props.left === "number" ? `${props.left}px` : props.left};
|
|
108
|
+
right: ${(props) => typeof props.right === "number" ? `${props.right}px` : props.right};
|
|
109
|
+
flex: ${(props) => props.flex};
|
|
110
|
+
flex-shrink: ${(props) => props.flexShrink ?? 1};
|
|
111
|
+
gap: ${(props) => typeof props.gap === "number" ? `${props.gap}px` : props.gap || 0};
|
|
112
|
+
align-self: ${(props) => props.alignSelf || "auto"};
|
|
113
|
+
overflow: ${(props) => props.overflow || "visible"};
|
|
114
|
+
overflow-x: ${(props) => props.overflowX || "visible"};
|
|
115
|
+
overflow-y: ${(props) => props.overflowY || "visible"};
|
|
116
|
+
z-index: ${(props) => props.zIndex};
|
|
117
|
+
opacity: ${(props) => props.disabled ? 0.5 : 1};
|
|
118
|
+
pointer-events: ${(props) => props.disabled ? "none" : "auto"};
|
|
119
|
+
|
|
120
|
+
&:hover {
|
|
121
|
+
${(props) => props.hoverStyle?.backgroundColor && `background-color: ${props.hoverStyle.backgroundColor};`}
|
|
122
|
+
${(props) => props.hoverStyle?.borderColor && `border-color: ${props.hoverStyle.borderColor};`}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
&:active {
|
|
126
|
+
${(props) => props.pressStyle?.backgroundColor && `background-color: ${props.pressStyle.backgroundColor};`}
|
|
127
|
+
}
|
|
128
|
+
`;
|
|
129
|
+
var Box = import_react.default.forwardRef(
|
|
130
|
+
({
|
|
131
|
+
children,
|
|
132
|
+
onPress,
|
|
133
|
+
onKeyDown,
|
|
134
|
+
onKeyUp,
|
|
135
|
+
role,
|
|
136
|
+
"aria-label": ariaLabel,
|
|
137
|
+
"aria-labelledby": ariaLabelledBy,
|
|
138
|
+
"aria-current": ariaCurrent,
|
|
139
|
+
"aria-disabled": ariaDisabled,
|
|
140
|
+
"aria-live": ariaLive,
|
|
141
|
+
"aria-busy": ariaBusy,
|
|
142
|
+
"aria-describedby": ariaDescribedBy,
|
|
143
|
+
"aria-expanded": ariaExpanded,
|
|
144
|
+
"aria-haspopup": ariaHasPopup,
|
|
145
|
+
"aria-pressed": ariaPressed,
|
|
146
|
+
"aria-controls": ariaControls,
|
|
147
|
+
tabIndex,
|
|
148
|
+
as,
|
|
149
|
+
src,
|
|
150
|
+
alt,
|
|
151
|
+
type,
|
|
152
|
+
disabled,
|
|
153
|
+
id,
|
|
154
|
+
...props
|
|
155
|
+
}, ref) => {
|
|
156
|
+
if (as === "img" && src) {
|
|
157
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
158
|
+
"img",
|
|
159
|
+
{
|
|
160
|
+
src,
|
|
161
|
+
alt: alt || "",
|
|
162
|
+
style: {
|
|
163
|
+
display: "block",
|
|
164
|
+
objectFit: "cover",
|
|
165
|
+
width: typeof props.width === "number" ? `${props.width}px` : props.width,
|
|
166
|
+
height: typeof props.height === "number" ? `${props.height}px` : props.height,
|
|
167
|
+
borderRadius: typeof props.borderRadius === "number" ? `${props.borderRadius}px` : props.borderRadius,
|
|
168
|
+
position: props.position,
|
|
169
|
+
top: typeof props.top === "number" ? `${props.top}px` : props.top,
|
|
170
|
+
left: typeof props.left === "number" ? `${props.left}px` : props.left,
|
|
171
|
+
right: typeof props.right === "number" ? `${props.right}px` : props.right,
|
|
172
|
+
bottom: typeof props.bottom === "number" ? `${props.bottom}px` : props.bottom
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
178
|
+
StyledBox,
|
|
179
|
+
{
|
|
180
|
+
ref,
|
|
181
|
+
as,
|
|
182
|
+
id,
|
|
183
|
+
type: as === "button" ? type || "button" : void 0,
|
|
184
|
+
disabled: as === "button" ? disabled : void 0,
|
|
185
|
+
onClick: onPress,
|
|
186
|
+
onKeyDown,
|
|
187
|
+
onKeyUp,
|
|
188
|
+
role,
|
|
189
|
+
"aria-label": ariaLabel,
|
|
190
|
+
"aria-labelledby": ariaLabelledBy,
|
|
191
|
+
"aria-current": ariaCurrent,
|
|
192
|
+
"aria-disabled": ariaDisabled,
|
|
193
|
+
"aria-busy": ariaBusy,
|
|
194
|
+
"aria-describedby": ariaDescribedBy,
|
|
195
|
+
"aria-expanded": ariaExpanded,
|
|
196
|
+
"aria-haspopup": ariaHasPopup,
|
|
197
|
+
"aria-pressed": ariaPressed,
|
|
198
|
+
"aria-controls": ariaControls,
|
|
199
|
+
"aria-live": ariaLive,
|
|
200
|
+
tabIndex: tabIndex !== void 0 ? tabIndex : void 0,
|
|
201
|
+
...props,
|
|
202
|
+
children
|
|
203
|
+
}
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
);
|
|
207
|
+
Box.displayName = "Box";
|
|
208
|
+
|
|
209
|
+
// ../primitives-web/src/Text.tsx
|
|
210
|
+
var import_styled_components2 = __toESM(require("styled-components"));
|
|
211
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
212
|
+
var StyledText = import_styled_components2.default.span`
|
|
213
|
+
color: ${(props) => props.color || "inherit"};
|
|
214
|
+
font-size: ${(props) => typeof props.fontSize === "number" ? `${props.fontSize}px` : props.fontSize || "inherit"};
|
|
215
|
+
font-weight: ${(props) => props.fontWeight || "normal"};
|
|
216
|
+
font-family: ${(props) => props.fontFamily || '"Pilat Wide Bold", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important'};
|
|
217
|
+
line-height: ${(props) => typeof props.lineHeight === "number" ? `${props.lineHeight}px` : props.lineHeight || "inherit"};
|
|
218
|
+
white-space: ${(props) => props.whiteSpace || "normal"};
|
|
219
|
+
text-align: ${(props) => props.textAlign || "inherit"};
|
|
220
|
+
text-decoration: ${(props) => props.textDecoration || "none"};
|
|
221
|
+
`;
|
|
222
|
+
var Text = ({
|
|
223
|
+
style,
|
|
224
|
+
className,
|
|
225
|
+
id,
|
|
226
|
+
role,
|
|
227
|
+
...props
|
|
228
|
+
}) => {
|
|
229
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
230
|
+
StyledText,
|
|
231
|
+
{
|
|
232
|
+
...props,
|
|
233
|
+
style,
|
|
234
|
+
className,
|
|
235
|
+
id,
|
|
236
|
+
role
|
|
237
|
+
}
|
|
238
|
+
);
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
// ../primitives-web/src/Icon.tsx
|
|
242
|
+
var import_styled_components3 = __toESM(require("styled-components"));
|
|
243
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
244
|
+
var StyledIcon = import_styled_components3.default.div`
|
|
245
|
+
display: flex;
|
|
246
|
+
align-items: center;
|
|
247
|
+
justify-content: center;
|
|
248
|
+
width: ${(props) => typeof props.size === "number" ? `${props.size}px` : props.size || "24px"};
|
|
249
|
+
height: ${(props) => typeof props.size === "number" ? `${props.size}px` : props.size || "24px"};
|
|
250
|
+
color: ${(props) => props.color || "currentColor"};
|
|
251
|
+
|
|
252
|
+
svg {
|
|
253
|
+
width: 100%;
|
|
254
|
+
height: 100%;
|
|
255
|
+
fill: none;
|
|
256
|
+
stroke: currentColor;
|
|
257
|
+
}
|
|
258
|
+
`;
|
|
259
|
+
var Icon = ({ children, ...props }) => {
|
|
260
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(StyledIcon, { ...props, children });
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
// src/ToggleButtonGroup.tsx
|
|
264
|
+
var import_xui_core = require("@xsolla/xui-core");
|
|
265
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
266
|
+
var ToggleButtonGroup = ({
|
|
267
|
+
items,
|
|
268
|
+
value,
|
|
269
|
+
defaultValue,
|
|
270
|
+
onChange,
|
|
271
|
+
size = "md",
|
|
272
|
+
appearance = "separated",
|
|
273
|
+
multiple = false,
|
|
274
|
+
id,
|
|
275
|
+
testID,
|
|
276
|
+
"aria-label": ariaLabel,
|
|
277
|
+
"aria-labelledby": ariaLabelledBy
|
|
278
|
+
}) => {
|
|
279
|
+
const { theme } = (0, import_xui_core.useDesignSystem)();
|
|
280
|
+
const sizeStyles = theme.sizing.toggleButtonGroup(size);
|
|
281
|
+
const itemRefs = (0, import_react2.useRef)([]);
|
|
282
|
+
const [internalValue, setInternalValue] = (0, import_react2.useState)(() => {
|
|
283
|
+
if (defaultValue !== void 0) {
|
|
284
|
+
return Array.isArray(defaultValue) ? defaultValue : [defaultValue];
|
|
285
|
+
}
|
|
286
|
+
return [];
|
|
287
|
+
});
|
|
288
|
+
const currentValue = value !== void 0 ? Array.isArray(value) ? value : [value] : internalValue;
|
|
289
|
+
const isItemActive = (itemId) => currentValue.includes(itemId);
|
|
290
|
+
const enabledIndices = items.map((item, index) => !item.disabled ? index : -1).filter((i) => i !== -1);
|
|
291
|
+
const focusItem = (0, import_react2.useCallback)((index) => {
|
|
292
|
+
const element = itemRefs.current[index];
|
|
293
|
+
if (element) {
|
|
294
|
+
element.focus();
|
|
295
|
+
}
|
|
296
|
+
}, []);
|
|
297
|
+
const handleSelect = (0, import_react2.useCallback)(
|
|
298
|
+
(itemId) => {
|
|
299
|
+
let newValue;
|
|
300
|
+
if (multiple) {
|
|
301
|
+
if (currentValue.includes(itemId)) {
|
|
302
|
+
newValue = currentValue.filter((v) => v !== itemId);
|
|
303
|
+
} else {
|
|
304
|
+
newValue = [...currentValue, itemId];
|
|
305
|
+
}
|
|
306
|
+
} else {
|
|
307
|
+
newValue = [itemId];
|
|
308
|
+
}
|
|
309
|
+
if (value === void 0) {
|
|
310
|
+
setInternalValue(newValue);
|
|
311
|
+
}
|
|
312
|
+
if (onChange) {
|
|
313
|
+
if (multiple) {
|
|
314
|
+
onChange(newValue);
|
|
315
|
+
} else {
|
|
316
|
+
onChange(newValue[0] || "");
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
},
|
|
320
|
+
[currentValue, multiple, value, onChange]
|
|
321
|
+
);
|
|
322
|
+
const handleKeyDown = (0, import_react2.useCallback)(
|
|
323
|
+
(e, currentIndex) => {
|
|
324
|
+
const currentEnabledIndex = enabledIndices.indexOf(currentIndex);
|
|
325
|
+
switch (e.key) {
|
|
326
|
+
case "ArrowRight":
|
|
327
|
+
case "ArrowDown":
|
|
328
|
+
e.preventDefault();
|
|
329
|
+
{
|
|
330
|
+
const nextEnabledIndex = currentEnabledIndex < enabledIndices.length - 1 ? enabledIndices[currentEnabledIndex + 1] : enabledIndices[0];
|
|
331
|
+
focusItem(nextEnabledIndex);
|
|
332
|
+
}
|
|
333
|
+
break;
|
|
334
|
+
case "ArrowLeft":
|
|
335
|
+
case "ArrowUp":
|
|
336
|
+
e.preventDefault();
|
|
337
|
+
{
|
|
338
|
+
const prevEnabledIndex = currentEnabledIndex > 0 ? enabledIndices[currentEnabledIndex - 1] : enabledIndices[enabledIndices.length - 1];
|
|
339
|
+
focusItem(prevEnabledIndex);
|
|
340
|
+
}
|
|
341
|
+
break;
|
|
342
|
+
case "Enter":
|
|
343
|
+
case " ":
|
|
344
|
+
e.preventDefault();
|
|
345
|
+
if (!items[currentIndex].disabled) {
|
|
346
|
+
handleSelect(items[currentIndex].id);
|
|
347
|
+
}
|
|
348
|
+
break;
|
|
349
|
+
default:
|
|
350
|
+
break;
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
[enabledIndices, focusItem, handleSelect, items]
|
|
354
|
+
);
|
|
355
|
+
const isSeparated = appearance === "separated";
|
|
356
|
+
const containerGap = isSeparated ? sizeStyles.itemGap : 0;
|
|
357
|
+
const firstActiveIndex = items.findIndex(
|
|
358
|
+
(item) => currentValue.includes(item.id)
|
|
359
|
+
);
|
|
360
|
+
const firstEnabledIndex = enabledIndices[0] ?? 0;
|
|
361
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
362
|
+
Box,
|
|
363
|
+
{
|
|
364
|
+
id,
|
|
365
|
+
role: multiple ? "group" : "radiogroup",
|
|
366
|
+
"aria-label": ariaLabel,
|
|
367
|
+
"aria-labelledby": ariaLabelledBy,
|
|
368
|
+
testID,
|
|
369
|
+
flexDirection: "row",
|
|
370
|
+
alignItems: "center",
|
|
371
|
+
flexWrap: "wrap",
|
|
372
|
+
gap: containerGap,
|
|
373
|
+
...!isSeparated && {
|
|
374
|
+
borderWidth: 1,
|
|
375
|
+
borderColor: theme.colors.control.toggleButton.border,
|
|
376
|
+
borderStyle: "solid",
|
|
377
|
+
borderRadius: sizeStyles.borderRadius,
|
|
378
|
+
width: "fit-content"
|
|
379
|
+
},
|
|
380
|
+
children: items.map((item, index) => {
|
|
381
|
+
const isActive = isItemActive(item.id);
|
|
382
|
+
const isDisabled = item.disabled;
|
|
383
|
+
const itemId = id ? `${id}-item-${item.id}` : void 0;
|
|
384
|
+
let tabIndex;
|
|
385
|
+
if (isDisabled) {
|
|
386
|
+
tabIndex = -1;
|
|
387
|
+
} else if (multiple) {
|
|
388
|
+
tabIndex = 0;
|
|
389
|
+
} else {
|
|
390
|
+
tabIndex = isActive || firstActiveIndex === -1 && index === firstEnabledIndex ? 0 : -1;
|
|
391
|
+
}
|
|
392
|
+
const handlePress = () => {
|
|
393
|
+
if (!isDisabled) {
|
|
394
|
+
handleSelect(item.id);
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
const toggleColors = theme.colors.control.toggleButton;
|
|
398
|
+
const bgColor = isDisabled ? toggleColors.bgDisable : isActive ? toggleColors.bgPress : toggleColors.bg;
|
|
399
|
+
const textColor = isDisabled ? toggleColors.textDisable : toggleColors.text;
|
|
400
|
+
const borderColor = isDisabled ? toggleColors.borderDisable : isActive ? toggleColors.borderPress : toggleColors.border;
|
|
401
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
402
|
+
Box,
|
|
403
|
+
{
|
|
404
|
+
as: "button",
|
|
405
|
+
role: multiple ? "checkbox" : "radio",
|
|
406
|
+
id: itemId,
|
|
407
|
+
"aria-checked": isActive,
|
|
408
|
+
"aria-disabled": isDisabled,
|
|
409
|
+
"aria-label": item["aria-label"] || item.label,
|
|
410
|
+
tabIndex,
|
|
411
|
+
disabled: isDisabled,
|
|
412
|
+
ref: (el) => {
|
|
413
|
+
itemRefs.current[index] = el;
|
|
414
|
+
},
|
|
415
|
+
onPress: handlePress,
|
|
416
|
+
onKeyDown: (e) => handleKeyDown(e, index),
|
|
417
|
+
height: sizeStyles.height,
|
|
418
|
+
paddingHorizontal: sizeStyles.paddingHorizontal,
|
|
419
|
+
flexDirection: "row",
|
|
420
|
+
alignItems: "center",
|
|
421
|
+
justifyContent: "center",
|
|
422
|
+
gap: sizeStyles.gap,
|
|
423
|
+
backgroundColor: bgColor,
|
|
424
|
+
...isSeparated && {
|
|
425
|
+
borderWidth: 1,
|
|
426
|
+
borderColor,
|
|
427
|
+
borderStyle: "solid",
|
|
428
|
+
borderRadius: sizeStyles.borderRadius
|
|
429
|
+
},
|
|
430
|
+
cursor: isDisabled ? "not-allowed" : "pointer",
|
|
431
|
+
hoverStyle: !isDisabled && !isActive ? {
|
|
432
|
+
backgroundColor: toggleColors.bgHover,
|
|
433
|
+
borderColor: toggleColors.borderHover
|
|
434
|
+
} : void 0,
|
|
435
|
+
...!isSeparated && {
|
|
436
|
+
borderLeftWidth: index > 0 ? 1 : 0,
|
|
437
|
+
borderLeftColor: theme.colors.control.toggleButton.border,
|
|
438
|
+
borderLeftStyle: "solid"
|
|
439
|
+
},
|
|
440
|
+
style: {
|
|
441
|
+
flexShrink: 0,
|
|
442
|
+
...!isSeparated && index === 0 && {
|
|
443
|
+
borderTopLeftRadius: sizeStyles.borderRadius - 1,
|
|
444
|
+
borderBottomLeftRadius: sizeStyles.borderRadius - 1
|
|
445
|
+
},
|
|
446
|
+
...!isSeparated && index === items.length - 1 && {
|
|
447
|
+
borderTopRightRadius: sizeStyles.borderRadius - 1,
|
|
448
|
+
borderBottomRightRadius: sizeStyles.borderRadius - 1
|
|
449
|
+
}
|
|
450
|
+
},
|
|
451
|
+
children: [
|
|
452
|
+
item.iconLeft && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { size: sizeStyles.iconSize, color: textColor, "aria-hidden": true, children: item.iconLeft }),
|
|
453
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
454
|
+
Text,
|
|
455
|
+
{
|
|
456
|
+
color: textColor,
|
|
457
|
+
fontSize: sizeStyles.fontSize,
|
|
458
|
+
fontWeight: "400",
|
|
459
|
+
textAlign: "center",
|
|
460
|
+
style: {
|
|
461
|
+
lineHeight: `${sizeStyles.lineHeight}px`
|
|
462
|
+
},
|
|
463
|
+
children: item.label
|
|
464
|
+
}
|
|
465
|
+
),
|
|
466
|
+
item.iconRight && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { size: sizeStyles.iconSize, color: textColor, "aria-hidden": true, children: item.iconRight })
|
|
467
|
+
]
|
|
468
|
+
},
|
|
469
|
+
item.id
|
|
470
|
+
);
|
|
471
|
+
})
|
|
472
|
+
}
|
|
473
|
+
);
|
|
474
|
+
};
|
|
475
|
+
ToggleButtonGroup.displayName = "ToggleButtonGroup";
|
|
476
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
477
|
+
0 && (module.exports = {
|
|
478
|
+
ToggleButtonGroup
|
|
479
|
+
});
|
|
480
|
+
//# sourceMappingURL=index.js.map
|