@octavian-tocan/react-dropdown 1.0.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,27 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [1.0.0] - 2026-02-01
9
+
10
+ ### Added
11
+
12
+ - Initial release of `@octavian-tocan/react-dropdown`
13
+ - Composable dropdown component system with compound component pattern
14
+ - Pre-made components: `Dropdown.Simple`, `Dropdown.Searchable`, `Dropdown.Menu`
15
+ - Core components: `Dropdown.Root`, `Dropdown.Trigger`, `Dropdown.Content`, `Dropdown.Search`, `Dropdown.List`
16
+ - Support for search/filter functionality
17
+ - Support for icons, descriptions, and grouped sections
18
+ - Portal rendering support to avoid overflow clipping
19
+ - Top/bottom placement control
20
+ - Keyboard navigation (Arrow keys, Enter, Escape)
21
+ - Click-outside detection
22
+ - TypeScript support with full type safety
23
+ - Comprehensive Storybook stories
24
+ - Vitest test suite
25
+ - Accessible by default with proper ARIA attributes
26
+ - Uses Motion (latest version of Framer Motion) for animations
27
+ - Pure React implementation (no React Native dependencies)
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Octavian Tocan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,250 @@
1
+ # @octavian-tocan/react-dropdown
2
+
3
+ A flexible, composable dropdown (select) component system for React with TypeScript support. Built with accessibility in mind and featuring smooth animations powered by Motion (the latest version of Framer Motion).
4
+
5
+ ## Features
6
+
7
+ - 🎯 **Composable API** - Mix and match components or use pre-made convenience components
8
+ - 🔍 **Searchable** - Built-in search/filter functionality
9
+ - ♿ **Accessible** - Proper ARIA attributes and keyboard navigation
10
+ - 🎨 **Customizable** - Support for icons, descriptions, sections, and custom styling
11
+ - 📱 **Portal Support** - Render dropdowns in portals to avoid overflow clipping
12
+ - 🎭 **Type-Safe** - Full TypeScript support with generics
13
+ - ⚡ **Performant** - Optimized with React hooks and memoization
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @octavian-tocan/react-dropdown
19
+ # or
20
+ pnpm add @octavian-tocan/react-dropdown
21
+ # or
22
+ yarn add @octavian-tocan/react-dropdown
23
+ ```
24
+
25
+ ## Peer Dependencies
26
+
27
+ This package requires:
28
+
29
+ - `react` >= 18
30
+ - `react-dom` >= 18
31
+ - `motion` >= 12 (Motion for React - the latest version of Framer Motion)
32
+
33
+ ## Quick Start
34
+
35
+ ### Pre-made Searchable Dropdown
36
+
37
+ ```tsx
38
+ import Dropdown from '@octavian-tocan/react-dropdown';
39
+
40
+ function MyComponent() {
41
+ const [selectedLanguage, setSelectedLanguage] = useState(null);
42
+
43
+ const languages = [
44
+ { code: 'en', name: 'English' },
45
+ { code: 'es', name: 'Spanish' },
46
+ { code: 'fr', name: 'French' },
47
+ ];
48
+
49
+ return (
50
+ <Dropdown.Root
51
+ items={languages}
52
+ selectedItem={selectedLanguage}
53
+ onSelect={setSelectedLanguage}
54
+ getItemKey={(lang) => lang.code}
55
+ getItemDisplay={(lang) => lang.name}
56
+ >
57
+ <Dropdown.Trigger displayValue={selectedLanguage?.name || ''} />
58
+ <Dropdown.Searchable searchPlaceholder="Search languages..." />
59
+ </Dropdown.Root>
60
+ );
61
+ }
62
+ ```
63
+
64
+ ### Simple Dropdown (No Search)
65
+
66
+ ```tsx
67
+ <Dropdown.Root items={priorities} {...config}>
68
+ <Dropdown.Trigger displayValue={priority?.label || ''} />
69
+ <Dropdown.Simple />
70
+ </Dropdown.Root>
71
+ ```
72
+
73
+ ### Action Menu
74
+
75
+ ```tsx
76
+ import Dropdown from '@octavian-tocan/react-dropdown';
77
+ import { MoreHorizontal } from 'lucide-react';
78
+
79
+ function MenuExample() {
80
+ const menuItems = [
81
+ { id: '1', label: 'Edit', icon: <Edit />, onClick: handleEdit },
82
+ { id: '2', label: 'Delete', icon: <Trash />, onClick: handleDelete, showSeparator: true },
83
+ ];
84
+
85
+ return (
86
+ <Dropdown.Menu
87
+ items={menuItems}
88
+ trigger={<MoreHorizontal />}
89
+ onSelect={(item) => item.onClick()}
90
+ getItemKey={(item) => item.id}
91
+ getItemDisplay={(item) => item.label}
92
+ getItemIcon={(item) => item.icon}
93
+ getItemSeparator={(item) => item.showSeparator ?? false}
94
+ />
95
+ );
96
+ }
97
+ ```
98
+
99
+ ## API Reference
100
+
101
+ ### Compound Components
102
+
103
+ The package exports a compound component `Dropdown` with the following sub-components:
104
+
105
+ - **`Dropdown.Root`** - Provider component that manages all state
106
+ - **`Dropdown.Trigger`** - Button that opens/closes the dropdown
107
+ - **`Dropdown.Content`** - Container for custom compositions
108
+ - **`Dropdown.Search`** - Search input component
109
+ - **`Dropdown.List`** - Scrollable list of options
110
+ - **`Dropdown.Simple`** - Pre-made dropdown with list only
111
+ - **`Dropdown.Searchable`** - Pre-made dropdown with search + list
112
+ - **`Dropdown.Menu`** - Action menu variant
113
+
114
+ ### Hooks
115
+
116
+ - **`useDropdownContext<T>()`** - Access dropdown context (throws if used outside Root)
117
+ - **`useKeyboardNavigation<T>(items, getItemKey, onSelect, closeDropdown)`** - Keyboard navigation helpers
118
+ - **`useClickOutside(ref, closeDropdown, isOpen)`** - Click outside detection
119
+
120
+ ### Types
121
+
122
+ All TypeScript types are exported. Key types include:
123
+
124
+ - `DropdownRootProps<T>`
125
+ - `DropdownTriggerProps`
126
+ - `DropdownListProps<T>`
127
+ - `DropdownMenuProps<T>`
128
+ - `DropdownContextValue<T>`
129
+ - `DropdownSectionMeta`
130
+ - `DropdownPlacement`
131
+
132
+ ## Advanced Usage
133
+
134
+ ### Custom Composition
135
+
136
+ Build your own dropdown layout:
137
+
138
+ ```tsx
139
+ <Dropdown.Content>
140
+ <CustomHeader />
141
+ <Dropdown.Search placeholder="Filter..." />
142
+ <Dropdown.List />
143
+ <CustomFooter />
144
+ </Dropdown.Content>
145
+ ```
146
+
147
+ ### Sections and Grouping
148
+
149
+ Group items into sections with headers:
150
+
151
+ ```tsx
152
+ <Dropdown.Root
153
+ items={items}
154
+ getItemSection={(item) => ({
155
+ key: item.category,
156
+ label: item.category,
157
+ icon: '📁',
158
+ })}
159
+ // ...
160
+ >
161
+ ```
162
+
163
+ ### Icons and Descriptions
164
+
165
+ Add icons and descriptions to items:
166
+
167
+ ```tsx
168
+ <Dropdown.Root
169
+ items={items}
170
+ getItemIcon={(item) => <Icon name={item.icon} />}
171
+ getItemDescription={(item) => item.description}
172
+ // ...
173
+ >
174
+ ```
175
+
176
+ ### Portal Rendering
177
+
178
+ Render dropdown in a portal to avoid overflow clipping:
179
+
180
+ ```tsx
181
+ <Dropdown.Root
182
+ items={items}
183
+ usePortal={true}
184
+ triggerRef={triggerRef}
185
+ // ...
186
+ >
187
+ ```
188
+
189
+ ### Placement Control
190
+
191
+ Control dropdown placement (top or bottom):
192
+
193
+ ```tsx
194
+ <Dropdown.Root
195
+ items={items}
196
+ dropdownPlacement="top" // or "bottom" (default)
197
+ // ...
198
+ >
199
+ ```
200
+
201
+ ### Hiding Search for Small Lists
202
+
203
+ Hide search input for small lists:
204
+
205
+ ```tsx
206
+ <Dropdown.Searchable hideSearchThreshold={4} />
207
+ ```
208
+
209
+ When `items.length <= hideSearchThreshold`, search is hidden.
210
+
211
+ ## Examples
212
+
213
+ See the [Storybook stories](./*.stories.tsx) for comprehensive examples covering:
214
+
215
+ - Simple dropdowns
216
+ - Searchable dropdowns
217
+ - Action menus
218
+ - Custom compositions
219
+ - Sections and grouping
220
+ - Icons and descriptions
221
+ - Disabled items
222
+ - Portal rendering
223
+ - Placement options
224
+
225
+ ## Development
226
+
227
+ ```bash
228
+ # Install dependencies
229
+ pnpm install
230
+
231
+ # Build
232
+ pnpm build
233
+
234
+ # Type check
235
+ pnpm typecheck
236
+
237
+ # Run tests
238
+ pnpm test
239
+
240
+ # Watch mode
241
+ pnpm dev
242
+ ```
243
+
244
+ ## License
245
+
246
+ MIT
247
+
248
+ ## Repository
249
+
250
+ [https://github.com/OctavianTocan/react-dropdown](https://github.com/OctavianTocan/react-dropdown)