@xsolla/xui-autocomplete 0.99.0 → 0.101.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 +152 -21
  2. package/package.json +4 -4
package/README.md CHANGED
@@ -1,41 +1,172 @@
1
- # @xsolla/xui-autocomplete
1
+ # Autocomplete
2
2
 
3
- Text input with a filterable dropdown of suggestions supporting keyboard navigation.
3
+ A cross-platform React autocomplete component that provides a filterable dropdown list of suggestions as the user types. Supports both simple string options and rich objects with icons and descriptions.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
+ npm install @xsolla/xui-autocomplete
9
+ # or
8
10
  yarn add @xsolla/xui-autocomplete
9
11
  ```
10
12
 
11
- ## Usage
13
+ ## Demo
14
+
15
+ ### Basic Autocomplete
16
+
17
+ ```tsx
18
+ import * as React from 'react';
19
+ import { Autocomplete } from '@xsolla/xui-autocomplete';
20
+
21
+ export default function BasicAutocomplete() {
22
+ const [value, setValue] = React.useState('');
23
+
24
+ return (
25
+ <Autocomplete
26
+ value={value}
27
+ onValueChange={setValue}
28
+ options={['Apple', 'Banana', 'Cherry', 'Date', 'Elderberry']}
29
+ placeholder="Search fruits..."
30
+ />
31
+ );
32
+ }
33
+ ```
34
+
35
+ ### Rich Options with Icons
36
+
37
+ ```tsx
38
+ import * as React from 'react';
39
+ import { Autocomplete } from '@xsolla/xui-autocomplete';
40
+ import { Settings, User } from '@xsolla/xui-icons';
41
+ import { LayoutDashboard } from '@xsolla/xui-icons-base';
42
+
43
+ export default function RichAutocomplete() {
44
+ const [value, setValue] = React.useState('');
45
+
46
+ const options = [
47
+ { id: '1', label: 'Dashboard', description: 'View your dashboard', icon: <LayoutDashboard size={16} /> },
48
+ { id: '2', label: 'Settings', description: 'Manage your settings', icon: <Settings size={16} /> },
49
+ { id: '3', label: 'Profile', description: 'Edit your profile', icon: <User size={16} /> },
50
+ ];
51
+
52
+ return (
53
+ <Autocomplete
54
+ value={value}
55
+ onValueChange={setValue}
56
+ list={options}
57
+ onSelect={(option) => console.log('Selected:', option)}
58
+ placeholder="Search pages..."
59
+ />
60
+ );
61
+ }
62
+ ```
63
+
64
+ ### Loading State
12
65
 
13
66
  ```tsx
67
+ import * as React from 'react';
68
+ import { Autocomplete } from '@xsolla/xui-autocomplete';
69
+
70
+ export default function LoadingAutocomplete() {
71
+ const [value, setValue] = React.useState('');
72
+ const [loading, setLoading] = React.useState(false);
73
+ const [options, setOptions] = React.useState([]);
74
+
75
+ const handleSearch = async (query: string) => {
76
+ setValue(query);
77
+ if (query.length >= 2) {
78
+ setLoading(true);
79
+ // Simulate API call
80
+ await new Promise(r => setTimeout(r, 500));
81
+ setOptions(['Result 1', 'Result 2', 'Result 3']);
82
+ setLoading(false);
83
+ }
84
+ };
85
+
86
+ return (
87
+ <Autocomplete
88
+ value={value}
89
+ onValueChange={handleSearch}
90
+ options={options}
91
+ isLoading={loading}
92
+ placeholder="Type to search..."
93
+ />
94
+ );
95
+ }
96
+ ```
97
+
98
+ ## Anatomy
99
+
100
+ ```jsx
14
101
  import { Autocomplete } from '@xsolla/xui-autocomplete';
15
102
 
16
103
  <Autocomplete
17
- label="Search games"
18
- options={['Cyberpunk 2077', 'Elden Ring', 'Starfield']}
19
- onValueChange={(text) => console.log(text)}
20
- onSelect={(value) => console.log(value)}
104
+ value={inputValue} // Input text value
105
+ onValueChange={setValue} // Input change handler
106
+ options={['a', 'b']} // Simple string options
107
+ list={[{id, label, ...}]} // Rich options with metadata
108
+ onSelect={handleSelect} // Selection handler
109
+ isLoading={false} // Show loading spinner
110
+ placeholder="Search..." // Placeholder text
111
+ size="md" // Size variant
112
+ label="Label" // Label above input
113
+ errorLabel="Error" // Error message
114
+ state="default" // Visual state
115
+ maxHeight={200} // Dropdown max height
116
+ emptyMessage="No results" // Empty state message
21
117
  />
