@xsolla/xui-segmented 0.148.0 → 0.148.2

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 +202 -0
  2. package/package.json +4 -4
package/README.md ADDED
@@ -0,0 +1,202 @@
1
+ # Segmented
2
+
3
+ A cross-platform React segmented control component for switching between related views or filters. Similar to iOS's UISegmentedControl.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @xsolla/xui-segmented
9
+ # or
10
+ yarn add @xsolla/xui-segmented
11
+ ```
12
+
13
+ ## Demo
14
+
15
+ ### Basic Segmented
16
+
17
+ ```tsx
18
+ import * as React from 'react';
19
+ import { Segmented } from '@xsolla/xui-segmented';
20
+
21
+ export default function BasicSegmented() {
22
+ const [active, setActive] = React.useState('day');
23
+
24
+ return (
25
+ <Segmented
26
+ items={[
27
+ { id: 'day', label: 'Day' },
28
+ { id: 'week', label: 'Week' },
29
+ { id: 'month', label: 'Month' },
30
+ ]}
31
+ activeId={active}
32
+ onChange={setActive}
33
+ />
34
+ );
35
+ }
36
+ ```
37
+
38
+ ### With Icons
39
+
40
+ ```tsx
41
+ import * as React from 'react';
42
+ import { Segmented } from '@xsolla/xui-segmented';
43
+ import { Grid, List } from '@xsolla/xui-icons-base';
44
+
45
+ export default function IconSegmented() {
46
+ const [active, setActive] = React.useState('grid');
47
+
48
+ return (
49
+ <Segmented
50
+ items={[
51
+ { id: 'grid', label: 'Grid', icon: <Grid size={16} /> },
52
+ { id: 'list', label: 'List', icon: <List size={16} /> },
53
+ ]}
54
+ activeId={active}
55
+ onChange={setActive}
56
+ />
57
+ );
58
+ }
59
+ ```
60
+
61
+ ### Full Width
62
+
63
+ ```tsx
64
+ import * as React from 'react';
65
+ import { Segmented } from '@xsolla/xui-segmented';
66
+
67
+ export default function FullWidthSegmented() {
68
+ const [active, setActive] = React.useState('all');
69
+
70
+ return (
71
+ <div style={{ width: 400 }}>
72
+ <Segmented
73
+ fullWidth={true}
74
+ items={[
75
+ { id: 'all', label: 'All' },
76
+ { id: 'active', label: 'Active' },
77
+ { id: 'completed', label: 'Completed' },
78
+ ]}
79
+ activeId={active}
80
+ onChange={setActive}
81
+ />
82
+ </div>
83
+ );
84
+ }
85
+ ```
86
+
87
+ ## Anatomy
88
+
89
+ ```jsx
90
+ import { Segmented } from '@xsolla/xui-segmented';
91
+
92
+ <Segmented
93
+ items={[ // Array of segment items
94
+ { id: 'a', label: 'A' },
95
+ { id: 'b', label: 'B' },
96
+ ]}
97
+ activeId="a" // Currently active item ID
98
+ onChange={handleChange} // Selection change handler
99
+ size="md" // Size variant
100
+ fullWidth={false} // Expand to container width
101
+ />
102
+ ```
103
+
104
+ ## Examples
105
+
106
+ ### Segmented Sizes
107
+
108
+ ```tsx
109
+ import * as React from 'react';
110
+ import { Segmented } from '@xsolla/xui-segmented';
111
+
112
+ export default function SegmentedSizes() {
113
+ const items = [
114
+ { id: 'a', label: 'Option A' },
115
+ { id: 'b', label: 'Option B' },
116
+ { id: 'c', label: 'Option C' },
117
+ ];
118
+
119
+ return (
120
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
121
+ <Segmented size="sm" items={items} activeId="a" />
122
+ <Segmented size="md" items={items} activeId="a" />
123
+ <Segmented size="lg" items={items} activeId="a" />
124
+ <Segmented size="xl" items={items} activeId="a" />
125
+ </div>
126
+ );
127
+ }
128
+ ```
129
+
130
+ ### With Disabled Items
131
+
132
+ ```tsx
133
+ import * as React from 'react';
134
+ import { Segmented } from '@xsolla/xui-segmented';
135
+
136
+ export default function DisabledItemSegmented() {
137
+ const [active, setActive] = React.useState('enabled1');
138
+
139
+ return (
140
+ <Segmented
141
+ items={[
142
+ { id: 'enabled1', label: 'Enabled' },
143
+ { id: 'disabled', label: 'Disabled', disabled: true },
144
+ { id: 'enabled2', label: 'Enabled' },
145
+ ]}
146
+ activeId={active}
147
+ onChange={setActive}
148
+ />
149
+ );
150
+ }
151
+ ```
152
+
153
+ ## API Reference
154
+
155
+ ### Segmented
156
+
157
+ **Segmented Props:**
158
+
159
+ | Prop | Type | Default | Description |
160
+ | :--- | :--- | :------ | :---------- |
161
+ | items | `SegmentedItemType[]` | - | **Required.** Array of segment items. |
162
+ | activeId | `string` | - | ID of the currently active item. |
163
+ | onChange | `(id: string) => void` | - | Selection change handler. |
164
+ | size | `"xl" \| "lg" \| "md" \| "sm"` | `"md"` | Size variant. |
165
+ | fullWidth | `boolean` | `false` | Expand segments to fill container width. |
166
+ | id | `string` | - | HTML id attribute. |
167
+ | testID | `string` | - | Test identifier. |
168
+
169
+ **SegmentedItemType:**
170
+
171
+ ```typescript
172
+ interface SegmentedItemType {
173
+ id: string; // Unique identifier
174
+ label: string; // Display text
175
+ icon?: ReactNode; // Optional icon
176
+ disabled?: boolean; // Disabled state
177
+ "aria-label"?: string; // Accessible label
178
+ }
179
+ ```
180
+
181
+ ## Keyboard Navigation
182
+
183
+ | Key | Action |
184
+ | :-- | :----- |
185
+ | Arrow Right/Down | Move to next item |
186
+ | Arrow Left/Up | Move to previous item |
187
+ | Enter/Space | Select focused item |
188
+
189
+ ## Behavior
190
+
191
+ - Active segment has elevated background with smooth sliding animation
192
+ - Disabled segments show reduced opacity
193
+ - Keyboard navigation wraps around
194
+ - Hover effect on non-active segments
195
+
196
+ ## Accessibility
197
+
198
+ - Uses `role="radiogroup"` on container
199
+ - Each segment has `role="radio"`
200
+ - `aria-checked` indicates selection state
201
+ - `aria-disabled` for disabled items
202
+ - Roving tabindex for keyboard navigation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xsolla/xui-segmented",
3
- "version": "0.148.0",
3
+ "version": "0.148.2",
4
4
  "main": "./web/index.js",
5
5
  "module": "./web/index.mjs",
6
6
  "types": "./web/index.d.ts",
@@ -10,9 +10,9 @@
10
10
  "build:native": "PLATFORM=native tsup"
11
11
  },
12
12
  "dependencies": {
13
- "@xsolla/xui-badge": "0.148.0",
14
- "@xsolla/xui-core": "0.148.0",
15
- "@xsolla/xui-primitives-core": "0.148.0"
13
+ "@xsolla/xui-badge": "0.148.2",
14
+ "@xsolla/xui-core": "0.148.2",
15
+ "@xsolla/xui-primitives-core": "0.148.2"
16
16
  },
17
17
  "peerDependencies": {
18
18
  "react": ">=16.8.0",