dash-core-components 4.0.0-rc2 → 4.0.0-rc3

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 (68) 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 -2
  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-graph.js.map +1 -1
  7. package/dash_core_components/async-highlight.js +1 -1
  8. package/dash_core_components/async-highlight.js.map +1 -1
  9. package/dash_core_components/async-markdown.js +1 -1
  10. package/dash_core_components/async-markdown.js.map +1 -1
  11. package/dash_core_components/async-mathjax.js +1 -1
  12. package/dash_core_components/async-slider.js +1 -1
  13. package/dash_core_components/async-slider.js.map +1 -1
  14. package/dash_core_components/async-upload.js +1 -1
  15. package/dash_core_components/async-upload.js.map +1 -1
  16. package/dash_core_components/dash_core_components-shared.js +1 -1
  17. package/dash_core_components/dash_core_components-shared.js.map +1 -1
  18. package/dash_core_components/dash_core_components.js +1 -1
  19. package/dash_core_components/dash_core_components.js.map +1 -1
  20. package/dash_core_components/proptypes.js +116 -12
  21. package/lib/components/Clipboard.react.js +1 -1
  22. package/lib/components/DatePickerRange.tsx +70 -0
  23. package/lib/components/DatePickerSingle.tsx +72 -0
  24. package/lib/components/Input.tsx +1 -1
  25. package/lib/components/Tab.tsx +19 -0
  26. package/lib/components/Tabs.tsx +311 -0
  27. package/lib/components/css/calendar.css +66 -0
  28. package/lib/components/css/datepickers.css +233 -0
  29. package/lib/components/css/dcc.css +1 -0
  30. package/lib/components/css/dropdown.css +6 -3
  31. package/lib/components/css/input.css +8 -2
  32. package/lib/components/css/sliders.css +22 -0
  33. package/lib/components/css/tabs.css +113 -0
  34. package/lib/fragments/DatePickerRange.tsx +444 -0
  35. package/lib/fragments/DatePickerSingle.tsx +249 -0
  36. package/lib/fragments/Dropdown.tsx +8 -4
  37. package/lib/fragments/Graph.react.js +18 -45
  38. package/lib/fragments/RangeSlider.tsx +2 -0
  39. package/lib/index.ts +4 -6
  40. package/lib/types.ts +353 -27
  41. package/lib/utils/DatePickerPersistence.ts +14 -0
  42. package/lib/utils/LazyLoader/datePickerRange.ts +4 -0
  43. package/lib/utils/LazyLoader/datePickerSingle.ts +4 -0
  44. package/lib/utils/calendar/Calendar.tsx +382 -0
  45. package/lib/utils/calendar/CalendarDay.tsx +75 -0
  46. package/lib/utils/calendar/CalendarDayPadding.tsx +15 -0
  47. package/lib/utils/calendar/CalendarMonth.tsx +247 -0
  48. package/lib/utils/calendar/CalendarMonthHeader.tsx +23 -0
  49. package/lib/utils/calendar/createMonthGrid.ts +28 -0
  50. package/lib/utils/calendar/helpers.ts +272 -0
  51. package/lib/utils/computeSliderMarkers.ts +71 -116
  52. package/lib/utils/optionRendering.tsx +22 -15
  53. package/lib/utils/sliderRendering.tsx +40 -2
  54. package/package.json +16 -13
  55. package/lib/components/DatePickerRange.react.js +0 -244
  56. package/lib/components/DatePickerSingle.react.js +0 -209
  57. package/lib/components/Dropdown.react.js.old +0 -228
  58. package/lib/components/Tab.react.js +0 -80
  59. package/lib/components/Tab.react.js.old +0 -79
  60. package/lib/components/Tabs.react.js +0 -295
  61. package/lib/components/Textarea.react.js.old +0 -287
  62. package/lib/fragments/DatePickerRange.react.js +0 -188
  63. package/lib/fragments/DatePickerSingle.react.js +0 -132
  64. package/lib/utils/DatePickerPersistence.js +0 -18
  65. package/lib/utils/LazyLoader/datePickerRange.js +0 -8
  66. package/lib/utils/LazyLoader/datePickerSingle.js +0 -8
  67. package/lib/utils/convertToMoment.js +0 -30
  68. package/lib/utils/optionTypes.js +0 -39
