@xsolla/xui-dropdown 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 +163 -25
  2. package/package.json +6 -6
package/README.md CHANGED
@@ -1,49 +1,187 @@
1
- # @xsolla/xui-dropdown
1
+ ---
2
+ title: Dropdown
3
+ subtitle: A dropdown menu component.
4
+ description: A cross-platform React dropdown menu component with trigger-based activation and customizable items.
5
+ ---
2
6
 
3
- Generic dropdown container that attaches a positioned menu to any trigger element.
7
+ # Dropdown
8
+
9
+ A cross-platform React dropdown menu component that displays a list of actions when triggered. Supports controlled and uncontrolled modes.
4
10
 
5
11
  ## Installation
6
12
 
7
13
  ```bash
14
+ npm install @xsolla/xui-dropdown
15
+ # or
8
16
  yarn add @xsolla/xui-dropdown
9
17
  ```
10
18
 
11
- ## Usage
19
+ ## Demo
20
+
21
+ ### Basic Dropdown
12
22
 
13
23
  ```tsx
24
+ import * as React from 'react';
14
25
  import { Dropdown, DropdownItem } from '@xsolla/xui-dropdown';
26
+ import { Button } from '@xsolla/xui-button';
15
27
 
16
- <Dropdown trigger={<button>Options</button>}>
17
- <DropdownItem onPress={() => console.log('Edit')}>Edit</DropdownItem>
18
- <DropdownItem onPress={() => console.log('Delete')}>Delete</DropdownItem>
19
- </Dropdown>
28
+ export default function BasicDropdown() {
29
+ return (
30
+ <Dropdown trigger={<Button>Open Menu</Button>}>
31
+ <DropdownItem onPress={() => console.log('Edit')}>Edit</DropdownItem>
32
+ <DropdownItem onPress={() => console.log('Duplicate')}>Duplicate</DropdownItem>
33
+ <DropdownItem onPress={() => console.log('Delete')}>Delete</DropdownItem>
34
+ </Dropdown>
35
+ );
36
+ }
37
+ ```
38
+
39
+ ### Dropdown with Icons
40
+
41
+ ```tsx
42
+ import * as React from 'react';
43
+ import { Dropdown, DropdownItem } from '@xsolla/xui-dropdown';
44
+ import { Button } from '@xsolla/xui-button';
45
+ import { Copy } from '@xsolla/xui-icons';
46
+ import { Edit, TrashCan } from '@xsolla/xui-icons-base';
47
+
48
+ export default function DropdownWithIcons() {
49
+ return (
50
+ <Dropdown trigger={<Button>Actions</Button>}>
51
+ <DropdownItem icon={<Edit size={16} />}>Edit</DropdownItem>
52
+ <DropdownItem icon={<Copy size={16} />}>Duplicate</DropdownItem>
53
+ <DropdownItem icon={<TrashCan size={16} />}>Delete</DropdownItem>
54
+ </Dropdown>
55
+ );
56
+ }
57
+ ```
58
+
59
+ ### Controlled Dropdown
60
+
61
+ ```tsx
62
+ import * as React from 'react';
63
+ import { Dropdown, DropdownItem } from '@xsolla/xui-dropdown';
64
+ import { Button } from '@xsolla/xui-button';
65
+
66
+ export default function ControlledDropdown() {
67
+ const [isOpen, setIsOpen] = React.useState(false);
68
+
69
+ return (
70
+ <div>
71
+ <Dropdown
72
+ trigger={<Button>Menu</Button>}
73
+ isOpen={isOpen}
74
+ onOpenChange={setIsOpen}
75
+ >
76
+ <DropdownItem onPress={() => setIsOpen(false)}>Action 1</DropdownItem>
77
+ <DropdownItem onPress={() => setIsOpen(false)}>Action 2</DropdownItem>
78
+ </Dropdown>
79
+ <p>Dropdown is: {isOpen ? 'Open' : 'Closed'}</p>
80
+ </div>
81
+ );
82
+ }
83
+ ```
84
+
85
+ ### Selection Indicator
86
+
87
+ ```tsx
88
+ import * as React from 'react';
89
+ import { Dropdown, DropdownItem } from '@xsolla/xui-dropdown';
90
+ import { Button } from '@xsolla/xui-button';
91
+
92
+ export default function SelectionDropdown() {
93
+ const [selected, setSelected] = React.useState('option1');
94
+
95
+ return (
96
+ <Dropdown trigger={<Button>Select Option</Button>}>
97
+ <DropdownItem
98
+ selected={selected === 'option1'}
99
+ onPress={() => setSelected('option1')}
100
+ >
101
+ Option 1
102
+ </DropdownItem>
103
+ <DropdownItem
104
+ selected={selected === 'option2'}
105
+ onPress={() => setSelected('option2')}
106
+ >
107
+ Option 2
108
+ </DropdownItem>
109
+ <DropdownItem
110
+ selected={selected === 'option3'}
111
+ onPress={() => setSelected('option3')}
112
+ >
113
+ Option 3
114
+ </DropdownItem>
115
+ </Dropdown>
116
+ );
117
+ }
20
118
  ```
