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.
- package/dash_core_components/async-datepicker.js +1 -1
- package/dash_core_components/async-datepicker.js.map +1 -1
- package/dash_core_components/async-dropdown.js +1 -1
- package/dash_core_components/async-dropdown.js.map +1 -1
- package/dash_core_components/async-graph.js +1 -1
- package/dash_core_components/async-slider.js +1 -2
- package/dash_core_components/async-slider.js.map +1 -1
- package/dash_core_components/dash_core_components-shared.js +1 -1
- package/dash_core_components/dash_core_components-shared.js.map +1 -1
- package/dash_core_components/dash_core_components.js +1 -1
- package/dash_core_components/dash_core_components.js.map +1 -1
- package/dash_core_components/proptypes.js +118 -1
- package/lib/components/Checklist.tsx +67 -0
- package/lib/components/Dropdown.tsx +68 -0
- package/lib/components/Loading.tsx +185 -0
- package/lib/components/RadioItems.tsx +69 -0
- package/lib/components/RangeSlider.tsx +12 -1
- package/lib/components/Slider.tsx +12 -1
- package/lib/components/Tab.react.js.old +79 -0
- package/lib/components/Textarea.react.js.old +287 -0
- package/lib/components/Textarea.tsx +79 -0
- package/lib/components/Tooltip.tsx +66 -0
- package/lib/components/css/checklist.css +4 -0
- package/lib/components/css/dcc.css +3 -0
- package/lib/components/css/dropdown.css +211 -0
- package/lib/components/css/input.css +22 -6
- package/lib/components/css/optionslist.css +34 -0
- package/lib/components/css/radioitems.css +4 -0
- package/lib/components/css/sliders.css +19 -7
- package/lib/components/css/textarea.css +21 -0
- package/lib/components/css/tooltip.css +127 -0
- package/lib/fragments/Dropdown.tsx +513 -0
- package/lib/fragments/Loading/spinners/CircleSpinner.tsx +185 -0
- package/lib/fragments/Loading/spinners/CubeSpinner.tsx +193 -0
- package/lib/fragments/Loading/spinners/DebugTitle.tsx +11 -0
- package/lib/fragments/Loading/spinners/DefaultSpinner.tsx +110 -0
- package/lib/fragments/Loading/spinners/DotSpinner.tsx +96 -0
- package/lib/fragments/Loading/spinners/GraphSpinner.tsx +332 -0
- package/lib/fragments/Loading/types.ts +13 -0
- package/lib/fragments/RangeSlider.tsx +235 -105
- package/lib/index.ts +6 -6
- package/lib/types.ts +571 -64
- package/lib/utils/LazyLoader/dropdown.ts +2 -0
- package/lib/utils/_LoadingElement.tsx +8 -18
- package/lib/utils/dropdownSearch.ts +92 -0
- package/lib/utils/optionRendering.tsx +168 -0
- package/lib/utils/optionTypes.ts +27 -0
- package/lib/utils/sliderRendering.tsx +23 -4
- package/package.json +7 -4
- package/lib/components/Checklist.react.js +0 -193
- package/lib/components/Dropdown.react.js +0 -182
- package/lib/components/Input.react.js.old +0 -507
- package/lib/components/Loading.react.js +0 -254
- package/lib/components/RadioItems.react.js +0 -192
- package/lib/components/Slider.react.js.old +0 -214
- package/lib/components/Textarea.react.js +0 -223
- package/lib/components/Tooltip.react.js +0 -120
- package/lib/components/css/Dropdown.css +0 -8
- package/lib/fragments/Dropdown.react.js +0 -158
- package/lib/fragments/Loading/spinners/CircleSpinner.js +0 -68
- package/lib/fragments/Loading/spinners/CubeSpinner.js +0 -57
- package/lib/fragments/Loading/spinners/DebugTitle.js +0 -15
- package/lib/fragments/Loading/spinners/DefaultSpinner.js +0 -54
- package/lib/fragments/Loading/spinners/DotSpinner.js +0 -50
- package/lib/fragments/Loading/spinners/GraphSpinner.js +0 -68
- package/lib/fragments/Slider.tsx.old +0 -364
- package/lib/utils/LazyLoader/dropdown.js +0 -8
|
@@ -1,17 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
declare global {
|
|
4
|
-
interface Window {
|
|
5
|
-
dash_component_api: {
|
|
6
|
-
useDashContext: () => {
|
|
7
|
-
useLoading: () => boolean;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
3
|
interface LoadingElementProps {
|
|
14
|
-
|
|
4
|
+
children: (props: Record<string, unknown>) => React.ReactElement;
|
|
15
5
|
}
|
|
16
6
|
|
|
17
7
|
/**
|
|
@@ -22,15 +12,15 @@ interface LoadingElementProps {
|
|
|
22
12
|
* See: https://dash.plotly.com/loading-states#check-loading-states-from-components
|
|
23
13
|
*/
|
|
24
14
|
function LoadingElement({children}: LoadingElementProps) {
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
const ctx = window.dash_component_api.useDashContext();
|
|
16
|
+
const loading = ctx.useLoading();
|
|
27
17
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
18
|
+
const additionalProps: Record<string, unknown> = {};
|
|
19
|
+
if (loading) {
|
|
20
|
+
additionalProps['data-dash-is-loading'] = true;
|
|
21
|
+
}
|
|
32
22
|
|
|
33
|
-
|
|
23
|
+
return children(additionalProps);
|
|
34
24
|
}
|
|
35
25
|
|
|
36
26
|
export default LoadingElement;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Search,
|
|
4
|
+
AllSubstringsIndexStrategy,
|
|
5
|
+
UnorderedSearchIndex,
|
|
6
|
+
} from 'js-search';
|
|
7
|
+
import {sanitizeOptions} from './optionTypes';
|
|
8
|
+
import {DetailedOption, DropdownProps} from '../types';
|
|
9
|
+
|
|
10
|
+
// Custom tokenizer, see https://github.com/bvaughn/js-search/issues/43
|
|
11
|
+
// Split on spaces
|
|
12
|
+
const REGEX = /\s+/;
|
|
13
|
+
const TOKENIZER = {
|
|
14
|
+
tokenize(text: string) {
|
|
15
|
+
return text.split(REGEX).filter(
|
|
16
|
+
// Filter empty tokens
|
|
17
|
+
text => text
|
|
18
|
+
);
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
interface FilteredOptionsResult {
|
|
23
|
+
sanitizedOptions: DetailedOption[];
|
|
24
|
+
filteredOptions: DetailedOption[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Creates filtered dropdown options using js-search with the exact same behavior
|
|
29
|
+
* as react-select-fast-filter-options
|
|
30
|
+
*/
|
|
31
|
+
export function createFilteredOptions(
|
|
32
|
+
options: DropdownProps['options'],
|
|
33
|
+
searchable: boolean,
|
|
34
|
+
searchValue?: string
|
|
35
|
+
): FilteredOptionsResult {
|
|
36
|
+
// Sanitize and prepare options
|
|
37
|
+
let sanitized = sanitizeOptions(options);
|
|
38
|
+
|
|
39
|
+
const indexes = ['value'];
|
|
40
|
+
let hasElement = false,
|
|
41
|
+
hasSearch = false;
|
|
42
|
+
|
|
43
|
+
sanitized = Array.isArray(sanitized)
|
|
44
|
+
? sanitized.map(option => {
|
|
45
|
+
if (option.search) {
|
|
46
|
+
hasSearch = true;
|
|
47
|
+
}
|
|
48
|
+
if (React.isValidElement(option.label)) {
|
|
49
|
+
hasElement = true;
|
|
50
|
+
}
|
|
51
|
+
return option;
|
|
52
|
+
})
|
|
53
|
+
: sanitized;
|
|
54
|
+
|
|
55
|
+
if (!hasElement) {
|
|
56
|
+
indexes.push('label');
|
|
57
|
+
}
|
|
58
|
+
if (hasSearch) {
|
|
59
|
+
indexes.push('search');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// If not searchable or no search value, return all sanitized options
|
|
63
|
+
if (!searchable || !searchValue) {
|
|
64
|
+
return {
|
|
65
|
+
sanitizedOptions: sanitized || [],
|
|
66
|
+
filteredOptions: sanitized || [],
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Create js-search instance exactly like react-select-fast-filter-options
|
|
71
|
+
const search = new Search('value'); // valueKey defaults to 'value'
|
|
72
|
+
search.searchIndex = new UnorderedSearchIndex();
|
|
73
|
+
search.indexStrategy = new AllSubstringsIndexStrategy();
|
|
74
|
+
search.tokenizer = TOKENIZER;
|
|
75
|
+
|
|
76
|
+
// Add indexes
|
|
77
|
+
indexes.forEach(index => {
|
|
78
|
+
search.addIndex(index);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// Add documents
|
|
82
|
+
if (sanitized && sanitized.length > 0) {
|
|
83
|
+
search.addDocuments(sanitized);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const filtered = search.search(searchValue) as DetailedOption[];
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
sanitizedOptions: sanitized || [],
|
|
90
|
+
filteredOptions: filtered || [],
|
|
91
|
+
};
|
|
92
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {append, includes, without} from 'ramda';
|
|
3
|
+
import {DetailedOption, OptionValue} from 'src/types';
|
|
4
|
+
import '../components/css/optionslist.css';
|
|
5
|
+
|
|
6
|
+
interface StylingProps {
|
|
7
|
+
id?: string;
|
|
8
|
+
className?: string;
|
|
9
|
+
style?: React.CSSProperties;
|
|
10
|
+
optionClassName?: string;
|
|
11
|
+
optionStyle?: React.CSSProperties;
|
|
12
|
+
inputType?: 'checkbox' | 'radio';
|
|
13
|
+
inputClassName?: string;
|
|
14
|
+
inputStyle?: React.CSSProperties;
|
|
15
|
+
labelClassName?: string;
|
|
16
|
+
labelStyle?: React.CSSProperties;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface OptionLabelProps extends DetailedOption {
|
|
20
|
+
index: string | number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const OptionLabel: React.FC<OptionLabelProps> = ({
|
|
24
|
+
index,
|
|
25
|
+
label,
|
|
26
|
+
title,
|
|
27
|
+
value,
|
|
28
|
+
}) => {
|
|
29
|
+
const ctx = window.dash_component_api.useDashContext();
|
|
30
|
+
const ExternalWrapper = window.dash_component_api.ExternalWrapper;
|
|
31
|
+
|
|
32
|
+
if (typeof label === 'object') {
|
|
33
|
+
const labels = label instanceof Array ? label : [label];
|
|
34
|
+
return (
|
|
35
|
+
<>
|
|
36
|
+
{labels.map((label, i) => (
|
|
37
|
+
<ExternalWrapper
|
|
38
|
+
key={i}
|
|
39
|
+
component={label}
|
|
40
|
+
componentPath={[...ctx.componentPath, index, i]}
|
|
41
|
+
/>
|
|
42
|
+
))}
|
|
43
|
+
</>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const displayLabel = `${label ?? value}`;
|
|
48
|
+
return <span title={title}>{displayLabel}</span>;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
interface OptionProps extends StylingProps {
|
|
52
|
+
index: number;
|
|
53
|
+
option: DetailedOption;
|
|
54
|
+
isSelected: boolean;
|
|
55
|
+
onChange: (option: DetailedOption) => void;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const Option: React.FC<OptionProps> = ({
|
|
59
|
+
option,
|
|
60
|
+
isSelected,
|
|
61
|
+
onChange,
|
|
62
|
+
optionClassName,
|
|
63
|
+
optionStyle,
|
|
64
|
+
inputType = 'checkbox',
|
|
65
|
+
inputClassName,
|
|
66
|
+
inputStyle,
|
|
67
|
+
labelClassName,
|
|
68
|
+
labelStyle,
|
|
69
|
+
index,
|
|
70
|
+
id,
|
|
71
|
+
}) => {
|
|
72
|
+
const classNames = [
|
|
73
|
+
'dash-options-list-option',
|
|
74
|
+
isSelected ? 'selected' : '',
|
|
75
|
+
optionClassName,
|
|
76
|
+
].filter(Boolean);
|
|
77
|
+
|
|
78
|
+
const inputClassNames = [
|
|
79
|
+
'dash-options-list-option-checkbox',
|
|
80
|
+
inputClassName,
|
|
81
|
+
].filter(Boolean);
|
|
82
|
+
|
|
83
|
+
const labelClassNames = [
|
|
84
|
+
'dash-options-list-option-text',
|
|
85
|
+
labelClassName,
|
|
86
|
+
].filter(Boolean);
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<label
|
|
90
|
+
className={classNames.join(' ')}
|
|
91
|
+
role="option"
|
|
92
|
+
aria-selected={isSelected}
|
|
93
|
+
style={optionStyle}
|
|
94
|
+
>
|
|
95
|
+
<input
|
|
96
|
+
type={inputType}
|
|
97
|
+
checked={isSelected}
|
|
98
|
+
name={id}
|
|
99
|
+
value={
|
|
100
|
+
typeof option.value === 'boolean'
|
|
101
|
+
? `${option.value}`
|
|
102
|
+
: option.value
|
|
103
|
+
}
|
|
104
|
+
disabled={!!option.disabled}
|
|
105
|
+
onChange={() => onChange(option)}
|
|
106
|
+
readOnly
|
|
107
|
+
className={inputClassNames.join(' ')}
|
|
108
|
+
style={inputStyle}
|
|
109
|
+
/>
|
|
110
|
+
<span
|
|
111
|
+
className={labelClassNames.join(' ')}
|
|
112
|
+
style={labelStyle}
|
|
113
|
+
title={option.title}
|
|
114
|
+
>
|
|
115
|
+
<OptionLabel {...option} index={index} />
|
|
116
|
+
</span>
|
|
117
|
+
</label>
|
|
118
|
+
);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
interface OptionsListProps extends StylingProps {
|
|
122
|
+
options: DetailedOption[];
|
|
123
|
+
selected: OptionValue[];
|
|
124
|
+
onSelectionChange: (selected: OptionValue[]) => void;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export const OptionsList: React.FC<OptionsListProps> = ({
|
|
128
|
+
options,
|
|
129
|
+
selected,
|
|
130
|
+
onSelectionChange,
|
|
131
|
+
id,
|
|
132
|
+
className,
|
|
133
|
+
style,
|
|
134
|
+
...passThruProps
|
|
135
|
+
}) => {
|
|
136
|
+
const classNames = ['dash-options-list', className].filter(Boolean);
|
|
137
|
+
return (
|
|
138
|
+
<div
|
|
139
|
+
id={id}
|
|
140
|
+
className={classNames.join(' ')}
|
|
141
|
+
style={style}
|
|
142
|
+
role="listbox"
|
|
143
|
+
>
|
|
144
|
+
{options.map((option, i) => {
|
|
145
|
+
const isSelected = includes(option.value, selected);
|
|
146
|
+
return (
|
|
147
|
+
<Option
|
|
148
|
+
id={id}
|
|
149
|
+
key={i}
|
|
150
|
+
index={i}
|
|
151
|
+
option={option}
|
|
152
|
+
isSelected={isSelected}
|
|
153
|
+
onChange={option => {
|
|
154
|
+
let newValue: OptionValue[];
|
|
155
|
+
if (includes(option.value, selected)) {
|
|
156
|
+
newValue = without([option.value], selected);
|
|
157
|
+
} else {
|
|
158
|
+
newValue = append(option.value, selected);
|
|
159
|
+
}
|
|
160
|
+
onSelectionChange(newValue);
|
|
161
|
+
}}
|
|
162
|
+
{...passThruProps}
|
|
163
|
+
/>
|
|
164
|
+
);
|
|
165
|
+
})}
|
|
166
|
+
</div>
|
|
167
|
+
);
|
|
168
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {DetailedOption, DropdownProps, OptionValue} from '../types';
|
|
3
|
+
|
|
4
|
+
const isOptionValue = (option: unknown): option is OptionValue => {
|
|
5
|
+
return ['string', 'number', 'boolean'].includes(typeof option);
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const sanitizeOptions = (
|
|
9
|
+
options: DropdownProps['options']
|
|
10
|
+
): DetailedOption[] => {
|
|
11
|
+
if (typeof options === 'object' && !(options instanceof Array)) {
|
|
12
|
+
return Object.entries(options).map(([value, label]) => ({
|
|
13
|
+
label: React.isValidElement(label) ? label : String(label),
|
|
14
|
+
value,
|
|
15
|
+
}));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (options instanceof Array) {
|
|
19
|
+
return options.map(option => {
|
|
20
|
+
return isOptionValue(option)
|
|
21
|
+
? {label: String(option), value: option}
|
|
22
|
+
: option;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return [];
|
|
27
|
+
};
|
|
@@ -58,11 +58,19 @@ export const renderSliderMarks = (
|
|
|
58
58
|
renderedMarks: SliderMarks,
|
|
59
59
|
vertical: boolean,
|
|
60
60
|
minMaxValues: {min_mark: number; max_mark: number},
|
|
61
|
-
dots: boolean
|
|
61
|
+
dots: boolean,
|
|
62
|
+
reverse = false
|
|
62
63
|
) => {
|
|
63
64
|
return Object.entries(renderedMarks).map(([position, mark]) => {
|
|
64
65
|
const pos = parseFloat(position);
|
|
65
|
-
|
|
66
|
+
|
|
67
|
+
// When reversed, use the inverted value for positioning
|
|
68
|
+
const displayPos = reverse
|
|
69
|
+
? minMaxValues.max_mark - pos + minMaxValues.min_mark
|
|
70
|
+
: pos;
|
|
71
|
+
|
|
72
|
+
const thumbPosition = getRadixThumbPosition(displayPos, minMaxValues);
|
|
73
|
+
|
|
66
74
|
const style = vertical
|
|
67
75
|
? {
|
|
68
76
|
bottom: `calc(${thumbPosition.percentage}% + ${thumbPosition.offset}px - 13px)`,
|
|
@@ -95,7 +103,8 @@ export const renderSliderMarks = (
|
|
|
95
103
|
export const renderSliderDots = (
|
|
96
104
|
stepValue: number,
|
|
97
105
|
minMaxValues: {min_mark: number; max_mark: number},
|
|
98
|
-
vertical: boolean
|
|
106
|
+
vertical: boolean,
|
|
107
|
+
reverse = false
|
|
99
108
|
) => {
|
|
100
109
|
if (stepValue <= 1) {
|
|
101
110
|
return null;
|
|
@@ -117,7 +126,17 @@ export const renderSliderDots = (
|
|
|
117
126
|
},
|
|
118
127
|
(_, i) => {
|
|
119
128
|
const dotValue = minMaxValues.min_mark + i * stepValue;
|
|
120
|
-
|
|
129
|
+
|
|
130
|
+
// When reversed, use the inverted value for positioning
|
|
131
|
+
const displayValue = reverse
|
|
132
|
+
? minMaxValues.max_mark - dotValue + minMaxValues.min_mark
|
|
133
|
+
: dotValue;
|
|
134
|
+
|
|
135
|
+
const thumbPosition = getRadixThumbPosition(
|
|
136
|
+
displayValue,
|
|
137
|
+
minMaxValues
|
|
138
|
+
);
|
|
139
|
+
|
|
121
140
|
const dotStyle = vertical
|
|
122
141
|
? {
|
|
123
142
|
bottom: `calc(${thumbPosition.percentage}% + ${thumbPosition.offset}px)`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dash-core-components",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-rc2",
|
|
4
4
|
"description": "Core component suite for Dash",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -40,14 +40,17 @@
|
|
|
40
40
|
"@fortawesome/free-regular-svg-icons": "^5.15.4",
|
|
41
41
|
"@fortawesome/free-solid-svg-icons": "^5.15.4",
|
|
42
42
|
"@fortawesome/react-fontawesome": "^0.1.17",
|
|
43
|
+
"@radix-ui/react-icons": "^1.3.2",
|
|
44
|
+
"@radix-ui/react-popover": "^1.1.15",
|
|
45
|
+
"@radix-ui/react-select": "^2.1.3",
|
|
43
46
|
"@radix-ui/react-slider": "^1.3.6",
|
|
44
47
|
"@radix-ui/react-tooltip": "^1.2.8",
|
|
45
48
|
"base64-js": "^1.5.1",
|
|
46
|
-
"color": "^4.2.3",
|
|
47
49
|
"d3-format": "^1.4.5",
|
|
48
50
|
"fast-isnumeric": "^1.1.4",
|
|
49
51
|
"file-saver": "^2.0.5",
|
|
50
52
|
"highlight.js": "^11.8.0",
|
|
53
|
+
"js-search": "^2.0.1",
|
|
51
54
|
"mathjax": "^3.2.2",
|
|
52
55
|
"moment": "^2.29.4",
|
|
53
56
|
"node-polyfill-webpack-plugin": "^2.0.1",
|
|
@@ -59,7 +62,6 @@
|
|
|
59
62
|
"react-dropzone": "^4.1.2",
|
|
60
63
|
"react-fast-compare": "^3.2.2",
|
|
61
64
|
"react-markdown": "^4.3.1",
|
|
62
|
-
"react-select-fast-filter-options": "^0.2.3",
|
|
63
65
|
"react-virtualized-select": "^3.1.3",
|
|
64
66
|
"remark-math": "^3.0.1",
|
|
65
67
|
"uniqid": "^5.4.0"
|
|
@@ -77,6 +79,7 @@
|
|
|
77
79
|
"@types/d3-format": "^3.0.4",
|
|
78
80
|
"@types/fast-isnumeric": "^1.1.2",
|
|
79
81
|
"@types/jest": "^29.5.0",
|
|
82
|
+
"@types/js-search": "^1.4.4",
|
|
80
83
|
"@types/ramda": "^0.31.0",
|
|
81
84
|
"@types/react": "^16.14.8",
|
|
82
85
|
"@types/react-dom": "^16.9.13",
|
|
@@ -120,5 +123,5 @@
|
|
|
120
123
|
"browserslist": [
|
|
121
124
|
"last 9 years and not dead"
|
|
122
125
|
],
|
|
123
|
-
"gitHead": "
|
|
126
|
+
"gitHead": "fdbd6e0b8dc2448175dad301ed9004c918332d34"
|
|
124
127
|
}
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
8
|
-
var _ramda = require("ramda");
|
|
9
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
-
var _optionTypes = require("../utils/optionTypes");
|
|
11
|
-
var _LoadingElement = _interopRequireDefault(require("../utils/LoadingElement"));
|
|
12
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
13
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
15
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
16
|
-
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
17
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
18
|
-
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
19
|
-
/**
|
|
20
|
-
* Checklist is a component that encapsulates several checkboxes.
|
|
21
|
-
* The values and labels of the checklist are specified in the `options`
|
|
22
|
-
* property and the checked items are specified with the `value` property.
|
|
23
|
-
* Each checkbox is rendered as an input with a surrounding label.
|
|
24
|
-
*/
|
|
25
|
-
class Checklist extends _react.Component {
|
|
26
|
-
render() {
|
|
27
|
-
var _this$props = this.props,
|
|
28
|
-
className = _this$props.className,
|
|
29
|
-
id = _this$props.id,
|
|
30
|
-
inputClassName = _this$props.inputClassName,
|
|
31
|
-
inputStyle = _this$props.inputStyle,
|
|
32
|
-
labelClassName = _this$props.labelClassName,
|
|
33
|
-
labelStyle = _this$props.labelStyle,
|
|
34
|
-
options = _this$props.options,
|
|
35
|
-
setProps = _this$props.setProps,
|
|
36
|
-
style = _this$props.style,
|
|
37
|
-
value = _this$props.value,
|
|
38
|
-
inline = _this$props.inline;
|
|
39
|
-
return /*#__PURE__*/_react.default.createElement(_LoadingElement.default, {
|
|
40
|
-
id: id,
|
|
41
|
-
style: style,
|
|
42
|
-
className: className
|
|
43
|
-
}, (0, _optionTypes.sanitizeOptions)(options).map(option => {
|
|
44
|
-
return /*#__PURE__*/_react.default.createElement("label", {
|
|
45
|
-
key: option.value,
|
|
46
|
-
style: _objectSpread({
|
|
47
|
-
display: inline ? 'inline-block' : 'block'
|
|
48
|
-
}, labelStyle),
|
|
49
|
-
className: labelClassName,
|
|
50
|
-
title: option.title
|
|
51
|
-
}, /*#__PURE__*/_react.default.createElement("input", {
|
|
52
|
-
checked: (0, _ramda.includes)(option.value, value),
|
|
53
|
-
className: inputClassName,
|
|
54
|
-
disabled: Boolean(option.disabled),
|
|
55
|
-
style: inputStyle,
|
|
56
|
-
type: "checkbox",
|
|
57
|
-
onChange: () => {
|
|
58
|
-
var newValue;
|
|
59
|
-
if ((0, _ramda.includes)(option.value, value)) {
|
|
60
|
-
newValue = (0, _ramda.without)([option.value], value);
|
|
61
|
-
} else {
|
|
62
|
-
newValue = (0, _ramda.append)(option.value, value);
|
|
63
|
-
}
|
|
64
|
-
setProps({
|
|
65
|
-
value: newValue
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
}), option.label);
|
|
69
|
-
}));
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
exports.default = Checklist;
|
|
73
|
-
Checklist.propTypes = {
|
|
74
|
-
/**
|
|
75
|
-
* An array of options
|
|
76
|
-
*/
|
|
77
|
-
options: _propTypes.default.oneOfType([
|
|
78
|
-
/**
|
|
79
|
-
* Array of options where the label and the value are the same thing - [string|number|bool]
|
|
80
|
-
*/
|
|
81
|
-
_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number, _propTypes.default.bool])),
|
|
82
|
-
/**
|
|
83
|
-
* Simpler `options` representation in dictionary format. The order is not guaranteed.
|
|
84
|
-
* {`value1`: `label1`, `value2`: `label2`, ... }
|
|
85
|
-
* which is equal to
|
|
86
|
-
* [{label: `label1`, value: `value1`}, {label: `label2`, value: `value2`}, ...]
|
|
87
|
-
*/
|
|
88
|
-
_propTypes.default.object,
|
|
89
|
-
/**
|
|
90
|
-
* An array of options {label: [string|number], value: [string|number]},
|
|
91
|
-
* an optional disabled field can be used for each option
|
|
92
|
-
*/
|
|
93
|
-
_propTypes.default.arrayOf(_propTypes.default.exact({
|
|
94
|
-
/**
|
|
95
|
-
* The option's label
|
|
96
|
-
*/
|
|
97
|
-
label: _propTypes.default.node.isRequired,
|
|
98
|
-
/**
|
|
99
|
-
* The value of the option. This value
|
|
100
|
-
* corresponds to the items specified in the
|
|
101
|
-
* `value` property.
|
|
102
|
-
*/
|
|
103
|
-
value: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number, _propTypes.default.bool]).isRequired,
|
|
104
|
-
/**
|
|
105
|
-
* If true, this option is disabled and cannot be selected.
|
|
106
|
-
*/
|
|
107
|
-
disabled: _propTypes.default.bool,
|
|
108
|
-
/**
|
|
109
|
-
* The HTML 'title' attribute for the option. Allows for
|
|
110
|
-
* information on hover. For more information on this attribute,
|
|
111
|
-
* see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/title
|
|
112
|
-
*/
|
|
113
|
-
title: _propTypes.default.string
|
|
114
|
-
}))]),
|
|
115
|
-
/**
|
|
116
|
-
* The currently selected value
|
|
117
|
-
*/
|
|
118
|
-
value: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number, _propTypes.default.bool])),
|
|
119
|
-
/**
|
|
120
|
-
* Indicates whether the options labels should be displayed inline (true=horizontal)
|
|
121
|
-
* or in a block (false=vertical).
|
|
122
|
-
*/
|
|
123
|
-
inline: _propTypes.default.bool,
|
|
124
|
-
/**
|
|
125
|
-
* The class of the container (div)
|
|
126
|
-
*/
|
|
127
|
-
className: _propTypes.default.string,
|
|
128
|
-
/**
|
|
129
|
-
* The style of the container (div)
|
|
130
|
-
*/
|
|
131
|
-
style: _propTypes.default.object,
|
|
132
|
-
/**
|
|
133
|
-
* The style of the <input> checkbox element
|
|
134
|
-
*/
|
|
135
|
-
inputStyle: _propTypes.default.object,
|
|
136
|
-
/**
|
|
137
|
-
* The class of the <input> checkbox element
|
|
138
|
-
*/
|
|
139
|
-
inputClassName: _propTypes.default.string,
|
|
140
|
-
/**
|
|
141
|
-
* The style of the <label> that wraps the checkbox input
|
|
142
|
-
* and the option's label
|
|
143
|
-
*/
|
|
144
|
-
labelStyle: _propTypes.default.object,
|
|
145
|
-
/**
|
|
146
|
-
* The class of the <label> that wraps the checkbox input
|
|
147
|
-
* and the option's label
|
|
148
|
-
*/
|
|
149
|
-
labelClassName: _propTypes.default.string,
|
|
150
|
-
/**
|
|
151
|
-
* The ID of this component, used to identify dash components
|
|
152
|
-
* in callbacks. The ID needs to be unique across all of the
|
|
153
|
-
* components in an app.
|
|
154
|
-
*/
|
|
155
|
-
id: _propTypes.default.string,
|
|
156
|
-
/**
|
|
157
|
-
* Dash-assigned callback that gets fired when the value changes.
|
|
158
|
-
*/
|
|
159
|
-
setProps: _propTypes.default.func,
|
|
160
|
-
/**
|
|
161
|
-
* Used to allow user interactions in this component to be persisted when
|
|
162
|
-
* the component - or the page - is refreshed. If `persisted` is truthy and
|
|
163
|
-
* hasn't changed from its previous value, a `value` that the user has
|
|
164
|
-
* changed while using the app will keep that change, as long as
|
|
165
|
-
* the new `value` also matches what was given originally.
|
|
166
|
-
* Used in conjunction with `persistence_type`.
|
|
167
|
-
*/
|
|
168
|
-
persistence: _propTypes.default.oneOfType([_propTypes.default.bool, _propTypes.default.string, _propTypes.default.number]),
|
|
169
|
-
/**
|
|
170
|
-
* Properties whose user interactions will persist after refreshing the
|
|
171
|
-
* component or the page. Since only `value` is allowed this prop can
|
|
172
|
-
* normally be ignored.
|
|
173
|
-
*/
|
|
174
|
-
persisted_props: _propTypes.default.arrayOf(_propTypes.default.oneOf(['value'])),
|
|
175
|
-
/**
|
|
176
|
-
* Where persisted user changes will be stored:
|
|
177
|
-
* memory: only kept in memory, reset on page refresh.
|
|
178
|
-
* local: window.localStorage, data is kept after the browser quit.
|
|
179
|
-
* session: window.sessionStorage, data is cleared once the browser quit.
|
|
180
|
-
*/
|
|
181
|
-
persistence_type: _propTypes.default.oneOf(['local', 'session', 'memory'])
|
|
182
|
-
};
|
|
183
|
-
Checklist.defaultProps = {
|
|
184
|
-
inputStyle: {},
|
|
185
|
-
inputClassName: '',
|
|
186
|
-
labelStyle: {},
|
|
187
|
-
labelClassName: '',
|
|
188
|
-
options: [],
|
|
189
|
-
value: [],
|
|
190
|
-
persisted_props: ['value'],
|
|
191
|
-
persistence_type: 'local',
|
|
192
|
-
inline: false
|
|
193
|
-
};
|