@xsolla/xui-toggle-button-group 0.150.0 → 0.152.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 (2) hide show
  1. package/README.md +80 -38
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,21 +1,30 @@
1
- # @xsolla/xui-toggle-button-group
1
+ # ToggleButtonGroup
2
2
 
3
- A control for picking one or several options from a linear set of closely related options. Can be used to filter or to sort elements.
3
+ A control for picking one or several options from a linear set of closely related options; useful for filtering or sorting.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
8
  npm install @xsolla/xui-toggle-button-group
9
- # or
10
- yarn add @xsolla/xui-toggle-button-group
11
9
  ```
12
10
 
13
- ## Usage
11
+ ## Imports
14
12
 
15
13
  ```tsx
16
14
  import { ToggleButtonGroup } from '@xsolla/xui-toggle-button-group';
15
+ import type {
16
+ ToggleButtonGroupProps,
17
+ ToggleButtonGroupItem,
18
+ ToggleButtonGroupSize,
19
+ ToggleButtonGroupAppearance,
20
+ } from '@xsolla/xui-toggle-button-group';
21
+ ```
22
+
23
+ ## Quick start
17
24
 
18
- // Single selection (default)
25
+ `onChange` is typed `(value: string | string[]) => void` regardless of `multiple`, so single-select callers cast the value to `string`.
26
+
27
+ ```tsx
19
28
  const [value, setValue] = useState('item1');
20
29
 
21
30
  <ToggleButtonGroup
@@ -26,12 +35,59 @@ const [value, setValue] = useState('item1');
26
35
  ]}
27
36
  value={value}
28
37
  onChange={(v) => setValue(v as string)}
29
- />
38
+ />;
39
+ ```
40
+
41
+ ## API Reference
42
+
43
+ ### `<ToggleButtonGroup>`
30
44
 
31
- // Multiple selection
45
+ | Prop | Type | Default | Description |
46
+ | --- | --- | --- | --- |
47
+ | `items` | `ToggleButtonGroupItem[]` | — | Items to display. |
48
+ | `value` | `string \| string[]` | — | Controlled value; string for single, array for multiple. |
49
+ | `defaultValue` | `string \| string[]` | — | Initial value for uncontrolled mode. |
50
+ | `onChange` | `(value: string \| string[]) => void` | — | Fired when the selection changes. |
51
+ | `size` | `'xs' \| 'sm' \| 'md' \| 'lg' \| 'xl'` | `'md'` | Size variant. |
52
+ | `appearance` | `'separated' \| 'united'` | `'separated'` | `separated` adds gaps; `united` connects items. |
53
+ | `multiple` | `boolean` | `false` | Allow multiple selections. |
54
+ | `fullWidth` | `boolean` | `false` | Stretch to fill the container. |
55
+ | `id` | `string` | — | HTML id. |
56
+ | `testID` | `string` | — | Test identifier. |
57
+ | `aria-label` | `string` | — | Accessible label for the group. |
58
+ | `aria-labelledby` | `string` | — | ID of an element that labels the group. |
59
+
60
+ Inherits `ThemeOverrideProps` (`themeMode`, `themeProductContext`).
61
+
62
+ ### `ToggleButtonGroupItem`
63
+
64
+ | Field | Type | Description |
65
+ | --- | --- | --- |
66
+ | `id` | `string` | Unique identifier. |
67
+ | `label` | `string` | Display text. |
68
+ | `iconLeft` | `ReactNode` | Icon shown before the label. |
69
+ | `iconRight` | `ReactNode` | Icon shown after the label. |
70
+ | `disabled` | `boolean` | Disable the individual item. |
71
+ | `aria-label` | `string` | Accessible label for the item. |
72
+
73
+ ### Types
74
+
75
+ ```ts
76
+ type ToggleButtonGroupSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
77
+ type ToggleButtonGroupAppearance = 'separated' | 'united';
78
+ ```
79
+
80
+ ## Examples
81
+
82
+ ### Multiple selection
83
+
84
+ `onChange` is still typed `(value: string | string[]) => void`, so multi-select callers cast the value to `string[]`.
85
+
86
+ ```tsx
32
87
  const [values, setValues] = useState(['item1', 'item3']);
