dash-core-components 4.0.0-rc0 → 4.0.0-rc2
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/dash_core_components/async-datepicker.js +1 -1
- package/dash_core_components/async-datepicker.js.map +1 -1
- package/dash_core_components/async-dropdown.js +1 -1
- package/dash_core_components/async-dropdown.js.map +1 -1
- package/dash_core_components/async-graph.js +1 -1
- package/dash_core_components/async-slider.js +1 -2
- package/dash_core_components/async-slider.js.map +1 -1
- package/dash_core_components/dash_core_components-shared.js +1 -1
- package/dash_core_components/dash_core_components-shared.js.map +1 -1
- package/dash_core_components/dash_core_components.js +1 -1
- package/dash_core_components/dash_core_components.js.map +1 -1
- package/dash_core_components/proptypes.js +118 -1
- package/lib/components/Checklist.tsx +67 -0
- package/lib/components/Dropdown.tsx +68 -0
- package/lib/components/Loading.tsx +185 -0
- package/lib/components/RadioItems.tsx +69 -0
- package/lib/components/RangeSlider.tsx +12 -1
- package/lib/components/Slider.tsx +12 -1
- package/lib/components/Tab.react.js.old +79 -0
- package/lib/components/Textarea.react.js.old +287 -0
- package/lib/components/Textarea.tsx +79 -0
- package/lib/components/Tooltip.tsx +66 -0
- package/lib/components/css/checklist.css +4 -0
- package/lib/components/css/dcc.css +3 -0
- package/lib/components/css/dropdown.css +211 -0
- package/lib/components/css/input.css +22 -6
- package/lib/components/css/optionslist.css +34 -0
- package/lib/components/css/radioitems.css +4 -0
- package/lib/components/css/sliders.css +19 -7
- package/lib/components/css/textarea.css +21 -0
- package/lib/components/css/tooltip.css +127 -0
- package/lib/fragments/Dropdown.tsx +513 -0
- package/lib/fragments/Loading/spinners/CircleSpinner.tsx +185 -0
- package/lib/fragments/Loading/spinners/CubeSpinner.tsx +193 -0
- package/lib/fragments/Loading/spinners/DebugTitle.tsx +11 -0
- package/lib/fragments/Loading/spinners/DefaultSpinner.tsx +110 -0
- package/lib/fragments/Loading/spinners/DotSpinner.tsx +96 -0
- package/lib/fragments/Loading/spinners/GraphSpinner.tsx +332 -0
- package/lib/fragments/Loading/types.ts +13 -0
- package/lib/fragments/RangeSlider.tsx +235 -105
- package/lib/index.ts +6 -6
- package/lib/types.ts +571 -64
- package/lib/utils/LazyLoader/dropdown.ts +2 -0
- package/lib/utils/_LoadingElement.tsx +8 -18
- package/lib/utils/dropdownSearch.ts +92 -0
- package/lib/utils/optionRendering.tsx +168 -0
- package/lib/utils/optionTypes.ts +27 -0
- package/lib/utils/sliderRendering.tsx +23 -4
- package/package.json +7 -4
- package/lib/components/Checklist.react.js +0 -193
- package/lib/components/Dropdown.react.js +0 -182
- package/lib/components/Input.react.js.old +0 -507
- package/lib/components/Loading.react.js +0 -254
- package/lib/components/RadioItems.react.js +0 -192
- package/lib/components/Slider.react.js.old +0 -214
- package/lib/components/Textarea.react.js +0 -223
- package/lib/components/Tooltip.react.js +0 -120
- package/lib/components/css/Dropdown.css +0 -8
- package/lib/fragments/Dropdown.react.js +0 -158
- package/lib/fragments/Loading/spinners/CircleSpinner.js +0 -68
- package/lib/fragments/Loading/spinners/CubeSpinner.js +0 -57
- package/lib/fragments/Loading/spinners/DebugTitle.js +0 -15
- package/lib/fragments/Loading/spinners/DefaultSpinner.js +0 -54
- package/lib/fragments/Loading/spinners/DotSpinner.js +0 -50
- package/lib/fragments/Loading/spinners/GraphSpinner.js +0 -68
- package/lib/fragments/Slider.tsx.old +0 -364
- package/lib/utils/LazyLoader/dropdown.js +0 -8
|
@@ -0,0 +1,513 @@
|
|
|
1
|
+
import {isNil, without, isEmpty} from 'ramda';
|
|
2
|
+
import React, {
|
|
3
|
+
useState,
|
|
4
|
+
useCallback,
|
|
5
|
+
useEffect,
|
|
6
|
+
useMemo,
|
|
7
|
+
useRef,
|
|
8
|
+
MouseEvent,
|
|
9
|
+
} from 'react';
|
|
10
|
+
import {createFilteredOptions} from '../utils/dropdownSearch';
|
|
11
|
+
import {
|
|
12
|
+
CaretDownIcon,
|
|
13
|
+
MagnifyingGlassIcon,
|
|
14
|
+
Cross1Icon,
|
|
15
|
+
} from '@radix-ui/react-icons';
|
|
16
|
+
import * as Popover from '@radix-ui/react-popover';
|
|
17
|
+
import '../components/css/dropdown.css';
|
|
18
|
+
|
|
19
|
+
import isEqual from 'react-fast-compare';
|
|
20
|
+
import {DetailedOption, DropdownProps, OptionValue} from '../types';
|
|
21
|
+
import {OptionsList, OptionLabel} from '../utils/optionRendering';
|
|
22
|
+
import uuid from 'uniqid';
|
|
23
|
+
|
|
24
|
+
const Dropdown = (props: DropdownProps) => {
|
|
25
|
+
const {
|
|
26
|
+
id,
|
|
27
|
+
className,
|
|
28
|
+
closeOnSelect,
|
|
29
|
+
clearable,
|
|
30
|
+
disabled,
|
|
31
|
+
labels,
|
|
32
|
+
maxHeight,
|
|
33
|
+
multi,
|
|
34
|
+
options,
|
|
35
|
+
optionHeight,
|
|
36
|
+
setProps,
|
|
37
|
+
searchable,
|
|
38
|
+
search_value,
|
|
39
|
+
style,
|
|
40
|
+
value,
|
|
41
|
+
} = props;
|
|
42
|
+
const [optionsCheck, setOptionsCheck] = useState<DetailedOption[]>();
|
|
43
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
44
|
+
const [displayOptions, setDisplayOptions] = useState<DetailedOption[]>([]);
|
|
45
|
+
const persistentOptions = useRef<DropdownProps['options']>([]);
|
|
46
|
+
const dropdownContainerRef = useRef<HTMLButtonElement>(null);
|
|
47
|
+
const dropdownContentRef = useRef<HTMLDivElement>(
|
|
48
|
+
document.createElement('div')
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const ctx = window.dash_component_api.useDashContext();
|
|
52
|
+
const loading = ctx.useLoading();
|
|
53
|
+
|
|
54
|
+
if (!persistentOptions || !isEqual(options, persistentOptions.current)) {
|
|
55
|
+
persistentOptions.current = options;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const {sanitizedOptions, filteredOptions} = useMemo(
|
|
59
|
+
() =>
|
|
60
|
+
createFilteredOptions(
|
|
61
|
+
persistentOptions.current,
|
|
62
|
+
!!searchable,
|
|
63
|
+
search_value
|
|
64
|
+
),
|
|
65
|
+
[persistentOptions.current, searchable, search_value]
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const sanitizedValues: OptionValue[] = useMemo(() => {
|
|
69
|
+
if (value instanceof Array) {
|
|
70
|
+
return value;
|
|
71
|
+
}
|
|
72
|
+
if (isNil(value)) {
|
|
73
|
+
return [];
|
|
74
|
+
}
|
|
75
|
+
return [value];
|
|
76
|
+
}, [value]);
|
|
77
|
+
|
|
78
|
+
const updateSelection = useCallback(
|
|
79
|
+
(selection: OptionValue[]) => {
|
|
80
|
+
if (closeOnSelect !== false) {
|
|
81
|
+
setIsOpen(false);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (multi) {
|
|
85
|
+
// For multi-select, validate the selection respects clearable rules
|
|
86
|
+
if (selection.length === 0) {
|
|
87
|
+
// Empty selection: only allow if clearable is true
|
|
88
|
+
if (clearable) {
|
|
89
|
+
setProps({value: []});
|
|
90
|
+
}
|
|
91
|
+
// If clearable is false and trying to set empty, do nothing
|
|
92
|
+
// return;
|
|
93
|
+
} else {
|
|
94
|
+
// Non-empty selection: always allowed in multi-select
|
|
95
|
+
setProps({value: selection});
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
// For single-select, take the first value or null
|
|
99
|
+
if (selection.length === 0) {
|
|
100
|
+
// Empty selection: only allow if clearable is true
|
|
101
|
+
if (clearable) {
|
|
102
|
+
setProps({value: null});
|
|
103
|
+
}
|
|
104
|
+
// If clearable is false and trying to set empty, do nothing
|
|
105
|
+
// return;
|
|
106
|
+
} else {
|
|
107
|
+
// Take the first value for single-select
|
|
108
|
+
setProps({value: selection[selection.length - 1]});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
[multi, clearable, closeOnSelect]
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
const onInputChange = useCallback(
|
|
116
|
+
search_value => setProps({search_value}),
|
|
117
|
+
[]
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
const handleClearSearch = useCallback((e: MouseEvent) => {
|
|
121
|
+
if (e.currentTarget instanceof HTMLElement) {
|
|
122
|
+
const parentElement = e.currentTarget.parentElement;
|
|
123
|
+
parentElement?.querySelector('input')?.focus();
|
|
124
|
+
}
|
|
125
|
+
setProps({search_value: undefined});
|
|
126
|
+
}, []);
|
|
127
|
+
|
|
128
|
+
useEffect(() => {
|
|
129
|
+
if (
|
|
130
|
+
!search_value &&
|
|
131
|
+
!isNil(sanitizedOptions) &&
|
|
132
|
+
optionsCheck !== sanitizedOptions &&
|
|
133
|
+
!isNil(value) &&
|
|
134
|
+
!isEmpty(value)
|
|
135
|
+
) {
|
|
136
|
+
const values = sanitizedOptions.map(option => option.value);
|
|
137
|
+
if (Array.isArray(value)) {
|
|
138
|
+
if (multi) {
|
|
139
|
+
const invalids = value.filter(v => !values.includes(v));
|
|
140
|
+
if (invalids.length) {
|
|
141
|
+
setProps({value: without(invalids, value)});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
} else {
|
|
145
|
+
if (!values.includes(value)) {
|
|
146
|
+
setProps({value: null});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
setOptionsCheck(sanitizedOptions);
|
|
150
|
+
}
|
|
151
|
+
}, [sanitizedOptions, optionsCheck, multi, value]);
|
|
152
|
+
|
|
153
|
+
const displayValue = useMemo(() => {
|
|
154
|
+
const labels = sanitizedValues.map((val, i) => {
|
|
155
|
+
const option = sanitizedOptions.find(
|
|
156
|
+
option => option.value === val
|
|
157
|
+
);
|
|
158
|
+
return (
|
|
159
|
+
<React.Fragment key={`${option?.value}-${i}`}>
|
|
160
|
+
{option && <OptionLabel {...option} index={i} />}
|
|
161
|
+
{i === sanitizedValues.length - 1 ? '' : ', '}
|
|
162
|
+
</React.Fragment>
|
|
163
|
+
);
|
|
164
|
+
});
|
|
165
|
+
return labels;
|
|
166
|
+
}, [sanitizedOptions, sanitizedValues]);
|
|
167
|
+
|
|
168
|
+
const canDeselectAll = useMemo(() => {
|
|
169
|
+
if (clearable) {
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
return !sanitizedValues.every(value =>
|
|
173
|
+
displayOptions.some(option => option.value === value)
|
|
174
|
+
);
|
|
175
|
+
}, [clearable, sanitizedValues, displayOptions, search_value]);
|
|
176
|
+
|
|
177
|
+
const handleClear = useCallback(() => {
|
|
178
|
+
const finalValue: DropdownProps['value'] = multi ? [] : null;
|
|
179
|
+
setProps({value: finalValue});
|
|
180
|
+
}, [multi]);
|
|
181
|
+
|
|
182
|
+
const handleSelectAll = useCallback(() => {
|
|
183
|
+
if (multi) {
|
|
184
|
+
const allValues = sanitizedValues.concat(
|
|
185
|
+
displayOptions
|
|
186
|
+
.filter(option => !sanitizedValues.includes(option.value))
|
|
187
|
+
.map(option => option.value)
|
|
188
|
+
);
|
|
189
|
+
setProps({value: allValues});
|
|
190
|
+
}
|
|
191
|
+
if (closeOnSelect) {
|
|
192
|
+
setIsOpen(false);
|
|
193
|
+
}
|
|
194
|
+
}, [multi, displayOptions, sanitizedValues, closeOnSelect]);
|
|
195
|
+
|
|
196
|
+
const handleDeselectAll = useCallback(() => {
|
|
197
|
+
if (multi) {
|
|
198
|
+
const withDeselected = sanitizedValues.filter(option => {
|
|
199
|
+
return !displayOptions.some(
|
|
200
|
+
displayOption => displayOption.value === option
|
|
201
|
+
);
|
|
202
|
+
});
|
|
203
|
+
setProps({value: withDeselected});
|
|
204
|
+
}
|
|
205
|
+
if (closeOnSelect) {
|
|
206
|
+
setIsOpen(false);
|
|
207
|
+
}
|
|
208
|
+
}, [multi, displayOptions, sanitizedValues, closeOnSelect]);
|
|
209
|
+
|
|
210
|
+
// Sort options when popover opens - selected options first
|
|
211
|
+
// Update display options when filtered options or selection changes
|
|
212
|
+
useEffect(() => {
|
|
213
|
+
if (isOpen) {
|
|
214
|
+
let sortedOptions = filteredOptions;
|
|
215
|
+
if (multi) {
|
|
216
|
+
// Sort filtered options: selected first, then unselected
|
|
217
|
+
sortedOptions = [...filteredOptions].sort((a, b) => {
|
|
218
|
+
const aSelected = sanitizedValues.includes(a.value);
|
|
219
|
+
const bSelected = sanitizedValues.includes(b.value);
|
|
220
|
+
|
|
221
|
+
if (aSelected && !bSelected) {
|
|
222
|
+
return -1;
|
|
223
|
+
}
|
|
224
|
+
if (!aSelected && bSelected) {
|
|
225
|
+
return 1;
|
|
226
|
+
}
|
|
227
|
+
return 0; // Maintain original order within each group
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
setDisplayOptions(sortedOptions);
|
|
232
|
+
}
|
|
233
|
+
}, [filteredOptions, isOpen]);
|
|
234
|
+
|
|
235
|
+
// Focus (and scroll) the first selected item when dropdown opens
|
|
236
|
+
useEffect(() => {
|
|
237
|
+
if (!isOpen || multi || search_value) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// waiting for the DOM to be ready after the dropdown renders
|
|
242
|
+
requestAnimationFrame(() => {
|
|
243
|
+
const selectedValue = sanitizedValues[0];
|
|
244
|
+
|
|
245
|
+
const selectedElement = dropdownContentRef.current.querySelector(
|
|
246
|
+
`.dash-options-list-option-checkbox[value="${selectedValue}"]`
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
if (selectedElement instanceof HTMLElement) {
|
|
250
|
+
selectedElement?.focus();
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
}, [isOpen, multi, displayOptions, sanitizedValues]);
|
|
254
|
+
|
|
255
|
+
// Handle keyboard navigation in popover
|
|
256
|
+
const handleKeyDown = useCallback((e: React.KeyboardEvent) => {
|
|
257
|
+
const relevantKeys = [
|
|
258
|
+
'ArrowDown',
|
|
259
|
+
'ArrowUp',
|
|
260
|
+
'PageDown',
|
|
261
|
+
'PageUp',
|
|
262
|
+
'Home',
|
|
263
|
+
'End',
|
|
264
|
+
];
|
|
265
|
+
if (!relevantKeys.includes(e.key)) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// Don't interfere with the event if the user is using Home/End keys on the search input
|
|
270
|
+
if (
|
|
271
|
+
['Home', 'End'].includes(e.key) &&
|
|
272
|
+
document.activeElement instanceof HTMLInputElement
|
|
273
|
+
) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const focusableElements = e.currentTarget.querySelectorAll(
|
|
278
|
+
'input[type="search"], input[type="checkbox"]:not([disabled])'
|
|
279
|
+
) as NodeListOf<HTMLElement>;
|
|
280
|
+
|
|
281
|
+
// Don't interfere with the event if there aren't any options that the user can interact with
|
|
282
|
+
if (focusableElements.length === 0) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
e.preventDefault();
|
|
287
|
+
|
|
288
|
+
const currentIndex = Array.from(focusableElements).indexOf(
|
|
289
|
+
document.activeElement as HTMLElement
|
|
290
|
+
);
|
|
291
|
+
let nextIndex = -1;
|
|
292
|
+
|
|
293
|
+
switch (e.key) {
|
|
294
|
+
case 'ArrowDown':
|
|
295
|
+
nextIndex =
|
|
296
|
+
currentIndex < focusableElements.length - 1
|
|
297
|
+
? currentIndex + 1
|
|
298
|
+
: 0;
|
|
299
|
+
break;
|
|
300
|
+
|
|
301
|
+
case 'ArrowUp':
|
|
302
|
+
nextIndex =
|
|
303
|
+
currentIndex > 0
|
|
304
|
+
? currentIndex - 1
|
|
305
|
+
: focusableElements.length - 1;
|
|
306
|
+
|
|
307
|
+
break;
|
|
308
|
+
case 'PageDown':
|
|
309
|
+
nextIndex = Math.min(
|
|
310
|
+
currentIndex + 10,
|
|
311
|
+
focusableElements.length - 1
|
|
312
|
+
);
|
|
313
|
+
break;
|
|
314
|
+
case 'PageUp':
|
|
315
|
+
nextIndex = Math.max(currentIndex - 10, 0);
|
|
316
|
+
break;
|
|
317
|
+
case 'Home':
|
|
318
|
+
nextIndex = 0;
|
|
319
|
+
break;
|
|
320
|
+
case 'End':
|
|
321
|
+
nextIndex = focusableElements.length - 1;
|
|
322
|
+
break;
|
|
323
|
+
default:
|
|
324
|
+
break;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (nextIndex > -1) {
|
|
328
|
+
focusableElements[nextIndex].focus();
|
|
329
|
+
if (nextIndex === 0) {
|
|
330
|
+
// first element is a sticky search bar, so if we are focusing
|
|
331
|
+
// on that, also move the scroll to the top
|
|
332
|
+
dropdownContentRef.current?.scrollTo({top: 0});
|
|
333
|
+
} else {
|
|
334
|
+
focusableElements[nextIndex].scrollIntoView({
|
|
335
|
+
behavior: 'auto',
|
|
336
|
+
block: 'center',
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}, []);
|
|
341
|
+
|
|
342
|
+
// Handle popover open/close
|
|
343
|
+
const handleOpenChange = useCallback(
|
|
344
|
+
(open: boolean) => {
|
|
345
|
+
setIsOpen(open);
|
|
346
|
+
|
|
347
|
+
if (!open) {
|
|
348
|
+
setProps({search_value: undefined});
|
|
349
|
+
}
|
|
350
|
+
},
|
|
351
|
+
[filteredOptions, sanitizedValues]
|
|
352
|
+
);
|
|
353
|
+
|
|
354
|
+
const accessibleId = id ?? uuid();
|
|
355
|
+
|
|
356
|
+
return (
|
|
357
|
+
<Popover.Root open={isOpen} onOpenChange={handleOpenChange}>
|
|
358
|
+
<Popover.Trigger asChild>
|
|
359
|
+
<button
|
|
360
|
+
id={id}
|
|
361
|
+
ref={dropdownContainerRef}
|
|
362
|
+
disabled={disabled}
|
|
363
|
+
type="button"
|
|
364
|
+
onKeyDown={e => {
|
|
365
|
+
if (e.key === 'ArrowDown') {
|
|
366
|
+
setIsOpen(true);
|
|
367
|
+
}
|
|
368
|
+
}}
|
|
369
|
+
className={`dash-dropdown ${className ?? ''}`}
|
|
370
|
+
style={style}
|
|
371
|
+
aria-labelledby={`${accessibleId}-value-count ${accessibleId}-value`}
|
|
372
|
+
aria-haspopup="listbox"
|
|
373
|
+
aria-expanded={isOpen}
|
|
374
|
+
data-dash-is-loading={loading || undefined}
|
|
375
|
+
>
|
|
376
|
+
<span className="dash-dropdown-grid-container dash-dropdown-trigger">
|
|
377
|
+
{displayValue.length > 0 && (
|
|
378
|
+
<span
|
|
379
|
+
id={accessibleId + '-value'}
|
|
380
|
+
className="dash-dropdown-value"
|
|
381
|
+
>
|
|
382
|
+
{displayValue}
|
|
383
|
+
</span>
|
|
384
|
+
)}
|
|
385
|
+
{displayValue.length === 0 && (
|
|
386
|
+
<span
|
|
387
|
+
id={accessibleId + '-value'}
|
|
388
|
+
className="dash-dropdown-value dash-dropdown-placeholder"
|
|
389
|
+
>
|
|
390
|
+
{props.placeholder}
|
|
391
|
+
</span>
|
|
392
|
+
)}
|
|
393
|
+
{sanitizedValues.length > 1 && (
|
|
394
|
+
<span
|
|
395
|
+
id={accessibleId + '-value-count'}
|
|
396
|
+
className="dash-dropdown-value-count"
|
|
397
|
+
>
|
|
398
|
+
{labels?.selected_count?.replace(
|
|
399
|
+
'{num_selected}',
|
|
400
|
+
`${sanitizedValues.length}`
|
|
401
|
+
)}
|
|
402
|
+
</span>
|
|
403
|
+
)}
|
|
404
|
+
{clearable && !disabled && !!sanitizedValues.length && (
|
|
405
|
+
<a
|
|
406
|
+
className="dash-dropdown-clear"
|
|
407
|
+
onClick={e => {
|
|
408
|
+
e.preventDefault();
|
|
409
|
+
handleClear();
|
|
410
|
+
}}
|
|
411
|
+
title={labels?.clear_selection}
|
|
412
|
+
aria-label={labels?.clear_selection}
|
|
413
|
+
>
|
|
414
|
+
<Cross1Icon />
|
|
415
|
+
</a>
|
|
416
|
+
)}
|
|
417
|
+
|
|
418
|
+
<CaretDownIcon className="dash-dropdown-trigger-icon" />
|
|
419
|
+
</span>
|
|
420
|
+
</button>
|
|
421
|
+
</Popover.Trigger>
|
|
422
|
+
|
|
423
|
+
<Popover.Portal
|
|
424
|
+
// container is required otherwise popover will be rendered
|
|
425
|
+
// at document root, which may be outside of the Dash app (i.e.
|
|
426
|
+
// an embedded app)
|
|
427
|
+
container={dropdownContainerRef.current?.parentElement}
|
|
428
|
+
>
|
|
429
|
+
<Popover.Content
|
|
430
|
+
ref={dropdownContentRef}
|
|
431
|
+
className="dash-dropdown-content"
|
|
432
|
+
align="start"
|
|
433
|
+
sideOffset={5}
|
|
434
|
+
onOpenAutoFocus={e => e.preventDefault()}
|
|
435
|
+
onKeyDown={handleKeyDown}
|
|
436
|
+
style={{
|
|
437
|
+
maxHeight: maxHeight ? `${maxHeight}px` : 'auto',
|
|
438
|
+
}}
|
|
439
|
+
>
|
|
440
|
+
{searchable && (
|
|
441
|
+
<div className="dash-dropdown-grid-container dash-dropdown-search-container">
|
|
442
|
+
<MagnifyingGlassIcon className="dash-dropdown-search-icon" />
|
|
443
|
+
<input
|
|
444
|
+
type="search"
|
|
445
|
+
className="dash-dropdown-search"
|
|
446
|
+
placeholder={labels?.search}
|
|
447
|
+
value={search_value || ''}
|
|
448
|
+
autoComplete="off"
|
|
449
|
+
onChange={e => onInputChange(e.target.value)}
|
|
450
|
+
autoFocus
|
|
451
|
+
/>
|
|
452
|
+
{search_value && (
|
|
453
|
+
<button
|
|
454
|
+
type="button"
|
|
455
|
+
className="dash-dropdown-clear"
|
|
456
|
+
onClick={handleClearSearch}
|
|
457
|
+
aria-label={labels?.clear_search}
|
|
458
|
+
>
|
|
459
|
+
<Cross1Icon />
|
|
460
|
+
</button>
|
|
461
|
+
)}
|
|
462
|
+
</div>
|
|
463
|
+
)}
|
|
464
|
+
{multi && (
|
|
465
|
+
<div className="dash-dropdown-actions">
|
|
466
|
+
<button
|
|
467
|
+
type="button"
|
|
468
|
+
className="dash-dropdown-action-button"
|
|
469
|
+
onClick={handleSelectAll}
|
|
470
|
+
>
|
|
471
|
+
{labels?.select_all}
|
|
472
|
+
</button>
|
|
473
|
+
{canDeselectAll && (
|
|
474
|
+
<button
|
|
475
|
+
type="button"
|
|
476
|
+
className="dash-dropdown-action-button"
|
|
477
|
+
onClick={handleDeselectAll}
|
|
478
|
+
>
|
|
479
|
+
{labels?.deselect_all}
|
|
480
|
+
</button>
|
|
481
|
+
)}
|
|
482
|
+
</div>
|
|
483
|
+
)}
|
|
484
|
+
{isOpen && !!displayOptions.length && (
|
|
485
|
+
<>
|
|
486
|
+
<OptionsList
|
|
487
|
+
options={displayOptions}
|
|
488
|
+
selected={sanitizedValues}
|
|
489
|
+
onSelectionChange={updateSelection}
|
|
490
|
+
className="dash-dropdown-options"
|
|
491
|
+
optionClassName="dash-dropdown-option"
|
|
492
|
+
optionStyle={{
|
|
493
|
+
height: optionHeight
|
|
494
|
+
? `${optionHeight}px`
|
|
495
|
+
: undefined,
|
|
496
|
+
}}
|
|
497
|
+
/>
|
|
498
|
+
</>
|
|
499
|
+
)}
|
|
500
|
+
{isOpen && search_value && !displayOptions.length && (
|
|
501
|
+
<div className="dash-dropdown-options">
|
|
502
|
+
<span className="dash-dropdown-option">
|
|
503
|
+
{labels?.no_options_found}
|
|
504
|
+
</span>
|
|
505
|
+
</div>
|
|
506
|
+
)}
|
|
507
|
+
</Popover.Content>
|
|
508
|
+
</Popover.Portal>
|
|
509
|
+
</Popover.Root>
|
|
510
|
+
);
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
export default Dropdown;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import DebugTitle from './DebugTitle';
|
|
3
|
+
import {SpinnerProps} from '../types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Spinner created by Tobias Ahlin, https://github.com/tobiasahlin/SpinKit
|
|
7
|
+
*/
|
|
8
|
+
const CircleSpinner = ({
|
|
9
|
+
status,
|
|
10
|
+
color,
|
|
11
|
+
fullscreen,
|
|
12
|
+
debug,
|
|
13
|
+
className,
|
|
14
|
+
style,
|
|
15
|
+
}: SpinnerProps) => {
|
|
16
|
+
let debugTitle;
|
|
17
|
+
if (debug && status) {
|
|
18
|
+
debugTitle = status.map((s, i) => <DebugTitle key={i} {...s} />);
|
|
19
|
+
}
|
|
20
|
+
let spinnerClass = fullscreen ? 'dash-spinner-container' : '';
|
|
21
|
+
if (className) {
|
|
22
|
+
spinnerClass += ` ${className}`;
|
|
23
|
+
}
|
|
24
|
+
return (
|
|
25
|
+
<div style={style ? style : {}} className={spinnerClass}>
|
|
26
|
+
{debugTitle}
|
|
27
|
+
<div className="dash-spinner dash-sk-circle">
|
|
28
|
+
<div className="dash-sk-circle1 dash-sk-child" />
|
|
29
|
+
<div className="dash-sk-circle2 dash-sk-child" />
|
|
30
|
+
<div className="dash-sk-circle3 dash-sk-child" />
|
|
31
|
+
<div className="dash-sk-circle4 dash-sk-child" />
|
|
32
|
+
<div className="dash-sk-circle5 dash-sk-child" />
|
|
33
|
+
<div className="dash-sk-circle6 dash-sk-child" />
|
|
34
|
+
<div className="dash-sk-circle7 dash-sk-child" />
|
|
35
|
+
<div className="dash-sk-circle8 dash-sk-child" />
|
|
36
|
+
<div className="dash-sk-circle9 dash-sk-child" />
|
|
37
|
+
<div className="dash-sk-circle10 dash-sk-child" />
|
|
38
|
+
<div className="dash-sk-circle11 dash-sk-child" />
|
|
39
|
+
<div className="dash-sk-circle12 dash-sk-child" />
|
|
40
|
+
</div>
|
|
41
|
+
<style>
|
|
42
|
+
{`
|
|
43
|
+
.dash-spinner-container {
|
|
44
|
+
position: fixed;
|
|
45
|
+
width: 100vw;
|
|
46
|
+
height: 100vh;
|
|
47
|
+
top: 0;
|
|
48
|
+
left: 0;
|
|
49
|
+
background-color: white;
|
|
50
|
+
z-index: 99;
|
|
51
|
+
display: flex;
|
|
52
|
+
justify-content: center;
|
|
53
|
+
align-items: center;
|
|
54
|
+
}
|
|
55
|
+
.dash-loading-title {
|
|
56
|
+
text-align: center;
|
|
57
|
+
}
|
|
58
|
+
.dash-sk-circle {
|
|
59
|
+
margin: 1rem auto;
|
|
60
|
+
width: 40px;
|
|
61
|
+
height: 40px;
|
|
62
|
+
position: relative;
|
|
63
|
+
}
|
|
64
|
+
.dash-sk-circle .dash-sk-child {
|
|
65
|
+
width: 100%;
|
|
66
|
+
height: 100%;
|
|
67
|
+
position: absolute;
|
|
68
|
+
left: 0;
|
|
69
|
+
top: 0;
|
|
70
|
+
}
|
|
71
|
+
.dash-sk-circle .dash-sk-child:before {
|
|
72
|
+
content: '';
|
|
73
|
+
display: block;
|
|
74
|
+
margin: 0 auto;
|
|
75
|
+
width: 15%;
|
|
76
|
+
height: 15%;
|
|
77
|
+
background-color: ${color};
|
|
78
|
+
border-radius: 100%;
|
|
79
|
+
-webkit-animation: dash-sk-circleBounceDelay 1.2s infinite ease-in-out both;
|
|
80
|
+
animation: dash-sk-circleBounceDelay 1.2s infinite ease-in-out both;
|
|
81
|
+
}
|
|
82
|
+
.dash-sk-circle .dash-sk-circle2 {
|
|
83
|
+
-webkit-transform: rotate(30deg);
|
|
84
|
+
-ms-transform: rotate(30deg);
|
|
85
|
+
transform: rotate(30deg); }
|
|
86
|
+
.dash-sk-circle .dash-sk-circle3 {
|
|
87
|
+
-webkit-transform: rotate(60deg);
|
|
88
|
+
-ms-transform: rotate(60deg);
|
|
89
|
+
transform: rotate(60deg); }
|
|
90
|
+
.dash-sk-circle .dash-sk-circle4 {
|
|
91
|
+
-webkit-transform: rotate(90deg);
|
|
92
|
+
-ms-transform: rotate(90deg);
|
|
93
|
+
transform: rotate(90deg); }
|
|
94
|
+
.dash-sk-circle .dash-sk-circle5 {
|
|
95
|
+
-webkit-transform: rotate(120deg);
|
|
96
|
+
-ms-transform: rotate(120deg);
|
|
97
|
+
transform: rotate(120deg); }
|
|
98
|
+
.dash-sk-circle .dash-sk-circle6 {
|
|
99
|
+
-webkit-transform: rotate(150deg);
|
|
100
|
+
-ms-transform: rotate(150deg);
|
|
101
|
+
transform: rotate(150deg); }
|
|
102
|
+
.dash-sk-circle .dash-sk-circle7 {
|
|
103
|
+
-webkit-transform: rotate(180deg);
|
|
104
|
+
-ms-transform: rotate(180deg);
|
|
105
|
+
transform: rotate(180deg); }
|
|
106
|
+
.dash-sk-circle .dash-sk-circle8 {
|
|
107
|
+
-webkit-transform: rotate(210deg);
|
|
108
|
+
-ms-transform: rotate(210deg);
|
|
109
|
+
transform: rotate(210deg); }
|
|
110
|
+
.dash-sk-circle .dash-sk-circle9 {
|
|
111
|
+
-webkit-transform: rotate(240deg);
|
|
112
|
+
-ms-transform: rotate(240deg);
|
|
113
|
+
transform: rotate(240deg); }
|
|
114
|
+
.dash-sk-circle .dash-sk-circle10 {
|
|
115
|
+
-webkit-transform: rotate(270deg);
|
|
116
|
+
-ms-transform: rotate(270deg);
|
|
117
|
+
transform: rotate(270deg); }
|
|
118
|
+
.dash-sk-circle .dash-sk-circle11 {
|
|
119
|
+
-webkit-transform: rotate(300deg);
|
|
120
|
+
-ms-transform: rotate(300deg);
|
|
121
|
+
transform: rotate(300deg); }
|
|
122
|
+
.dash-sk-circle .dash-sk-circle12 {
|
|
123
|
+
-webkit-transform: rotate(330deg);
|
|
124
|
+
-ms-transform: rotate(330deg);
|
|
125
|
+
transform: rotate(330deg); }
|
|
126
|
+
.dash-sk-circle .dash-sk-circle2:before {
|
|
127
|
+
-webkit-animation-delay: -1.1s;
|
|
128
|
+
animation-delay: -1.1s; }
|
|
129
|
+
.dash-sk-circle .dash-sk-circle3:before {
|
|
130
|
+
-webkit-animation-delay: -1s;
|
|
131
|
+
animation-delay: -1s; }
|
|
132
|
+
.dash-sk-circle .dash-sk-circle4:before {
|
|
133
|
+
-webkit-animation-delay: -0.9s;
|
|
134
|
+
animation-delay: -0.9s; }
|
|
135
|
+
.dash-sk-circle .dash-sk-circle5:before {
|
|
136
|
+
-webkit-animation-delay: -0.8s;
|
|
137
|
+
animation-delay: -0.8s; }
|
|
138
|
+
.dash-sk-circle .dash-sk-circle6:before {
|
|
139
|
+
-webkit-animation-delay: -0.7s;
|
|
140
|
+
animation-delay: -0.7s; }
|
|
141
|
+
.dash-sk-circle .dash-sk-circle7:before {
|
|
142
|
+
-webkit-animation-delay: -0.6s;
|
|
143
|
+
animation-delay: -0.6s; }
|
|
144
|
+
.dash-sk-circle .dash-sk-circle8:before {
|
|
145
|
+
-webkit-animation-delay: -0.5s;
|
|
146
|
+
animation-delay: -0.5s; }
|
|
147
|
+
.dash-sk-circle .dash-sk-circle9:before {
|
|
148
|
+
-webkit-animation-delay: -0.4s;
|
|
149
|
+
animation-delay: -0.4s; }
|
|
150
|
+
.dash-sk-circle .dash-sk-circle10:before {
|
|
151
|
+
-webkit-animation-delay: -0.3s;
|
|
152
|
+
animation-delay: -0.3s; }
|
|
153
|
+
.dash-spinner-container > .sk-circle .sk-circle11:before {
|
|
154
|
+
-webkit-animation-delay: -0.2s;
|
|
155
|
+
animation-delay: -0.2s; }
|
|
156
|
+
.dash-spinner-container .sk-circle .sk-circle12:before {
|
|
157
|
+
-webkit-animation-delay: -0.1s;
|
|
158
|
+
animation-delay: -0.1s; }
|
|
159
|
+
|
|
160
|
+
@-webkit-keyframes dash-sk-circleBounceDelay {
|
|
161
|
+
0%, 80%, 100% {
|
|
162
|
+
-webkit-transform: scale(0);
|
|
163
|
+
transform: scale(0);
|
|
164
|
+
} 40% {
|
|
165
|
+
-webkit-transform: scale(1);
|
|
166
|
+
transform: scale(1);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
@keyframes dash-sk-circleBounceDelay {
|
|
171
|
+
0%, 80%, 100% {
|
|
172
|
+
-webkit-transform: scale(0);
|
|
173
|
+
transform: scale(0);
|
|
174
|
+
} 40% {
|
|
175
|
+
-webkit-transform: scale(1);
|
|
176
|
+
transform: scale(1);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
`}
|
|
180
|
+
</style>
|
|
181
|
+
</div>
|
|
182
|
+
);
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
export default CircleSpinner;
|