@@ -0,0 +1,249 @@
1
+ import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
2
+ import * as Popover from '@radix-ui/react-popover';
3
+ import {CalendarIcon, CaretDownIcon, Cross1Icon} from '@radix-ui/react-icons';
4
+ import AutosizeInput from 'react-input-autosize';
5
+ import uuid from 'uniqid';
6
+
7
+ import {CalendarDirection, DatePickerSingleProps} from '../types';
8
+ import Calendar, {CalendarHandle} from '../utils/calendar/Calendar';
9
+ import {
10
+ dateAsStr,
11
+ formatDate,
12
+ isDateDisabled,
13
+ isSameDay,
14
+ strAsDate,
15
+ } from '../utils/calendar/helpers';
16
+ import '../components/css/datepickers.css';
17
+
18
+ const DatePickerSingle = ({
19
+ id,
20
+ className,
21
+ date,
22
+ min_date_allowed,
23
+ max_date_allowed,
24
+ initial_visible_month = date ?? min_date_allowed,
25
+ disabled_days,
26
+ first_day_of_week,
27
+ show_outside_days,
28
+ placeholder = 'Select Date',
29
+ clearable,
30
+ reopen_calendar_on_clear,
31
+ disabled,
32
+ display_format,
33
+ month_format = 'MMMM YYYY',
34
+ stay_open_on_select,
35
+ is_RTL = false,
36
+ setProps,
37
+ style,
38
+ // eslint-disable-next-line no-magic-numbers
39
+ day_size = 34,
40
+ number_of_months_shown = 1,
41
+ calendar_orientation,
42
+ }: DatePickerSingleProps) => {
43
+ const [internalDate, setInternalDate] = useState(strAsDate(date));
44
+ const direction = is_RTL
45
+ ? CalendarDirection.RightToLeft
46
+ : CalendarDirection.LeftToRight;
47
+ const initialMonth = strAsDate(initial_visible_month) || internalDate;
48
+ const minDate = strAsDate(min_date_allowed);
49
+ const maxDate = strAsDate(max_date_allowed);
50
+ const disabledDates = useMemo(() => {
51
+ return disabled_days
52
+ ?.map(d => strAsDate(d))
53
+ .filter((d): d is Date => d !== undefined);
54
+ }, [disabled_days]);
55
+
56
+ const [isCalendarOpen, setIsCalendarOpen] = useState(false);
57
+ const [inputValue, setInputValue] = useState<string>(
58
+ (internalDate && formatDate(internalDate, display_format)) ?? ''
59
+ );
60
+
61
+ const containerRef = useRef<HTMLDivElement>(null);
62
+ const inputRef = useRef<HTMLInputElement | null>(null);
63
+ const calendarRef = useRef<CalendarHandle>(null);
64
+
65
+ useEffect(() => {
66
+ setInternalDate(strAsDate(date));
67
+ }, [date]);
68
+
69
+ useEffect(() => {
70
+ setInputValue(formatDate(internalDate, display_format));
71
+ }, [internalDate, display_format]);
72
+
73
+ useEffect(() => {
74
+ const dateChanged = !(date && isSameDay(date, internalDate));
75
+
76
+ if (dateChanged) {
77
+ setProps({date: dateAsStr(internalDate)});
78
+ }
79
+ }, [internalDate]);
80
+
81
+ const parseUserInput = useCallback(
82
+ (focusCalendar = false) => {
83
+ if (inputValue === '') {
84
+ setInternalDate(undefined);
85
+ }
86
+ const parsed = strAsDate(inputValue, display_format);
87
+ const isValid =
88
+ parsed &&
89
+ !isDateDisabled(parsed, minDate, maxDate, disabledDates);
90
+
91
+ if (isValid) {
92
+ setInternalDate(parsed);
93
+ if (focusCalendar) {
94
+ calendarRef.current?.focusDate(parsed);
95
+ } else {
96
+ calendarRef.current?.setVisibleDate(parsed);
97
+ }
98
+ } else {
99
+ // Invalid or disabled input: revert to previous valid date with proper formatting
100
+ const previousDate = strAsDate(date);
101
+ setInputValue(
102
+ previousDate ? formatDate(previousDate, display_format) : ''
103
+ );
104
+ if (focusCalendar) {
105
+ calendarRef.current?.focusDate(previousDate);
106
+ }
107
+ }
108
+ },
109
+ [inputValue, display_format, date, minDate, maxDate, disabledDates]
110
+ );
111
+
112
+ const clearSelection = useCallback(
113
+ (e: React.MouseEvent<HTMLAnchorElement>) => {
114
+ setInternalDate(undefined);
115
+ inputRef.current?.focus();
116
+ e.preventDefault();
117
+ e.stopPropagation();
118
+ if (reopen_calendar_on_clear) {
119
+ setIsCalendarOpen(true);
120
+ }
121
+ },
122
+ [reopen_calendar_on_clear]
123
+ );
124
+
125
+ const handleInputKeyDown = useCallback(
126
+ (e: React.KeyboardEvent<HTMLInputElement>) => {
127
+ if (['ArrowUp', 'ArrowDown'].includes(e.key)) {
128
+ e.preventDefault();
129
+ parseUserInput(true);
130
+ if (!isCalendarOpen) {
131
+ // open the calendar after resolving prop changes, so that
132
+ // it opens with the correct date showing
133
+ setTimeout(() => setIsCalendarOpen(true), 0);
134
+ }
135
+ } else if (['Enter', 'Tab'].includes(e.key)) {
136
+ parseUserInput();
137
+ }
138
+ },
139
+ [isCalendarOpen, parseUserInput]
140
+ );
141
+
142
+ const accessibleId = id ?? uuid();
143
+ let classNames = 'dash-datepicker-input-wrapper';
144
+ if (disabled) {
145
+ classNames += ' dash-datepicker-input-wrapper-disabled';
146
+ }
147
+ if (className) {
148
+ classNames += ' ' + className;
149
+ }
150
+
151
+ return (
152
+ <div className="dash-datepicker" ref={containerRef}>
153
+ <Popover.Root
154
+ open={!disabled && isCalendarOpen}
155
+ onOpenChange={disabled ? undefined : setIsCalendarOpen}
156
+ >
157
+ <Popover.Trigger asChild disabled={disabled}>
158
+ <div
159
+ id={accessibleId + '-wrapper'}
160
+ className={classNames}
161
+ style={style}
162
+ aria-labelledby={`${accessibleId}`}
163
+ aria-haspopup="dialog"
164
+ aria-expanded={isCalendarOpen}
165
+ aria-disabled={disabled}
166
+ onClick={e => {
167
+ e.preventDefault();
168
+ if (!isCalendarOpen && !disabled) {
169
+ setIsCalendarOpen(true);
170
+ }
171
+ }}
172
+ >
173
+ <CalendarIcon className="dash-datepicker-trigger-icon" />
174
+ <AutosizeInput
175
+ inputRef={node => {
176
+ inputRef.current = node;
177
+ }}
178
+ type="text"
179
+ id={accessibleId}
180
+ inputClassName="dash-datepicker-input dash-datepicker-end-date"
181
+ value={inputValue}
182
+ onChange={e => setInputValue(e.target.value)}
183
+ onKeyDown={handleInputKeyDown}
184
+ placeholder={placeholder}
185
+ disabled={disabled}
186
+ dir={direction}
187
+ aria-label={placeholder}
188
+ />
189
+ {clearable && !disabled && !!date && (
190
+ <a
191
+ className="dash-datepicker-clear"
192
+ onClick={clearSelection}
193
+ aria-label="Clear date"
194
+ >
195
+ <Cross1Icon />
196
+ </a>
197
+ )}
198
+
199
+ <CaretDownIcon className="dash-datepicker-caret-icon" />
200
+ </div>
201
+ </Popover.Trigger>
202
+
203
+ <Popover.Portal container={containerRef.current}>
204
+ <Popover.Content
205
+ className="dash-datepicker-content"
206
+ align="start"
207
+ sideOffset={5}
208
+ onOpenAutoFocus={e => e.preventDefault()}
209
+ onCloseAutoFocus={e => {
210
+ e.preventDefault();
211
+ // Only focus if focus is not already on the input
212
+ if (document.activeElement !== inputRef.current) {
213
+ inputRef.current?.focus();
214
+ }
215
+ }}
216
+ >
217
+ <Calendar
218
+ ref={calendarRef}
219
+ initialVisibleDate={initialMonth}
220
+ selectionStart={internalDate}
221
+ selectionEnd={internalDate}
222
+ minDateAllowed={minDate}
223
+ maxDateAllowed={maxDate}
224
+ disabledDates={disabledDates}
225
+ firstDayOfWeek={first_day_of_week}
226
+ showOutsideDays={show_outside_days}
227
+ monthFormat={month_format}
228
+ numberOfMonthsShown={number_of_months_shown}
229
+ calendarOrientation={calendar_orientation}
230
+ daySize={day_size}
231
+ direction={direction}
232
+ onSelectionChange={(_, selection) => {
233
+ if (!selection) {
234
+ return;
235
+ }
236
+ setInternalDate(selection);
237
+ if (!stay_open_on_select) {
238
+ setIsCalendarOpen(false);
239
+ }
240
+ }}
241
+ />
242
+ </Popover.Content>
243
+ </Popover.Portal>
244
+ </Popover.Root>
245
+ </div>
246
+ );
247
+ };
248
+
249
+ export default DatePickerSingle;
@@ -156,10 +156,12 @@ const Dropdown = (props: DropdownProps) => {
156
156
  option => option.value === val
157
157
  );
