dash-core-components 4.0.0-rc0 → 4.0.0-rc1

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 (31) 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 -1
  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-slider.js +1 -2
  7. package/dash_core_components/async-slider.js.map +1 -1
  8. package/dash_core_components/dash_core_components-shared.js +1 -1
  9. package/dash_core_components/dash_core_components-shared.js.map +1 -1
  10. package/dash_core_components/dash_core_components.js +1 -1
  11. package/dash_core_components/dash_core_components.js.map +1 -1
  12. package/dash_core_components/proptypes.js +18 -0
  13. package/lib/components/Dropdown.tsx +52 -0
  14. package/lib/components/RangeSlider.tsx +8 -1
  15. package/lib/components/Textarea.react.js.old +287 -0
  16. package/lib/components/css/dcc.css +1 -0
  17. package/lib/components/css/dropdown.css +230 -0
  18. package/lib/components/css/sliders.css +8 -0
  19. package/lib/fragments/Dropdown.tsx +577 -0
  20. package/lib/fragments/RangeSlider.tsx +71 -71
  21. package/lib/index.ts +1 -1
  22. package/lib/types.ts +168 -0
  23. package/lib/utils/LazyLoader/dropdown.ts +2 -0
  24. package/lib/utils/_LoadingElement.tsx +8 -18
  25. package/lib/utils/dropdownSearch.ts +92 -0
  26. package/lib/utils/optionTypes.ts +27 -0
  27. package/package.json +7 -3
  28. package/lib/components/Dropdown.react.js +0 -182
  29. package/lib/fragments/Dropdown.react.js +0 -158
  30. package/lib/fragments/Slider.tsx.old +0 -364
  31. package/lib/utils/LazyLoader/dropdown.js +0 -8
