dash-core-components 4.0.0-rc1 → 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 (103) 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 +209 -6
  21. package/lib/components/Checklist.tsx +67 -0
  22. package/lib/components/Clipboard.react.js +1 -1
  23. package/lib/components/DatePickerRange.tsx +70 -0
  24. package/lib/components/DatePickerSingle.tsx +72 -0
  25. package/lib/components/Dropdown.tsx +19 -3
  26. package/lib/components/Input.tsx +1 -1
  27. package/lib/components/Loading.tsx +185 -0
  28. package/lib/components/RadioItems.tsx +69 -0
  29. package/lib/components/RangeSlider.tsx +5 -1
  30. package/lib/components/Slider.tsx +12 -1
  31. package/lib/components/Tab.tsx +19 -0
  32. package/lib/components/Tabs.tsx +311 -0
  33. package/lib/components/Textarea.tsx +79 -0
  34. package/lib/components/Tooltip.tsx +66 -0
  35. package/lib/components/css/calendar.css +66 -0
  36. package/lib/components/css/checklist.css +4 -0
  37. package/lib/components/css/datepickers.css +233 -0
  38. package/lib/components/css/dcc.css +3 -0
  39. package/lib/components/css/dropdown.css +34 -50
  40. package/lib/components/css/input.css +29 -7
  41. package/lib/components/css/optionslist.css +34 -0
  42. package/lib/components/css/radioitems.css +4 -0
  43. package/lib/components/css/sliders.css +33 -7
  44. package/lib/components/css/tabs.css +113 -0
  45. package/lib/components/css/textarea.css +21 -0
  46. package/lib/components/css/tooltip.css +127 -0
  47. package/lib/fragments/DatePickerRange.tsx +444 -0
  48. package/lib/fragments/DatePickerSingle.tsx +249 -0
  49. package/lib/fragments/Dropdown.tsx +212 -272
  50. package/lib/fragments/Graph.react.js +18 -45
  51. package/lib/fragments/Loading/spinners/CircleSpinner.tsx +185 -0
  52. package/lib/fragments/Loading/spinners/CubeSpinner.tsx +193 -0
  53. package/lib/fragments/Loading/spinners/DebugTitle.tsx +11 -0
  54. package/lib/fragments/Loading/spinners/DefaultSpinner.tsx +110 -0
  55. package/lib/fragments/Loading/spinners/DotSpinner.tsx +96 -0
  56. package/lib/fragments/Loading/spinners/GraphSpinner.tsx +332 -0
  57. package/lib/fragments/Loading/types.ts +13 -0
  58. package/lib/fragments/RangeSlider.tsx +195 -63
  59. package/lib/index.ts +9 -11
  60. package/lib/types.ts +797 -132
  61. package/lib/utils/DatePickerPersistence.ts +14 -0
  62. package/lib/utils/LazyLoader/datePickerRange.ts +4 -0
  63. package/lib/utils/LazyLoader/datePickerSingle.ts +4 -0
  64. package/lib/utils/calendar/Calendar.tsx +382 -0
  65. package/lib/utils/calendar/CalendarDay.tsx +75 -0
  66. package/lib/utils/calendar/CalendarDayPadding.tsx +15 -0
  67. package/lib/utils/calendar/CalendarMonth.tsx +247 -0
  68. package/lib/utils/calendar/CalendarMonthHeader.tsx +23 -0
  69. package/lib/utils/calendar/createMonthGrid.ts +28 -0
  70. package/lib/utils/calendar/helpers.ts +272 -0
  71. package/lib/utils/computeSliderMarkers.ts +71 -116
  72. package/lib/utils/dropdownSearch.ts +4 -4
  73. package/lib/utils/optionRendering.tsx +175 -0
  74. package/lib/utils/optionTypes.ts +5 -5
  75. package/lib/utils/sliderRendering.tsx +63 -6
  76. package/package.json +16 -14
  77. package/lib/components/Checklist.react.js +0 -193
  78. package/lib/components/DatePickerRange.react.js +0 -244
  79. package/lib/components/DatePickerSingle.react.js +0 -209
  80. package/lib/components/Dropdown.react.js.old +0 -228
  81. package/lib/components/Input.react.js.old +0 -507
  82. package/lib/components/Loading.react.js +0 -254
  83. package/lib/components/RadioItems.react.js +0 -192
  84. package/lib/components/Slider.react.js.old +0 -214
  85. package/lib/components/Tab.react.js +0 -80
  86. package/lib/components/Tabs.react.js +0 -295
  87. package/lib/components/Textarea.react.js +0 -223
  88. package/lib/components/Textarea.react.js.old +0 -287
  89. package/lib/components/Tooltip.react.js +0 -120
  90. package/lib/components/css/Dropdown.css +0 -8
  91. package/lib/fragments/DatePickerRange.react.js +0 -188
  92. package/lib/fragments/DatePickerSingle.react.js +0 -132
  93. package/lib/fragments/Loading/spinners/CircleSpinner.js +0 -68
  94. package/lib/fragments/Loading/spinners/CubeSpinner.js +0 -57
  95. package/lib/fragments/Loading/spinners/DebugTitle.js +0 -15
  96. package/lib/fragments/Loading/spinners/DefaultSpinner.js +0 -54
  97. package/lib/fragments/Loading/spinners/DotSpinner.js +0 -50
  98. package/lib/fragments/Loading/spinners/GraphSpinner.js +0 -68
  99. package/lib/utils/DatePickerPersistence.js +0 -18
  100. package/lib/utils/LazyLoader/datePickerRange.js +0 -8
  101. package/lib/utils/LazyLoader/datePickerSingle.js +0 -8
  102. package/lib/utils/convertToMoment.js +0 -30
  103. package/lib/utils/optionTypes.js +0 -39
