react-animated-select 0.5.6 → 0.6.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/demo/package.json DELETED
@@ -1,35 +0,0 @@
1
- {
2
- "name": "demo",
3
- "private": true,
4
- "version": "0.0.0",
5
- "type": "module",
6
- "scripts": {
7
- "dev": "vite",
8
- "build": "vite build",
9
- "predeploy": "npm run build",
10
- "deploy": "gh-pages -d dist",
11
- "lint": "eslint .",
12
- "preview": "vite preview"
13
- },
14
- "dependencies": {
15
- "@fortawesome/fontawesome-svg-core": "^7.1.0",
16
- "@fortawesome/free-solid-svg-icons": "^7.1.0",
17
- "@fortawesome/react-fontawesome": "^3.1.1",
18
- "framer-motion": "^12.29.0",
19
- "react": "^19.2.3",
20
- "react-animated-select": "^0.4.0",
21
- "react-dom": "^19.2.3",
22
- "vite": "^7.3.1"
23
- },
24
- "devDependencies": {
25
- "@eslint/js": "^9.39.1",
26
- "@types/react": "^19.2.5",
27
- "@types/react-dom": "^19.2.3",
28
- "@vitejs/plugin-react": "^5.1.1",
29
- "eslint": "^9.39.1",
30
- "eslint-plugin-react-hooks": "^7.0.1",
31
- "eslint-plugin-react-refresh": "^0.4.24",
32
- "gh-pages": "^6.3.0",
33
- "globals": "^16.5.0"
34
- }
35
- }
@@ -1 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
package/demo/src/App.tsx DELETED
@@ -1,437 +0,0 @@
1
- import {JSX, useEffect, useRef, useState} from 'react'
2
- import {Select, Option, OptGroup} from 'react-animated-select'
3
- import SlideDown from './slideDown'
4
- import {motion, useInView} from 'framer-motion'
5
- import {shake, clearShake} from './shake'
6
-
7
- import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'
8
- import {faTrashCan} from '@fortawesome/free-solid-svg-icons'
9
-
10
- import './rac.css'
11
- function App() {
12
- const [loading, setLoading] = useState<boolean>(false)
13
- const [error, setError] = useState<boolean>(false)
14
- const [disabled, setDisabled] = useState<boolean>(false)
15
-
16
- type Primitive = string | number | boolean | undefined
17
-
18
- type ObjectOption = {
19
- id?: string | number
20
- name?: string
21
- value?: string | number
22
- label?: string
23
- disabled?: boolean
24
- }
25
-
26
- type SelectOption = Primitive | ObjectOption
27
-
28
- const [options, setOptions] = useState<SelectOption[]>(['Option 1', true, false, undefined, console.log, {name: 'Option 6', disabled: true}, 'Option 7', {name: 'Option 8'}, {disabled: true}, {name: 'Option 10', id: 2, group: 2}, 'Option 11', 'Option 12', 'Option 13', 'Option 14', 'Option 15'])
29
-
30
- const [value, setValue] = useState<Primitive>()
31
- const [placeholder, setPlaceholder] = useState<string>('Choose option')
32
- const [emptyText, setEmptyText] = useState<string>('No options')
33
- const [loadingText, setLoadingText] = useState<string>('Loading')
34
- const [errorText, setErrorText] = useState<string>('Failed to load')
35
- const [disabledText, setDisabledText] = useState<string>('Disabled')
36
- const [duration, setDuration] = useState<number>(300)
37
- const [easing, setEasing] = useState<string>('ease-out')
38
- const [offset, setOffset] = useState<number>(2)
39
- const [animateOpacity, setAnimateOpacity] = useState<boolean>(true)
40
- const [alwaysOpen, setAlwaysOpen] = useState<boolean>(false)
41
- const [hasMore, setHasMore] = useState<boolean>(false)
42
- const [loadButton, setLoadButton] = useState<boolean>(false)
43
- const [loadButtonText, setLoadButtonText] = useState<string>('Load more')
44
- const [loadMoreText, setLoadMoreText] = useState<string>('Loading')
45
- const [loadOffset, setLoadOffset] = useState<number>(100)
46
- const [loadAhead, setLoadAhead] = useState<number>(3)
47
- const [gropValue, setGroupValue] = useState<string>('')
48
- const [group, setGroup] = useState<boolean>(false)
49
- const [multiple, setMultiple] = useState<boolean>(false)
50
-
51
- type SettingItem = {
52
- label: string
53
- state: number | boolean
54
- default?: number
55
- min?: number
56
- max?: number
57
- step?: number
58
- unit?: string
59
- setState: (value: number | boolean) => void
60
- }
61
-
62
- const ranges: SettingItem[] = [
63
- {label: 'duration', default: 300, min: 0, max: 1000, step: 50, unit: 'ms', state: duration, setState: setDuration},
64
- {label: 'offset', default: 3, min: 0, max: 25, step: 1, unit: 'px', state: offset, setState: setOffset},
65
- {label: 'loadAhead', default: 3, min: 0, max: 15, step: 1, unit: 'options', state: loadAhead, setState: setLoadAhead},
66
- {label: 'loadOffset', default: 100, min: 0, max: 1000, step: 50, unit: 'px', state: loadOffset, setState: setLoadOffset}
67
- ]
68
-
69
- const renderRanges: JSX.Element[] = ranges.map((item) => (
70
- <label
71
- className='rac-range-label'
72
- key={item.label}
73
- >
74
- <span
75
- className='rac-prop-span'
76
- >
77
- {item.label}: {item.state ?? item.default}{item.unit}
78
- </span>
79
- <input
80
- className='rac-range-input'
81
- type='range'
82
- min={item.min}
83
- max={item.max}
84
- step={item.step}
85
- value={item.state ?? item.default}
86
- onChange={(e) => item.setState(Number(e.target.value))}
87
- />
88
- </label>
89
- ))
90
-
91
- const settings: SettingItem[] = [
92
- {label: 'multiple', state: multiple, setState: setMultiple},
93
- {label: 'loading', state: loading, setState: setLoading},
94
- {label: 'disabled', state: disabled, setState: setDisabled},
95
- {label: 'error', state: error, setState: setError},
96
- {label: 'alwaysOpen', state: alwaysOpen, setState: setAlwaysOpen},
97
- {label: 'animateOpacity', state: animateOpacity, setState: setAnimateOpacity},
98
- {label: 'hasMore', state: hasMore, setState: setHasMore},
99
- {label: 'loadButton', state: loadButton, setState: setLoadButton}
100
- ]
101
-
102
- const renderSettings: JSX.Element[] = settings.map((item) => (
103
- <label
104
- key={item.label}
105
- className='rac-checkbox-wrapper'
106
- >
107
- <input
108
- className='rac-demo-checkbox'
109
- type='checkbox'
110
- checked={item.state}
111
- onChange={(e) => item.setState(e.target.checked)}
112
- />
113
- {item.label}
114
- </label>
115
- ))
116
-
117
- type TextSettingItem = {
118
- label: string
119
- value: string | undefined
120
- setValue: (value: string) => void
121
- }
122
-
123
- const textSettings: TextSettingItem[] = [
124
- {label: 'placeholder', value: placeholder, setValue: setPlaceholder},
125
- {label: 'emptyText', value: emptyText, setValue: setEmptyText},
126
- {label: 'loadingText', value: loadingText, setValue: setLoadingText},
127
- {label: 'errorText', value: errorText, setValue: setErrorText},
128
- {label: 'disabledText', value: disabledText, setValue: setDisabledText},
129
- {label: 'loadButtonText', value: loadButtonText, setValue: setLoadButtonText},
130
- {label: 'loadMoreText', value: loadMoreText, setValue: setLoadMoreText}
131
- ]
132
-
133
- const renderTextSettings: JSX.Element[] = textSettings.map((item) => (
134
- <label
135
- key={item.label}
136
- className='rac-prop-label'
137
- >
138
- <span
139
- className='rac-prop-span'
140
- >
141
- {item.label}
142
- </span>
143
- <input
144
- className='rac-prop-value'
145
- placeholder={item.label}
146
- type='text'
147
- value={item.value}
148
- onChange={(e) => item.setValue(e.target.value)}
149
- />
150
- </label>
151
- ))
152
-
153
- const [inputValue, setInputValue] = useState('')
154
- const [disabledOption, setDisabledOption] = useState<boolean>(false)
155
-
156
- const buttonRef = useRef<HTMLInputElement>(null)
157
-
158
- const addOption = (disabled: boolean) => {
159
- !inputValue && shake(buttonRef.current)
160
- const newOption = {name: inputValue, disabled: disabled, group: gropValue}
161
-
162
- setOptions((prev) => [newOption, ...prev])
163
- setInputValue('')
164
- setGroupValue('')
165
- }
166
-
167
-
168
- const removeOption = (index: number) => {
169
- setOptions((prev) => prev.filter((_, i) => i !== index))
170
- }
171
-
172
- const renderOptionValue = (value: SelectOption): string => {
173
- if (typeof value === 'string') return value
174
- if (typeof value === 'number') return String(value)
175
- if (typeof value === 'boolean') return value ? 'true' : 'false'
176
- if (typeof value === 'function') return value.toString()
177
- if (value === undefined) return 'undefined'
178
- if (value === null) return 'null'
179
-
180
- if (typeof value === 'object') {
181
- if ('name' in value && typeof value.name === 'string') {
182
- return value.name
183
- }
184
-
185
- return JSON.stringify(value)
186
- }
187
-
188
- return String(value)
189
- }
190
-
191
- const ref = useRef(null)
192
- const visible = useInView(ref, {amount: 0.1, margin: '100px 0px 50px 0px'})
193
-
194
- const renderOptionList = options.map((element, index) =>
195
- <motion.div
196
- key={index}
197
- tabIndex={0}
198
- className='rac-option-demo'
199
- style={{
200
- willChange: 'transform, opacity, height',
201
- backfaceVisibility: 'hidden',
202
- transform: 'translateZ(0)'
203
- }}
204
- ref={ref}
205
- layoutId={String(index)}
206
- layout={visible}
207
- viewport={{once: false, amount: 0.1, margin: '0px 0px 0px 0px'}}
208
- initial={{opacity: 0, scale: 0.9}}
209
- whileInView={{opacity: 1, scale: 1}}
210
- transition={{
211
- layout: {
212
- type: 'spring',
213
- stiffness: 300,
214
- damping: 30
215
- },
216
- default: {
217
- duration: 0.3,
218
- ease: 'easeInOut'
219
- },
220
- opacity: {duration: 0.3}
221
- }}
222
- exit={{opacity: 0, scale: 0.8, transition: {duration: 0.3}}}
223
- >
224
- <span>
225
- {renderOptionValue(element)}
226
- </span>
227
- <button
228
- onClick={() => removeOption(index)}
229
- className='rac-delete-demo-option'
230
- >
231
- <FontAwesomeIcon
232
- icon={faTrashCan}
233
- className='rac-delete-button-icon'
234
- />
235
- </button>
236
- </motion.div>
237
- )
238
-
239
- const [demolist, setDemolist] = useState<boolean>(false)
240
-
241
- const [showAdded, setShowAdded] = useState(false)
242
- const timeoutRef = useRef<number | null>(null)
243
-
244
- const handleAdd = () => {
245
- setShowAdded(true)
246
-
247
- if (timeoutRef.current) {
248
- clearTimeout(timeoutRef.current)
249
- }
250
-
251
- timeoutRef.current = setTimeout(() => {
252
- setShowAdded(false)
253
- timeoutRef.current = null
254
- }, 3000)
255
- }
256
-
257
- useEffect(() => {
258
- return () => {
259
- if (timeoutRef.current) clearTimeout(timeoutRef.current)
260
- }
261
- }, [])
262
-
263
- return (
264
- <div
265
- className='rac-main'
266
- >
267
- <h1
268
- className='rac-lead-title'
269
- >
270
- react-animated-select demo
271
- </h1>
272
- <div
273
- className='rac-groups'
274
- >
275
- <div
276
- className='rac-props'
277
- >
278
- <h2
279
- className='rac-props-title'
280
- >
281
- Select states
282
- </h2>
283
- {renderSettings}
284
- {renderRanges}
285
- <label
286
- className='rac-prop-label'
287
- >
288
- <span
289
- className='rac-prop-span'
290
- >
291
- easing
292
- </span>
293
- <input
294
- type='text'
295
- className='rac-prop-value'
296
- value={easing}
297
- onChange={e => setEasing(e.target.value)}
298
- />
299
- </label>
300
- </div>
301
- <div
302
- className='rac-visual'
303
- >
304
- <div
305
- className='rac-texts'
306
- >
307
- <h2
308
- className='rac-placeholders-title'
309
- >
310
- State placeholders
311
- </h2>
312
- <div
313
- className='rac-placeholders-list'
314
- >
315
- {renderTextSettings}
316
- </div>
317
- </div>
318
- </div>
319
- <div
320
- className='rac-select-wrapper'
321
- >
322
- <h3
323
- className='rac-select-overview-title'
324
- >
325
- react-animated-select overview
326
- </h3>
327
- <Select
328
- multiple={multiple}
329
- hasMore={hasMore}
330
- loadButton={loadButton}
331
- loadButtonText={loadButtonText}
332
- loadMoreText={loadMoreText}
333
- loadOffset={loadOffset}
334
- loadAhead={loadAhead}
335
- className='rac-demo-select'
336
- loading={loading}
337
- error={error}
338
- disabled={disabled}
339
- options={options}
340
- value={value}
341
- placeholder={placeholder}
342
- emptyText={emptyText}
343
- loadingText={loadingText}
344
- errorText={errorText}
345
- disabledText={disabledText}
346
- duration={duration}
347
- offset={offset}
348
- animateOpacity={animateOpacity}
349
- alwaysOpen={alwaysOpen}
350
- onChange={setValue}
351
- />
352
- <h3
353
- className='rac-option-title'
354
- >
355
- Add option
356
- </h3>
357
- <div
358
- className='rac-form-group'
359
- >
360
- <input
361
- className='rac-add-option'
362
- type='text'
363
- value={inputValue}
364
- onChange={(e) => setInputValue(e.target.value)}
365
- placeholder='name'
366
- />
367
- <label
368
- className='rac-checkbox-wrapper'
369
- >
370
- <input
371
- type='checkbox'
372
- className='rac-demo-checkbox'
373
- checked={disabledOption}
374
- onChange={(e) => setDisabledOption(e.target.checked)}
375
- />
376
- <span
377
- className='rac-disabled-title'
378
- >
379
- Disabled
380
- </span>
381
- </label>
382
- <input
383
- className='rac-add-option'
384
- type='text'
385
- value={gropValue}
386
- placeholder='group'
387
- onChange={(e) => setGroupValue(e.target.value)}
388
- />
389
- <button
390
- ref={buttonRef}
391
- onClick={() => {
392
- addOption(disabledOption)
393
- handleAdd()
394
- }}
395
- className='rac-add-option-button'
396
- >
397
- Add
398
- </button>
399
- <SlideDown
400
- visibility={showAdded}
401
- >
402
- <span
403
- className='rac-added-option'
404
- // style={{color: inputValue ? '#35bb61' : 'red'}}
405
- style={{color: '#35bb61'}}
406
- >
407
- Added!
408
- {/* {inputValue ? 'Added!' : 'You created an empty option'} */}
409
- </span>
410
- </SlideDown>
411
- </div>
412
- <button
413
- onClick={() => setDemolist(!demolist)}
414
- className='rac-option-list-button'
415
- >
416
- <span
417
- key={String(demolist)}
418
- className='rac-fade-text'
419
- >
420
- {demolist ? 'Hide options' : 'Show options'}
421
- </span>
422
- </button>
423
- <SlideDown
424
- visibility={demolist}
425
- >
426
- <div
427
- className='rac-demo-option-list'
428
- >
429
- {renderOptionList}
430
- </div>
431
- </SlideDown>
432
- </div>
433
- </div>
434
- </div>
435
- )
436
- }
437
- export default App
package/demo/src/main.jsx DELETED
@@ -1,9 +0,0 @@
1
- import {StrictMode} from 'react'
2
- import {createRoot} from 'react-dom/client'
3
- import App from './App.tsx'
4
-
5
- createRoot(document.getElementById('root')).render(
6
- <StrictMode>
7
- <App />
8
- </StrictMode>,
9
- )