@@ -1,182 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.propTypes = exports.defaultProps = exports.default = void 0;
7
- var _propTypes = _interopRequireDefault(require("prop-types"));
8
- var _react = _interopRequireWildcard(require("react"));
9
- var _dropdown = _interopRequireDefault(require("../utils/LazyLoader/dropdown"));
10
- 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); }
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
- var RealDropdown = /*#__PURE__*/(0, _react.lazy)(_dropdown.default);
13
-
14
- /**
15
- * Dropdown is an interactive dropdown element for selecting one or more
16
- * items.
17
- * The values and labels of the dropdown items are specified in the `options`
18
- * property and the selected item(s) are specified with the `value` property.
19
- *
20
- * Use a dropdown when you have many options (more than 5) or when you are
21
- * constrained for space. Otherwise, you can use RadioItems or a Checklist,
22
- * which have the benefit of showing the users all of the items at once.
23
- */
24
- class Dropdown extends _react.Component {
25
- render() {
26
- return /*#__PURE__*/_react.default.createElement(_react.Suspense, {
27
- fallback: null
28
- }, /*#__PURE__*/_react.default.createElement(RealDropdown, this.props));
29
- }
30
- }
31
- exports.default = Dropdown;
32
- Dropdown.propTypes = {
33
- /**
34
- * An array of options {label: [string|number], value: [string|number]},
35
- * an optional disabled field can be used for each option
36
- */
37
- options: _propTypes.default.oneOfType([
38
- /**
39
- * Array of options where the label and the value are the same thing - [string|number|bool]
40
- */
41
- _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number, _propTypes.default.bool])),
42
- /**
43
- * Simpler `options` representation in dictionary format. The order is not guaranteed.
44
- * {`value1`: `label1`, `value2`: `label2`, ... }
45
- * which is equal to
46
- * [{label: `label1`, value: `value1`}, {label: `label2`, value: `value2`}, ...]
47
- */
48
- _propTypes.default.object,
49
- /**
50
- * An array of options {label: [string|number], value: [string|number]},
51
- * an optional disabled field can be used for each option
52
- */
53
- _propTypes.default.arrayOf(_propTypes.default.exact({
54
- /**
55
- * The option's label
56
- */
57
- label: _propTypes.default.node.isRequired,
58
- /**
59
- * The value of the option. This value
60
- * corresponds to the items specified in the
61
- * `value` property.
62
- */
63
- value: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number, _propTypes.default.bool]).isRequired,
64
- /**
65
- * If true, this option is disabled and cannot be selected.
66
- */
67
- disabled: _propTypes.default.bool,
68
- /**
69
- * The HTML 'title' attribute for the option. Allows for
70
- * information on hover. For more information on this attribute,
71
- * see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/title
72
- */
73
- title: _propTypes.default.string,
74
- /**
75
- * Optional search value for the option, to use if the label
76
- * is a component or provide a custom search value different
77
- * from the label. If no search value and the label is a
78
- * component, the `value` will be used for search.
79
- */
80
- search: _propTypes.default.string
81
- }))]),
82
- /**
83
- * The value of the input. If `multi` is false (the default)
84
- * then value is just a string that corresponds to the values
85
- * provided in the `options` property. If `multi` is true, then
86
- * multiple values can be selected at once, and `value` is an
87
- * array of items with values corresponding to those in the
88
- * `options` prop.
89
- */
90
- value: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number, _propTypes.default.bool, _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number, _propTypes.default.bool]))]),
91
- /**
92
- * If true, the user can select multiple values
93
- */
94
- multi: _propTypes.default.bool,
95
- /**
96
- * Whether or not the dropdown is "clearable", that is, whether or
97
- * not a small "x" appears on the right of the dropdown that removes
98
- * the selected value.
99
- */
100
- clearable: _propTypes.default.bool,
101
- /**
102
- * Whether to enable the searching feature or not
103
- */
104
- searchable: _propTypes.default.bool,
105
- /**
106
- * The value typed in the DropDown for searching.
107
- */
108
- search_value: _propTypes.default.string,
109
- /**
110
- * The grey, default text shown when no option is selected
111
- */
112
- placeholder: _propTypes.default.string,
113
- /**
114
- * If true, this dropdown is disabled and the selection cannot be changed.
115
- */
116
- disabled: _propTypes.default.bool,
117
- /**
118
- * If false, the menu of the dropdown will not close once a value is selected.
119
- */
120
- closeOnSelect: _propTypes.default.bool,
121
- /**
122
- * height of each option. Can be increased when label lengths would wrap around
123
- */
124
- optionHeight: _propTypes.default.number,
125
- /**
126
- * height of the options dropdown.
127
- */
128
- maxHeight: _propTypes.default.number,
129
- /**
130
- * Defines CSS styles which will override styles previously set.
131
- */
132
- style: _propTypes.default.object,
133
- /**
134
- * className of the dropdown element
135
- */
136
- className: _propTypes.default.string,
137
- /**
138
- * The ID of this component, used to identify dash components
139
- * in callbacks. The ID needs to be unique across all of the
140
- * components in an app.
141
- */
142
- id: _propTypes.default.string,
143
- /**
144
- * Dash-assigned callback that gets fired when the input changes
145
- */
146
- setProps: _propTypes.default.func,
147
- /**
148
- * Used to allow user interactions in this component to be persisted when
149
- * the component - or the page - is refreshed. If `persisted` is truthy and
150
- * hasn't changed from its previous value, a `value` that the user has
151
- * changed while using the app will keep that change, as long as
152
- * the new `value` also matches what was given originally.
153
- * Used in conjunction with `persistence_type`.
154
- */
155
- persistence: _propTypes.default.oneOfType([_propTypes.default.bool, _propTypes.default.string, _propTypes.default.number]),
156
- /**
157
- * Properties whose user interactions will persist after refreshing the
158
- * component or the page. Since only `value` is allowed this prop can
159
- * normally be ignored.
160
- */
161
- persisted_props: _propTypes.default.arrayOf(_propTypes.default.oneOf(['value'])),
162
- /**
163
- * Where persisted user changes will be stored:
164
- * memory: only kept in memory, reset on page refresh.
165
- * local: window.localStorage, data is kept after the browser quit.
166
- * session: window.sessionStorage, data is cleared once the browser quit.
167
- */
168
- persistence_type: _propTypes.default.oneOf(['local', 'session', 'memory'])
169
- };
170
- Dropdown.defaultProps = {
171
- clearable: true,
172
- disabled: false,
173
- multi: false,
174
- searchable: true,
175
- optionHeight: 35,
176
- maxHeight: 200,
177
- closeOnSelect: true,
178
- persisted_props: ['value'],
179
- persistence_type: 'local'
180
- };
181
- var propTypes = exports.propTypes = Dropdown.propTypes;
182
- var defaultProps = exports.defaultProps = Dropdown.defaultProps;
@@ -1,158 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _ramda = require("ramda");
8
- var _react = _interopRequireWildcard(require("react"));
9
- var _reactVirtualizedSelect = _interopRequireDefault(require("react-virtualized-select"));
10
- var _reactSelectFastFilterOptions = _interopRequireDefault(require("react-select-fast-filter-options"));
11
- require("react-virtualized-select/styles.css");
12
- require("../components/css/react-virtualized@9.9.0.css");
13
- require("../components/css/Dropdown.css");
14
- var _Dropdown2 = require("../components/Dropdown.react");
15
- var _optionTypes = require("../utils/optionTypes");
16
- var _reactFastCompare = _interopRequireDefault(require("react-fast-compare"));
17
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
18
- 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); }
19
- function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
20
- 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; }
21
- 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; }
22
- 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; }
23
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
24
- 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); }
25
- function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
26
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
27
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
28
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
29
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
30
- function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
31
- // Custom tokenizer, see https://github.com/bvaughn/js-search/issues/43
32
- // Split on spaces
33
- var REGEX = /\s+/;
34
- var TOKENIZER = {
35
- tokenize(text) {
36
- return text.split(REGEX).filter(
37
- // Filter empty tokens
38
- text => text);
39
- }
40
- };
41
- var RDProps = ['multi', 'clearable', 'searchable', 'search_value', 'placeholder', 'disabled', 'optionHeight', 'maxHeight', 'style', 'className', 'closeOnSelect'];
42
- var Dropdown = props => {
43
- var id = props.id,
44
- clearable = props.clearable,
45
- multi = props.multi,
46
- options = props.options,
47
- setProps = props.setProps,
48
- search_value = props.search_value,
49
- style = props.style,
50
- value = props.value,
51
- searchable = props.searchable;
52
- var _useState = (0, _react.useState)(null),
53
- _useState2 = _slicedToArray(_useState, 2),
54
- optionsCheck = _useState2[0],
55
- setOptionsCheck = _useState2[1];
56
- var persistentOptions = (0, _react.useRef)(null);
57
- var ctx = window.dash_component_api.useDashContext();
58
- var loading = ctx.useLoading();
59
- if (!persistentOptions || !(0, _reactFastCompare.default)(options, persistentOptions.current)) {
60
- persistentOptions.current = options;
61
- }
62
- var _useMemo = (0, _react.useMemo)(() => {
63
- var sanitized = (0, _optionTypes.sanitizeOptions)(options);
64
- var indexes = ['strValue'];
65
- var hasElement = false,
66
- hasSearch = false;
67
- sanitized = Array.isArray(sanitized) ? sanitized.map(option => {
68
- if (option.search) {
69
- hasSearch = true;
70
- }
71
- if (/*#__PURE__*/_react.default.isValidElement(option.label)) {
72
- hasElement = true;
73
- }
74
- return _objectSpread(_objectSpread({}, option), {}, {
75
- strValue: String(option.value)
76
- });
77
- }) : sanitized;
78
- if (!hasElement) {
79
- indexes.push('label');
80
- }
81
- if (hasSearch) {
82
- indexes.push('search');
83
- }
84
- return [sanitized, (0, _reactSelectFastFilterOptions.default)({
85
- options: sanitized,
86
- tokenizer: TOKENIZER,
87
- indexes
88
- })];
89
- }, [persistentOptions.current]),
90
- _useMemo2 = _slicedToArray(_useMemo, 2),
91
- sanitizedOptions = _useMemo2[0],
92
- filterOptions = _useMemo2[1];
93
- var onChange = (0, _react.useCallback)(selectedOption => {
94
- if (multi) {
95
- var _value;
96
- if ((0, _ramda.isNil)(selectedOption)) {
97
- _value = [];
98
- } else {
99
- _value = (0, _ramda.pluck)('value', selectedOption);
100
- }
101
- setProps({
102
- value: _value
103
- });
104
- } else {
105
- var _value2;
106
- if ((0, _ramda.isNil)(selectedOption)) {
107
- _value2 = null;
108
- } else {
109
- _value2 = selectedOption.value;
110
- }
111
- setProps({
112
- value: _value2
113
- });
114
- }
115
- }, [multi]);
116
- var onInputChange = (0, _react.useCallback)(search_value => setProps({
117
- search_value
118
- }), []);
119
- (0, _react.useEffect)(() => {
120
- if (!search_value && !(0, _ramda.isNil)(sanitizedOptions) && optionsCheck !== sanitizedOptions && !(0, _ramda.isNil)(value) && !(0, _ramda.isEmpty)(value)) {
121
- var values = sanitizedOptions.map(option => option.value);
122
- if (multi && Array.isArray(value)) {
123
- var invalids = value.filter(v => !values.includes(v));
124
- if (invalids.length) {
125
- setProps({
126
- value: (0, _ramda.without)(invalids, value)
127
- });
128
- }
129
- } else {
130
- if (!values.includes(value)) {
131
- setProps({
132
- value: null
133
- });
134
- }
135
- }
136
- setOptionsCheck(sanitizedOptions);
137
- }
138
- }, [sanitizedOptions, optionsCheck, multi, value]);
139
- return /*#__PURE__*/_react.default.createElement("div", {
140
- id: id,
141
- className: "dash-dropdown",
142
- style: style,
143
- "data-dash-is-loading": loading || undefined
144
- }, /*#__PURE__*/_react.default.createElement(_reactVirtualizedSelect.default, _extends({
145
- filterOptions: filterOptions,
146
- options: sanitizedOptions,
147
- value: value,
148
- onChange: onChange,
149
- onInputChange: searchable ? onInputChange : undefined,
150
- backspaceRemoves: clearable,
151
- deleteRemoves: clearable,
152
- inputProps: {
153
- autoComplete: 'off'
154
- }
155
- }, (0, _ramda.pick)(RDProps, props))));
156
- };
157
- Dropdown.propTypes = _Dropdown2.propTypes;
158
- var _default = exports.default = Dropdown;