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
package/lib/types.ts CHANGED
@@ -1,16 +1,5 @@
1
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
- }
2
+ import {BaseDashProps, DashComponent} from '@dash-renderer/types';
14
3
 
15
4
  export enum PersistenceTypes {
16
5
  'local' = 'local',
@@ -20,16 +9,13 @@ export enum PersistenceTypes {
20
9
 
21
10
  export enum PersistedProps {
22
11
  'value' = 'value',
12
+ 'date' = 'date',
13
+ 'start_date' = 'start_date',
14
+ 'end_date' = 'end_date',
23
15
  }
24
16
 
25
- export interface BaseComponentProps<T> {
26
- /**
27
- * The ID of this component, used to identify dash components
28
- * in callbacks. The ID needs to be unique across all of the
29
- * components in an app.
30
- */
31
- id?: string;
32
-
17
+ export interface BaseDccProps<T>
18
+ extends Pick<BaseDashProps, 'id' | 'componentPath'> {
33
19
  /**
34
20
  * Additional CSS class for the root DOM node
35
21
  */
@@ -122,7 +108,7 @@ export type SliderTooltip = {
122
108
  transform?: string;
123
109
  };
124
110
 
125
- export interface SliderProps extends BaseComponentProps<SliderProps> {
111
+ export interface SliderProps extends BaseDccProps<SliderProps> {
126
112
  /**
127
113
  * Minimum allowed value of the slider
128
114
  */
@@ -209,7 +195,7 @@ export interface SliderProps extends BaseComponentProps<SliderProps> {
209
195
  verticalHeight?: number;
210
196
  }
211
197
 
212
- export interface RangeSliderProps extends BaseComponentProps<RangeSliderProps> {
198
+ export interface RangeSliderProps extends BaseDccProps<RangeSliderProps> {
213
199
  /**
214
200
  * Minimum allowed value of the slider
215
201
  */
@@ -356,7 +342,7 @@ export type OptionsArray = (OptionValue | DetailedOption)[];
356
342
  */
357
343
  export type OptionsDict = Record<string, string>;
358
344
 
359
- export interface DropdownProps extends BaseComponentProps<DropdownProps> {
345
+ export interface DropdownProps extends BaseDccProps<DropdownProps> {
360
346
  /**
361
347
  * An array of options {label: [string|number], value: [string|number]},
362
348
  * an optional disabled field can be used for each option
@@ -439,7 +425,7 @@ export interface DropdownProps extends BaseComponentProps<DropdownProps> {
439
425
  };
440
426
  }
441
427
 
442
- export interface ChecklistProps extends BaseComponentProps<ChecklistProps> {
428
+ export interface ChecklistProps extends BaseDccProps<ChecklistProps> {
443
429
  /**
444
430
  * An array of options
445
431
  */
@@ -484,7 +470,7 @@ export interface ChecklistProps extends BaseComponentProps<ChecklistProps> {
484
470
  labelClassName?: string;
485
471
  }
486
472
 
487
- export interface RadioItemsProps extends BaseComponentProps<RadioItemsProps> {
473
+ export interface RadioItemsProps extends BaseDccProps<RadioItemsProps> {
488
474
  /**
489
475
  * An array of options
490
476
  */
@@ -529,7 +515,7 @@ export interface RadioItemsProps extends BaseComponentProps<RadioItemsProps> {
529
515
  labelClassName?: string;
530
516
  }
531
517
 
532
- export interface TextAreaProps extends BaseComponentProps<TextAreaProps> {
518
+ export interface TextAreaProps extends BaseDccProps<TextAreaProps> {
533
519
  /**
534
520
  * The value of the textarea
535
521
  */
@@ -753,7 +739,7 @@ export interface TooltipProps {
753
739
  setProps: (props: Partial<TooltipProps>) => void;
754
740
  }
755
741
 
756
- export interface LoadingProps extends BaseComponentProps<LoadingProps> {
742
+ export interface LoadingProps extends BaseDccProps<LoadingProps> {
757
743
  /**
758
744
  * Array that holds components to render
759
745
  */
@@ -836,3 +822,343 @@ export interface LoadingProps extends BaseComponentProps<LoadingProps> {
836
822
  */
837
823
  custom_spinner?: React.ReactNode;
838
824
  }
825
+
826
+ export interface TabsProps extends BaseDccProps<TabsProps> {
827
+ /**
828
+ * The value of the currently selected Tab
829
+ */
830
+ value?: string;
831
+
832
+ /**
833
+ * Appends a class to the Tab content container holding the children of the Tab that is selected.
834
+ */
835
+ content_className?: string;
836
+
837
+ /**
838
+ * Appends a class to the top-level parent container holding both the Tabs container and the content container.
839
+ */
840
+ parent_className?: string;
841
+
842
+ /**
843
+ * Appends (inline) styles to the Tabs container holding the individual Tab components.
844
+ */
845
+ style?: React.CSSProperties;
846
+
847
+ /**
848
+ * Appends (inline) styles to the top-level parent container holding both the Tabs container and the content container.
849
+ */
850
+ parent_style?: React.CSSProperties;
851
+
852
+ /**
853
+ * Appends (inline) styles to the tab content container holding the children of the Tab that is selected.
854
+ */
855
+ content_style?: React.CSSProperties;
856
+
857
+ /**
858
+ * Renders the tabs vertically (on the side)
859
+ */
860
+ vertical?: boolean;
861
+
862
+ /**
863
+ * Breakpoint at which tabs are rendered full width (can be 0 if you don't want full width tabs on mobile)
864
+ */
865
+ mobile_breakpoint?: number;
866
+
867
+ /**
868
+ * Array that holds Tab components
869
+ */
870
+ children?: DashComponent;
871
+
872
+ /**
873
+ * Holds the colors used by the Tabs and Tab components. If you set these, you should specify colors for all properties, so:
874
+ * colors: {
875
+ * border: '#d6d6d6',
876
+ * primary: '#1975FA',
877
+ * background: '#f9f9f9'
878
+ * }
879
+ */
880
+ colors?: {
881
+ border: string;
882
+ primary: string;
883
+ background: string;
884
+ };
885
+ }
886
+
887
+ // Note a quirk in how this extends the BaseDccProps: `setProps` is shared
888
+ // with `TabsProps` (plural!) due to how tabs are implemented. This is
889
+ // intentional.
890
+ export interface TabProps extends BaseDccProps<TabsProps> {
891
+ /**
892
+ * The tab's label
893
+ */
894
+ label?: string | DashComponent;
895
+
896
+ /**
897
+ * The content of the tab - will only be displayed if this tab is selected
898
+ */
899
+ children?: DashComponent;
900
+
901
+ /**
902
+ * Value for determining which Tab is currently selected
903
+ */
904
+ value?: string;
905
+
906
+ /**
907
+ * Determines if tab is disabled or not - defaults to false
908
+ */
909
+ disabled?: boolean;
910
+
911
+ /**
912
+ * Overrides the default (inline) styles when disabled
913
+ */
914
+ disabled_style?: React.CSSProperties;
915
+
916
+ /**
917
+ * Appends a class to the Tab component when it is disabled.
918
+ */
919
+ disabled_className?: string;
920
+
921
+ /**
922
+ * Appends a class to the Tab component.
923
+ */
924
+ className?: string;
925
+
926
+ /**
927
+ * Appends a class to the Tab component when it is selected.
928
+ */
929
+ selected_className?: string;
930
+
931
+ /**
932
+ * Overrides the default (inline) styles for the Tab component.
933
+ */
934
+ style?: React.CSSProperties;
935
+
936
+ /**
937
+ * Overrides the default (inline) styles for the Tab component when it is selected.
938
+ */
939
+ selected_style?: React.CSSProperties;
940
+
941
+ /**
942
+ * A custom width for this tab, in the format of `50px` or `50%`; numbers
943
+ * are treated as pixel values. By default, there is no width and this Tab
944
+ * is evenly spaced along with all the other tabs to occupy the available
945
+ * space. Setting this value will "fix" this tab width to the given size.
946
+ * while the other "non-fixed" tabs will continue to automatically
947
+ * occupying the remaining available space.
948
+ * This property has no effect when tabs are displayed vertically.
949
+ */
950
+ width?: string | number;
951
+ }
952
+
953
+ export enum DayOfWeek {
954
+ Sunday = 0,
955
+ Monday = 1,
956
+ Tuesday = 2,
957
+ Wednesday = 3,
958
+ Thursday = 4,
959
+ Friday = 5,
960
+ Saturday = 6,
961
+ }
962
+
963
+ export enum CalendarDirection {
964
+ LeftToRight = 'ltr',
965
+ RightToLeft = 'rtl',
966
+ }
967
+
968
+ export interface DatePickerSingleProps
969
+ extends BaseDccProps<DatePickerSingleProps> {
970
+ /**
971
+ * Specifies the starting date for the component, best practice is to pass
972
+ * value via datetime object
973
+ */
974
+ date?: `${string}-${string}-${string}`;
975
+
976
+ /**
977
+ * Specifies the lowest selectable date for the component.
978
+ * Accepts datetime.datetime objects or strings
979
+ * in the format 'YYYY-MM-DD'
980
+ */
981
+ min_date_allowed?: string;
982
+
983
+ /**
984
+ * Specifies the highest selectable date for the component.
985
+ * Accepts datetime.datetime objects or strings
986
+ * in the format 'YYYY-MM-DD'
987
+ */
988
+ max_date_allowed?: string;
989
+
990
+ /**
991
+ * Specifies additional days between min_date_allowed and max_date_allowed
992
+ * that should be disabled. Accepted datetime.datetime objects or strings
993
+ * in the format 'YYYY-MM-DD'
994
+ */
995
+ disabled_days?: string[];
996
+
997
+ /**
998
+ * Text that will be displayed in the input
999
+ * box of the date picker when no date is selected.
1000
+ */
1001
+ placeholder?: string;
1002
+
1003
+ /**
1004
+ * Specifies the month that is initially presented when the user
1005
+ * opens the calendar. Accepts datetime.datetime objects or strings
1006
+ * in the format 'YYYY-MM-DD'
1007
+ *
1008
+ */
1009
+ initial_visible_month?: string;
1010
+
1011
+ /**
1012
+ * Whether or not the dropdown is "clearable", that is, whether or
1013
+ * not a small "x" appears on the right of the dropdown that removes
1014
+ * the selected value.
1015
+ */
1016
+ clearable?: boolean;
1017
+
1018
+ /**
1019
+ * If True, the calendar will automatically open when cleared
1020
+ */
1021
+ reopen_calendar_on_clear?: boolean;
1022
+
1023
+ /**
1024
+ * Specifies the format that the selected dates will be displayed
1025
+ * valid formats are variations of "MM YY DD". For example:
1026
+ * "MM YY DD" renders as '05 10 97' for May 10th 1997
1027
+ * "MMMM, YY" renders as 'May, 1997' for May 10th 1997
1028
+ * "M, D, YYYY" renders as '07, 10, 1997' for September 10th 1997
1029
+ * "MMMM" renders as 'May' for May 10 1997
1030
+ */
1031
+ display_format?: string;
1032
+
1033
+ /**
1034
+ * Specifies the format that the month will be displayed in the calendar,
1035
+ * valid formats are variations of "MM YY". For example:
1036
+ * "MM YY" renders as '05 97' for May 1997
1037
+ * "MMMM, YYYY" renders as 'May, 1997' for May 1997
1038
+ * "MMM, YY" renders as 'Sep, 97' for September 1997
1039
+ */
1040
+ month_format?: string;
1041
+
1042
+ /**
1043
+ * Specifies what day is the first day of the week, values must be
1044
+ * from [0, ..., 6] with 0 denoting Sunday and 6 denoting Saturday
1045
+ */
1046
+ first_day_of_week?: DayOfWeek;
1047
+
1048
+ /**
1049
+ * If True the calendar will display days that rollover into
1050
+ * the next month
1051
+ */
1052
+ show_outside_days?: boolean;
1053
+
1054
+ /**
1055
+ * If True the calendar will not close when the user has selected a value
1056
+ * and will wait until the user clicks off the calendar
1057
+ */
1058
+ stay_open_on_select?: boolean;
1059
+
1060
+ /**
1061
+ * Orientation of calendar, either vertical or horizontal.
1062
+ * Valid options are 'vertical' or 'horizontal'.
1063
+ */
1064
+ calendar_orientation?: 'vertical' | 'horizontal';
1065
+
1066
+ /**
1067
+ * Number of calendar months that are shown when calendar is opened
1068
+ */
1069
+ number_of_months_shown?: number;
1070
+
1071
+ /**
1072
+ * If True, calendar will open in a screen overlay portal,
1073
+ * not supported on vertical calendar
1074
+ */
1075
+ with_portal?: boolean;
1076
+
1077
+ /**
1078
+ * If True, calendar will open in a full screen overlay portal, will
1079
+ * take precedent over 'withPortal' if both are set to True,
1080
+ * not supported on vertical calendar
1081
+ */
1082
+ with_full_screen_portal?: boolean;
1083
+
1084
+ /**
1085
+ * Size of rendered calendar days, higher number
1086
+ * means bigger day size and larger calendar overall
1087
+ */
1088
+ day_size?: number;
1089
+
1090
+ /**
1091
+ * Determines whether the calendar and days operate
1092
+ * from left to right or from right to left
1093
+ */
1094
+ is_RTL?: boolean;
1095
+
1096
+ /**
1097
+ * If True, no dates can be selected.
1098
+ */
1099
+ disabled?: boolean;
1100
+
1101
+ /**
1102
+ * CSS styles appended to wrapper div
1103
+ */
1104
+ style?: React.CSSProperties;
1105
+ }
1106
+
1107
+ export interface DatePickerRangeProps
1108
+ extends Omit<DatePickerSingleProps, 'date'> {
1109
+ /**
1110
+ * Specifies the starting date for the component.
1111
+ * Accepts datetime.datetime objects or strings
1112
+ * in the format 'YYYY-MM-DD'
1113
+ */
1114
+ start_date?: `${string}-${string}-${string}`;
1115
+
1116
+ /**
1117
+ * Specifies the ending date for the component.
1118
+ * Accepts datetime.datetime objects or strings
1119
+ * in the format 'YYYY-MM-DD'
1120
+ */
1121
+ end_date?: `${string}-${string}-${string}`;
1122
+
1123
+ /**
1124
+ * Specifies a minimum number of nights that must be selected between
1125
+ * the startDate and the endDate
1126
+ */
1127
+ minimum_nights?: number;
1128
+
1129
+ /**
1130
+ * Determines when the component should update
1131
+ * its value. If `bothdates`, then the DatePicker
1132
+ * will only trigger its value when the user has
1133
+ * finished picking both dates. If `singledate`, then
1134
+ * the DatePicker will update its value
1135
+ * as one date is picked.
1136
+ */
1137
+ updatemode?: 'singledate' | 'bothdates';
1138
+
1139
+ /**
1140
+ * Text that will be displayed in the first input
1141
+ * box of the date picker when no date is selected. Default value is 'Start Date'
1142
+ */
1143
+ start_date_placeholder_text?: string;
1144
+
1145
+ /**
1146
+ * Text that will be displayed in the second input
1147
+ * box of the date picker when no date is selected. Default value is 'End Date'
1148
+ */
1149
+ end_date_placeholder_text?: string;
1150
+
1151
+ /**
1152
+ * The HTML element ID of the start date input field.
1153
+ * Not used by Dash, only by CSS.
1154
+ */
1155
+ start_date_id?: string;
1156
+
1157
+ /**
1158
+ * The HTML element ID of the end date input field.
1159
+ * Not used by Dash, only by CSS.
1160
+ */
1161
+ end_date_id?: string;
1162
+
1163
+ setProps: (props: Partial<DatePickerRangeProps>) => void;
1164
+ }
@@ -0,0 +1,14 @@
1
+ import {format, startOfDay, parseISO} from 'date-fns';
2
+ import {isNil} from 'ramda';
3
+
4
+ export default {
5
+ extract: (propValue?: string) => {
6
+ if (isNil(propValue)) {
7
+ return propValue;
8
+ }
9
+
10
+ const parsed = parseISO(propValue);
11
+ return format(startOfDay(parsed), 'yyyy-MM-dd');
12
+ },
13
+ apply: (storedValue?: string) => storedValue,
14
+ };
@@ -0,0 +1,4 @@
1
+ export default () =>
2
+ import(
3
+ /* webpackChunkName: "datepicker" */ '../../fragments/DatePickerRange'
4
+ );
@@ -0,0 +1,4 @@
1
+ export default () =>
2
+ import(
3
+ /* webpackChunkName: "datepicker" */ '../../fragments/DatePickerSingle'
4
+ );