22
118
  ```
23
119
 
24
- ## Props
120
+ ## API Reference
25
121
 
26
122
  ### Autocomplete
27
123
 
124
+ **Autocomplete Props:**
125
+
28
126
  | Prop | Type | Default | Description |
29
- |------|------|---------|-------------|
30
- | `options` | `string[]` | `[]` | Simple string options |
31
- | `list` | `AutocompleteOption[]` | | Rich options with `id`, `label`, `description`, `icon`; takes priority over `options` |
32
- | `value` | `string` | | Controlled input value |
33
- | `onValueChange` | `(value: string) => void` | | Called on every keystroke |
34
- | `onSelect` | `(option: string \| AutocompleteOption) => void` | | Called when an option is selected |
35
- | `placeholder` | `string` | `"Search..."` | Input placeholder text |
36
- | `label` | `string` | | Label displayed above the input |
37
- | `size` | `"xl" \| "lg" \| "md" \| "sm" \| "xs"` | `"md"` | Size of the control |
38
- | `state` | `"default" \| "hover" \| "focus" \| "disable" \| "error"` | | Visual state |
39
- | `isLoading` | `boolean` | `false` | Shows a spinner in the dropdown while loading |
40
- | `errorLabel` | `string` | | Error message shown below the control |
41
- | `emptyMessage` | `string` | `"No results found"` | Shown when no options match |
127
+ | :--- | :--- | :------ | :---------- |
128
+ | value | `string` | - | Current input value. |
129
+ | onValueChange | `(value: string) => void` | - | Input change handler. |
130
+ | options | `string[]` | - | Simple string options array. |
131
+ | list | `AutocompleteOption[]` | - | Rich options with metadata. |
132
+ | onSelect | `(option: string \| AutocompleteOption) => void` | - | Selection handler. |
133
+ | isLoading | `boolean` | `false` | Show loading spinner. |
134
+ | placeholder | `string` | - | Input placeholder text. |
135
+ | size | `"xl" \| "lg" \| "md" \| "sm" \| "xs"` | `"md"` | Component size. |
136
+ | state | `"default" \| "hover" \| "focus" \| "disable" \| "error"` | `"default"` | Visual state. |
137
+ | label | `string` | - | Label above input. |
138
+ | errorLabel | `string` | - | Error message below input. |
139
+ | iconLeft | `ReactNode` | - | Icon on left side. |
140
+ | chevronRight | `boolean` | - | Show chevron on right. |
141
+ | filled | `boolean` | - | Filled background style. |
142
+ | maxHeight | `number` | - | Dropdown max height in px. |
143
+ | dropdownWidth | `number \| string` | - | Custom dropdown width. |
144
+ | emptyMessage | `string` | - | Message when no results. |
145
+
146
+ **AutocompleteOption:**
147
+
148
+ ```typescript
149
+ interface AutocompleteOption {
150
+ id: string; // Unique identifier
151
+ label: string; // Display text
152
+ description?: string; // Optional description
153
+ icon?: ReactNode; // Optional leading icon
154
+ disabled?: boolean; // Disabled state
155
+ }
156
+ ```
157
+
158
+ ## Keyboard Navigation
159
+
160
+ | Key | Action |
161
+ | :-- | :----- |
162
+ | Arrow Down | Move to next option |
163
+ | Arrow Up | Move to previous option |
164
+ | Enter | Select highlighted option |
165
+ | Escape | Close dropdown |
166
+
167
+ ## Accessibility
168
+
169
+ - Uses `role="combobox"` pattern
170
+ - `aria-expanded` indicates dropdown state
171
+ - `aria-autocomplete="list"` for screen readers
172
+ - Options have proper focus management
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xsolla/xui-autocomplete",
3
- "version": "0.99.0",
3
+ "version": "0.101.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-core": "0.99.0",
14
- "@xsolla/xui-primitives-core": "0.99.0",
15
- "@xsolla/xui-spinner": "0.99.0"
13
+ "@xsolla/xui-core": "0.101.0",
14
+ "@xsolla/xui-primitives-core": "0.101.0",
15
+ "@xsolla/xui-spinner": "0.101.0"
16
16
  },
17
17
  "peerDependencies": {
18
18
  "react": ">=16.8.0",