react-animated-select 0.2.9 → 0.3.6
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/README.md +53 -29
- package/demo/README.md +16 -0
- package/demo/eslint.config.js +29 -0
- package/demo/index.html +13 -0
- package/demo/package-lock.json +3436 -0
- package/demo/package.json +38 -0
- package/demo/public/vite.svg +1 -0
- package/demo/src/App.tsx +425 -0
- package/demo/src/main.jsx +9 -0
- package/demo/src/rac.css +735 -0
- package/demo/src/shake.js +11 -0
- package/demo/src/slideDown.jsx +35 -0
- package/demo/vite.config.js +7 -0
- package/dist/index.cjs.js +6 -9
- package/dist/index.css +1 -1
- package/dist/index.es.js +926 -687
- package/index.d.ts +20 -2
- package/package.json +3 -2
- package/src/index.js +1 -0
- package/src/optgroup.jsx +36 -0
- package/src/option.jsx +31 -11
- package/src/options.jsx +11 -11
- package/src/select.css +45 -1
- package/src/select.jsx +209 -238
- package/src/selectContext.js +1 -1
- package/src/selectJSX.jsx +148 -0
- package/src/slideDown.jsx +36 -0
- package/src/useSelect.jsx +113 -79
- package/src/useSelectLogic.jsx +215 -131
package/README.md
CHANGED
|
@@ -2,30 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
A lightweight, high-performance, and fully customizable Select component for React. Featuring smooth CSS animations, accessible keyboard navigation, and flexible option rendering.
|
|
4
4
|
|
|
5
|
+
**Try it out:**
|
|
6
|
+
|
|
7
|
+
[](https://l1nway.github.io/react-animated-select/)
|
|
8
|
+
|
|
5
9
|
## Features
|
|
6
10
|
|
|
7
11
|
- **Smooth Animations**
|
|
8
|
-
|
|
9
12
|
Powered by `react-transition-group` with height-expanding dropdowns and sliding side-elements.
|
|
10
13
|
|
|
11
14
|
- **Accessible**
|
|
12
|
-
|
|
13
15
|
Full keyboard support (Arrow keys, Enter, Space, Escape, Tab) and ARIA attributes built-in.
|
|
14
16
|
|
|
15
17
|
- **Flexible Data**
|
|
16
|
-
|
|
17
|
-
Supports simple arrays, objects, or declarative JSX children (`<Option />`).
|
|
18
|
+
Supports simple arrays, objects, or declarative JSX children (`<Option />`). **Smart deep parsing** extracts labels from any available object key.
|
|
18
19
|
|
|
19
20
|
- **Smart Auto-Positioning**
|
|
20
|
-
|
|
21
21
|
Recalculates dropdown position using `ResizeObserver`.
|
|
22
22
|
|
|
23
23
|
- **Zero-Config Styles**
|
|
24
|
-
|
|
25
24
|
The minimum styles required for the select to work are built into the project, but you can add your own on top of the basic ones.
|
|
26
25
|
|
|
27
26
|
- **Search & Clear**
|
|
28
|
-
|
|
29
27
|
Built-in “Clear” button and intelligent state handling (loading, error, empty, disabled).
|
|
30
28
|
|
|
31
29
|
## Installation
|
|
@@ -81,10 +79,10 @@ function App() {
|
|
|
81
79
|
| `disabled` | `boolean` | `false` | Disables the entire component. |
|
|
82
80
|
| `loading` | `boolean` | `false` | Shows a loading animation and disables interaction. |
|
|
83
81
|
| `error` | `boolean` | `false` | Shows the error state and `errorText`. |
|
|
84
|
-
| `style` | `object` | `{}` | Inline styles for the root container.
|
|
85
|
-
| `className` | `string` | '' | Additional CSS class for the root container .rac-select.
|
|
82
|
+
| `style` | `object` | `{}` | Inline styles for the root container. |
|
|
83
|
+
| `className` | `string` | '' | Additional CSS class for the root container .rac-select. |
|
|
86
84
|
| `ArrowIcon` | `ElementType \ string \ JSX` | Default icon | Custom arrow icon. Accepts a component, image path, or JSX. |
|
|
87
|
-
| `ClearIcon` | `ElementType \ string \ JSX` | Default icon | Custom clear icon. Accepts a component, image path, or JSX.
|
|
85
|
+
| `ClearIcon` | `ElementType \ string \ JSX` | Default icon | Custom clear icon. Accepts a component, image path, or JSX. |
|
|
88
86
|
|
|
89
87
|
---
|
|
90
88
|
|
|
@@ -101,12 +99,20 @@ function App() {
|
|
|
101
99
|
|
|
102
100
|
### Behavioral Props
|
|
103
101
|
|
|
104
|
-
| Prop
|
|
105
|
-
|
|
106
|
-
| `visibility`
|
|
107
|
-
| `ownBehavior`
|
|
108
|
-
| `alwaysOpen`
|
|
109
|
-
| `unmount`
|
|
102
|
+
| Prop | Type | Default | Description |
|
|
103
|
+
| --------------- | ---------- | ---------- | ------------------------------------------------------------------------------------------------------- |
|
|
104
|
+
| `visibility` | `boolean` | `false` | Manually controls the visibility of the list (used with `ownBehavior`). |
|
|
105
|
+
| `ownBehavior` | `boolean` | `false` | If `true`, the component stops managing its own open/close state and relies on the `visibility` prop. |
|
|
106
|
+
| `alwaysOpen` | `boolean` | `false` | Keeps the list permanently visible. Primarily used for debugging or specific UI layouts. |
|
|
107
|
+
| `unmount` | `boolean` | `true` | When `true`, the list is removed from the DOM when closed. When `false`, it stays invisible in the DOM. |
|
|
108
|
+
| `hasMore` | `boolean` | `false` | Indicates whether more options are available for loading (used for infinite loading). |
|
|
109
|
+
| `loadMore` | `function` | `() => {}` | Callback triggered when more options need to be loaded. |
|
|
110
|
+
| `loadMoreText` | `string` | `'Loading'` | Text displayed inside the options list during loading. |
|
|
111
|
+
| `loadOffset` | `number` | `100` | Distance (in pixels) from the bottom of the list that triggers `loadMore`. |
|
|
112
|
+
| `loadAhead` | `number` | `3` | Number of remaining options before the end at which loading is triggered during keyboard navigation. |
|
|
113
|
+
| `loadButton` | `boolean` | `false` | Enables a manual “Load more” button instead of automatic loading. |
|
|
114
|
+
| `loadButtonText` | `string` | `'Load more'` | Text displayed on the load button. |
|
|
115
|
+
| `childrenFirst` | `boolean` | `false` | Determines priority of JSX `<Option />` children over options passed via props. |
|
|
110
116
|
|
|
111
117
|
---
|
|
112
118
|
|
|
@@ -125,12 +131,21 @@ function App() {
|
|
|
125
131
|
|
|
126
132
|
| Prop | Type | Description |
|
|
127
133
|
|------|------|-------------|
|
|
128
|
-
| `id` | `string` | Optional unique ID (generated automatically if not provided). value may be used instead of id (lower priority)|
|
|
134
|
+
| `id` | `string` | Optional unique ID (generated automatically if not provided). value may be used instead of id (lower priority). |
|
|
129
135
|
| `disabled` | `boolean` | If true, this option cannot be selected or highlighted. |
|
|
130
136
|
| `className` | `string` | Custom class for individual option styling. |
|
|
131
137
|
|
|
132
138
|
---
|
|
133
139
|
|
|
140
|
+
### `<OptGroup />`
|
|
141
|
+
|
|
142
|
+
| Prop | Type | Description |
|
|
143
|
+
|------|------|-------------|
|
|
144
|
+
| `id` | `string` | Optional unique ID (generated automatically if not provided). value may be used instead of id (lower priority). |
|
|
145
|
+
| `name` | `string` | OptGroup title. label may be used instead of id (lower priority). |
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
134
149
|
## Keyboard Support
|
|
135
150
|
|
|
136
151
|
| Key | Action |
|
|
@@ -202,8 +217,17 @@ The component uses CSS variables for deep styling. These are based on system col
|
|
|
202
217
|
| `--rac-true-option-color` | `color-mix(...)` | Text color for "Boolean True" items. |
|
|
203
218
|
| `--rac-false-option-color` | `color-mix(...)` | Text color for "Boolean False" items. |
|
|
204
219
|
| `--rac-option-padding` | `0.5em` | Internal padding for each option item. |
|
|
220
|
+
| `--rac-option-min-height` | `1em` | Minimum option height. |
|
|
205
221
|
| `--rac-invalid-option-color` | `color-mix(...)` | Text color for invalid options. |
|
|
206
222
|
| `--rac-warning-option-color` | `color-mix(...)` | Text color for warning/caution options. |
|
|
223
|
+
| **Group Headers** | | |
|
|
224
|
+
| `--rac-group-header-font-size` | `1.25em` | Font size of the group header label. |
|
|
225
|
+
| `--rac-group-header-font-weight` | `bold` | Font weight of the group header text. |
|
|
226
|
+
| `--rac-group-header-min-height` | `1em` | Minimum height of the group header item. |
|
|
227
|
+
| `--rac-group-header-padding` | `0.5em` | Internal padding for the group header. |
|
|
228
|
+
| `--rac-group-arrow-height` | `1em` | Height of the group expand/collapse arrow icon. |
|
|
229
|
+
| `--rac-group-arrow-width` | `1em` | Width of the group expand/collapse arrow icon. |
|
|
230
|
+
| `--rac-group-arrow-padding` | `1px 0 2px` | Padding applied to the group arrow icon. |
|
|
207
231
|
|
|
208
232
|
---
|
|
209
233
|
|
|
@@ -241,23 +265,23 @@ The select and its options react to internal states by applying the following cl
|
|
|
241
265
|
- `.rac-invalid-option`: Applied to items that are not valid data types (e.g., functions).
|
|
242
266
|
- `.rac-true-option`: Specialized styling when the option's raw value is exactly `true`.
|
|
243
267
|
- `.rac-false-option`: Specialized styling when the option's raw value is exactly `false`.
|
|
268
|
+
#### Group Header States (applied to group-related elements)
|
|
269
|
+
- `.rac-group-header`: Base class for the group header container.
|
|
270
|
+
- `.rac-group-title-text`: Applied to the text/label inside the group header.
|
|
271
|
+
- `.rac-group-arrow-wrapper`: Wrapper class for the group expand/collapse arrow icon.
|
|
244
272
|
|
|
245
273
|
#### Trigger States
|
|
246
274
|
- `.rac-select-arrow-wrapper.--open`: Applied to the arrow icon when the dropdown is expanded.
|
|
247
275
|
|
|
248
276
|
## Change log
|
|
249
|
-
### 0.
|
|
250
|
-
|
|
251
|
-
- **
|
|
252
|
-
-
|
|
253
|
-
-
|
|
254
|
-
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
- **CSS Variable Injection:** Refactored animation parameters into CSS custom properties (`--rac-title-anim-shift`, `--rac-title-anim-entry-ease`
|
|
258
|
-
|
|
259
|
-
#### **Bug Fixes**
|
|
260
|
-
- **Opacity Animation:** Resolved an issue where the optional opacity transition for the dropdown list was not triggering correctly during the enter/exit phases.
|
|
277
|
+
### 0.3.5
|
|
278
|
+
### New Features
|
|
279
|
+
- **Hierarchical Grouping Engine**: Added full support for nested options using a flat-array normalization technique. This allows for clear visual separation of categories with zero performance overhead.
|
|
280
|
+
- **Smart "SlideDown" Groups**: Implemented collapsible group headers with smooth animations.
|
|
281
|
+
- _Self-Aware UI:_ Group arrows now automatically hide if a group contains no items, providing a cleaner look for empty categories.
|
|
282
|
+
- **Flexible Data Normalization**: The logic now seamlessly handles `Arrays`, `Objects` (maps), and `JSX` children simultaneously.
|
|
283
|
+
### Bug Fixes
|
|
284
|
+
- **Dynamic Load Button Toggle**: Fixed a critical bug where the "Load More" button's visibility wouldn't update dynamically. The component now correctly reacts to real-time changes in the `loadButton` and `hasMore` props.
|
|
261
285
|
|
|
262
286
|
## License
|
|
263
287
|
|
package/demo/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# React + Vite
|
|
2
|
+
|
|
3
|
+
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
|
4
|
+
|
|
5
|
+
Currently, two official plugins are available:
|
|
6
|
+
|
|
7
|
+
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
|
|
8
|
+
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
|
9
|
+
|
|
10
|
+
## React Compiler
|
|
11
|
+
|
|
12
|
+
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
|
|
13
|
+
|
|
14
|
+
## Expanding the ESLint configuration
|
|
15
|
+
|
|
16
|
+
If you are developing a production application, we recommend using TypeScript with type-aware lint rules enabled. Check out the [TS template](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-react-ts) for information on how to integrate TypeScript and [`typescript-eslint`](https://typescript-eslint.io) in your project.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import js from '@eslint/js'
|
|
2
|
+
import globals from 'globals'
|
|
3
|
+
import reactHooks from 'eslint-plugin-react-hooks'
|
|
4
|
+
import reactRefresh from 'eslint-plugin-react-refresh'
|
|
5
|
+
import {defineConfig, globalIgnores} from 'eslint/config'
|
|
6
|
+
|
|
7
|
+
export default defineConfig([
|
|
8
|
+
globalIgnores(['dist']),
|
|
9
|
+
{
|
|
10
|
+
files: ['**/*.{js,jsx}'],
|
|
11
|
+
extends: [
|
|
12
|
+
js.configs.recommended,
|
|
13
|
+
reactHooks.configs.flat.recommended,
|
|
14
|
+
reactRefresh.configs.vite,
|
|
15
|
+
],
|
|
16
|
+
languageOptions: {
|
|
17
|
+
ecmaVersion: 2020,
|
|
18
|
+
globals: globals.browser,
|
|
19
|
+
parserOptions: {
|
|
20
|
+
ecmaVersion: 'latest',
|
|
21
|
+
ecmaFeatures: {jsx: true},
|
|
22
|
+
sourceType: 'module',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
rules: {
|
|
26
|
+
'no-unused-vars': ['error', { varsIgnorePattern: '^[A-Z_]' }],
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
])
|
package/demo/index.html
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>demo</title>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<div id="root"></div>
|
|
11
|
+
<script type="module" src="/src/main.jsx"></script>
|
|
12
|
+
</body>
|
|
13
|
+
</html>
|