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.
Files changed (67) hide show
  1. package/dash_core_components/async-datepicker.js +1 -1
  2. package/dash_core_components/async-datepicker.js.map +1 -1
  3. package/dash_core_components/async-dropdown.js +1 -1
  4. package/dash_core_components/async-dropdown.js.map +1 -1
  5. package/dash_core_components/async-graph.js +1 -1
  6. package/dash_core_components/async-slider.js +1 -2
  7. package/dash_core_components/async-slider.js.map +1 -1
  8. package/dash_core_components/dash_core_components-shared.js +1 -1
  9. package/dash_core_components/dash_core_components-shared.js.map +1 -1
  10. package/dash_core_components/dash_core_components.js +1 -1
  11. package/dash_core_components/dash_core_components.js.map +1 -1
  12. package/dash_core_components/proptypes.js +118 -1
  13. package/lib/components/Checklist.tsx +67 -0
  14. package/lib/components/Dropdown.tsx +68 -0
  15. package/lib/components/Loading.tsx +185 -0
  16. package/lib/components/RadioItems.tsx +69 -0
  17. package/lib/components/RangeSlider.tsx +12 -1
  18. package/lib/components/Slider.tsx +12 -1
  19. package/lib/components/Tab.react.js.old +79 -0
  20. package/lib/components/Textarea.react.js.old +287 -0
  21. package/lib/components/Textarea.tsx +79 -0
  22. package/lib/components/Tooltip.tsx +66 -0
  23. package/lib/components/css/checklist.css +4 -0
  24. package/lib/components/css/dcc.css +3 -0
  25. package/lib/components/css/dropdown.css +211 -0
  26. package/lib/components/css/input.css +22 -6
  27. package/lib/components/css/optionslist.css +34 -0
  28. package/lib/components/css/radioitems.css +4 -0
  29. package/lib/components/css/sliders.css +19 -7
  30. package/lib/components/css/textarea.css +21 -0
  31. package/lib/components/css/tooltip.css +127 -0
  32. package/lib/fragments/Dropdown.tsx +513 -0
  33. package/lib/fragments/Loading/spinners/CircleSpinner.tsx +185 -0
  34. package/lib/fragments/Loading/spinners/CubeSpinner.tsx +193 -0
  35. package/lib/fragments/Loading/spinners/DebugTitle.tsx +11 -0
  36. package/lib/fragments/Loading/spinners/DefaultSpinner.tsx +110 -0
  37. package/lib/fragments/Loading/spinners/DotSpinner.tsx +96 -0
  38. package/lib/fragments/Loading/spinners/GraphSpinner.tsx +332 -0
  39. package/lib/fragments/Loading/types.ts +13 -0
  40. package/lib/fragments/RangeSlider.tsx +235 -105
  41. package/lib/index.ts +6 -6
  42. package/lib/types.ts +571 -64
  43. package/lib/utils/LazyLoader/dropdown.ts +2 -0
  44. package/lib/utils/_LoadingElement.tsx +8 -18
  45. package/lib/utils/dropdownSearch.ts +92 -0
  46. package/lib/utils/optionRendering.tsx +168 -0
  47. package/lib/utils/optionTypes.ts +27 -0
  48. package/lib/utils/sliderRendering.tsx +23 -4
  49. package/package.json +7 -4
  50. package/lib/components/Checklist.react.js +0 -193
  51. package/lib/components/Dropdown.react.js +0 -182
  52. package/lib/components/Input.react.js.old +0 -507
  53. package/lib/components/Loading.react.js +0 -254
  54. package/lib/components/RadioItems.react.js +0 -192
  55. package/lib/components/Slider.react.js.old +0 -214
  56. package/lib/components/Textarea.react.js +0 -223
  57. package/lib/components/Tooltip.react.js +0 -120
  58. package/lib/components/css/Dropdown.css +0 -8
  59. package/lib/fragments/Dropdown.react.js +0 -158
  60. package/lib/fragments/Loading/spinners/CircleSpinner.js +0 -68
  61. package/lib/fragments/Loading/spinners/CubeSpinner.js +0 -57
  62. package/lib/fragments/Loading/spinners/DebugTitle.js +0 -15
  63. package/lib/fragments/Loading/spinners/DefaultSpinner.js +0 -54
  64. package/lib/fragments/Loading/spinners/DotSpinner.js +0 -50
  65. package/lib/fragments/Loading/spinners/GraphSpinner.js +0 -68
  66. package/lib/fragments/Slider.tsx.old +0 -364
  67. package/lib/utils/LazyLoader/dropdown.js +0 -8