@@ -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
+ };
@@ -24,7 +24,11 @@ export default function RangeSlider({
24
24
  // Some considerations for the default value of `step`:
25
25
  // If the range consists of integers, default to a value of `1`
26
26
  // Otherwise, leave it undefined
27
- if (Number.isInteger(props.min) && Number.isInteger(props.max)) {
27
+ if (
28
+ typeof step === 'undefined' &&
29
+ Number.isInteger(props.min) &&
30
+ Number.isInteger(props.max)
31
+ ) {
28
32
  step = 1;
29
33
  }
30
34
 
@@ -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,19 @@
1
+ import React from 'react';
2
+ import './css/tabs.css';
3
+ import {TabProps} from '../types';
4
+
5
+ /**
6
+ * Part of dcc.Tabs - this is the child Tab component used to render a tabbed page.
7
+ * Its children will be set as the content of that tab, which if clicked will become visible.
8
+ */
9
+ function Tab({
10
+ children,
11
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
12
+ disabled = false,
13
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
14
+ disabled_style = {color: 'var(--Dash-Text-Disabled)'},
15
+ }: TabProps) {
16
+ return <>{children}</>;
17
+ }
18
+
19
+ export default Tab;
@@ -0,0 +1,311 @@
1
+ import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
2
+ import {has, isNil} from 'ramda';
3
+
4
+ import LoadingElement from '../utils/_LoadingElement';
5
+ import {PersistedProps, PersistenceTypes, TabProps, TabsProps} from '../types';
6
+ import './css/tabs.css';
7
+ import {DashComponent} from '@dash-renderer/types';
8
+
9
+ interface EnhancedTabProps extends TabProps {
10
+ selected: boolean;
11
+ componentPath?: (string | number)[];
12
+ }
13
+
14
+ // EnhancedTab is defined here instead of in Tab.tsx because if exported there,
15
+ // it will mess up the Python imports and metadata.json
16
+ const EnhancedTab = ({
17
+ id,
18
+ label,
19
+ selected,
20
+ className,
21
+ style,
22
+ selected_className,
23
+ selected_style,
24
+ setProps: selectHandler,
25
+ value,
26
+ disabled = false,
27
+ disabled_style = {color: 'var(--Dash-Text-Disabled)'},
28
+ disabled_className,
29
+ componentPath,
30
+ }: EnhancedTabProps) => {
31
+ const ExternalWrapper = window.dash_component_api.ExternalWrapper;
32
+ const ctx = window.dash_component_api.useDashContext();
33
+ componentPath = componentPath ?? ctx.componentPath;
34
+ // We use the raw path here since it's up one level from
35
+ // the tabs child.
36
+ const isLoading = ctx.useLoading({rawPath: componentPath});
37
+ const tabStyle = useMemo(() => {
38
+ return {
39
+ ...style,
40
+ ...(disabled ? disabled_style : {}),
41
+ ...(selected ? selected_style : {}),
42
+ };
43
+ }, [style, disabled, disabled_style, selected, selected_style]);
44
+
45
+ const tabClassNames = useMemo(() => {
46
+ let names = 'tab';
47
+ if (disabled) {
48
+ names += ' tab--disabled';
49
+ if (disabled_className) {
50
+ names += ` ${disabled_className}`;
51
+ }
52
+ }
53
+ if (selected) {
54
+ names += ' tab--selected';
55
+ if (selected_className) {
56
+ names += ` ${selected_className}`;
57
+ }
58
+ }
59
+ if (className) {
60
+ names += ` ${className}`;
61
+ }
62
+ return names;
63
+ }, [className, disabled, disabled_className, selected, selected_className]);
64
+
65
+ let labelDisplay;
66
+ if (typeof label === 'object') {
67
+ labelDisplay = (
68
+ <ExternalWrapper
69
+ component={label}
70
+ componentPath={[...componentPath, 'props', 'label']}
71
+ />
72
+ );
73
+ } else {
74
+ labelDisplay = <span>{label}</span>;
75
+ }
76
+
77
+ return (
78
+ <div
79
+ data-dash-is-loading={isLoading}
80
+ className={tabClassNames}
81
+ id={id}
82
+ style={tabStyle}
83
+ onClick={() => {
84
+ if (!disabled) {
85
+ selectHandler({value});
86
+ }
87
+ }}
88
+ >
89
+ {labelDisplay}
90
+ </div>
91
+ );
92
+ };
93
+
94
+ /**
95
+ * A Dash component that lets you render pages with tabs - the Tabs component's children
96
+ * can be dcc.Tab components, which can hold a label that will be displayed as a tab, and can in turn hold
97
+ * children components that will be that tab's content.
98
+ */
99
+ function Tabs({
100
+ // eslint-disable-next-line no-magic-numbers
101
+ mobile_breakpoint = 800,
102
+ colors = {
103
+ border: 'var(--Dash-Stroke-Weak)',
104
+ primary: 'var(--Dash-Fill-Interactive-Strong)',
105
+ background: 'var(--Dash-Fill-Weak)',
106
+ },
107
+ vertical = false,
108
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
109
+ persisted_props = [PersistedProps.value],
110
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
111
+ persistence_type = PersistenceTypes.local,
112
+ children,
113
+ ...props
114
+ }: TabsProps) {
115
+ const initializedRef = useRef(false);
116
+ const [isAboveBreakpoint, setIsAboveBreakpoint] = useState(false);
117
+
118
+ const parseChildrenToArray = useCallback((): DashComponent[] => {
119
+ if (!children) {
120
+ return [];
121
+ }
122
+ if (children instanceof Array) {
123
+ return children;
124
+ }
125
+ return [children];
126
+ }, [children]);
127
+
128
+ const valueOrDefault = (): string | undefined => {
129
+ if (has('value', props)) {
130
+ return props.value;
131
+ }
132
+ const children = parseChildrenToArray();
133
+ if (children && children.length && children[0].props.componentPath) {
134
+ const firstChildren: TabProps = window.dash_component_api.getLayout(
135
+ [...children[0].props.componentPath, 'props']
136
+ );
137
+ return firstChildren.value ?? 'tab-1';
138
+ }
139
+ return 'tab-1';
140
+ };
141
+
142
+ // Initialize value on mount if not set
143
+ useEffect(() => {
144
+ if (!initializedRef.current && !has('value', props)) {
145
+ props.setProps({
146
+ value: `${valueOrDefault()}`,
147
+ });
148
+ initializedRef.current = true;
149
+ }
150
+ }, []);
151
+
152
+ // Setup matchMedia for responsive breakpoint
153
+ useEffect(() => {
154
+ const mediaQuery = window.matchMedia(
155
+ `(min-width: ${mobile_breakpoint}px)`
156
+ );
157
+
158
+ // Set initial value
159
+ setIsAboveBreakpoint(mediaQuery.matches);
160
+
161
+ // Listen for changes
162
+ const handler = (e: MediaQueryListEvent) =>
163
+ setIsAboveBreakpoint(e.matches);
164
+ mediaQuery.addEventListener('change', handler);
165
+
166
+ return () => mediaQuery.removeEventListener('change', handler);
167
+ }, [mobile_breakpoint]);
168
+
169
+ let EnhancedTabs: JSX.Element[];
170
+ let selectedTab;
171
+
172
+ const value = valueOrDefault();
173
+
174
+ if (children) {
175
+ const children = parseChildrenToArray();
176
+
177
+ EnhancedTabs = children.map((child, index) => {
178
+ // TODO: handle components that are not dcc.Tab components (throw error)
179
+ // enhance Tab components coming from Dash (as dcc.Tab) with methods needed for handling logic
180
+ let childProps: Omit<TabProps, 'setProps'>;
181
+
182
+ if (React.isValidElement(child) && child.props.componentPath) {
183
+ childProps = window.dash_component_api.getLayout([
184
+ ...child.props.componentPath,
185
+ 'props',
186
+ ]);
187
+ } else {
188
+ // In case the selected tab is a string.
189
+ childProps = {};
190
+ }
191
+
192
+ if (!childProps.value) {
193
+ childProps = {...childProps, value: `tab-${index + 1}`};
194
+ }
195
+
196
+ // check if this child/Tab is currently selected
197
+ if (childProps.value === value) {
198
+ selectedTab = child;
199
+ }
200
+
201
+ const style = childProps.style ?? {};
202
+ if (typeof childProps.width === 'number') {
203
+ style.width = `${childProps.width}px`;
204
+ style.flex = '0 0 auto';
205
+ } else if (typeof childProps.width === 'string') {
206
+ style.width = childProps.width;
207
+ style.flex = '0 0 auto';
208
+ }
209
+
210
+ return (
211
+ <EnhancedTab
212
+ key={index}
213
+ id={childProps.id}
214
+ label={childProps.label}
215
+ selected={value === childProps.value}
216
+ setProps={props.setProps}
217
+ className={childProps.className}
218
+ style={style}
219
+ selected_className={childProps.selected_className}
220
+ selected_style={childProps.selected_style}
221
+ value={childProps.value}
222
+ disabled={childProps.disabled}
223
+ disabled_style={childProps.disabled_style}
224
+ disabled_className={childProps.disabled_className}
225
+ componentPath={child.props.componentPath}
226
+ />
227
+ );
228
+ });
229
+ }
230
+
231
+ const selectedTabContent = !isNil(selectedTab) ? selectedTab : '';
232
+
233
+ const tabContainerClassNames = useMemo(() => {
234
+ let names = 'tab-container';
235
+ if (vertical) {
236
+ names += ` tab-container--vert`;
237
+ }
238
+ if (props.className) {
239
+ names += ` ${props.className}`;
240
+ }
241
+ return names;
242
+ }, [vertical, props.className]);
243
+
244
+ const tabContentClassNames = useMemo(() => {
245
+ let names = 'tab-content';
246
+ if (vertical) {
247
+ names += ` tab-content--vert`;
248
+ }
249
+ if (props.content_className) {
250
+ names += ` ${props.content_className}`;
251
+ }
252
+ return names;
253
+ }, [vertical, props.content_className]);
254
+
255
+ const tabParentClassNames = useMemo(() => {
256
+ let names = 'tab-parent';
257
+ if (vertical) {
258
+ names += ` tab-parent--vert`;
259
+ }
260
+ if (isAboveBreakpoint) {
261
+ names += ' tab-parent--above-breakpoint';
262
+ }
263
+ if (props.parent_className) {
264
+ names += ` ${props.parent_className}`;
265
+ }
266
+ return names;
267
+ }, [vertical, isAboveBreakpoint, props.parent_className]);
268
+
269
+ // Set CSS variables for dynamic styling
270
+ const cssVars = {
271
+ '--tabs-border': colors.border,
272
+ '--tabs-primary': colors.primary,
273
+ '--tabs-background': colors.background,
274
+ } as const;
275
+
276
+ return (
277
+ <LoadingElement>
278
+ {loadingProps => (
279
+ <div
280
+ className={tabParentClassNames}
281
+ style={{...cssVars, ...props.parent_style}}
282
+ id={props.id ? `${props.id}-parent` : undefined}
283
+ {...loadingProps}
284
+ >
285
+ <div
286
+ className={tabContainerClassNames}
287
+ style={props.style}
288
+ id={props.id}
289
+ >
290
+ {EnhancedTabs}
291
+ </div>
292
+ <div
293
+ className={tabContentClassNames}
294
+ style={props.content_style}
295
+ >
296
+ {selectedTabContent || ''}
297
+ </div>
298
+ </div>
299
+ )}
300
+ </LoadingElement>
301
+ );
302
+ }
303
+
304
+ Tabs.dashPersistence = {
305
+ persisted_props: [PersistedProps.value],
306
+ persistence_type: PersistenceTypes.local,
307
+ };
308
+
309
+ Tabs.dashChildrenUpdate = true;
310
+
311
+ export default Tabs;
@@ -0,0 +1,79 @@
1
+ /* eslint-disable no-unused-vars */
2
+ import React from 'react';
3
+ import {pick} from 'ramda';
4
+ import {PersistedProps, PersistenceTypes, TextAreaProps} from '../types';
5
+ import './css/textarea.css';
6
+
7
+ const textAreaProps = [
8
+ 'id',
9
+ 'cols',
10
+ 'rows',
11
+ 'minLength',
12
+ 'maxLength',
13
+ 'contentEditable',
14
+ 'tabIndex',
15
+ 'form',
16
+ 'name',
17
+ 'placeholder',
18
+ 'wrap',
19
+ 'accessKey',
20
+ 'contextMenu',
21
+ 'dir',
22
+ 'draggable',
23
+ 'lang',
24
+ 'spellCheck',
25
+ 'style',
26
+ 'title',
27
+ ] as const;
28
+
29
+ /**
30
+ * A basic HTML textarea for entering multiline text.
31
+ *
32
+ */
33
+ const Textarea = ({
34
+ setProps,
35
+ n_blur = 0,
36
+ n_blur_timestamp = -1,
37
+ n_clicks = 0,
38
+ n_clicks_timestamp = -1,
39
+ ...props
40
+ }: TextAreaProps) => {
41
+ const ctx = window.dash_component_api.useDashContext();
42
+ const isLoading = ctx.useLoading();
43
+
44
+ return (
45
+ <textarea
46
+ data-dash-is-loading={isLoading || undefined}
47
+ className={'dash-textarea ' + props.className}
48
+ value={props.value}
49
+ disabled={!!props.disabled}
50
+ readOnly={!!props.readOnly}
51
+ required={!!props.required}
52
+ autoFocus={!!props.autoFocus}
53
+ hidden={!!props.hidden}
54
+ onChange={e => {
55
+ setProps({value: e.target.value});
56
+ }}
57
+ onBlur={() => {
58
+ setProps({
59
+ n_blur: n_blur + 1,
60
+ n_blur_timestamp: Date.now(),
61
+ });
62
+ }}
63
+ onClick={() => {
64
+ setProps({
65
+ n_clicks: n_clicks + 1,
66
+ n_clicks_timestamp: Date.now(),
67
+ });
68
+ }}
69
+ {...pick(textAreaProps, props)}
70
+ />
71
+ );
72
+ };
73
+
74
+ Textarea.dashPersistence = {
75
+ persisted_props: [PersistedProps.value],
76
+ persistence_type: PersistenceTypes.local,
77
+ };
78
+
79
+ export default Textarea;