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