158
158
  return (
159
- <React.Fragment key={`${option?.value}-${i}`}>
159
+ <span
160
+ key={`${option?.value}-${i}`}
161
+ className="dash-dropdown-value-item"
162
+ >
160
163
  {option && <OptionLabel {...option} index={i} />}
161
- {i === sanitizedValues.length - 1 ? '' : ', '}
162
- </React.Fragment>
164
+ </span>
163
165
  );
164
166
  });
165
167
  return labels;
@@ -434,7 +436,9 @@ const Dropdown = (props: DropdownProps) => {
434
436
  onOpenAutoFocus={e => e.preventDefault()}
435
437
  onKeyDown={handleKeyDown}
436
438
  style={{
437
- maxHeight: maxHeight ? `${maxHeight}px` : 'auto',
439
+ maxHeight: maxHeight
440
+ ? `min(${maxHeight}px, calc(100vh - 100px))`
441
+ : 'calc(100vh - 100px)',
438
442
  }}
439
443
  >
440
444
  {searchable && (
@@ -335,6 +335,8 @@ class PlotlyGraph extends _react.Component {
335
335
  return;
336
336
  }
337
337
  gd.classList.add('dash-graph--pending');
338
+
339
+ // Calling resize enables layout.autosize in plotly.js
338
340
  Plotly.Plots.resize(gd).catch(() => {}).finally(() => gd.classList.remove('dash-graph--pending'));
339
341
  }
340
342
  bindEvents() {
@@ -405,26 +407,6 @@ class PlotlyGraph extends _react.Component {
405
407
  }
406
408
  });
407
409
  }
