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