@@ -3,6 +3,39 @@
3
3
  var pt = window.PropTypes;
4
4
  var pk = window['dash_core_components'];
5
5
 
6
+ pk.Checklist.propTypes = {options:pt.any,
7
+ value:pt.oneOfType([pt.arrayOf(pt.oneOfType([pt.string,pt.number,pt.bool]))]),
8
+ inline:pt.oneOfType([pt.bool]),
9
+ style:pt.any,
10
+ inputStyle:pt.any,
11
+ inputClassName:pt.oneOfType([pt.string]),
12
+ labelStyle:pt.any,
13
+ labelClassName:pt.oneOfType([pt.string]),
14
+ id:pt.oneOfType([pt.string]),
15
+ className:pt.oneOfType([pt.string]),
16
+ setProps:pt.any,
17
+ persistence:pt.oneOfType([pt.string,pt.number,pt.bool]),
18
+ persisted_props:pt.any,
19
+ persistence_type:pt.oneOf(['local','session','memory'])};
20
+ pk.Dropdown.propTypes = {options:pt.any,
21
+ value:pt.oneOfType([pt.string,pt.number,pt.bool,pt.arrayOf(pt.oneOfType([pt.string,pt.number,pt.bool]))]),
22
+ multi:pt.oneOfType([pt.bool]),
23
+ clearable:pt.oneOfType([pt.bool]),
24
+ searchable:pt.oneOfType([pt.bool]),
25
+ search_value:pt.oneOfType([pt.string]),
26
+ placeholder:pt.oneOfType([pt.string]),
27
+ disabled:pt.oneOfType([pt.bool]),
28
+ closeOnSelect:pt.oneOfType([pt.bool]),
29
+ optionHeight:pt.oneOfType([pt.number,pt.oneOf(["auto"])]),
30
+ maxHeight:pt.oneOfType([pt.number]),
31
+ style:pt.any,
32
+ labels:pt.oneOfType([pt.shape({select_all:pt.oneOfType([pt.string]),deselect_all:pt.oneOfType([pt.string]),selected_count:pt.oneOfType([pt.string]),search:pt.oneOfType([pt.string]),clear_search:pt.oneOfType([pt.string]),clear_selection:pt.oneOfType([pt.string]),no_options_found:pt.oneOfType([pt.string])})]),
33
+ id:pt.oneOfType([pt.string]),
34
+ className:pt.oneOfType([pt.string]),
35
+ setProps:pt.any,
36
+ persistence:pt.oneOfType([pt.string,pt.number,pt.bool]),
37
+ persisted_props:pt.any,
38
+ persistence_type:pt.oneOf(['local','session','memory'])};
6
39
  pk.Input.propTypes = {value:pt.oneOfType([pt.string,pt.number]),
7
40
  debounce:pt.oneOfType([pt.number,pt.bool]),
8
41
  placeholder:pt.oneOfType([pt.string,pt.number]),
@@ -38,6 +71,41 @@ pk.Input.propTypes = {value:pt.oneOfType([pt.string,pt.number]),
38
71
  persisted_props:pt.any,
39
72
  persistence_type:pt.oneOf(['local','session','memory']),
40
73
  type:pt.oneOf(['text','number','password','email','range','search','tel','url','hidden'])};
74
+ pk.Loading.propTypes = {children:pt.node,
75
+ type:pt.oneOf(['graph','cube','circle','dot','default']),
76
+ fullscreen:pt.oneOfType([pt.bool]),
77
+ debug:pt.oneOfType([pt.bool]),
78
+ style:pt.any,
79
+ parent_className:pt.oneOfType([pt.string]),
80
+ parent_style:pt.any,
81
+ overlay_style:pt.any,
82
+ color:pt.oneOfType([pt.string]),
83
+ display:pt.oneOf(['auto','show','hide']),
84
+ delay_hide:pt.oneOfType([pt.number]),
85
+ delay_show:pt.oneOfType([pt.number]),
86
+ show_initially:pt.oneOfType([pt.bool]),
87
+ target_components:pt.oneOfType([pt.shape({})]),
88
+ custom_spinner:pt.node,
89
+ id:pt.oneOfType([pt.string]),
90
+ className:pt.oneOfType([pt.string]),
91
+ setProps:pt.any,
92
+ persistence:pt.oneOfType([pt.string,pt.number,pt.bool]),
93
+ persisted_props:pt.any,
94
+ persistence_type:pt.oneOf(['local','session','memory'])};
95
+ pk.RadioItems.propTypes = {options:pt.any,
96
+ value:pt.oneOfType([pt.string,pt.number,pt.bool]),
97
+ inline:pt.oneOfType([pt.bool]),
98
+ style:pt.any,
99
+ inputStyle:pt.any,
100
+ inputClassName:pt.oneOfType([pt.string]),
101
+ labelStyle:pt.any,
102
+ labelClassName:pt.oneOfType([pt.string]),
103
+ id:pt.oneOfType([pt.string]),
104
+ className:pt.oneOfType([pt.string]),
105
+ setProps:pt.any,
106
+ persistence:pt.oneOfType([pt.string,pt.number,pt.bool]),
107
+ persisted_props:pt.any,
108
+ persistence_type:pt.oneOf(['local','session','memory'])};
41
109
  pk.RangeSlider.propTypes = {min:pt.oneOfType([pt.number]),
42
110
  max:pt.oneOfType([pt.number]),
43
111
  step:pt.oneOfType([pt.number]),
@@ -50,12 +118,13 @@ pk.RangeSlider.propTypes = {min:pt.oneOfType([pt.number]),
50
118
  count:pt.oneOfType([pt.number]),
51
119
  dots:pt.oneOfType([pt.bool]),
52
120
  included:pt.oneOfType([pt.bool]),
121
+ reverse:pt.oneOfType([pt.bool]),
53
122
  tooltip:pt.any,
54
123
  updatemode:pt.oneOf(['mouseup','drag']),
55
124
  vertical:pt.oneOfType([pt.bool]),
56
125
  verticalHeight:pt.oneOfType([pt.number]),
57
- className:pt.oneOfType([pt.string]),
58
126
  id:pt.oneOfType([pt.string]),
127
+ className:pt.oneOfType([pt.string]),
59
128
  setProps:pt.any,
60
129
  persistence:pt.oneOfType([pt.string,pt.number,pt.bool]),
61
130
  persisted_props:pt.any,
@@ -69,13 +138,61 @@ pk.Slider.propTypes = {min:pt.oneOfType([pt.number]),
69
138
  disabled:pt.oneOfType([pt.bool]),
70
139
  dots:pt.oneOfType([pt.bool]),
71
140
  included:pt.oneOfType([pt.bool]),
141
+ reverse:pt.oneOfType([pt.bool]),
72
142
  tooltip:pt.any,
73
143
  updatemode:pt.oneOf(['mouseup','drag']),
74
144
  vertical:pt.oneOfType([pt.bool]),
75
145
  verticalHeight:pt.oneOfType([pt.number]),
146
+ id:pt.oneOfType([pt.string]),
76
147
  className:pt.oneOfType([pt.string]),
148
+ setProps:pt.any,
149
+ persistence:pt.oneOfType([pt.string,pt.number,pt.bool]),
150
+ persisted_props:pt.any,
151
+ persistence_type:pt.oneOf(['local','session','memory'])};
152
+ pk.Textarea.propTypes = {value:pt.oneOfType([pt.string]),
153
+ autoFocus:pt.oneOfType([pt.string]),
154
+ cols:pt.oneOfType([pt.number]),
155
+ disabled:pt.oneOfType([pt.bool,pt.oneOf(["disabled"]),pt.oneOf(["DISABLED"])]),
156
+ form:pt.oneOfType([pt.string]),
157
+ maxLength:pt.oneOfType([pt.number]),
158
+ minLength:pt.oneOfType([pt.number]),
159
+ name:pt.oneOfType([pt.string]),
160
+ placeholder:pt.oneOfType([pt.string]),
161
+ readOnly:pt.oneOfType([pt.bool,pt.oneOf(["readOnly"]),pt.oneOf(["readonly"]),pt.oneOf(["READONLY"])]),
162
+ required:pt.oneOfType([pt.bool,pt.oneOf(["required"]),pt.oneOf(["REQUIRED"])]),
163
+ rows:pt.oneOfType([pt.number]),
164
+ wrap:pt.oneOfType([pt.string]),
165
+ accessKey:pt.oneOfType([pt.string]),
166
+ contentEditable:pt.oneOfType([pt.bool]),
167
+ contextMenu:pt.oneOfType([pt.string]),
168
+ dir:pt.oneOfType([pt.string]),
169
+ draggable:pt.oneOfType([pt.bool]),
170
+ hidden:pt.oneOfType([pt.string]),
171
+ lang:pt.oneOfType([pt.string]),
172
+ spellCheck:pt.oneOfType([pt.bool]),
173
+ style:pt.any,
174
+ tabIndex:pt.oneOfType([pt.number]),
175
+ title:pt.oneOfType([pt.string]),
176
+ n_blur:pt.oneOfType([pt.number]),
177
+ n_blur_timestamp:pt.oneOfType([pt.number]),
178
+ n_clicks:pt.oneOfType([pt.number]),
179
+ n_clicks_timestamp:pt.oneOfType([pt.number]),
77
180
  id:pt.oneOfType([pt.string]),
181
+ className:pt.oneOfType([pt.string]),
78
182
  setProps:pt.any,
79
183
  persistence:pt.oneOfType([pt.string,pt.number,pt.bool]),
80
184
  persisted_props:pt.any,
81
185
  persistence_type:pt.oneOf(['local','session','memory'])};
186
+ pk.Tooltip.propTypes = {children:pt.node,
187
+ id:pt.oneOfType([pt.string]),
188
+ className:pt.oneOfType([pt.string]),
189
+ style:pt.any,
190
+ bbox:pt.oneOfType([pt.shape({x0:pt.number,y0:pt.number,x1:pt.number,y1:pt.number})]),
191
+ show:pt.oneOfType([pt.bool]),
192
+ direction:pt.oneOf(['top','right','bottom','left']),
193
+ border_color:pt.oneOfType([pt.string]),
194
+ background_color:pt.oneOfType([pt.string]),
195
+ loading_text:pt.oneOfType([pt.string]),
196
+ zindex:pt.oneOfType([pt.number]),
197
+ targetable:pt.oneOfType([pt.bool]),
198
+ setProps:pt.any};
@@ -0,0 +1,67 @@
1
+ import React, {useMemo} from 'react';
2
+ import {ChecklistProps, PersistedProps, PersistenceTypes} from '../types';
3
+ import './css/checklist.css';
4
+
5
+ import {sanitizeOptions} from '../utils/optionTypes';
6
+ import LoadingElement from '../utils/_LoadingElement';
7
+ import {OptionsList} from '../utils/optionRendering';
8
+
9
+ /**
10
+ * Checklist is a component that encapsulates several checkboxes.
11
+ * The values and labels of the checklist are specified in the `options`
12
+ * property and the checked items are specified with the `value` property.
13
+ * Each checkbox is rendered as an input with a surrounding label.
14
+ */
15
+ export default function Checklist({
16
+ className,
17
+ id,
18
+ style,
19
+ setProps,
20
+ inputStyle = {},
21
+ inputClassName = '',
22
+ labelStyle = {},
23
+ labelClassName = '',
24
+ options = [],
25
+ value = [],
26
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
27
+ persisted_props = [PersistedProps.value],
28
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
29
+ persistence_type = PersistenceTypes.local,
30
+ inline = false,
31
+ }: ChecklistProps) {
32
+ const sanitizedOptions = useMemo(() => {
33
+ return sanitizeOptions(options);
34
+ }, [options]);
35
+
36
+ const stylingProps = {
37
+ id,
38
+ className: 'dash-checklist ' + (className ?? ''),
39
+ style,
40
+ optionClassName: inline ? 'dash-checklist-inline' : undefined,
41
+ inputStyle,
42
+ inputClassName,
43
+ labelStyle,
44
+ labelClassName,
45
+ };
46
+
47
+ return (
48
+ <LoadingElement>
49
+ {loadingProps => (
50
+ <OptionsList
51
+ {...loadingProps}
52
+ options={sanitizedOptions}
53
+ selected={value ?? []}
54
+ onSelectionChange={selection => {
55
+ setProps({value: selection});
56
+ }}
57
+ {...stylingProps}
58
+ />
59
+ )}
60
+ </LoadingElement>
61
+ );
62
+ }
63
+
64
+ Checklist.dashPersistence = {
65
+ persisted_props: [PersistedProps.value],
66
+ persistence_type: PersistenceTypes.local,
67
+ };
@@ -0,0 +1,68 @@
1
+ import React, {lazy, Suspense} from 'react';
2
+ import {DropdownProps, PersistedProps, PersistenceTypes} from '../types';
3
+ import dropdown from '../utils/LazyLoader/dropdown';
4
+
5
+ const RealDropdown = lazy(dropdown);
6
+
7
+ const defaultLabels: DropdownProps['labels'] = {
8
+ select_all: 'Select All',
9
+ deselect_all: 'Deselect All',
10
+ selected_count: '{num_selected} selected',
11
+ search: 'Search',
12
+ clear_search: 'Clear search',
13
+ clear_selection: 'Clear selection',
14
+ no_options_found: 'No options found',
15
+ };
16
+
17
+ /**
18
+ * Dropdown is an interactive dropdown element for selecting one or more
19
+ * items.
20
+ * The values and labels of the dropdown items are specified in the `options`
21
+ * property and the selected item(s) are specified with the `value` property.
22
+ *
23
+ * Use a dropdown when you have many options (more than 5) or when you are
24
+ * constrained for space. Otherwise, you can use RadioItems or a Checklist,
25
+ * which have the benefit of showing the users all of the items at once.
26
+ */
27
+ export default function Dropdown({
28
+ clearable = true,
29
+ disabled = false,
30
+ multi = false,
31
+ searchable = true,
32
+ labels = defaultLabels,
33
+ optionHeight = 'auto',
34
+ // eslint-disable-next-line no-magic-numbers
35
+ maxHeight = 200,
36
+ closeOnSelect = !multi,
37
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
38
+ persisted_props = [PersistedProps.value],
39
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
40
+ persistence_type = PersistenceTypes.local,
41
+ ...props
42
+ }: DropdownProps) {
43
+ labels = {
44
+ ...defaultLabels,
45
+ ...labels,
46
+ };
47
+
48
+ return (
49
+ <Suspense fallback={null}>
50
+ <RealDropdown
51
+ clearable={clearable}
52
+ disabled={disabled}
53
+ labels={labels}
54
+ multi={multi}
55
+ searchable={searchable}
56
+ optionHeight={optionHeight}
57
+ maxHeight={maxHeight}
58
+ closeOnSelect={closeOnSelect}
59
+ {...props}
60
+ />
61
+ </Suspense>
62
+ );
63
+ }
64
+
65
+ Dropdown.dashPersistence = {
66
+ persisted_props: [PersistedProps.value],
67
+ persistence_type: PersistenceTypes.local,
68
+ };
@@ -0,0 +1,185 @@
1
+ import React, {useState, useRef, useMemo, useEffect} from 'react';
2
+ import {equals, concat, includes, toPairs, any} from 'ramda';
3
+
4
+ import GraphSpinner from '../fragments/Loading/spinners/GraphSpinner';
5
+ import DefaultSpinner from '../fragments/Loading/spinners/DefaultSpinner';
6
+ import CubeSpinner from '../fragments/Loading/spinners/CubeSpinner';
7
+ import CircleSpinner from '../fragments/Loading/spinners/CircleSpinner';
8
+ import DotSpinner from '../fragments/Loading/spinners/DotSpinner';
9
+ import {LoadingProps} from 'src/types';
10
+ import {DebugTitleProps} from '../fragments/Loading/types';
11
+ import {DashLayoutPath} from '@dash-renderer/types/component';
12
+
13
+ const spinnerComponentOptions = {
14
+ graph: GraphSpinner,
15
+ cube: CubeSpinner,
16
+ circle: CircleSpinner,
17
+ dot: DotSpinner,
18
+ default: DefaultSpinner,
19
+ } as const;
20
+
21
+ const getSpinner = (spinnerType: keyof typeof spinnerComponentOptions) =>
22
+ spinnerComponentOptions[spinnerType];
23
+
24
+ const coveringSpinner: React.CSSProperties = {
25
+ visibility: 'visible',
26
+ position: 'absolute',
27
+ top: '0',
28
+ height: '100%',
29
+ width: '100%',
30
+ display: 'flex',
31
+ justifyContent: 'center',
32
+ alignItems: 'center',
33
+ };
34
+
35
+ type LoadingState = {
36
+ loading: Record<string, DebugTitleProps[]>;
37
+ };
38
+
39
+ const loadingSelector =
40
+ (
41
+ componentPath: DashLayoutPath,
42
+ targetComponents?: Record<string, string | string[]>
43
+ ) =>
44
+ (state: LoadingState): DebugTitleProps[] | null => {
45
+ let stringPath = JSON.stringify(componentPath);
46
+ // Remove the last ] for easy match and add `,` to make sure only children
47
+ // trigger the loading. See issue: https://github.com/plotly/dash/issues/3276
48
+ stringPath = stringPath.substring(0, stringPath.length - 1) + ',';
49
+ const loadingChildren = toPairs(state.loading).reduce(
50
+ (acc, [path, load]) => {
51
+ if (path.startsWith(stringPath) && load.length) {
52
+ if (
53
+ targetComponents &&
54
+ !any((l: DebugTitleProps) => {
55
+ const target = targetComponents[l.id];
56
+ if (!target) {
57
+ return false;
58
+ }
59
+ if (target === '*') {
60
+ return true;
61
+ }
62
+ if (Array.isArray(target)) {
63
+ return includes(l.property, target);
64
+ }
65
+ return l.property === target;
66
+ }, load)
67
+ ) {
68
+ return acc;
69
+ }
70
+ return concat(acc, load);
71
+ }
72
+ return acc;
73
+ },
74
+ [] as DebugTitleProps[]
75
+ );
76
+ if (loadingChildren.length) {
77
+ return loadingChildren;
78
+ }
79
+ return null;
80
+ };
81
+
82
+ function Loading({
83
+ children,
84
+ display = 'auto',
85
+ color = 'var(--Dash-Fill-Interactive-Strong)',
86
+ id,
87
+ className,
88
+ style,
89
+ parent_className,
90
+ parent_style,
91
+ overlay_style,
92
+ fullscreen,
93
+ debug,
94
+ show_initially = true,
95
+ type: spinnerType = 'default',
96
+ delay_hide = 0,
97
+ delay_show = 0,
98
+ target_components,
99
+ custom_spinner,
100
+ }: LoadingProps) {
101
+ const ctx = window.dash_component_api.useDashContext();
102
+
103
+ const loading = ctx.useSelector(
104
+ loadingSelector(ctx.componentPath, target_components),
105
+ equals
106
+ );
107
+
108
+ const [showSpinner, setShowSpinner] = useState(show_initially);
109
+ const dismissTimer = useRef<number | void>();
110
+ const showTimer = useRef<number | void>();
111
+
112
+ const containerStyle: React.CSSProperties = useMemo(() => {
113
+ if (showSpinner) {
114
+ return {visibility: 'hidden', ...overlay_style, ...parent_style};
115
+ }
116
+ return parent_style ?? {};
117
+ }, [showSpinner, parent_style]);
118
+
119
+ useEffect(() => {
120
+ if (display === 'show' || display === 'hide') {
121
+ setShowSpinner(display === 'show');
122
+ return;
123
+ }
124
+
125
+ if (loading) {
126
+ // if component is currently loading and there's a dismiss timer active
127
+ // we need to clear it.
128
+ if (dismissTimer.current) {
129
+ dismissTimer.current = window.clearTimeout(
130
+ dismissTimer.current
131
+ );
132
+ }
133
+ // if component is currently loading but the spinner is not showing and
134
+ // there is no timer set to show, then set a timeout to show
135
+ if (!showSpinner && !showTimer.current) {
136
+ showTimer.current = window.setTimeout(() => {
137
+ setShowSpinner(true);
138
+ showTimer.current = undefined;
139
+ }, delay_show);
140
+ }
141
+ } else {
142
+ // if component is not currently loading and there's a show timer
143
+ // active we need to clear it
144
+ if (showTimer.current) {
145
+ showTimer.current = window.clearTimeout(showTimer.current);
146
+ }
147
+ // if component is not currently loading and the spinner is showing and
148
+ // there's no timer set to dismiss it, then set a timeout to hide it
149
+ if (showSpinner && !dismissTimer.current) {
150
+ dismissTimer.current = window.setTimeout(() => {
151
+ setShowSpinner(false);
152
+ dismissTimer.current = undefined;
153
+ }, delay_hide);
154
+ }
155
+ }
156
+ }, [delay_hide, delay_show, loading, display, showSpinner]);
157
+
158
+ const Spinner = getSpinner(spinnerType);
159
+
160
+ return (
161
+ <div
162
+ style={{position: 'relative', ...parent_style}}
163
+ className={parent_className}
164
+ >
165
+ <div className={parent_className} style={containerStyle}>
166
+ {children}
167
+ </div>
168
+ <div id={id} style={showSpinner ? coveringSpinner : {}}>
169
+ {showSpinner &&
170
+ (custom_spinner || (
171
+ <Spinner
172
+ className={className}
173
+ style={style}
174
+ status={loading}
175
+ color={color}
176
+ debug={debug}
177
+ fullscreen={fullscreen}
178
+ />
179
+ ))}
180
+ </div>
181
+ </div>
182
+ );
183
+ }
184
+
185
+ export default Loading;
@@ -0,0 +1,69 @@
1
+ import React, {useMemo} from 'react';
2
+ import {RadioItemsProps, PersistedProps, PersistenceTypes} from '../types';
3
+ import './css/radioitems.css';
4
+
5
+ import {sanitizeOptions} from '../utils/optionTypes';
6
+ import LoadingElement from '../utils/_LoadingElement';
7
+ import {OptionsList} from '../utils/optionRendering';
8
+ import {isNil} from 'ramda';
9
+
10
+ /**
11
+ * RadioItems is a component that encapsulates several radio item inputs.
12
+ * The values and labels of the RadioItems is specified in the `options`
13
+ * property and the seleced item is specified with the `value` property.
14
+ * Each radio item is rendered as an input with a surrounding label.
15
+ */
16
+ export default function RadioItems({
17
+ className,
18
+ id,
19
+ style,
20
+ setProps,
21
+ value,
22
+ inputStyle = {},
23
+ inputClassName = '',
24
+ labelStyle = {},
25
+ labelClassName = '',
26
+ options = [],
27
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
28
+ persisted_props = [PersistedProps.value],
29
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
30
+ persistence_type = PersistenceTypes.local,
31
+ inline = false,
32
+ }: RadioItemsProps) {
33
+ const sanitizedOptions = useMemo(() => {
34
+ return sanitizeOptions(options);
35
+ }, [options]);
36
+
37
+ const stylingProps = {
38
+ id,
39
+ className: 'dash-radioitems ' + (className ?? ''),
40
+ style,
41
+ optionClassName: inline ? 'dash-radioitems-inline' : undefined,
42
+ inputStyle,
43
+ inputClassName,
44
+ labelStyle,
45
+ labelClassName,
46
+ };
47
+
48
+ return (
49
+ <LoadingElement>
50
+ {loadingProps => (
51
+ <OptionsList
52
+ {...loadingProps}
53
+ inputType="radio"
54
+ options={sanitizedOptions}
55
+ selected={isNil(value) ? [] : [value]}
56
+ onSelectionChange={selection => {
57
+ setProps({value: selection[selection.length - 1]});
58
+ }}
59
+ {...stylingProps}
60
+ />
61
+ )}
62
+ </LoadingElement>
63
+ );
64
+ }
65
+
66
+ RadioItems.dashPersistence = {
67
+ persisted_props: [PersistedProps.value],
68
+ persistence_type: PersistenceTypes.local,
69
+ };
@@ -18,9 +18,20 @@ export default function RangeSlider({
18
18
  persistence_type = PersistenceTypes.local,
19
19
  // eslint-disable-next-line no-magic-numbers
20
20
  verticalHeight = 400,
21
- step = 1,
21
+ step = undefined,
22
22
  ...props
23
23
  }: RangeSliderProps) {
24
+ // Some considerations for the default value of `step`:
25
+ // If the range consists of integers, default to a value of `1`
26
+ // Otherwise, leave it undefined
27
+ if (
28
+ typeof step === 'undefined' &&
29
+ Number.isInteger(props.min) &&
30
+ Number.isInteger(props.max)
31
+ ) {
32
+ step = 1;
33
+ }
34
+
24
35
  return (
25
36
  <Suspense fallback={null}>
26
37
  <RealRangeSlider
@@ -22,7 +22,7 @@ export default function Slider({
22
22
  persistence_type = PersistenceTypes.local,
23
23
  // eslint-disable-next-line no-magic-numbers
24
24
  verticalHeight = 400,
25
- step = 1,
25
+ step = undefined,
26
26
  setProps,
27
27
  value,
28
28
  drag_value,
@@ -31,6 +31,17 @@ export default function Slider({
31
31
  // This is actually a wrapper around a RangeSlider.
32
32
  // We'll modify key `Slider` props to be compatible with a Range Slider.
33
33
 
34
+ // Some considerations for the default value of `step`:
35
+ // If the range consists of integers, default to a value of `1`
36
+ // Otherwise, leave it undefined
37
+ if (
38
+ typeof step === 'undefined' &&
39
+ Number.isInteger(props.min) &&
40
+ Number.isInteger(props.max)
41
+ ) {
42
+ step = 1;
43
+ }
44
+
34
45
  const mappedValue: RangeSliderProps['value'] = useMemo(() => {
35
46
  return typeof value === 'number' ? [value] : value;
36
47
  }, [value]);
@@ -0,0 +1,79 @@
1
+ import React, {Fragment} from 'react';
2
+ import PropTypes from 'prop-types';
3
+
4
+ /**
5
+ * Part of dcc.Tabs - this is the child Tab component used to render a tabbed page.
6
+ * Its children will be set as the content of that tab, which if clicked will become visible.
7
+ */
8
+
9
+ /* eslint-disable no-unused-vars */
10
+ const Tab = ({
11
+ children,
12
+ disabled = false,
13
+ disabled_style = {color: '#d6d6d6'},
14
+ }) => <Fragment>{children}</Fragment>;
15
+ /* eslint-enable no-unused-vars */
16
+
17
+ // Default props are defined above for proper docstring generation in React 18.
18
+ // The actual default values are set in Tabs.react.js.
19
+
20
+ Tab.propTypes = {
21
+ /**
22
+ * The ID of this component, used to identify dash components
23
+ * in callbacks. The ID needs to be unique across all of the
24
+ * components in an app.
25
+ */
26
+ id: PropTypes.string,
27
+
28
+ /**
29
+ * The tab's label
30
+ */
31
+ label: PropTypes.string,
32
+
33
+ /**
34
+ * The content of the tab - will only be displayed if this tab is selected
35
+ */
36
+ children: PropTypes.node,
37
+
38
+ /**
39
+ * Value for determining which Tab is currently selected
40
+ */
41
+ value: PropTypes.string,
42
+
43
+ /**
44
+ * Determines if tab is disabled or not - defaults to false
45
+ */
46
+ disabled: PropTypes.bool,
47
+
48
+ /**
49
+ * Overrides the default (inline) styles when disabled
50
+ */
51
+ disabled_style: PropTypes.object,
52
+
53
+ /**
54
+ * Appends a class to the Tab component when it is disabled.
55
+ */
56
+ disabled_className: PropTypes.string,
57
+
58
+ /**
59
+ * Appends a class to the Tab component.
60
+ */
61
+ className: PropTypes.string,
62
+
63
+ /**
64
+ * Appends a class to the Tab component when it is selected.
65
+ */
66
+ selected_className: PropTypes.string,
67
+
68
+ /**
69
+ * Overrides the default (inline) styles for the Tab component.
70
+ */
71
+ style: PropTypes.object,
72
+
73
+ /**
74
+ * Overrides the default (inline) styles for the Tab component when it is selected.
75
+ */
76
+ selected_style: PropTypes.object,
77
+ };
78
+
79
+ export default Tab;