33
88
 
34
89
  <ToggleButtonGroup
90
+ multiple
35
91
  items={[
36
92
  { id: 'item1', label: 'Option 1' },
37
93
  { id: 'item2', label: 'Option 2' },
@@ -39,40 +95,26 @@ const [values, setValues] = useState(['item1', 'item3']);
39
95
  ]}
40
96
  value={values}
41
97
  onChange={(v) => setValues(v as string[])}
42
- multiple
43
98
  />
44
99
  ```
45
100
 
46
- ## Props
101
+ ### United appearance, full width
47
102
 
48
- | Prop | Type | Default | Description |
49
- |------|------|---------|-------------|
50
- | `items` | `ToggleButtonGroupItem[]` | required | Array of items to display |
51
- | `value` | `string \| string[]` | - | Controlled value(s) |
52
- | `defaultValue` | `string \| string[]` | - | Default value(s) for uncontrolled mode |
53
- | `onChange` | `(value: string \| string[]) => void` | - | Callback when selection changes |
54
- | `size` | `'xl' \| 'lg' \| 'md' \| 'sm'` | `'md'` | Size variant |
55
- | `appearance` | `'separated' \| 'united'` | `'separated'` | Visual style |
56
- | `multiple` | `boolean` | `false` | Allow multiple selections |
57
- | `id` | `string` | - | HTML id attribute |
58
- | `testID` | `string` | - | Test ID for testing frameworks |
59
- | `aria-label` | `string` | - | Accessible label for the group |
60
- | `aria-labelledby` | `string` | - | ID of element that labels this group |
61
-
62
- ### ToggleButtonGroupItem
63
-
64
- | Prop | Type | Description |
65
- |------|------|-------------|
66
- | `id` | `string` | Unique identifier |
67
- | `label` | `string` | Display text |
68
- | `iconLeft` | `ReactNode` | Optional icon on the left |
69
- | `iconRight` | `ReactNode` | Optional icon on the right |
70
- | `disabled` | `boolean` | Whether the item is disabled |
71
- | `aria-label` | `string` | Accessible label for screen readers |
103
+ ```tsx
104
+ <ToggleButtonGroup
105
+ appearance="united"
106
+ fullWidth
107
+ items={[
108
+ { id: 'day', label: 'Day' },
109
+ { id: 'week', label: 'Week' },
110
+ { id: 'month', label: 'Month' },
111
+ ]}
112
+ defaultValue="week"
113
+ />
114
+ ```
72
115
 
73
116
  ## Accessibility
74
117
 
75
- - Uses `role="radiogroup"` for single selection, `role="group"` for multiple
76
- - Arrow keys navigate between items
77
- - Enter/Space selects/toggles items
78
- - Proper `aria-checked` and `aria-disabled` states
118
+ - `role="radiogroup"` for single selection, `role="group"` for multiple selection.
119
+ - Arrow keys move between items; Enter/Space toggles selection.
120
+ - `aria-checked` and `aria-disabled` reflect item state.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xsolla/xui-toggle-button-group",
3
- "version": "0.150.0",
3
+ "version": "0.152.0",
4
4
  "main": "./web/index.js",
5
5
  "module": "./web/index.mjs",
6
6
  "types": "./web/index.d.ts",
@@ -10,8 +10,8 @@
10
10
  "build:native": "PLATFORM=native tsup"
11
11
  },
12
12
  "dependencies": {
13
- "@xsolla/xui-core": "0.150.0",
14
- "@xsolla/xui-primitives-core": "0.150.0"
13
+ "@xsolla/xui-core": "0.152.0",
14
+ "@xsolla/xui-primitives-core": "0.152.0"
15
15
  },
16
16
  "peerDependencies": {
17
17
  "react": ">=16.8.0",