dash-core-components 4.0.0-rc1 → 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.
Files changed (55) hide show
  1. package/dash_core_components/async-dropdown.js +1 -1
  2. package/dash_core_components/async-dropdown.js.map +1 -1
  3. package/dash_core_components/async-slider.js +1 -1
  4. package/dash_core_components/async-slider.js.map +1 -1
  5. package/dash_core_components/dash_core_components.js +1 -1
  6. package/dash_core_components/dash_core_components.js.map +1 -1
  7. package/dash_core_components/proptypes.js +102 -3
  8. package/lib/components/Checklist.tsx +67 -0
  9. package/lib/components/Dropdown.tsx +19 -3
  10. package/lib/components/Loading.tsx +185 -0
  11. package/lib/components/RadioItems.tsx +69 -0
  12. package/lib/components/RangeSlider.tsx +5 -1
  13. package/lib/components/Slider.tsx +12 -1
  14. package/lib/components/Tab.react.js.old +79 -0
  15. package/lib/components/Textarea.tsx +79 -0
  16. package/lib/components/Tooltip.tsx +66 -0
  17. package/lib/components/css/checklist.css +4 -0
  18. package/lib/components/css/dcc.css +2 -0
  19. package/lib/components/css/dropdown.css +30 -49
  20. package/lib/components/css/input.css +22 -6
  21. package/lib/components/css/optionslist.css +34 -0
  22. package/lib/components/css/radioitems.css +4 -0
  23. package/lib/components/css/sliders.css +11 -7
  24. package/lib/components/css/textarea.css +21 -0
  25. package/lib/components/css/tooltip.css +127 -0
  26. package/lib/fragments/Dropdown.tsx +205 -269
  27. package/lib/fragments/Loading/spinners/CircleSpinner.tsx +185 -0
  28. package/lib/fragments/Loading/spinners/CubeSpinner.tsx +193 -0
  29. package/lib/fragments/Loading/spinners/DebugTitle.tsx +11 -0
  30. package/lib/fragments/Loading/spinners/DefaultSpinner.tsx +110 -0
  31. package/lib/fragments/Loading/spinners/DotSpinner.tsx +96 -0
  32. package/lib/fragments/Loading/spinners/GraphSpinner.tsx +332 -0
  33. package/lib/fragments/Loading/types.ts +13 -0
  34. package/lib/fragments/RangeSlider.tsx +193 -63
  35. package/lib/index.ts +5 -5
  36. package/lib/types.ts +455 -116
  37. package/lib/utils/dropdownSearch.ts +4 -4
  38. package/lib/utils/optionRendering.tsx +168 -0
  39. package/lib/utils/optionTypes.ts +5 -5
  40. package/lib/utils/sliderRendering.tsx +23 -4
  41. package/package.json +1 -2
  42. package/lib/components/Checklist.react.js +0 -193
  43. package/lib/components/Input.react.js.old +0 -507
  44. package/lib/components/Loading.react.js +0 -254
  45. package/lib/components/RadioItems.react.js +0 -192
  46. package/lib/components/Slider.react.js.old +0 -214
  47. package/lib/components/Textarea.react.js +0 -223
  48. package/lib/components/Tooltip.react.js +0 -120
  49. package/lib/components/css/Dropdown.css +0 -8
  50. package/lib/fragments/Loading/spinners/CircleSpinner.js +0 -68
  51. package/lib/fragments/Loading/spinners/CubeSpinner.js +0 -57
  52. package/lib/fragments/Loading/spinners/DebugTitle.js +0 -15
  53. package/lib/fragments/Loading/spinners/DefaultSpinner.js +0 -54
  54. package/lib/fragments/Loading/spinners/DotSpinner.js +0 -50
  55. package/lib/fragments/Loading/spinners/GraphSpinner.js +0 -68
@@ -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
+ };
@@ -1,13 +1,13 @@
1
1
  import React from 'react';
2
- import {DetailedDropdownOption, DropdownProps, DropdownValue} from '../types';
2
+ import {DetailedOption, DropdownProps, OptionValue} from '../types';
3
3
 
4
- const isDropdownValue = (option: unknown): option is DropdownValue => {
4
+ const isOptionValue = (option: unknown): option is OptionValue => {
5
5
  return ['string', 'number', 'boolean'].includes(typeof option);
6
6
  };
7
7
 
8
8
  export const sanitizeOptions = (
9
9
  options: DropdownProps['options']
10
- ): DetailedDropdownOption[] => {
10
+ ): DetailedOption[] => {
11
11
  if (typeof options === 'object' && !(options instanceof Array)) {
12
12
  return Object.entries(options).map(([value, label]) => ({
13
13
  label: React.isValidElement(label) ? label : String(label),
@@ -17,11 +17,11 @@ export const sanitizeOptions = (
17
17
 
18
18
  if (options instanceof Array) {
19
19
  return options.map(option => {
20
- return isDropdownValue(option)
20
+ return isOptionValue(option)
21
21
  ? {label: String(option), value: option}
22
22
  : option;
23
23
  });
24
24
  }
25
25
 
26
- return options;
26
+ return [];
27
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
- const thumbPosition = getRadixThumbPosition(pos, minMaxValues);
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
- const thumbPosition = getRadixThumbPosition(dotValue, minMaxValues);
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-rc1",
3
+ "version": "4.0.0-rc2",
4
4
  "description": "Core component suite for Dash",
5
5
  "repository": {
6
6
  "type": "git",
@@ -46,7 +46,6 @@
46
46
  "@radix-ui/react-slider": "^1.3.6",
47
47
  "@radix-ui/react-tooltip": "^1.2.8",
48
48
  "base64-js": "^1.5.1",
49
- "color": "^4.2.3",
50
49
  "d3-format": "^1.4.5",
51
50
  "fast-isnumeric": "^1.1.4",
52
51
  "file-saver": "^2.0.5",
@@ -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
- };