21
119
 
22
- ## Components
120
+ ## Anatomy
23
121
 
24
- - `Dropdown` — wrapper that positions the menu relative to the trigger
25
- - `DropdownItem` individual menu item with optional icon and selected state
122
+ ```jsx
123
+ import { Dropdown, DropdownItem } from '@xsolla/xui-dropdown';
124
+
125
+ <Dropdown
126
+ trigger={<TriggerElement />} // Element that opens dropdown
127
+ isOpen={boolean} // Controlled open state
128
+ onOpenChange={handler} // Open state change handler
129
+ width={200} // Custom dropdown width
130
+ >
131
+ <DropdownItem
132
+ onPress={handler} // Click handler
133
+ icon={<Icon />} // Leading icon
134
+ selected={boolean} // Show selection checkmark
135
+ disabled={boolean} // Disabled state
136
+ >
137
+ Item Label
138
+ </DropdownItem>
139
+ </Dropdown>
140
+ ```
26
141
 
27
- ## Props
142
+ ## API Reference
28
143
 
29
144
  ### Dropdown
30
145
 
146
+ Container component for dropdown menu.
147
+
148
+ **Dropdown Props:**
149
+
31
150
  | Prop | Type | Default | Description |
32
- |------|------|---------|-------------|
33
- | `trigger` | `ReactNode` | | Element that opens/closes the menu on click |
34
- | `children` | `ReactNode` | | Menu content, typically `DropdownItem` elements |
35
- | `isOpen` | `boolean` | | Controlled open state |
36
- | `onOpenChange` | `(open: boolean) => void` | | Called when open state changes |
37
- | `align` | `"start" \| "end"` | `"start"` | Horizontal alignment of the menu relative to the trigger |
38
- | `width` | `string \| number` | `"auto"` | Width of the dropdown menu |
151
+ | :--- | :--- | :------ | :---------- |
152
+ | trigger | `ReactNode` | - | **Required.** Element that triggers dropdown. |
153
+ | children | `ReactNode` | - | **Required.** DropdownItem components. |
154
+ | isOpen | `boolean` | - | Controlled open state. |
155
+ | onOpenChange | `(open: boolean) => void` | - | Open state change handler. |
156
+ | width | `string \| number` | - | Custom dropdown width. |
157
+
158
+ ---
39
159
 
40
160
  ### DropdownItem
41
161
 
162
+ Individual menu item component.
163
+
164
+ **DropdownItem Props:**
165
+
42
166
  | Prop | Type | Default | Description |
43
- |------|------|---------|-------------|
44
- | `children` | `ReactNode` | | Item label content |
45
- | `onPress` | `() => void` | | Called when the item is activated |
46
- | `selected` | `boolean` | | Highlights item with brand colour and shows a checkmark |
47
- | `active` | `boolean` | | Highlights item with hover colour |
48
- | `disabled` | `boolean` | | Prevents interaction and dims the item |
49
- | `icon` | `ReactNode` | | Icon displayed to the left of the label |
167
+ | :--- | :--- | :------ | :---------- |
168
+ | children | `ReactNode` | - | **Required.** Item content. |
169
+ | onPress | `() => void` | - | Click handler. |
170
+ | icon | `ReactNode` | - | Leading icon. |
171
+ | selected | `boolean` | `false` | Show selection checkmark. |
172
+ | active | `boolean` | `false` | Active/hover state. |
173
+ | disabled | `boolean` | `false` | Disabled state. |
174
+
175
+ ## Behavior
176
+
177
+ - Clicking outside the dropdown closes it
178
+ - Selected items show a checkmark and highlighted background
179
+ - Disabled items are visually muted and not clickable
180
+ - Dropdown positions below trigger by default
181
+
182
+ ## Accessibility
183
+
184
+ - Uses `role="menu"` for dropdown container
185
+ - Items use `role="menuitem"`
186
+ - Keyboard support for navigation
187
+ - Focus management when opening/closing
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xsolla/xui-dropdown",
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",
@@ -13,11 +13,11 @@
13
13
  "test:coverage": "vitest run --coverage"
14
14
  },
15
15
  "dependencies": {
16
- "@xsolla/xui-button": "0.99.0",
17
- "@xsolla/xui-core": "0.99.0",
18
- "@xsolla/xui-divider": "0.99.0",
19
- "@xsolla/xui-icons": "0.99.0",
20
- "@xsolla/xui-primitives-core": "0.99.0"
16
+ "@xsolla/xui-button": "0.100.0",
17
+ "@xsolla/xui-core": "0.100.0",
18
+ "@xsolla/xui-divider": "0.100.0",
19
+ "@xsolla/xui-icons": "0.100.0",
20
+ "@xsolla/xui-primitives-core": "0.100.0"
21
21
  },
22
22
  "peerDependencies": {
23
23
  "react": ">=16.8.0",