dash-core-components 4.0.0-rc0 → 4.0.0-rc1
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 +18 -0
- package/lib/components/Dropdown.tsx +52 -0
- package/lib/components/RangeSlider.tsx +8 -1
- package/lib/components/Textarea.react.js.old +287 -0
- package/lib/components/css/dcc.css +1 -0
- package/lib/components/css/dropdown.css +230 -0
- package/lib/components/css/sliders.css +8 -0
- package/lib/fragments/Dropdown.tsx +577 -0
- package/lib/fragments/RangeSlider.tsx +71 -71
- package/lib/index.ts +1 -1
- package/lib/types.ts +168 -0
- 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/optionTypes.ts +27 -0
- package/package.json +7 -3
- package/lib/components/Dropdown.react.js +0 -182
- package/lib/fragments/Dropdown.react.js +0 -158
- package/lib/fragments/Slider.tsx.old +0 -364
- package/lib/utils/LazyLoader/dropdown.js +0 -8
|
@@ -262,6 +262,77 @@ export default function RangeSlider(props: RangeSliderProps) {
|
|
|
262
262
|
disabled={disabled}
|
|
263
263
|
/>
|
|
264
264
|
)}
|
|
265
|
+
{showInputs && !vertical && (
|
|
266
|
+
<input
|
|
267
|
+
type="number"
|
|
268
|
+
className="dash-input-container dash-range-slider-input dash-range-slider-max-input"
|
|
269
|
+
value={value[value.length - 1] ?? ''}
|
|
270
|
+
onChange={e => {
|
|
271
|
+
const inputValue = e.target.value;
|
|
272
|
+
// Allow empty string (user is clearing the field)
|
|
273
|
+
if (inputValue === '') {
|
|
274
|
+
// Don't update props while user is typing, just update local state
|
|
275
|
+
const newValue = [...value];
|
|
276
|
+
newValue[newValue.length - 1] = '' as any;
|
|
277
|
+
setValue(newValue);
|
|
278
|
+
} else {
|
|
279
|
+
const newMax = parseFloat(inputValue);
|
|
280
|
+
const constrainedMax = Math.max(
|
|
281
|
+
minMaxValues.min_mark,
|
|
282
|
+
Math.min(minMaxValues.max_mark, newMax)
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
if (newMax === constrainedMax) {
|
|
286
|
+
const newValue = [...value];
|
|
287
|
+
newValue[newValue.length - 1] = newMax;
|
|
288
|
+
setProps({
|
|
289
|
+
value: newValue,
|
|
290
|
+
drag_value: newValue,
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}}
|
|
295
|
+
onBlur={e => {
|
|
296
|
+
const inputValue = e.target.value;
|
|
297
|
+
let newMax: number;
|
|
298
|
+
|
|
299
|
+
// If empty, default to current value or max_mark
|
|
300
|
+
if (inputValue === '') {
|
|
301
|
+
newMax =
|
|
302
|
+
value[value.length - 1] ??
|
|
303
|
+
minMaxValues.max_mark;
|
|
304
|
+
} else {
|
|
305
|
+
newMax = parseFloat(inputValue);
|
|
306
|
+
newMax = isNaN(newMax)
|
|
307
|
+
? minMaxValues.max_mark
|
|
308
|
+
: newMax;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const constrainedMax = Math.min(
|
|
312
|
+
minMaxValues.max_mark,
|
|
313
|
+
Math.max(
|
|
314
|
+
value[0] ?? minMaxValues.min_mark,
|
|
315
|
+
newMax
|
|
316
|
+
)
|
|
317
|
+
);
|
|
318
|
+
const newValue = [...value];
|
|
319
|
+
newValue[newValue.length - 1] = constrainedMax;
|
|
320
|
+
setValue(newValue);
|
|
321
|
+
if (updatemode === 'mouseup') {
|
|
322
|
+
setProps({value: newValue});
|
|
323
|
+
}
|
|
324
|
+
}}
|
|
325
|
+
pattern="^\\d*\\.?\\d*$"
|
|
326
|
+
min={
|
|
327
|
+
value.length === 1
|
|
328
|
+
? minMaxValues.min_mark
|
|
329
|
+
: value[0]
|
|
330
|
+
}
|
|
331
|
+
max={minMaxValues.max_mark}
|
|
332
|
+
step={step || undefined}
|
|
333
|
+
disabled={disabled}
|
|
334
|
+
/>
|
|
335
|
+
)}
|
|
265
336
|
<div
|
|
266
337
|
className="dash-slider-wrapper"
|
|
267
338
|
onClickCapture={e => e.preventDefault()} // prevent interactions from "clicking" the parent, particularly when slider is inside a label tag
|
|
@@ -334,77 +405,6 @@ export default function RangeSlider(props: RangeSliderProps) {
|
|
|
334
405
|
})}
|
|
335
406
|
</RadixSlider.Root>
|
|
336
407
|
</div>
|
|
337
|
-
{showInputs && !vertical && (
|
|
338
|
-
<input
|
|
339
|
-
type="number"
|
|
340
|
-
className="dash-input-container dash-range-slider-input"
|
|
341
|
-
value={value[value.length - 1] ?? ''}
|
|
342
|
-
onChange={e => {
|
|
343
|
-
const inputValue = e.target.value;
|
|
344
|
-
// Allow empty string (user is clearing the field)
|
|
345
|
-
if (inputValue === '') {
|
|
346
|
-
// Don't update props while user is typing, just update local state
|
|
347
|
-
const newValue = [...value];
|
|
348
|
-
newValue[newValue.length - 1] = '' as any;
|
|
349
|
-
setValue(newValue);
|
|
350
|
-
} else {
|
|
351
|
-
const newMax = parseFloat(inputValue);
|
|
352
|
-
const constrainedMax = Math.max(
|
|
353
|
-
minMaxValues.min_mark,
|
|
354
|
-
Math.min(minMaxValues.max_mark, newMax)
|
|
355
|
-
);
|
|
356
|
-
|
|
357
|
-
if (newMax === constrainedMax) {
|
|
358
|
-
const newValue = [...value];
|
|
359
|
-
newValue[newValue.length - 1] = newMax;
|
|
360
|
-
setProps({
|
|
361
|
-
value: newValue,
|
|
362
|
-
drag_value: newValue,
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
}}
|
|
367
|
-
onBlur={e => {
|
|
368
|
-
const inputValue = e.target.value;
|
|
369
|
-
let newMax: number;
|
|
370
|
-
|
|
371
|
-
// If empty, default to current value or max_mark
|
|
372
|
-
if (inputValue === '') {
|
|
373
|
-
newMax =
|
|
374
|
-
value[value.length - 1] ??
|
|
375
|
-
minMaxValues.max_mark;
|
|
376
|
-
} else {
|
|
377
|
-
newMax = parseFloat(inputValue);
|
|
378
|
-
newMax = isNaN(newMax)
|
|
379
|
-
? minMaxValues.max_mark
|
|
380
|
-
: newMax;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
const constrainedMax = Math.min(
|
|
384
|
-
minMaxValues.max_mark,
|
|
385
|
-
Math.max(
|
|
386
|
-
value[0] ?? minMaxValues.min_mark,
|
|
387
|
-
newMax
|
|
388
|
-
)
|
|
389
|
-
);
|
|
390
|
-
const newValue = [...value];
|
|
391
|
-
newValue[newValue.length - 1] = constrainedMax;
|
|
392
|
-
setValue(newValue);
|
|
393
|
-
if (updatemode === 'mouseup') {
|
|
394
|
-
setProps({value: newValue});
|
|
395
|
-
}
|
|
396
|
-
}}
|
|
397
|
-
pattern="^\\d*\\.?\\d*$"
|
|
398
|
-
min={
|
|
399
|
-
value.length === 1
|
|
400
|
-
? minMaxValues.min_mark
|
|
401
|
-
: value[0]
|
|
402
|
-
}
|
|
403
|
-
max={minMaxValues.max_mark}
|
|
404
|
-
step={step || undefined}
|
|
405
|
-
disabled={disabled}
|
|
406
|
-
/>
|
|
407
|
-
)}
|
|
408
408
|
</div>
|
|
409
409
|
)}
|
|
410
410
|
</LoadingElement>
|
package/lib/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ import ConfirmDialogProvider from './components/ConfirmDialogProvider.react';
|
|
|
6
6
|
import DatePickerRange from './components/DatePickerRange.react';
|
|
7
7
|
import DatePickerSingle from './components/DatePickerSingle.react';
|
|
8
8
|
import Download from './components/Download.react';
|
|
9
|
-
import Dropdown from './components/Dropdown
|
|
9
|
+
import Dropdown from './components/Dropdown';
|
|
10
10
|
import Geolocation from './components/Geolocation.react';
|
|
11
11
|
import Graph from './components/Graph.react';
|
|
12
12
|
import Input from './components/Input';
|
package/lib/types.ts
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {DashComponent} from '@dash-renderer/types/component';
|
|
3
|
+
import ExternalWrapper from '@dash-renderer/wrapper/ExternalWrapper';
|
|
4
|
+
import {useDashContext} from '@dash-renderer/wrapper/DashContext';
|
|
5
|
+
|
|
6
|
+
declare global {
|
|
7
|
+
interface Window {
|
|
8
|
+
dash_component_api: {
|
|
9
|
+
useDashContext: typeof useDashContext;
|
|
10
|
+
ExternalWrapper: typeof ExternalWrapper;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
1
15
|
export enum PersistenceTypes {
|
|
2
16
|
'local' = 'local',
|
|
3
17
|
'session' = 'session',
|
|
@@ -329,3 +343,157 @@ export interface RangeSliderProps {
|
|
|
329
343
|
*/
|
|
330
344
|
persistence_type?: PersistenceTypes;
|
|
331
345
|
}
|
|
346
|
+
|
|
347
|
+
export type DropdownValue = string | number | boolean;
|
|
348
|
+
|
|
349
|
+
export type DetailedDropdownOption = {
|
|
350
|
+
label: string | DashComponent;
|
|
351
|
+
/**
|
|
352
|
+
* The value of the option. This value
|
|
353
|
+
* corresponds to the items specified in the
|
|
354
|
+
* `value` property.
|
|
355
|
+
*/
|
|
356
|
+
value: DropdownValue;
|
|
357
|
+
/**
|
|
358
|
+
* If true, this option is disabled and cannot be selected.
|
|
359
|
+
*/
|
|
360
|
+
disabled?: boolean;
|
|
361
|
+
/**
|
|
362
|
+
* The HTML 'title' attribute for the option. Allows for
|
|
363
|
+
* information on hover. For more information on this attribute,
|
|
364
|
+
* see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/title
|
|
365
|
+
*/
|
|
366
|
+
title?: string;
|
|
367
|
+
/**
|
|
368
|
+
* Optional search value for the option, to use if the label
|
|
369
|
+
* is a component or provide a custom search value different
|
|
370
|
+
* from the label. If no search value and the label is a
|
|
371
|
+
* component, the `value` will be used for search.
|
|
372
|
+
*/
|
|
373
|
+
search?: string;
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Array of options where the label and the value are the same thing, or an option dict
|
|
378
|
+
*/
|
|
379
|
+
export type DropdownOptionsArray = (DropdownValue | DetailedDropdownOption)[];
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Simpler `options` representation in dictionary format. The order is not guaranteed.
|
|
383
|
+
* {`value1`: `label1`, `value2`: `label2`, ... }
|
|
384
|
+
* which is equal to
|
|
385
|
+
* [{label: `label1`, value: `value1`}, {label: `label2`, value: `value2`}, ...]
|
|
386
|
+
*/
|
|
387
|
+
export type DropdownOptionsDict = Record<string, string>;
|
|
388
|
+
|
|
389
|
+
export interface DropdownProps {
|
|
390
|
+
/**
|
|
391
|
+
* An array of options {label: [string|number], value: [string|number]},
|
|
392
|
+
* an optional disabled field can be used for each option
|
|
393
|
+
*/
|
|
394
|
+
options?: DropdownOptionsArray | DropdownOptionsDict;
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* The value of the input. If `multi` is false (the default)
|
|
398
|
+
* then value is just a string that corresponds to the values
|
|
399
|
+
* provided in the `options` property. If `multi` is true, then
|
|
400
|
+
* multiple values can be selected at once, and `value` is an
|
|
401
|
+
* array of items with values corresponding to those in the
|
|
402
|
+
* `options` prop.
|
|
403
|
+
*/
|
|
404
|
+
value?: DropdownValue | DropdownValue[] | null;
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* If true, the user can select multiple values
|
|
408
|
+
*/
|
|
409
|
+
multi?: boolean;
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Whether or not the dropdown is "clearable", that is, whether or
|
|
413
|
+
* not a small "x" appears on the right of the dropdown that removes
|
|
414
|
+
* the selected value.
|
|
415
|
+
*/
|
|
416
|
+
clearable?: boolean;
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Whether to enable the searching feature or not
|
|
420
|
+
*/
|
|
421
|
+
searchable?: boolean;
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* The value typed in the DropDown for searching.
|
|
425
|
+
*/
|
|
426
|
+
search_value?: string;
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* The grey, default text shown when no option is selected
|
|
430
|
+
*/
|
|
431
|
+
placeholder?: string;
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* If true, this dropdown is disabled and the selection cannot be changed.
|
|
435
|
+
*/
|
|
436
|
+
disabled?: boolean;
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* If false, the menu of the dropdown will not close once a value is selected.
|
|
440
|
+
*/
|
|
441
|
+
closeOnSelect?: boolean;
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* height of each option. Can be increased when label lengths would wrap around
|
|
445
|
+
*/
|
|
446
|
+
optionHeight?: number;
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* height of the options dropdown.
|
|
450
|
+
*/
|
|
451
|
+
maxHeight?: number;
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* Defines CSS styles which will override styles previously set.
|
|
455
|
+
*/
|
|
456
|
+
style?: React.CSSProperties;
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* className of the dropdown element
|
|
460
|
+
*/
|
|
461
|
+
className?: string;
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* The ID of this component, used to identify dash components
|
|
465
|
+
* in callbacks. The ID needs to be unique across all of the
|
|
466
|
+
* components in an app.
|
|
467
|
+
*/
|
|
468
|
+
id?: string;
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Dash-assigned callback that gets fired when the input changes
|
|
472
|
+
*/
|
|
473
|
+
setProps: (props: Partial<DropdownProps>) => void;
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Used to allow user interactions in this component to be persisted when
|
|
477
|
+
* the component - or the page - is refreshed. If `persisted` is truthy and
|
|
478
|
+
* hasn't changed from its previous value, a `value` that the user has
|
|
479
|
+
* changed while using the app will keep that change, as long as
|
|
480
|
+
* the new `value` also matches what was given originally.
|
|
481
|
+
* Used in conjunction with `persistence_type`.
|
|
482
|
+
*/
|
|
483
|
+
persistence?: boolean | string | number;
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Properties whose user interactions will persist after refreshing the
|
|
487
|
+
* component or the page. Since only `value` is allowed this prop can
|
|
488
|
+
* normally be ignored.
|
|
489
|
+
*/
|
|
490
|
+
persisted_props?: PersistedProps[];
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* Where persisted user changes will be stored:
|
|
494
|
+
* memory: only kept in memory, reset on page refresh.
|
|
495
|
+
* local: window.localStorage, data is kept after the browser quit.
|
|
496
|
+
* session: window.sessionStorage, data is cleared once the browser quit.
|
|
497
|
+
*/
|
|
498
|
+
persistence_type?: PersistenceTypes;
|
|
499
|
+
}
|
|
@@ -1,17 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
declare global {
|
|
4
|
-
interface Window {
|
|
5
|
-
dash_component_api: {
|
|
6
|
-
useDashContext: () => {
|
|
7
|
-
useLoading: () => boolean;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
3
|
interface LoadingElementProps {
|
|
14
|
-
|
|
4
|
+
children: (props: Record<string, unknown>) => React.ReactElement;
|
|
15
5
|
}
|
|
16
6
|
|
|
17
7
|
/**
|
|
@@ -22,15 +12,15 @@ interface LoadingElementProps {
|
|
|
22
12
|
* See: https://dash.plotly.com/loading-states#check-loading-states-from-components
|
|
23
13
|
*/
|
|
24
14
|
function LoadingElement({children}: LoadingElementProps) {
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
const ctx = window.dash_component_api.useDashContext();
|
|
16
|
+
const loading = ctx.useLoading();
|
|
27
17
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
18
|
+
const additionalProps: Record<string, unknown> = {};
|
|
19
|
+
if (loading) {
|
|
20
|
+
additionalProps['data-dash-is-loading'] = true;
|
|
21
|
+
}
|
|
32
22
|
|
|
33
|
-
|
|
23
|
+
return children(additionalProps);
|
|
34
24
|
}
|
|
35
25
|
|
|
36
26
|
export default LoadingElement;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Search,
|
|
4
|
+
AllSubstringsIndexStrategy,
|
|
5
|
+
UnorderedSearchIndex,
|
|
6
|
+
} from 'js-search';
|
|
7
|
+
import {sanitizeOptions} from './optionTypes';
|
|
8
|
+
import {DetailedDropdownOption, DropdownProps} from '../types';
|
|
9
|
+
|
|
10
|
+
// Custom tokenizer, see https://github.com/bvaughn/js-search/issues/43
|
|
11
|
+
// Split on spaces
|
|
12
|
+
const REGEX = /\s+/;
|
|
13
|
+
const TOKENIZER = {
|
|
14
|
+
tokenize(text: string) {
|
|
15
|
+
return text.split(REGEX).filter(
|
|
16
|
+
// Filter empty tokens
|
|
17
|
+
text => text
|
|
18
|
+
);
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
interface FilteredOptionsResult {
|
|
23
|
+
sanitizedOptions: DetailedDropdownOption[];
|
|
24
|
+
filteredOptions: DetailedDropdownOption[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Creates filtered dropdown options using js-search with the exact same behavior
|
|
29
|
+
* as react-select-fast-filter-options
|
|
30
|
+
*/
|
|
31
|
+
export function createFilteredOptions(
|
|
32
|
+
options: DropdownProps['options'],
|
|
33
|
+
searchable: boolean,
|
|
34
|
+
searchValue?: string
|
|
35
|
+
): FilteredOptionsResult {
|
|
36
|
+
// Sanitize and prepare options
|
|
37
|
+
let sanitized = sanitizeOptions(options);
|
|
38
|
+
|
|
39
|
+
const indexes = ['value'];
|
|
40
|
+
let hasElement = false,
|
|
41
|
+
hasSearch = false;
|
|
42
|
+
|
|
43
|
+
sanitized = Array.isArray(sanitized)
|
|
44
|
+
? sanitized.map(option => {
|
|
45
|
+
if (option.search) {
|
|
46
|
+
hasSearch = true;
|
|
47
|
+
}
|
|
48
|
+
if (React.isValidElement(option.label)) {
|
|
49
|
+
hasElement = true;
|
|
50
|
+
}
|
|
51
|
+
return option;
|
|
52
|
+
})
|
|
53
|
+
: sanitized;
|
|
54
|
+
|
|
55
|
+
if (!hasElement) {
|
|
56
|
+
indexes.push('label');
|
|
57
|
+
}
|
|
58
|
+
if (hasSearch) {
|
|
59
|
+
indexes.push('search');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// If not searchable or no search value, return all sanitized options
|
|
63
|
+
if (!searchable || !searchValue) {
|
|
64
|
+
return {
|
|
65
|
+
sanitizedOptions: sanitized || [],
|
|
66
|
+
filteredOptions: sanitized || [],
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Create js-search instance exactly like react-select-fast-filter-options
|
|
71
|
+
const search = new Search('value'); // valueKey defaults to 'value'
|
|
72
|
+
search.searchIndex = new UnorderedSearchIndex();
|
|
73
|
+
search.indexStrategy = new AllSubstringsIndexStrategy();
|
|
74
|
+
search.tokenizer = TOKENIZER;
|
|
75
|
+
|
|
76
|
+
// Add indexes
|
|
77
|
+
indexes.forEach(index => {
|
|
78
|
+
search.addIndex(index);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// Add documents
|
|
82
|
+
if (sanitized && sanitized.length > 0) {
|
|
83
|
+
search.addDocuments(sanitized);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const filtered = search.search(searchValue) as DetailedDropdownOption[];
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
sanitizedOptions: sanitized || [],
|
|
90
|
+
filteredOptions: filtered || [],
|
|
91
|
+
};
|
|
92
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {DetailedDropdownOption, DropdownProps, DropdownValue} from '../types';
|
|
3
|
+
|
|
4
|
+
const isDropdownValue = (option: unknown): option is DropdownValue => {
|
|
5
|
+
return ['string', 'number', 'boolean'].includes(typeof option);
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const sanitizeOptions = (
|
|
9
|
+
options: DropdownProps['options']
|
|
10
|
+
): DetailedDropdownOption[] => {
|
|
11
|
+
if (typeof options === 'object' && !(options instanceof Array)) {
|
|
12
|
+
return Object.entries(options).map(([value, label]) => ({
|
|
13
|
+
label: React.isValidElement(label) ? label : String(label),
|
|
14
|
+
value,
|
|
15
|
+
}));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (options instanceof Array) {
|
|
19
|
+
return options.map(option => {
|
|
20
|
+
return isDropdownValue(option)
|
|
21
|
+
? {label: String(option), value: option}
|
|
22
|
+
: option;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return options;
|
|
27
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dash-core-components",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-rc1",
|
|
4
4
|
"description": "Core component suite for Dash",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -40,6 +40,9 @@
|
|
|
40
40
|
"@fortawesome/free-regular-svg-icons": "^5.15.4",
|
|
41
41
|
"@fortawesome/free-solid-svg-icons": "^5.15.4",
|
|
42
42
|
"@fortawesome/react-fontawesome": "^0.1.17",
|
|
43
|
+
"@radix-ui/react-icons": "^1.3.2",
|
|
44
|
+
"@radix-ui/react-popover": "^1.1.15",
|
|
45
|
+
"@radix-ui/react-select": "^2.1.3",
|
|
43
46
|
"@radix-ui/react-slider": "^1.3.6",
|
|
44
47
|
"@radix-ui/react-tooltip": "^1.2.8",
|
|
45
48
|
"base64-js": "^1.5.1",
|
|
@@ -48,6 +51,7 @@
|
|
|
48
51
|
"fast-isnumeric": "^1.1.4",
|
|
49
52
|
"file-saver": "^2.0.5",
|
|
50
53
|
"highlight.js": "^11.8.0",
|
|
54
|
+
"js-search": "^2.0.1",
|
|
51
55
|
"mathjax": "^3.2.2",
|
|
52
56
|
"moment": "^2.29.4",
|
|
53
57
|
"node-polyfill-webpack-plugin": "^2.0.1",
|
|
@@ -59,7 +63,6 @@
|
|
|
59
63
|
"react-dropzone": "^4.1.2",
|
|
60
64
|
"react-fast-compare": "^3.2.2",
|
|
61
65
|
"react-markdown": "^4.3.1",
|
|
62
|
-
"react-select-fast-filter-options": "^0.2.3",
|
|
63
66
|
"react-virtualized-select": "^3.1.3",
|
|
64
67
|
"remark-math": "^3.0.1",
|
|
65
68
|
"uniqid": "^5.4.0"
|
|
@@ -77,6 +80,7 @@
|
|
|
77
80
|
"@types/d3-format": "^3.0.4",
|
|
78
81
|
"@types/fast-isnumeric": "^1.1.2",
|
|
79
82
|
"@types/jest": "^29.5.0",
|
|
83
|
+
"@types/js-search": "^1.4.4",
|
|
80
84
|
"@types/ramda": "^0.31.0",
|
|
81
85
|
"@types/react": "^16.14.8",
|
|
82
86
|
"@types/react-dom": "^16.9.13",
|
|
@@ -120,5 +124,5 @@
|
|
|
120
124
|
"browserslist": [
|
|
121
125
|
"last 9 years and not dead"
|
|
122
126
|
],
|
|
123
|
-
"gitHead": "
|
|
127
|
+
"gitHead": "fdbd6e0b8dc2448175dad301ed9004c918332d34"
|
|
124
128
|
}
|