408
- getStyle() {
409
- var responsive = this.props.responsive;
410
- var style = this.props.style;
411
-
412
- // When there is no forced responsive style, return the original style property
413
- if (!responsive) {
414
- return style;
415
- }
416
-
417
- // Otherwise, if the height is not set, we make the graph size equal to the parent one
418
- if (!style) {
419
- style = {};
420
- }
421
- if (!style.height) {
422
- return Object.assign({
423
- height: '100%'
424
- }, style);
425
- }
426
- return style;
427
- }
428
410
  componentDidMount() {
429
411
  var p = this.plot(this.props);
430
412
  this._queue = this.amendTraces(p, {}, this.props);
@@ -465,34 +447,25 @@ class PlotlyGraph extends _react.Component {
465
447
  var _this$props2 = this.props,
466
448
  className = _this$props2.className,
467
449
  id = _this$props2.id,
468
- loading_state = _this$props2.loading_state;
469
- var style = this.getStyle();
470
- if (window.dash_component_api) {
471
- return /*#__PURE__*/_react.default.createElement(_LoadingElement.default, {
472
- id: id,
473
- key: id,
474
- className: className,
475
- style: style,
476
- ref: this.parentElement
477
- }, /*#__PURE__*/_react.default.createElement(_ResizeDetector.default, {
478
- onResize: this.graphResize,
479
- targets: [this.parentElement, this.gd]
480
- }), /*#__PURE__*/_react.default.createElement("div", {
481
- ref: this.gd,
482
- style: {
483
- height: '100%',
484
- width: '100%'
485
- }
486
- }));
450
+ loading_state = _this$props2.loading_state,
451
+ _this$props2$style = _this$props2.style,
452
+ style = _this$props2$style === void 0 ? {} : _this$props2$style;
453
+ if (this.isResponsive(this.props)) {
454
+ style.height || (style.height = '100%');
487
455
  }
488
- return /*#__PURE__*/_react.default.createElement("div", {
489
- id: id,
456
+ var Container = _LoadingElement.default;
457
+ var containerProps = {
458
+ className,
459
+ id,
490
460
  key: id,
491
- className: className,
492
- style: style,
493
461
  ref: this.parentElement,
494
- "data-dash-is-loading": loading_state && loading_state.is_loading || undefined
495
- }, /*#__PURE__*/_react.default.createElement(_ResizeDetector.default, {
462
+ style
463
+ };
464
+ if (!window.dash_component_api) {
465
+ Container = 'div';
466
+ containerProps['data-dash-is-loading'] = (loading_state === null || loading_state === void 0 ? void 0 : loading_state.is_loading) || undefined;
467
+ }
468
+ return /*#__PURE__*/_react.default.createElement(Container, containerProps, /*#__PURE__*/_react.default.createElement(_ResizeDetector.default, {
496
469
  onResize: this.graphResize,
497
470
  targets: [this.parentElement, this.gd]
498
471
  }), /*#__PURE__*/_react.default.createElement("div", {
@@ -500,6 +500,7 @@ export default function RangeSlider(props: RangeSliderProps) {
500
500
  renderedMarks,
501
501
  !!vertical,
502
502
  minMaxValues,
503
+ value,
503
504
  !!dots,
504
505
  !!reverse
505
506
  )}
@@ -508,6 +509,7 @@ export default function RangeSlider(props: RangeSliderProps) {
508
509
  renderSliderDots(
509
510
  stepValue,
510
511
  minMaxValues,
512
+ value,
511
513
  !!vertical,
512
514
  !!reverse
513
515
  )}
package/lib/index.ts CHANGED
@@ -3,8 +3,8 @@ import Checklist from './components/Checklist';
3
3
  import Clipboard from './components/Clipboard.react';
4
4
  import ConfirmDialog from './components/ConfirmDialog.react';
5
5
  import ConfirmDialogProvider from './components/ConfirmDialogProvider.react';
6
- import DatePickerRange from './components/DatePickerRange.react';
7
- import DatePickerSingle from './components/DatePickerSingle.react';
6
+ import DatePickerRange from './components/DatePickerRange';
7
+ import DatePickerSingle from './components/DatePickerSingle';
8
8
  import Download from './components/Download.react';
9
9
  import Dropdown from './components/Dropdown';
10
10
  import Geolocation from './components/Geolocation.react';
@@ -19,15 +19,13 @@ import RadioItems from './components/RadioItems';
19
19
  import RangeSlider from './components/RangeSlider';
20
20
  import Slider from './components/Slider';
21
21
  import Store from './components/Store.react';
22
- import Tab from './components/Tab.react';
23
- import Tabs from './components/Tabs.react';
22
+ import Tab from './components/Tab';
23
+ import Tabs from './components/Tabs';
24
24
  import Textarea from './components/Textarea';
25
25
  import Tooltip from './components/Tooltip';
26
26
  import Upload from './components/Upload.react';
27
27
 
28
28
  import './components/css/dcc.css';
29
- import 'react-dates/lib/css/_datepicker.css';
30
- import './components/css/react-dates@20.1.0-fix.css';
31
29
 
32
30
  export {
33
31
  Checklist,