@xsolla/xui-autocomplete 0.148.0 → 0.148.1

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 +172 -0
  2. package/package.json +4 -4
package/README.md ADDED
@@ -0,0 +1,172 @@
1
+ # Autocomplete
2
+
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
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @xsolla/xui-autocomplete
9
+ # or
10
+ yarn add @xsolla/xui-autocomplete
11
+ ```
12
+
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
65
+
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
101
+ import { Autocomplete } from '@xsolla/xui-autocomplete';
102
+
103
+ <Autocomplete
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
117
+ />
118
+ ```
119
+
120
+ ## API Reference
121
+
122
+ ### Autocomplete
123
+
124
+ **Autocomplete Props:**
125
+
126
+ | Prop | Type | Default | Description |
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.148.0",
3
+ "version": "0.148.1",
4
4
  "main": "./web/index.js",
5
5
  "module": "./web/index.mjs",
6
6
  "types": "./web/index.d.ts",
@@ -13,9 +13,9 @@
13
13
  "test:coverage": "vitest run --coverage"
14
14
  },
15
15
  "dependencies": {
16
- "@xsolla/xui-core": "0.148.0",
17
- "@xsolla/xui-primitives-core": "0.148.0",
18
- "@xsolla/xui-spinner": "0.148.0"
16
+ "@xsolla/xui-core": "0.148.1",
17
+ "@xsolla/xui-primitives-core": "0.148.1",
18
+ "@xsolla/xui-spinner": "0.148.1"
19
19
  },
20
20
  "peerDependencies": {
21
21
  "react": ">=16.8.0",