@dhis2-ui/select 8.1.11 → 8.2.2
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/build/cjs/multi-select/features/menu_width_matches_input/index.js +4 -2
- package/build/cjs/multi-select/features/position/index.js +12 -6
- package/build/cjs/multi-select/filterable-menu.js +25 -22
- package/build/cjs/multi-select/input.js +19 -18
- package/build/cjs/multi-select/menu.js +29 -25
- package/build/cjs/multi-select/multi-select.js +31 -30
- package/build/cjs/multi-select/multi-select.stories.e2e.js +30 -20
- package/build/cjs/multi-select/multi-select.stories.js +14 -23
- package/build/cjs/multi-select/selection-list.js +43 -37
- package/build/cjs/multi-select-field/multi-select-field.stories.js +5 -15
- package/build/cjs/multi-select-option/multi-select-option.js +31 -28
- package/build/cjs/select/debounce/debounce.js +8 -2
- package/build/cjs/select/empty.js +14 -11
- package/build/cjs/select/filter-input.js +24 -21
- package/build/cjs/select/filterable-menu.js +8 -7
- package/build/cjs/select/index.js +24 -24
- package/build/cjs/select/input-clear-button.js +16 -13
- package/build/cjs/select/input-placeholder.js +8 -6
- package/build/cjs/select/input-prefix.js +8 -6
- package/build/cjs/select/input-wrapper.js +15 -14
- package/build/cjs/select/loading.js +18 -15
- package/build/cjs/select/menu-wrapper.js +11 -10
- package/build/cjs/select/no-match.js +12 -9
- package/build/cjs/select/option-helpers.js +1 -1
- package/build/cjs/select/select.js +6 -6
- package/build/cjs/single-select/features/menu_width_matches_input/index.js +4 -2
- package/build/cjs/single-select/features/position/index.js +8 -4
- package/build/cjs/single-select/filterable-menu.js +25 -22
- package/build/cjs/single-select/input.js +19 -18
- package/build/cjs/single-select/menu.js +11 -10
- package/build/cjs/single-select/selection.js +8 -7
- package/build/cjs/single-select/single-select.js +31 -30
- package/build/cjs/single-select/single-select.stories.e2e.js +26 -17
- package/build/cjs/single-select/single-select.stories.js +14 -21
- package/build/cjs/single-select-field/single-select-field.stories.js +5 -15
- package/build/cjs/single-select-option/single-select-option.js +23 -20
- package/build/es/multi-select/features/menu_width_matches_input/index.js +4 -2
- package/build/es/multi-select/features/position/index.js +12 -6
- package/build/es/multi-select/filterable-menu.js +25 -22
- package/build/es/multi-select/input.js +19 -18
- package/build/es/multi-select/menu.js +28 -24
- package/build/es/multi-select/multi-select.js +31 -30
- package/build/es/multi-select/multi-select.stories.e2e.js +30 -20
- package/build/es/multi-select/multi-select.stories.js +13 -22
- package/build/es/multi-select/selection-list.js +43 -37
- package/build/es/multi-select-field/multi-select-field.stories.js +4 -14
- package/build/es/multi-select-option/multi-select-option.js +31 -28
- package/build/es/select/debounce/debounce.js +8 -2
- package/build/es/select/empty.js +14 -11
- package/build/es/select/filter-input.js +24 -21
- package/build/es/select/filterable-menu.js +8 -7
- package/build/es/select/input-clear-button.js +16 -13
- package/build/es/select/input-placeholder.js +8 -6
- package/build/es/select/input-prefix.js +8 -6
- package/build/es/select/input-wrapper.js +15 -14
- package/build/es/select/loading.js +18 -15
- package/build/es/select/menu-wrapper.js +11 -10
- package/build/es/select/no-match.js +12 -9
- package/build/es/select/select.js +6 -6
- package/build/es/single-select/features/menu_width_matches_input/index.js +4 -2
- package/build/es/single-select/features/position/index.js +8 -4
- package/build/es/single-select/filterable-menu.js +25 -22
- package/build/es/single-select/input.js +19 -18
- package/build/es/single-select/menu.js +11 -10
- package/build/es/single-select/selection.js +8 -7
- package/build/es/single-select/single-select.js +31 -30
- package/build/es/single-select/single-select.stories.e2e.js +26 -17
- package/build/es/single-select/single-select.stories.js +13 -20
- package/build/es/single-select-field/single-select-field.stories.js +4 -14
- package/build/es/single-select-option/single-select-option.js +23 -20
- package/package.json +14 -14
|
@@ -3,28 +3,31 @@ import React from 'react';
|
|
|
3
3
|
import { FilterableMenu as CommonFilterableMenu } from '../select/index.js';
|
|
4
4
|
import { Menu } from './menu.js';
|
|
5
5
|
|
|
6
|
-
const FilterableMenu =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
6
|
+
const FilterableMenu = _ref => {
|
|
7
|
+
let {
|
|
8
|
+
dataTest,
|
|
9
|
+
options,
|
|
10
|
+
onChange,
|
|
11
|
+
selected,
|
|
12
|
+
empty,
|
|
13
|
+
handleClose,
|
|
14
|
+
handleFocusInput,
|
|
15
|
+
placeholder,
|
|
16
|
+
noMatchText
|
|
17
|
+
} = _ref;
|
|
18
|
+
return /*#__PURE__*/React.createElement(CommonFilterableMenu, {
|
|
19
|
+
dataTest: dataTest,
|
|
20
|
+
options: options,
|
|
21
|
+
onChange: onChange,
|
|
22
|
+
selected: selected,
|
|
23
|
+
empty: empty,
|
|
24
|
+
handleClose: handleClose,
|
|
25
|
+
handleFocusInput: handleFocusInput,
|
|
26
|
+
placeholder: placeholder,
|
|
27
|
+
noMatchText: noMatchText,
|
|
28
|
+
Menu: Menu
|
|
29
|
+
});
|
|
30
|
+
};
|
|
28
31
|
|
|
29
32
|
FilterableMenu.propTypes = {
|
|
30
33
|
dataTest: PropTypes.string.isRequired,
|
|
@@ -7,19 +7,20 @@ import React from 'react';
|
|
|
7
7
|
import { InputClearButton, InputPlaceholder, InputPrefix } from '../select/index.js';
|
|
8
8
|
import { SelectionList } from './selection-list.js';
|
|
9
9
|
|
|
10
|
-
const Input =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
10
|
+
const Input = _ref => {
|
|
11
|
+
let {
|
|
12
|
+
selected,
|
|
13
|
+
onChange,
|
|
14
|
+
clearable,
|
|
15
|
+
clearText,
|
|
16
|
+
placeholder,
|
|
17
|
+
dataTest,
|
|
18
|
+
prefix,
|
|
19
|
+
options,
|
|
20
|
+
className,
|
|
21
|
+
disabled,
|
|
22
|
+
inputMaxHeight
|
|
23
|
+
} = _ref;
|
|
23
24
|
const hasSelection = selected.length > 0;
|
|
24
25
|
|
|
25
26
|
const onClear = (_, e) => {
|
|
@@ -34,10 +35,10 @@ const Input = ({
|
|
|
34
35
|
className: _JSXStyle.dynamic([["1360178250", [colors.grey900]], ["1331770409", [inputMaxHeight]]]) + " " + (cx('root', className) || "")
|
|
35
36
|
}, /*#__PURE__*/React.createElement(InputPrefix, {
|
|
36
37
|
prefix: prefix,
|
|
37
|
-
dataTest:
|
|
38
|
+
dataTest: "".concat(dataTest, "-prefix")
|
|
38
39
|
}), !hasSelection && !prefix && /*#__PURE__*/React.createElement(InputPlaceholder, {
|
|
39
40
|
placeholder: placeholder,
|
|
40
|
-
dataTest:
|
|
41
|
+
dataTest: "".concat(dataTest, "-placeholder")
|
|
41
42
|
}), hasSelection && /*#__PURE__*/React.createElement("div", {
|
|
42
43
|
className: _JSXStyle.dynamic([["1360178250", [colors.grey900]], ["1331770409", [inputMaxHeight]]]) + " " + "root-input"
|
|
43
44
|
}, /*#__PURE__*/React.createElement(SelectionList, {
|
|
@@ -50,14 +51,14 @@ const Input = ({
|
|
|
50
51
|
}, /*#__PURE__*/React.createElement(InputClearButton, {
|
|
51
52
|
onClear: onClear,
|
|
52
53
|
clearText: clearText,
|
|
53
|
-
dataTest:
|
|
54
|
+
dataTest: "".concat(dataTest, "-clear")
|
|
54
55
|
})), /*#__PURE__*/React.createElement(_JSXStyle, {
|
|
55
56
|
id: "1360178250",
|
|
56
57
|
dynamic: [colors.grey900]
|
|
57
|
-
}, [
|
|
58
|
+
}, [".root.__jsx-style-dynamic-selector{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;color:".concat(colors.grey900, ";font-size:14px;line-height:16px;}"), ".root-input.__jsx-style-dynamic-selector{overflow-y:auto;-webkit-flex:1;-ms-flex:1;flex:1;}", ".root-right.__jsx-style-dynamic-selector{margin-left:auto;margin-right:10px;}"]), /*#__PURE__*/React.createElement(_JSXStyle, {
|
|
58
59
|
id: "1331770409",
|
|
59
60
|
dynamic: [inputMaxHeight]
|
|
60
|
-
}, [
|
|
61
|
+
}, [".root-input.__jsx-style-dynamic-selector{max-height:".concat(inputMaxHeight, ";}")]));
|
|
61
62
|
};
|
|
62
63
|
|
|
63
64
|
Input.defaultProps = {
|
|
@@ -7,36 +7,40 @@ const onDisabledClick = (_, e) => {
|
|
|
7
7
|
e.preventDefault();
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
const createHandler =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
const createHandler = _ref => {
|
|
11
|
+
let {
|
|
12
|
+
isActive,
|
|
13
|
+
onChange,
|
|
14
|
+
selected,
|
|
15
|
+
value
|
|
16
|
+
} = _ref;
|
|
17
|
+
return (_, e) => {
|
|
18
|
+
e.stopPropagation(); // If the option is currently selected remove it from the array of selected options
|
|
19
|
+
|
|
20
|
+
if (isActive) {
|
|
21
|
+
const filtered = removeOption(value, selected);
|
|
22
|
+
const data = {
|
|
23
|
+
selected: filtered
|
|
24
|
+
};
|
|
25
|
+
return onChange(data, e);
|
|
26
|
+
} // Otherwise, add it to selected
|
|
27
|
+
|
|
17
28
|
|
|
18
|
-
if (isActive) {
|
|
19
|
-
const filtered = removeOption(value, selected);
|
|
20
29
|
const data = {
|
|
21
|
-
selected:
|
|
30
|
+
selected: selected.concat([value])
|
|
22
31
|
};
|
|
23
32
|
return onChange(data, e);
|
|
24
|
-
} // Otherwise, add it to selected
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const data = {
|
|
28
|
-
selected: selected.concat([value])
|
|
29
33
|
};
|
|
30
|
-
return onChange(data, e);
|
|
31
34
|
};
|
|
32
35
|
|
|
33
|
-
const Menu =
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
const Menu = _ref2 => {
|
|
37
|
+
let {
|
|
38
|
+
options,
|
|
39
|
+
onChange,
|
|
40
|
+
selected,
|
|
41
|
+
empty,
|
|
42
|
+
dataTest
|
|
43
|
+
} = _ref2;
|
|
40
44
|
const renderedOptions = filterIgnored(options);
|
|
41
45
|
|
|
42
46
|
if (React.Children.count(renderedOptions) === 0) {
|
|
@@ -44,7 +48,7 @@ const Menu = ({
|
|
|
44
48
|
if (typeof empty === 'string') {
|
|
45
49
|
return /*#__PURE__*/React.createElement(Empty, {
|
|
46
50
|
message: empty,
|
|
47
|
-
dataTest:
|
|
51
|
+
dataTest: "".concat(dataTest, "-empty")
|
|
48
52
|
});
|
|
49
53
|
} // Otherwise just render the supplied markup
|
|
50
54
|
|
|
@@ -9,34 +9,35 @@ import { FilterableMenu } from './filterable-menu.js';
|
|
|
9
9
|
import { Input } from './input.js';
|
|
10
10
|
import { Menu } from './menu.js';
|
|
11
11
|
|
|
12
|
-
const MultiSelect =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
12
|
+
const MultiSelect = _ref => {
|
|
13
|
+
let {
|
|
14
|
+
className,
|
|
15
|
+
selected,
|
|
16
|
+
tabIndex,
|
|
17
|
+
maxHeight,
|
|
18
|
+
inputMaxHeight,
|
|
19
|
+
onChange,
|
|
20
|
+
onFocus,
|
|
21
|
+
onBlur,
|
|
22
|
+
loading,
|
|
23
|
+
error,
|
|
24
|
+
warning,
|
|
25
|
+
valid,
|
|
26
|
+
disabled,
|
|
27
|
+
children,
|
|
28
|
+
clearable,
|
|
29
|
+
clearText,
|
|
30
|
+
filterable,
|
|
31
|
+
filterPlaceholder,
|
|
32
|
+
placeholder,
|
|
33
|
+
prefix,
|
|
34
|
+
empty,
|
|
35
|
+
loadingText,
|
|
36
|
+
noMatchText,
|
|
37
|
+
initialFocus,
|
|
38
|
+
dense,
|
|
39
|
+
dataTest
|
|
40
|
+
} = _ref;
|
|
40
41
|
// If the select is filterable, use a filterable menu
|
|
41
42
|
const menu = filterable ? /*#__PURE__*/React.createElement(FilterableMenu, {
|
|
42
43
|
dataTest: dataTest,
|
|
@@ -77,7 +78,7 @@ const MultiSelect = ({
|
|
|
77
78
|
dense: dense
|
|
78
79
|
}, children, loading && /*#__PURE__*/React.createElement(CommonLoading, {
|
|
79
80
|
message: loadingText,
|
|
80
|
-
dataTest:
|
|
81
|
+
dataTest: "".concat(dataTest, "-loading")
|
|
81
82
|
}))), /*#__PURE__*/React.createElement(StatusIcon, {
|
|
82
83
|
error: error,
|
|
83
84
|
valid: valid,
|
|
@@ -85,7 +86,7 @@ const MultiSelect = ({
|
|
|
85
86
|
}), /*#__PURE__*/React.createElement(_JSXStyle, {
|
|
86
87
|
id: "2180377457",
|
|
87
88
|
dynamic: [spacers.dp8]
|
|
88
|
-
}, [
|
|
89
|
+
}, [".root.__jsx-style-dynamic-selector{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;gap:".concat(spacers.dp8, ";}"), ".root-input.__jsx-style-dynamic-selector{-webkit-flex:1;-ms-flex:1;flex:1;}"]));
|
|
89
90
|
};
|
|
90
91
|
|
|
91
92
|
MultiSelect.defaultProps = {
|
|
@@ -10,12 +10,15 @@ window.onChange = window.Cypress && window.Cypress.cy.stub();
|
|
|
10
10
|
window.onFocus = window.Cypress && window.Cypress.cy.stub();
|
|
11
11
|
window.onBlur = window.Cypress && window.Cypress.cy.stub();
|
|
12
12
|
|
|
13
|
-
const CustomMultiSelectOption =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
const CustomMultiSelectOption = _ref => {
|
|
14
|
+
let {
|
|
15
|
+
label,
|
|
16
|
+
onClick
|
|
17
|
+
} = _ref;
|
|
18
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
19
|
+
onClick: e => onClick({}, e)
|
|
20
|
+
}, label);
|
|
21
|
+
};
|
|
19
22
|
|
|
20
23
|
CustomMultiSelectOption.propTypes = {
|
|
21
24
|
label: PropTypes.string,
|
|
@@ -528,9 +531,10 @@ storiesOf('MultiSelect', module).add('With options', () => /*#__PURE__*/React.cr
|
|
|
528
531
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(MultiSelect, {
|
|
529
532
|
className: "select",
|
|
530
533
|
selected: values,
|
|
531
|
-
onChange:
|
|
532
|
-
|
|
533
|
-
|
|
534
|
+
onChange: _ref2 => {
|
|
535
|
+
let {
|
|
536
|
+
selected
|
|
537
|
+
} = _ref2;
|
|
534
538
|
window.onChange && window.onChange({
|
|
535
539
|
selected
|
|
536
540
|
});
|
|
@@ -569,17 +573,23 @@ storiesOf('MultiSelect', module).add('With options', () => /*#__PURE__*/React.cr
|
|
|
569
573
|
flexGrow: 1
|
|
570
574
|
}
|
|
571
575
|
}, /*#__PURE__*/React.createElement(MultiSelect, {
|
|
572
|
-
onChange:
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
576
|
+
onChange: _ref3 => {
|
|
577
|
+
let {
|
|
578
|
+
selected
|
|
579
|
+
} = _ref3;
|
|
580
|
+
return console.log('size changed to ' + selected);
|
|
581
|
+
}
|
|
582
|
+
}, options.map(_ref4 => {
|
|
583
|
+
let {
|
|
584
|
+
name,
|
|
585
|
+
id
|
|
586
|
+
} = _ref4;
|
|
587
|
+
return /*#__PURE__*/React.createElement(MultiSelectOption, {
|
|
588
|
+
key: id,
|
|
589
|
+
value: id,
|
|
590
|
+
label: name
|
|
591
|
+
});
|
|
592
|
+
}))), toggle && /*#__PURE__*/React.createElement("div", {
|
|
583
593
|
style: {
|
|
584
594
|
padding: '30px',
|
|
585
595
|
border: '1px solid green'
|
|
@@ -4,35 +4,26 @@ import PropTypes from 'prop-types';
|
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import { MultiSelectOption } from '../index.js';
|
|
6
6
|
import { MultiSelect } from './index.js';
|
|
7
|
-
const description = `
|
|
8
|
-
Multiple selection allows the user to select more than one option from the list. Checkboxes are used to highlight the possibility of making more than one selection. Selected options are displayed as chips inside the input. Make sure to communicate clearly to the user if there is a limit to the number of selectable elements.
|
|
9
|
-
|
|
10
|
-
Use multiple selection wherever the user needs to make more than one selection. If the multiple selection is complex, requires a defined order or needs to made from different groups, consider using a transfer component instead.
|
|
11
|
-
|
|
12
|
-
Read more about using \`Select\` components at [Design System: Select](https://github.com/dhis2/design-system/blob/master/molecules/select.md).
|
|
13
|
-
|
|
14
|
-
\`\`\`js
|
|
15
|
-
import { MultiSelect, MultiSelectOption } from '@dhis2/ui'
|
|
16
|
-
\`\`\`
|
|
17
|
-
|
|
18
|
-
_**Note:** Due to demo limitations on this page, only one representative example is rendered here. For more (props-interactive) examples, see individual stories in the 'Canvas' tab._
|
|
19
|
-
`;
|
|
7
|
+
const description = "\nMultiple selection allows the user to select more than one option from the list. Checkboxes are used to highlight the possibility of making more than one selection. Selected options are displayed as chips inside the input. Make sure to communicate clearly to the user if there is a limit to the number of selectable elements.\n\nUse multiple selection wherever the user needs to make more than one selection. If the multiple selection is complex, requires a defined order or needs to made from different groups, consider using a transfer component instead.\n\nRead more about using `Select` components at [Design System: Select](https://github.com/dhis2/design-system/blob/master/molecules/select.md).\n\n```js\nimport { MultiSelect, MultiSelectOption } from '@dhis2/ui'\n```\n\n_**Note:** Due to demo limitations on this page, only one representative example is rendered here. For more (props-interactive) examples, see individual stories in the 'Canvas' tab._\n";
|
|
20
8
|
|
|
21
9
|
const eventHandler = handlerName => (payload, event) => {
|
|
22
|
-
console.log(
|
|
23
|
-
console.log(
|
|
10
|
+
console.log("".concat(handlerName, " payload"), payload);
|
|
11
|
+
console.log("".concat(handlerName, " event"), event);
|
|
24
12
|
};
|
|
25
13
|
|
|
26
14
|
const onChange = eventHandler('onChange');
|
|
27
15
|
const onFocus = eventHandler('onFocus');
|
|
28
16
|
const onBlur = eventHandler('onBlur');
|
|
29
17
|
|
|
30
|
-
const CustomMultiSelectOption =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
18
|
+
const CustomMultiSelectOption = _ref => {
|
|
19
|
+
let {
|
|
20
|
+
label,
|
|
21
|
+
onClick
|
|
22
|
+
} = _ref;
|
|
23
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
24
|
+
onClick: e => onClick({}, e)
|
|
25
|
+
}, label);
|
|
26
|
+
};
|
|
36
27
|
|
|
37
28
|
CustomMultiSelectOption.propTypes = {
|
|
38
29
|
label: PropTypes.string,
|
|
@@ -49,7 +40,7 @@ const requiredIfArgType = {
|
|
|
49
40
|
}
|
|
50
41
|
};
|
|
51
42
|
export default {
|
|
52
|
-
title: '
|
|
43
|
+
title: 'Multi Select',
|
|
53
44
|
component: MultiSelect,
|
|
54
45
|
parameters: {
|
|
55
46
|
docs: {
|
|
@@ -3,50 +3,56 @@ import PropTypes from 'prop-types';
|
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import { removeOption, findOptionChild } from '../select/index.js';
|
|
5
5
|
|
|
6
|
-
const createRemoveHandler =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
const createRemoveHandler = _ref => {
|
|
7
|
+
let {
|
|
8
|
+
selected,
|
|
9
|
+
onChange,
|
|
10
|
+
value
|
|
11
|
+
} = _ref;
|
|
12
|
+
return (_, e) => {
|
|
13
|
+
const filtered = removeOption(value, selected);
|
|
14
|
+
const data = {
|
|
15
|
+
selected: filtered
|
|
16
|
+
};
|
|
17
|
+
onChange(data, e);
|
|
14
18
|
};
|
|
15
|
-
onChange(data, e);
|
|
16
19
|
};
|
|
17
20
|
|
|
18
|
-
const SelectionList =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
const SelectionList = _ref2 => {
|
|
22
|
+
let {
|
|
23
|
+
selected,
|
|
24
|
+
onChange,
|
|
25
|
+
disabled,
|
|
26
|
+
options
|
|
27
|
+
} = _ref2;
|
|
28
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, selected.map(value => {
|
|
29
|
+
const selectedOption = findOptionChild(value, options);
|
|
25
30
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
if (!selectedOption) {
|
|
32
|
+
const message = "There is no option with the value: \"".concat(value, "\". ") + 'Make sure that all the values passed to the selected ' + 'prop match the value of an existing option.';
|
|
33
|
+
throw new Error(message);
|
|
34
|
+
} // The chip should be disabled if the option or the select are disabled
|
|
30
35
|
|
|
31
36
|
|
|
32
|
-
|
|
37
|
+
const isDisabled = selectedOption.props.disabled || disabled; // Create an onRemove handler, but only if it's not disabled
|
|
33
38
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}));
|
|
39
|
+
const onRemove = isDisabled ? undefined : createRemoveHandler({
|
|
40
|
+
selected,
|
|
41
|
+
onChange,
|
|
42
|
+
value
|
|
43
|
+
});
|
|
44
|
+
return /*#__PURE__*/React.createElement(Chip, {
|
|
45
|
+
key: value,
|
|
46
|
+
onRemove: onRemove,
|
|
47
|
+
disabled: isDisabled,
|
|
48
|
+
marginBottom: "0",
|
|
49
|
+
marginLeft: "0",
|
|
50
|
+
marginTop: "0",
|
|
51
|
+
overflow: true,
|
|
52
|
+
dense: true
|
|
53
|
+
}, selectedOption.props.label);
|
|
54
|
+
}));
|
|
55
|
+
};
|
|
50
56
|
|
|
51
57
|
SelectionList.propTypes = {
|
|
52
58
|
disabled: PropTypes.bool,
|
|
@@ -2,19 +2,9 @@ import { sharedPropTypes } from '@dhis2/ui-constants';
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { MultiSelectOption } from '../index.js';
|
|
4
4
|
import { MultiSelectField } from './index.js';
|
|
5
|
-
const description = `
|
|
6
|
-
\`MultiSelectField\` is a wrapper around a \`MultiSelect\` component that adds a label, help text, validation text, and other features.
|
|
5
|
+
const description = "\n`MultiSelectField` is a wrapper around a `MultiSelect` component that adds a label, help text, validation text, and other features.\n\nSee the MultiSelect for more information, and read more at [Design System: Select](https://github.com/dhis2/design-system/blob/master/molecules/select.md#multiple-selection).\n\n```js\nimport { MultiSelectField, MultiSelectOption } from '@dhis2/ui'\n```\n\n_**Note**: The dropdowns in some of the following stories won't appear correctly on this page. View these demos in the 'Canvas' tab._\n";
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
\`\`\`js
|
|
11
|
-
import { MultiSelectField, MultiSelectOption } from '@dhis2/ui'
|
|
12
|
-
\`\`\`
|
|
13
|
-
|
|
14
|
-
_**Note**: The dropdowns in some of the following stories won't appear correctly on this page. View these demos in the 'Canvas' tab._
|
|
15
|
-
`;
|
|
16
|
-
|
|
17
|
-
const onChange = selected => alert(`Selected changed to: ${JSON.stringify(selected, null, 2)}`);
|
|
7
|
+
const onChange = selected => alert("Selected changed to: ".concat(JSON.stringify(selected, null, 2)));
|
|
18
8
|
|
|
19
9
|
const options = [/*#__PURE__*/React.createElement(MultiSelectOption, {
|
|
20
10
|
key: "1",
|
|
@@ -58,7 +48,7 @@ const options = [/*#__PURE__*/React.createElement(MultiSelectOption, {
|
|
|
58
48
|
label: "ten"
|
|
59
49
|
})];
|
|
60
50
|
export default {
|
|
61
|
-
title: '
|
|
51
|
+
title: 'Multi Select Field',
|
|
62
52
|
component: MultiSelectField,
|
|
63
53
|
subcomponents: {
|
|
64
54
|
MultiSelectOption
|
|
@@ -98,7 +88,7 @@ WithHelpText.args = {
|
|
|
98
88
|
WithHelpText.parameters = {
|
|
99
89
|
docs: {
|
|
100
90
|
description: {
|
|
101
|
-
story:
|
|
91
|
+
story: "_**Note**: The dropdowns in the following stories won't appear correctly on this page. View these demos in the 'Canvas' tab._"
|
|
102
92
|
}
|
|
103
93
|
}
|
|
104
94
|
};
|
|
@@ -11,37 +11,40 @@ const {
|
|
|
11
11
|
} = {
|
|
12
12
|
styles: /*#__PURE__*/React.createElement(_JSXStyle, {
|
|
13
13
|
id: "2013783366"
|
|
14
|
-
}, [
|
|
14
|
+
}, [".jsx-2013783366{padding:".concat(spacers.dp8, " ").concat(spacers.dp12, ";}")]),
|
|
15
15
|
className: "jsx-2013783366"
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
const MultiSelectOption =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
18
|
+
const MultiSelectOption = _ref => {
|
|
19
|
+
let {
|
|
20
|
+
label,
|
|
21
|
+
active,
|
|
22
|
+
disabled,
|
|
23
|
+
onClick,
|
|
24
|
+
className,
|
|
25
|
+
dataTest,
|
|
26
|
+
value
|
|
27
|
+
} = _ref;
|
|
28
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
29
|
+
"data-test": dataTest,
|
|
30
|
+
"data-value": value,
|
|
31
|
+
"data-label": label,
|
|
32
|
+
className: _JSXStyle.dynamic([["3813980210", [colors.grey200]]]) + " " + (cx(className, {
|
|
33
|
+
disabled
|
|
34
|
+
}) || "")
|
|
35
|
+
}, /*#__PURE__*/React.createElement(Checkbox, {
|
|
36
|
+
name: label,
|
|
37
|
+
className: checkboxClassname,
|
|
38
|
+
checked: active,
|
|
39
|
+
label: label,
|
|
40
|
+
onChange: onClick,
|
|
41
|
+
disabled: disabled,
|
|
42
|
+
dense: true
|
|
43
|
+
}), styles, /*#__PURE__*/React.createElement(_JSXStyle, {
|
|
44
|
+
id: "3813980210",
|
|
45
|
+
dynamic: [colors.grey200]
|
|
46
|
+
}, ["div.__jsx-style-dynamic-selector:hover{background-color:".concat(colors.grey200, ";}"), "div.disabled.__jsx-style-dynamic-selector:hover{background-color:initial;}"]));
|
|
47
|
+
};
|
|
45
48
|
|
|
46
49
|
MultiSelectOption.defaultProps = {
|
|
47
50
|
dataTest: 'dhis2-uicore-multiselectoption'
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
var _this = this;
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Returns a function, that, as long as it continues to be invoked, will not be triggered. The
|
|
3
5
|
* function will be called after it stops being called for N milliseconds. If `immediate` is
|
|
@@ -5,8 +7,12 @@
|
|
|
5
7
|
*/
|
|
6
8
|
export const debounce = (func, wait, immediate) => {
|
|
7
9
|
let timeout;
|
|
8
|
-
return (
|
|
9
|
-
|
|
10
|
+
return function () {
|
|
11
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
12
|
+
args[_key] = arguments[_key];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const context = _this;
|
|
10
16
|
|
|
11
17
|
const later = () => {
|
|
12
18
|
timeout = null;
|