dash-core-components 3.2.0 → 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.
Files changed (60) 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-highlight.js +1 -1
  7. package/dash_core_components/async-highlight.js.map +1 -1
  8. package/dash_core_components/async-markdown.js +1 -1
  9. package/dash_core_components/async-markdown.js.map +1 -1
  10. package/dash_core_components/async-slider.js +1 -2
  11. package/dash_core_components/async-slider.js.map +1 -1
  12. package/dash_core_components/dash_core_components-shared.js +1 -1
  13. package/dash_core_components/dash_core_components-shared.js.map +1 -1
  14. package/dash_core_components/dash_core_components.js +1 -1
  15. package/dash_core_components/dash_core_components.js.map +1 -1
  16. package/dash_core_components/plotly.min.js +8 -0
  17. package/dash_core_components/proptypes.js +99 -0
  18. package/lib/components/Dropdown.react.js.old +228 -0
  19. package/lib/components/Dropdown.tsx +52 -0
  20. package/lib/components/Input.react.js.old +507 -0
  21. package/lib/components/Input.tsx +543 -0
  22. package/lib/components/RangeSlider.tsx +46 -0
  23. package/lib/components/Slider.react.js.old +214 -0
  24. package/lib/components/Slider.tsx +81 -0
  25. package/lib/components/Textarea.react.js.old +287 -0
  26. package/lib/components/css/dcc.css +14 -0
  27. package/lib/components/css/dropdown.css +230 -0
  28. package/lib/components/css/input.css +116 -2
  29. package/lib/components/css/react-select@1.0.0-rc.3.min.css +1 -1
  30. package/lib/components/css/sliders.css +206 -4
  31. package/lib/fragments/Dropdown.tsx +577 -0
  32. package/lib/fragments/RangeSlider.tsx +412 -0
  33. package/lib/index.ts +58 -0
  34. package/lib/types.ts +499 -0
  35. package/lib/utils/LazyLoader/dropdown.ts +2 -0
  36. package/lib/utils/LazyLoader/rangeSlider.ts +2 -0
  37. package/lib/utils/LazyLoader/slider.ts +2 -0
  38. package/lib/utils/_LoadingElement.tsx +26 -0
  39. package/lib/utils/computeSliderMarkers.ts +302 -0
  40. package/lib/utils/dropdownSearch.ts +92 -0
  41. package/lib/utils/formatSliderTooltip.ts +20 -0
  42. package/lib/utils/optionTypes.ts +27 -0
  43. package/lib/utils/sliderRendering.tsx +144 -0
  44. package/lib/utils/sliderSnapToMark.ts +17 -0
  45. package/lib/utils/sliderTooltip.tsx +65 -0
  46. package/package.json +27 -5
  47. package/lib/components/Dropdown.react.js +0 -182
  48. package/lib/components/Input.react.js +0 -403
  49. package/lib/components/RangeSlider.react.js +0 -194
  50. package/lib/components/Slider.react.js +0 -179
  51. package/lib/fragments/Dropdown.react.js +0 -158
  52. package/lib/fragments/RangeSlider.react.js +0 -143
  53. package/lib/fragments/Slider.react.js +0 -159
  54. package/lib/index.js +0 -183
  55. package/lib/utils/LazyLoader/dropdown.js +0 -8
  56. package/lib/utils/LazyLoader/rangeSlider.js +0 -8
  57. package/lib/utils/LazyLoader/slider.js +0 -8
  58. package/lib/utils/computeSliderMarkers.js +0 -153
  59. package/lib/utils/computeSliderStyle.js +0 -26
  60. package/lib/utils/formatSliderTooltip.js +0 -19
package/lib/types.ts ADDED
@@ -0,0 +1,499 @@
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
+
15
+ export enum PersistenceTypes {
16
+ 'local' = 'local',
17
+ 'session' = 'session',
18
+ 'memory' = 'memory',
19
+ }
20
+
21
+ export enum PersistedProps {
22
+ 'value' = 'value',
23
+ }
24
+
25
+ export type SliderMarks = {
26
+ [key: number]: string | {label: string; style?: React.CSSProperties};
27
+ };
28
+
29
+ export type SliderTooltip = {
30
+ /**
31
+ * Determines whether tooltips should always be visible
32
+ * (as opposed to the default, visible on hover)
33
+ */
34
+ always_visible?: boolean;
35
+
36
+ /**
37
+ * Determines the placement of tooltips
38
+ * See https://github.com/react-component/tooltip#api
39
+ * top/bottom{*} sets the _origin_ of the tooltip, so e.g. `topLeft`
40
+ * will in reality appear to be on the top right of the handle
41
+ */
42
+ placement?:
43
+ | 'left'
44
+ | 'right'
45
+ | 'top'
46
+ | 'bottom'
47
+ | 'topLeft'
48
+ | 'topRight'
49
+ | 'bottomLeft'
50
+ | 'bottomRight';
51
+
52
+ /**
53
+ * Template string to display the tooltip in.
54
+ * Must contain `{value}`, which will be replaced with either
55
+ * the default string representation of the value or the result of the
56
+ * transform function if there is one.
57
+ */
58
+ template?: string;
59
+
60
+ /**
61
+ * Custom style for the tooltip.
62
+ */
63
+ style?: React.CSSProperties;
64
+
65
+ /**
66
+ * Reference to a function in the `window.dccFunctions` namespace.
67
+ * This can be added in a script in the asset folder.
68
+ *
69
+ * For example, in `assets/tooltip.js`:
70
+ * ```
71
+ * window.dccFunctions = window.dccFunctions || {};
72
+ * window.dccFunctions.multByTen = function(value) {
73
+ * return value * 10;
74
+ * }
75
+ * ```
76
+ * Then in the component `tooltip={'transform': 'multByTen'}`
77
+ */
78
+ transform?: string;
79
+ };
80
+
81
+ export interface SliderProps {
82
+ /**
83
+ * Minimum allowed value of the slider
84
+ */
85
+ min?: number;
86
+
87
+ /**
88
+ * Maximum allowed value of the slider
89
+ */
90
+ max?: number;
91
+
92
+ /**
93
+ * Value by which increments or decrements are made
94
+ */
95
+ step?: number | null;
96
+
97
+ /**
98
+ * Marks on the slider.
99
+ * The key determines the position (a number),
100
+ * and the value determines what will show.
101
+ * If you want to set the style of a specific mark point,
102
+ * the value should be an object which
103
+ * contains style and label properties.
104
+ */
105
+ marks?: SliderMarks | null;
106
+
107
+ /**
108
+ * The value of the input
109
+ */
110
+ value?: number | null;
111
+
112
+ /**
113
+ * The value of the input during a drag
114
+ */
115
+ drag_value?: number;
116
+
117
+ /**
118
+ * If true, the handles can't be moved.
119
+ */
120
+ disabled?: boolean;
121
+
122
+ /**
123
+ * When the step value is greater than 1,
124
+ * you can set the dots to true if you want to
125
+ * render the slider with dots.
126
+ */
127
+ dots?: boolean;
128
+
129
+ /**
130
+ * If the value is true, it means a continuous
131
+ * value is included. Otherwise, it is an independent value.
132
+ */
133
+ included?: boolean;
134
+
135
+ /**
136
+ * Configuration for tooltips describing the current slider value
137
+ */
138
+ tooltip?: SliderTooltip;
139
+
140
+ /**
141
+ * Determines when the component should update its `value`
142
+ * property. If `mouseup` (the default) then the slider
143
+ * will only trigger its value when the user has finished
144
+ * dragging the slider. If `drag`, then the slider will
145
+ * update its value continuously as it is being dragged.
146
+ * If you want different actions during and after drag,
147
+ * leave `updatemode` as `mouseup` and use `drag_value`
148
+ * for the continuously updating value.
149
+ */
150
+ updatemode?: 'mouseup' | 'drag';
151
+
152
+ /**
153
+ * If true, the slider will be vertical
154
+ */
155
+ vertical?: boolean;
156
+
157
+ /**
158
+ * The height, in px, of the slider if it is vertical.
159
+ */
160
+ verticalHeight?: number;
161
+
162
+ /**
163
+ * Additional CSS class for the root DOM node
164
+ */
165
+ className?: string;
166
+
167
+ /**
168
+ * The ID of this component, used to identify dash components
169
+ * in callbacks. The ID needs to be unique across all of the
170
+ * components in an app.
171
+ */
172
+ id?: string;
173
+
174
+ /**
175
+ * Dash-assigned callback that gets fired when the value or drag_value changes.
176
+ */
177
+ setProps: (props: Partial<SliderProps>) => void;
178
+
179
+ /**
180
+ * Used to allow user interactions in this component to be persisted when
181
+ * the component - or the page - is refreshed. If `persisted` is truthy and
182
+ * hasn't changed from its previous value, a `value` that the user has
183
+ * changed while using the app will keep that change, as long as
184
+ * the new `value` also matches what was given originally.
185
+ * Used in conjunction with `persistence_type`.
186
+ */
187
+ persistence?: boolean | string | number;
188
+
189
+ /**
190
+ * Properties whose user interactions will persist after refreshing the
191
+ * component or the page. Since only `value` is allowed this prop can
192
+ * normally be ignored.
193
+ */
194
+ persisted_props?: PersistedProps[];
195
+
196
+ /**
197
+ * Where persisted user changes will be stored:
198
+ * memory: only kept in memory, reset on page refresh.
199
+ * local: window.localStorage, data is kept after the browser quit.
200
+ * session: window.sessionStorage, data is cleared once the browser quit.
201
+ */
202
+ persistence_type?: PersistenceTypes;
203
+ }
204
+
205
+ export interface RangeSliderProps {
206
+ /**
207
+ * Minimum allowed value of the slider
208
+ */
209
+ min?: number;
210
+
211
+ /**
212
+ * Maximum allowed value of the slider
213
+ */
214
+ max?: number;
215
+
216
+ /**
217
+ * Value by which increments or decrements are made
218
+ */
219
+ step?: number | null;
220
+
221
+ /**
222
+ * Marks on the slider.
223
+ * The key determines the position (a number),
224
+ * and the value determines what will show.
225
+ * If you want to set the style of a specific mark point,
226
+ * the value should be an object which
227
+ * contains style and label properties.
228
+ */
229
+ marks?: SliderMarks | null;
230
+
231
+ /**
232
+ * The value of the input
233
+ */
234
+ value?: number[] | null;
235
+
236
+ /**
237
+ * The value of the input during a drag
238
+ */
239
+ drag_value?: number[];
240
+
241
+ /**
242
+ * allowCross could be set as true to allow those handles to cross.
243
+ */
244
+ allowCross?: boolean;
245
+
246
+ /**
247
+ * pushable could be set as true to allow pushing of
248
+ * surrounding handles when moving an handle.
249
+ * When set to a number, the number will be the
250
+ * minimum ensured distance between handles.
251
+ */
252
+ pushable?: boolean | number;
253
+
254
+ /**
255
+ * If true, the handles can't be moved.
256
+ */
257
+ disabled?: boolean;
258
+
259
+ /**
260
+ * Determine how many ranges to render, and multiple handles
261
+ * will be rendered (number + 1).
262
+ */
263
+ count?: number;
264
+
265
+ /**
266
+ * When the step value is greater than 1,
267
+ * you can set the dots to true if you want to
268
+ * render the slider with dots.
269
+ */
270
+ dots?: boolean;
271
+
272
+ /**
273
+ * If the value is true, it means a continuous
274
+ * value is included. Otherwise, it is an independent value.
275
+ */
276
+ included?: boolean;
277
+
278
+ /**
279
+ * Configuration for tooltips describing the current slider values
280
+ */
281
+ tooltip?: SliderTooltip;
282
+
283
+ /**
284
+ * Determines when the component should update its `value`
285
+ * property. If `mouseup` (the default) then the slider
286
+ * will only trigger its value when the user has finished
287
+ * dragging the slider. If `drag`, then the slider will
288
+ * update its value continuously as it is being dragged.
289
+ * Note that for the latter case, the `drag_value`
290
+ * property could be used instead.
291
+ */
292
+ updatemode?: 'mouseup' | 'drag';
293
+
294
+ /**
295
+ * If true, the slider will be vertical
296
+ */
297
+ vertical?: boolean;
298
+
299
+ /**
300
+ * The height, in px, of the slider if it is vertical.
301
+ */
302
+ verticalHeight?: number;
303
+
304
+ /**
305
+ * Additional CSS class for the root DOM node
306
+ */
307
+ className?: string;
308
+
309
+ /**
310
+ * The ID of this component, used to identify dash components
311
+ * in callbacks. The ID needs to be unique across all of the
312
+ * components in an app.
313
+ */
314
+ id?: string;
315
+
316
+ /**
317
+ * Dash-assigned callback that gets fired when the value or drag_value changes.
318
+ */
319
+ setProps: (props: Partial<RangeSliderProps>) => void;
320
+
321
+ /**
322
+ * Used to allow user interactions in this component to be persisted when
323
+ * the component - or the page - is refreshed. If `persisted` is truthy and
324
+ * hasn't changed from its previous value, a `value` that the user has
325
+ * changed while using the app will keep that change, as long as
326
+ * the new `value` also matches what was given originally.
327
+ * Used in conjunction with `persistence_type`.
328
+ */
329
+ persistence?: boolean | string | number;
330
+
331
+ /**
332
+ * Properties whose user interactions will persist after refreshing the
333
+ * component or the page. Since only `value` is allowed this prop can
334
+ * normally be ignored.
335
+ */
336
+ persisted_props?: PersistedProps[];
337
+
338
+ /**
339
+ * Where persisted user changes will be stored:
340
+ * memory: only kept in memory, reset on page refresh.
341
+ * local: window.localStorage, data is kept after the browser quit.
342
+ * session: window.sessionStorage, data is cleared once the browser quit.
343
+ */
344
+ persistence_type?: PersistenceTypes;
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
+ }
@@ -0,0 +1,2 @@
1
+ export default () =>
2
+ import(/* webpackChunkName: "dropdown" */ '../../fragments/Dropdown');
@@ -0,0 +1,2 @@
1
+ export default () =>
2
+ import(/* webpackChunkName: "slider" */ '../../fragments/RangeSlider');
@@ -0,0 +1,2 @@
1
+ export default () =>
2
+ import(/* webpackChunkName: "slider" */ '../../fragments/Slider');
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+
3
+ interface LoadingElementProps {
4
+ children: (props: Record<string, unknown>) => React.ReactElement;
5
+ }
6
+
7
+ /**
8
+ * The loading element is used to add `data-dash-is-loading` attribute
9
+ * on html elements. This is used to customize CSS when a component is
10
+ * loading.
11
+ *
12
+ * See: https://dash.plotly.com/loading-states#check-loading-states-from-components
13
+ */
14
+ function LoadingElement({children}: LoadingElementProps) {
15
+ const ctx = window.dash_component_api.useDashContext();
16
+ const loading = ctx.useLoading();
17
+
18
+ const additionalProps: Record<string, unknown> = {};
19
+ if (loading) {
20
+ additionalProps['data-dash-is-loading'] = true;
21
+ }
22
+
23
+ return children(additionalProps);
24
+ }
25
+
26
+ export default LoadingElement;