@dhis2-ui/select 9.11.0 → 9.11.1-beta.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/index.js +0 -6
- package/build/cjs/locales/index.js +3 -69
- package/build/cjs/multi-select/__tests__/multi-select.test.js +1 -7
- package/build/cjs/multi-select/__tests__/selection-list.test.js +7 -18
- package/build/cjs/multi-select/features/accepts_blur_cb/index.js +1 -2
- package/build/cjs/multi-select/features/accepts_focus_cb/index.js +1 -2
- package/build/cjs/multi-select/features/accepts_initial_focus/index.js +1 -2
- package/build/cjs/multi-select/features/accepts_loading/index.js +0 -1
- package/build/cjs/multi-select/features/accepts_max_height/index.js +1 -2
- package/build/cjs/multi-select/features/accepts_placeholder/index.js +0 -1
- package/build/cjs/multi-select/features/accepts_prefix/index.js +0 -1
- package/build/cjs/multi-select/features/allows_invalid_options/index.js +0 -1
- package/build/cjs/multi-select/features/allows_selecting/index.js +2 -3
- package/build/cjs/multi-select/features/can_be_cleared/index.js +1 -2
- package/build/cjs/multi-select/features/can_be_disabled/index.js +0 -1
- package/build/cjs/multi-select/features/can_be_empty/index.js +0 -1
- package/build/cjs/multi-select/features/can_be_filtered/index.js +0 -1
- package/build/cjs/multi-select/features/can_be_opened_and_closed/index.js +0 -1
- package/build/cjs/multi-select/features/common/index.js +2 -3
- package/build/cjs/multi-select/features/duplicate_option_values/index.js +0 -1
- package/build/cjs/multi-select/features/menu_width_matches_input/index.js +1 -2
- package/build/cjs/multi-select/features/position/index.js +4 -5
- package/build/cjs/multi-select/features/position.feature +0 -1
- package/build/cjs/multi-select/features/shows_selections/index.js +0 -1
- package/build/cjs/multi-select/filterable-menu.js +1 -8
- package/build/cjs/multi-select/index.js +0 -1
- package/build/cjs/multi-select/input.js +6 -19
- package/build/cjs/multi-select/menu.js +16 -23
- package/build/cjs/multi-select/multi-select.e2e.stories.js +675 -0
- package/build/cjs/multi-select/multi-select.js +4 -21
- package/build/cjs/multi-select/{multi-select.stories.js → multi-select.prod.stories.js} +62 -101
- package/build/cjs/multi-select/selection-list.js +10 -18
- package/build/cjs/multi-select-field/__tests__/multi-select-field.test.js +1 -7
- package/build/cjs/multi-select-field/features/accepts_help_text/index.js +0 -1
- package/build/cjs/multi-select-field/features/accepts_label/index.js +0 -1
- package/build/cjs/multi-select-field/features/accepts_validation_text/index.js +0 -1
- package/build/cjs/multi-select-field/features/can_be_required/index.js +0 -1
- package/build/cjs/multi-select-field/features/has_default_clear_text/index.js +0 -1
- package/build/cjs/multi-select-field/features/has_default_empty_text/index.js +0 -1
- package/build/cjs/multi-select-field/features/has_default_filter_nomatch_text/index.js +0 -1
- package/build/cjs/multi-select-field/features/has_default_filter_placeholder/index.js +0 -1
- package/build/cjs/multi-select-field/features/has_default_loading_text/index.js +0 -1
- package/build/cjs/multi-select-field/index.js +0 -1
- package/build/cjs/multi-select-field/multi-select-field.e2e.stories.js +89 -0
- package/build/cjs/multi-select-field/multi-select-field.js +10 -51
- package/build/cjs/multi-select-field/{multi-select-field.stories.js → multi-select-field.prod.stories.js} +31 -39
- package/build/cjs/multi-select-option/index.js +0 -1
- package/build/cjs/multi-select-option/multi-select-option.js +4 -14
- package/build/cjs/select/__tests__/select.test.js +1 -7
- package/build/cjs/select/debounce/debounce.js +1 -8
- package/build/cjs/select/debounce/debounce.spec.js +0 -1
- package/build/cjs/select/empty.js +2 -9
- package/build/cjs/select/filter-input.js +3 -11
- package/build/cjs/select/filterable-menu.js +15 -29
- package/build/cjs/select/index.js +0 -8
- package/build/cjs/select/input-clear-button.js +3 -11
- package/build/cjs/select/input-placeholder.js +2 -11
- package/build/cjs/select/input-prefix.js +2 -11
- package/build/cjs/select/input-wrapper.js +2 -11
- package/build/cjs/select/loading.js +3 -12
- package/build/cjs/select/menu-wrapper.js +4 -13
- package/build/cjs/select/no-match.js +2 -9
- package/build/cjs/select/option-helpers.js +9 -18
- package/build/cjs/select/select.js +23 -69
- package/build/cjs/single-select/__tests__/selection.test.js +7 -18
- package/build/cjs/single-select/__tests__/single-select.test.js +1 -7
- package/build/cjs/single-select/features/accepts_blur_cb/index.js +1 -2
- package/build/cjs/single-select/features/accepts_focus_cb/index.js +1 -2
- package/build/cjs/single-select/features/accepts_initial_focus/index.js +1 -2
- package/build/cjs/single-select/features/accepts_loading/index.js +0 -1
- package/build/cjs/single-select/features/accepts_max_height/index.js +1 -2
- package/build/cjs/single-select/features/accepts_placeholder/index.js +0 -1
- package/build/cjs/single-select/features/accepts_prefix/index.js +0 -1
- package/build/cjs/single-select/features/allows_invalid_options/index.js +0 -1
- package/build/cjs/single-select/features/allows_selecting/index.js +2 -3
- package/build/cjs/single-select/features/can_be_cleared/index.js +1 -2
- package/build/cjs/single-select/features/can_be_disabled/index.js +0 -1
- package/build/cjs/single-select/features/can_be_empty/index.js +0 -1
- package/build/cjs/single-select/features/can_be_filtered/index.js +0 -1
- package/build/cjs/single-select/features/can_be_opened_and_closed/index.js +0 -1
- package/build/cjs/single-select/features/common/index.js +2 -3
- package/build/cjs/single-select/features/duplicate_option_values/index.js +0 -1
- package/build/cjs/single-select/features/menu_width_matches_input/index.js +1 -2
- package/build/cjs/single-select/features/position/index.js +3 -4
- package/build/cjs/single-select/features/shows_selections/index.js +0 -1
- package/build/cjs/single-select/filterable-menu.js +1 -8
- package/build/cjs/single-select/index.js +0 -1
- package/build/cjs/single-select/input.js +6 -19
- package/build/cjs/single-select/menu.js +12 -21
- package/build/cjs/single-select/selection.js +5 -17
- package/build/cjs/single-select/single-select.e2e.stories.js +633 -0
- package/build/cjs/single-select/single-select.js +4 -25
- package/build/cjs/single-select/{single-select.stories.js → single-select.prod.stories.js} +58 -95
- package/build/cjs/single-select-field/__tests__/single-select-field.test.js +1 -7
- package/build/cjs/single-select-field/features/accepts_help_text/index.js +0 -1
- package/build/cjs/single-select-field/features/accepts_label/index.js +0 -1
- package/build/cjs/single-select-field/features/accepts_validation_text/index.js +0 -1
- package/build/cjs/single-select-field/features/can_be_required/index.js +0 -1
- package/build/cjs/single-select-field/features/has_default_clear_text/index.js +0 -1
- package/build/cjs/single-select-field/features/has_default_empty_text/index.js +0 -1
- package/build/cjs/single-select-field/features/has_default_filter_nomatch_text/index.js +0 -1
- package/build/cjs/single-select-field/features/has_default_filter_placeholder/index.js +0 -1
- package/build/cjs/single-select-field/features/has_default_loading_text/index.js +0 -1
- package/build/cjs/single-select-field/index.js +0 -1
- package/build/cjs/single-select-field/single-select-field.e2e.stories.js +89 -0
- package/build/cjs/single-select-field/single-select-field.js +10 -51
- package/build/cjs/single-select-field/{single-select-field.stories.js → single-select-field.prod.stories.js} +31 -39
- package/build/cjs/single-select-option/index.js +0 -1
- package/build/cjs/single-select-option/single-select-option.js +2 -10
- package/build/es/multi-select/__tests__/selection-list.test.js +6 -3
- package/build/es/multi-select/features/accepts_blur_cb/index.js +1 -1
- package/build/es/multi-select/features/accepts_focus_cb/index.js +1 -1
- package/build/es/multi-select/features/accepts_initial_focus/index.js +1 -1
- package/build/es/multi-select/features/accepts_max_height/index.js +1 -1
- package/build/es/multi-select/features/allows_selecting/index.js +2 -2
- package/build/es/multi-select/features/can_be_cleared/index.js +1 -1
- package/build/es/multi-select/features/common/index.js +2 -2
- package/build/es/multi-select/features/menu_width_matches_input/index.js +1 -1
- package/build/es/multi-select/features/position/index.js +4 -4
- package/build/es/multi-select/features/position.feature +0 -1
- package/build/es/multi-select/filterable-menu.js +0 -2
- package/build/es/multi-select/input.js +5 -9
- package/build/es/multi-select/menu.js +15 -17
- package/build/es/multi-select/{multi-select.stories.e2e.js → multi-select.e2e.stories.js} +74 -42
- package/build/es/multi-select/multi-select.js +3 -9
- package/build/es/multi-select/{multi-select.stories.js → multi-select.prod.stories.js} +40 -24
- package/build/es/multi-select/selection-list.js +9 -12
- package/build/es/multi-select-field/{multi-select-field.stories.e2e.js → multi-select-field.e2e.stories.js} +18 -9
- package/build/es/multi-select-field/multi-select-field.js +4 -35
- package/build/es/multi-select-field/{multi-select-field.stories.js → multi-select-field.prod.stories.js} +19 -9
- package/build/es/multi-select-option/multi-select-option.js +3 -5
- package/build/es/select/debounce/debounce.js +1 -6
- package/build/es/select/empty.js +1 -3
- package/build/es/select/filter-input.js +2 -4
- package/build/es/select/filterable-menu.js +12 -15
- package/build/es/select/input-clear-button.js +2 -4
- package/build/es/select/input-placeholder.js +1 -5
- package/build/es/select/input-prefix.js +1 -5
- package/build/es/select/input-wrapper.js +1 -3
- package/build/es/select/loading.js +2 -2
- package/build/es/select/menu-wrapper.js +3 -5
- package/build/es/select/no-match.js +1 -3
- package/build/es/select/option-helpers.js +10 -6
- package/build/es/select/select.js +22 -51
- package/build/es/single-select/__tests__/selection.test.js +6 -3
- package/build/es/single-select/features/accepts_blur_cb/index.js +1 -1
- package/build/es/single-select/features/accepts_focus_cb/index.js +1 -1
- package/build/es/single-select/features/accepts_initial_focus/index.js +1 -1
- package/build/es/single-select/features/accepts_max_height/index.js +1 -1
- package/build/es/single-select/features/allows_selecting/index.js +2 -2
- package/build/es/single-select/features/can_be_cleared/index.js +1 -1
- package/build/es/single-select/features/common/index.js +2 -2
- package/build/es/single-select/features/menu_width_matches_input/index.js +1 -1
- package/build/es/single-select/features/position/index.js +3 -3
- package/build/es/single-select/input.js +5 -9
- package/build/es/single-select/menu.js +11 -15
- package/build/es/single-select/selection.js +4 -9
- package/build/es/single-select/{single-select.stories.e2e.js → single-select.e2e.stories.js} +68 -38
- package/build/es/single-select/single-select.js +3 -13
- package/build/es/single-select/{single-select.stories.js → single-select.prod.stories.js} +37 -24
- package/build/es/single-select-field/{single-select-field.stories.e2e.js → single-select-field.e2e.stories.js} +18 -9
- package/build/es/single-select-field/single-select-field.js +4 -35
- package/build/es/single-select-field/{single-select-field.stories.js → single-select-field.prod.stories.js} +19 -9
- package/build/es/single-select-option/single-select-option.js +1 -3
- package/package.json +18 -18
- package/build/cjs/multi-select/multi-select.stories.e2e.js +0 -618
- package/build/cjs/multi-select-field/multi-select-field.stories.e2e.js +0 -73
- package/build/cjs/single-select/single-select.stories.e2e.js +0 -579
- package/build/cjs/single-select-field/single-select-field.stories.e2e.js +0 -73
|
@@ -4,17 +4,26 @@ import PropTypes from 'prop-types';
|
|
|
4
4
|
import React, { useEffect } from 'react';
|
|
5
5
|
import { MultiSelectOption } from '../index.js';
|
|
6
6
|
import { MultiSelect } from './index.js';
|
|
7
|
-
const description =
|
|
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.
|
|
8
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
|
+
`;
|
|
9
20
|
const eventHandler = handlerName => (payload, event) => {
|
|
10
|
-
console.log(
|
|
11
|
-
console.log(
|
|
21
|
+
console.log(`${handlerName} payload`, payload);
|
|
22
|
+
console.log(`${handlerName} event`, event);
|
|
12
23
|
};
|
|
13
|
-
|
|
14
24
|
const onChange = eventHandler('onChange');
|
|
15
25
|
const onFocus = eventHandler('onFocus');
|
|
16
26
|
const onBlur = eventHandler('onBlur');
|
|
17
|
-
|
|
18
27
|
const CustomMultiSelectOption = _ref => {
|
|
19
28
|
let {
|
|
20
29
|
label,
|
|
@@ -24,7 +33,6 @@ const CustomMultiSelectOption = _ref => {
|
|
|
24
33
|
onClick: e => onClick({}, e)
|
|
25
34
|
}, label);
|
|
26
35
|
};
|
|
27
|
-
|
|
28
36
|
CustomMultiSelectOption.propTypes = {
|
|
29
37
|
label: PropTypes.string,
|
|
30
38
|
onClick: PropTypes.func
|
|
@@ -61,19 +69,23 @@ export default {
|
|
|
61
69
|
onChange
|
|
62
70
|
},
|
|
63
71
|
argTypes: {
|
|
64
|
-
valid: {
|
|
72
|
+
valid: {
|
|
73
|
+
...sharedPropTypes.statusArgType
|
|
65
74
|
},
|
|
66
|
-
warning: {
|
|
75
|
+
warning: {
|
|
76
|
+
...sharedPropTypes.statusArgType
|
|
67
77
|
},
|
|
68
|
-
error: {
|
|
78
|
+
error: {
|
|
79
|
+
...sharedPropTypes.statusArgType
|
|
69
80
|
},
|
|
70
|
-
clearText: {
|
|
81
|
+
clearText: {
|
|
82
|
+
...requiredIfArgType
|
|
71
83
|
},
|
|
72
|
-
noMatchText: {
|
|
84
|
+
noMatchText: {
|
|
85
|
+
...requiredIfArgType
|
|
73
86
|
}
|
|
74
87
|
}
|
|
75
88
|
};
|
|
76
|
-
|
|
77
89
|
const WithOptionsTemplate = args => /*#__PURE__*/React.createElement(MultiSelect, args, /*#__PURE__*/React.createElement(MultiSelectOption, {
|
|
78
90
|
value: "1",
|
|
79
91
|
label: "option one"
|
|
@@ -84,16 +96,14 @@ const WithOptionsTemplate = args => /*#__PURE__*/React.createElement(MultiSelect
|
|
|
84
96
|
value: "3",
|
|
85
97
|
label: "option three"
|
|
86
98
|
}));
|
|
87
|
-
|
|
88
99
|
const EmptyTemplate = args => /*#__PURE__*/React.createElement(MultiSelect, args);
|
|
89
|
-
|
|
90
100
|
export const WithOptionsAndOnChange = WithOptionsTemplate.bind({});
|
|
91
101
|
WithOptionsAndOnChange.storyName = 'With options and onChange';
|
|
92
102
|
export const WithOptionsAndASelection = WithOptionsTemplate.bind({});
|
|
93
103
|
WithOptionsAndASelection.args = {
|
|
94
104
|
selected: ['1']
|
|
95
|
-
};
|
|
96
|
-
|
|
105
|
+
};
|
|
106
|
+
// Enable this story as the primary for the docs page
|
|
97
107
|
WithOptionsAndASelection.parameters = {
|
|
98
108
|
docs: {
|
|
99
109
|
disable: false
|
|
@@ -104,7 +114,7 @@ export const WithOnFocus = WithOptionsTemplate.bind({});
|
|
|
104
114
|
WithOnFocus.args = {
|
|
105
115
|
onFocus
|
|
106
116
|
};
|
|
107
|
-
WithOnFocus.storyName = 'With
|
|
117
|
+
WithOnFocus.storyName = 'With on focus';
|
|
108
118
|
export const WithOnBlur = WithOptionsTemplate.bind({});
|
|
109
119
|
WithOnBlur.args = {
|
|
110
120
|
onBlur
|
|
@@ -154,7 +164,7 @@ WithInitialFocus.parameters = {
|
|
|
154
164
|
disable: true
|
|
155
165
|
}
|
|
156
166
|
};
|
|
157
|
-
WithInitialFocus.storyName = 'With
|
|
167
|
+
WithInitialFocus.storyName = 'With initial focus';
|
|
158
168
|
export const Dense = WithOptionsTemplate.bind({});
|
|
159
169
|
Dense.args = {
|
|
160
170
|
dense: true,
|
|
@@ -183,7 +193,8 @@ WithOptionsAndLoading.args = {
|
|
|
183
193
|
loading: true
|
|
184
194
|
};
|
|
185
195
|
export const WithOptionsLoadingAndLoadingText = WithOptionsTemplate.bind({});
|
|
186
|
-
WithOptionsLoadingAndLoadingText.args = {
|
|
196
|
+
WithOptionsLoadingAndLoadingText.args = {
|
|
197
|
+
...WithOptionsAndLoading.args,
|
|
187
198
|
loadingText: 'Loading options'
|
|
188
199
|
};
|
|
189
200
|
WithOptionsLoadingAndLoadingText.storyName = 'With options, loading and loading text';
|
|
@@ -271,7 +282,8 @@ WithOptionsAndDisabled.args = {
|
|
|
271
282
|
};
|
|
272
283
|
WithOptionsAndDisabled.storyName = 'With options and disabled';
|
|
273
284
|
export const WithOptionsASelectionAndDisabled = WithOptionsTemplate.bind({});
|
|
274
|
-
WithOptionsASelectionAndDisabled.args = {
|
|
285
|
+
WithOptionsASelectionAndDisabled.args = {
|
|
286
|
+
...WithOptionsAndDisabled.args,
|
|
275
287
|
...WithOptionsAndASelection.args
|
|
276
288
|
};
|
|
277
289
|
WithOptionsASelectionAndDisabled.storyName = 'With options, a selection and disabled';
|
|
@@ -280,7 +292,8 @@ WithPrefix.args = {
|
|
|
280
292
|
prefix: 'Prefix text'
|
|
281
293
|
};
|
|
282
294
|
export const WithPrefixAndSelection = WithOptionsTemplate.bind({});
|
|
283
|
-
WithPrefixAndSelection.args = {
|
|
295
|
+
WithPrefixAndSelection.args = {
|
|
296
|
+
...WithPrefix.args,
|
|
284
297
|
...WithOptionsAndASelection.args
|
|
285
298
|
};
|
|
286
299
|
export const WithPlaceholder = WithOptionsTemplate.bind({});
|
|
@@ -288,7 +301,8 @@ WithPlaceholder.args = {
|
|
|
288
301
|
placeholder: 'Placeholder text'
|
|
289
302
|
};
|
|
290
303
|
export const WithPlaceholderAndSelection = WithOptionsTemplate.bind({});
|
|
291
|
-
WithPlaceholderAndSelection.args = {
|
|
304
|
+
WithPlaceholderAndSelection.args = {
|
|
305
|
+
...WithPlaceholder.args,
|
|
292
306
|
...WithOptionsAndASelection.args
|
|
293
307
|
};
|
|
294
308
|
export const WithDisabledOptionAndOnChange = args => /*#__PURE__*/React.createElement(MultiSelect, args, /*#__PURE__*/React.createElement(MultiSelectOption, {
|
|
@@ -353,13 +367,15 @@ export const WithMultipleSelectionsWrapped = () => {
|
|
|
353
367
|
})));
|
|
354
368
|
};
|
|
355
369
|
export const WithClearButtonSelectionAndOnChange = WithOptionsTemplate.bind({});
|
|
356
|
-
WithClearButtonSelectionAndOnChange.args = {
|
|
370
|
+
WithClearButtonSelectionAndOnChange.args = {
|
|
371
|
+
...WithOptionsAndASelection.args,
|
|
357
372
|
clearable: true,
|
|
358
373
|
clearText: 'Clear'
|
|
359
374
|
};
|
|
360
375
|
WithClearButtonSelectionAndOnChange.storyName = 'With clear button, selection and onChange';
|
|
361
376
|
export const WithFilterField = WithOptionsTemplate.bind({});
|
|
362
|
-
WithFilterField.args = {
|
|
377
|
+
WithFilterField.args = {
|
|
378
|
+
...WithInvalidFilterableOptions.args
|
|
363
379
|
};
|
|
364
380
|
export const DefaultPosition = args => /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(MultiSelect, args, /*#__PURE__*/React.createElement(MultiSelectOption, {
|
|
365
381
|
value: "1",
|
|
@@ -2,7 +2,6 @@ import { Chip } from '@dhis2-ui/chip';
|
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import { removeOption, findOptionChild } from '../select/index.js';
|
|
5
|
-
|
|
6
5
|
const createRemoveHandler = _ref => {
|
|
7
6
|
let {
|
|
8
7
|
selected,
|
|
@@ -17,7 +16,6 @@ const createRemoveHandler = _ref => {
|
|
|
17
16
|
onChange(data, e);
|
|
18
17
|
};
|
|
19
18
|
};
|
|
20
|
-
|
|
21
19
|
const SelectionList = _ref2 => {
|
|
22
20
|
let {
|
|
23
21
|
selected,
|
|
@@ -28,10 +26,8 @@ const SelectionList = _ref2 => {
|
|
|
28
26
|
return /*#__PURE__*/React.createElement(React.Fragment, null, selected.map(value => {
|
|
29
27
|
const isProduction = process.env.NODE_ENV === 'production';
|
|
30
28
|
const selectedOption = findOptionChild(value, options);
|
|
31
|
-
|
|
32
29
|
if (!selectedOption) {
|
|
33
|
-
const message =
|
|
34
|
-
|
|
30
|
+
const message = `There is no option with the value: "${value}". ` + 'Make sure that all the values passed to the selected ' + 'prop match the value of an existing option.';
|
|
35
31
|
if (isProduction) {
|
|
36
32
|
// Don't crash the app if in production
|
|
37
33
|
console.error(message);
|
|
@@ -40,13 +36,15 @@ const SelectionList = _ref2 => {
|
|
|
40
36
|
throw new Error(message);
|
|
41
37
|
}
|
|
42
38
|
}
|
|
39
|
+
const isDisabled = selectedOption ?
|
|
40
|
+
// The chip should be disabled if the option or the select are disabled
|
|
41
|
+
selectedOption.props.disabled || disabled :
|
|
42
|
+
// If there is no selected option, just look at the select
|
|
43
|
+
disabled;
|
|
44
|
+
// Use the selected value if we do not have a label
|
|
45
|
+
const label = selectedOption ? selectedOption.props.label : value;
|
|
43
46
|
|
|
44
|
-
|
|
45
|
-
selectedOption.props.disabled || disabled : // If there is no selected option, just look at the select
|
|
46
|
-
disabled; // Use the selected value if we do not have a label
|
|
47
|
-
|
|
48
|
-
const label = selectedOption ? selectedOption.props.label : value; // Create an onRemove handler, but only if it's not disabled
|
|
49
|
-
|
|
47
|
+
// Create an onRemove handler, but only if it's not disabled
|
|
50
48
|
const onRemove = isDisabled ? undefined : createRemoveHandler({
|
|
51
49
|
selected,
|
|
52
50
|
onChange,
|
|
@@ -65,7 +63,6 @@ const SelectionList = _ref2 => {
|
|
|
65
63
|
}, label);
|
|
66
64
|
}));
|
|
67
65
|
};
|
|
68
|
-
|
|
69
66
|
SelectionList.propTypes = {
|
|
70
67
|
disabled: PropTypes.bool,
|
|
71
68
|
options: PropTypes.node,
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { storiesOf } from '@storybook/react';
|
|
2
1
|
import React from 'react';
|
|
3
2
|
import { MultiSelectOption } from '../index.js';
|
|
4
3
|
import { MultiSelectField } from './index.js';
|
|
5
|
-
|
|
4
|
+
export default {
|
|
5
|
+
title: 'MultiSelectField'
|
|
6
|
+
};
|
|
7
|
+
export const WithLabel = () => /*#__PURE__*/React.createElement(MultiSelectField, {
|
|
6
8
|
label: "The label"
|
|
7
9
|
}, /*#__PURE__*/React.createElement(MultiSelectOption, {
|
|
8
10
|
value: "1",
|
|
@@ -13,7 +15,8 @@ storiesOf('MultiSelectField', module).add('With label', () => /*#__PURE__*/React
|
|
|
13
15
|
}), /*#__PURE__*/React.createElement(MultiSelectOption, {
|
|
14
16
|
value: "3",
|
|
15
17
|
label: "three"
|
|
16
|
-
}))
|
|
18
|
+
}));
|
|
19
|
+
export const WithHelpText = () => /*#__PURE__*/React.createElement(MultiSelectField, {
|
|
17
20
|
helpText: "The help text"
|
|
18
21
|
}, /*#__PURE__*/React.createElement(MultiSelectOption, {
|
|
19
22
|
value: "1",
|
|
@@ -24,7 +27,8 @@ storiesOf('MultiSelectField', module).add('With label', () => /*#__PURE__*/React
|
|
|
24
27
|
}), /*#__PURE__*/React.createElement(MultiSelectOption, {
|
|
25
28
|
value: "3",
|
|
26
29
|
label: "three"
|
|
27
|
-
}))
|
|
30
|
+
}));
|
|
31
|
+
export const WithValidationText = () => /*#__PURE__*/React.createElement(MultiSelectField, {
|
|
28
32
|
validationText: "The validation text"
|
|
29
33
|
}, /*#__PURE__*/React.createElement(MultiSelectOption, {
|
|
30
34
|
value: "1",
|
|
@@ -35,7 +39,8 @@ storiesOf('MultiSelectField', module).add('With label', () => /*#__PURE__*/React
|
|
|
35
39
|
}), /*#__PURE__*/React.createElement(MultiSelectOption, {
|
|
36
40
|
value: "3",
|
|
37
41
|
label: "three"
|
|
38
|
-
}))
|
|
42
|
+
}));
|
|
43
|
+
export const WithLabelAndRequiredStatus = () => /*#__PURE__*/React.createElement(MultiSelectField, {
|
|
39
44
|
label: "The label",
|
|
40
45
|
required: true
|
|
41
46
|
}, /*#__PURE__*/React.createElement(MultiSelectOption, {
|
|
@@ -47,19 +52,23 @@ storiesOf('MultiSelectField', module).add('With label', () => /*#__PURE__*/React
|
|
|
47
52
|
}), /*#__PURE__*/React.createElement(MultiSelectOption, {
|
|
48
53
|
value: "3",
|
|
49
54
|
label: "three"
|
|
50
|
-
}))
|
|
55
|
+
}));
|
|
56
|
+
export const WithClearableAndSelectedOption = () => /*#__PURE__*/React.createElement(MultiSelectField, {
|
|
51
57
|
selected: ['1'],
|
|
52
58
|
clearable: true
|
|
53
59
|
}, /*#__PURE__*/React.createElement(MultiSelectOption, {
|
|
54
60
|
key: "1",
|
|
55
61
|
value: "1",
|
|
56
62
|
label: "One"
|
|
57
|
-
}))
|
|
63
|
+
}));
|
|
64
|
+
export const WithFilterable = () => /*#__PURE__*/React.createElement(MultiSelectField, {
|
|
58
65
|
filterable: true
|
|
59
66
|
}, /*#__PURE__*/React.createElement(MultiSelectOption, {
|
|
60
67
|
key: "1",
|
|
61
68
|
value: "1",
|
|
62
69
|
label: "One"
|
|
63
|
-
}))
|
|
70
|
+
}));
|
|
71
|
+
export const WithLoading = () => /*#__PURE__*/React.createElement(MultiSelectField, {
|
|
64
72
|
loading: true
|
|
65
|
-
})
|
|
73
|
+
});
|
|
74
|
+
export const WithoutOptions = () => /*#__PURE__*/React.createElement(MultiSelectField, null);
|
|
@@ -1,19 +1,18 @@
|
|
|
1
|
+
import { sharedPropTypes } from '@dhis2/ui-constants';
|
|
1
2
|
import { Box } from '@dhis2-ui/box';
|
|
2
3
|
import { Field } from '@dhis2-ui/field';
|
|
3
|
-
import { sharedPropTypes } from '@dhis2/ui-constants';
|
|
4
4
|
import PropTypes from 'prop-types';
|
|
5
5
|
import React from 'react';
|
|
6
|
-
import
|
|
7
|
-
import
|
|
6
|
+
import i18n from '../locales/index.js';
|
|
7
|
+
import { MultiSelect } from '../multi-select/index.js';
|
|
8
8
|
|
|
9
|
+
// TODO: translate
|
|
9
10
|
const translate = (prop, interpolationObject) => {
|
|
10
11
|
if (typeof prop === 'function') {
|
|
11
12
|
return prop(interpolationObject);
|
|
12
13
|
}
|
|
13
|
-
|
|
14
14
|
return prop;
|
|
15
15
|
};
|
|
16
|
-
|
|
17
16
|
class MultiSelectField extends React.Component {
|
|
18
17
|
render() {
|
|
19
18
|
const {
|
|
@@ -91,9 +90,7 @@ class MultiSelectField extends React.Component {
|
|
|
91
90
|
dense: dense
|
|
92
91
|
}, children)));
|
|
93
92
|
}
|
|
94
|
-
|
|
95
93
|
}
|
|
96
|
-
|
|
97
94
|
MultiSelectField.defaultProps = {
|
|
98
95
|
selected: [],
|
|
99
96
|
dataTest: 'dhis2-uiwidgets-multiselectfield',
|
|
@@ -107,90 +104,62 @@ MultiSelectField.propTypes = {
|
|
|
107
104
|
/** Should be `MultiSelectOption` components */
|
|
108
105
|
children: PropTypes.node,
|
|
109
106
|
className: PropTypes.string,
|
|
110
|
-
|
|
111
107
|
/** Label for the button that clears selections */
|
|
112
108
|
clearText: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
|
113
|
-
|
|
114
109
|
/** Adds a button to the MultiSelect that clears selections when pressed */
|
|
115
110
|
clearable: PropTypes.bool,
|
|
116
111
|
dataTest: PropTypes.string,
|
|
117
|
-
|
|
118
112
|
/** Makes the MultiSelect smaller */
|
|
119
113
|
dense: PropTypes.bool,
|
|
120
|
-
|
|
121
114
|
/** Disables the MultiSelect */
|
|
122
115
|
disabled: PropTypes.bool,
|
|
123
|
-
|
|
124
116
|
/** Text to display when there are no options */
|
|
125
117
|
empty: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
126
|
-
|
|
127
118
|
/** Adds 'error' appearance for validation feedback. Mutually exclusive with 'valid' and 'warning' props */
|
|
128
119
|
error: sharedPropTypes.statusPropType,
|
|
129
|
-
|
|
130
120
|
/** Placeholder text to show in the filter field when it is empty */
|
|
131
121
|
filterPlaceholder: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
132
|
-
|
|
133
122
|
/** Adds a field to filter options */
|
|
134
123
|
filterable: PropTypes.bool,
|
|
135
|
-
|
|
136
124
|
/** Useful guiding text to display below the MultiSelect */
|
|
137
125
|
helpText: PropTypes.string,
|
|
138
|
-
|
|
139
126
|
/** Grabs initial focus on the page */
|
|
140
127
|
initialFocus: PropTypes.bool,
|
|
141
|
-
|
|
142
128
|
/** Constrains the height of the input */
|
|
143
129
|
inputMaxHeight: PropTypes.string,
|
|
144
|
-
|
|
145
130
|
/** Sets the width of the input. Can be any valid CSS measurement */
|
|
146
131
|
inputWidth: PropTypes.string,
|
|
147
|
-
|
|
148
132
|
/** Text for the label above the MultiSelect */
|
|
149
133
|
label: PropTypes.string,
|
|
150
|
-
|
|
151
134
|
/** Applies a loading appearance to the dropdown options */
|
|
152
135
|
loading: PropTypes.bool,
|
|
153
|
-
|
|
154
136
|
/** Text to display when `loading` is true */
|
|
155
137
|
loadingText: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
|
156
|
-
|
|
157
138
|
/** Constrains height of the MultiSelect */
|
|
158
139
|
maxHeight: PropTypes.string,
|
|
159
|
-
|
|
160
140
|
/** Text to display when there are no filter results */
|
|
161
141
|
noMatchText: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
|
162
|
-
|
|
163
142
|
/** Placeholder text when the MultiSelect is empty */
|
|
164
143
|
placeholder: PropTypes.string,
|
|
165
|
-
|
|
166
144
|
/** Leading text to prefix selections */
|
|
167
145
|
prefix: PropTypes.string,
|
|
168
|
-
|
|
169
146
|
/** Indicates that a selection is required */
|
|
170
147
|
required: PropTypes.bool,
|
|
171
|
-
|
|
172
148
|
/** Selected items in the MultiSelect (each string should refer to the item's `value` attribute) */
|
|
173
149
|
selected: PropTypes.arrayOf(PropTypes.string),
|
|
174
150
|
tabIndex: PropTypes.string,
|
|
175
|
-
|
|
176
151
|
/** Adds 'valid' appearance for validation feedback. Mutually exclusive with 'error' and 'warning' props */
|
|
177
152
|
valid: sharedPropTypes.statusPropType,
|
|
178
|
-
|
|
179
153
|
/** Text to provide form validation feedback. Receives styles according to validation status */
|
|
180
154
|
validationText: PropTypes.string,
|
|
181
|
-
|
|
182
155
|
/** Adds 'warning' appearance for validation feedback. Mutually exclusive with 'valid' and 'error' props */
|
|
183
156
|
warning: sharedPropTypes.statusPropType,
|
|
184
|
-
|
|
185
157
|
/** Called with signature `({ selected: [String] }, event)` */
|
|
186
158
|
onBlur: PropTypes.func,
|
|
187
|
-
|
|
188
159
|
/** Called with signature `({ selected: [String] }, event)` */
|
|
189
160
|
onChange: PropTypes.func,
|
|
190
|
-
|
|
191
161
|
/** Called with signature `({ selected: [String] }, event)` */
|
|
192
162
|
onFocus: PropTypes.func,
|
|
193
|
-
|
|
194
163
|
/** Called with signature `({ selected: [String] }, event)` */
|
|
195
164
|
onKeyDown: PropTypes.func
|
|
196
165
|
};
|
|
@@ -2,10 +2,18 @@ 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 =
|
|
5
|
+
const description = `
|
|
6
|
+
\`MultiSelectField\` is a wrapper around a \`MultiSelect\` component that adds a label, help text, validation text, and other features.
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
See 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).
|
|
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
|
+
const onChange = selected => alert(`Selected changed to: ${JSON.stringify(selected, null, 2)}`);
|
|
9
17
|
const options = [/*#__PURE__*/React.createElement(MultiSelectOption, {
|
|
10
18
|
key: "1",
|
|
11
19
|
value: "1",
|
|
@@ -61,7 +69,8 @@ export default {
|
|
|
61
69
|
}
|
|
62
70
|
},
|
|
63
71
|
// default args for stories
|
|
64
|
-
args: {
|
|
72
|
+
args: {
|
|
73
|
+
// Fix default prop issues - causes 'i18n is not defined' error
|
|
65
74
|
...MultiSelectField.defaultProps,
|
|
66
75
|
label: 'Default label',
|
|
67
76
|
selected: ['1'],
|
|
@@ -69,17 +78,18 @@ export default {
|
|
|
69
78
|
onChange: onChange
|
|
70
79
|
},
|
|
71
80
|
argTypes: {
|
|
72
|
-
valid: {
|
|
81
|
+
valid: {
|
|
82
|
+
...sharedPropTypes.statusArgType
|
|
73
83
|
},
|
|
74
|
-
warning: {
|
|
84
|
+
warning: {
|
|
85
|
+
...sharedPropTypes.statusArgType
|
|
75
86
|
},
|
|
76
|
-
error: {
|
|
87
|
+
error: {
|
|
88
|
+
...sharedPropTypes.statusArgType
|
|
77
89
|
}
|
|
78
90
|
}
|
|
79
91
|
};
|
|
80
|
-
|
|
81
92
|
const Template = args => /*#__PURE__*/React.createElement(MultiSelectField, args);
|
|
82
|
-
|
|
83
93
|
export const Default = Template.bind({});
|
|
84
94
|
export const WithHelpText = Template.bind({});
|
|
85
95
|
WithHelpText.args = {
|
|
@@ -88,7 +98,7 @@ WithHelpText.args = {
|
|
|
88
98
|
WithHelpText.parameters = {
|
|
89
99
|
docs: {
|
|
90
100
|
description: {
|
|
91
|
-
story:
|
|
101
|
+
story: `_**Note**: The dropdowns in the following stories won't appear correctly on this page. View these demos in the 'Canvas' tab._`
|
|
92
102
|
}
|
|
93
103
|
}
|
|
94
104
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _JSXStyle from "styled-jsx/style";
|
|
2
|
-
import { Checkbox } from '@dhis2-ui/checkbox';
|
|
3
2
|
import { colors, spacers } from '@dhis2/ui-constants';
|
|
3
|
+
import { Checkbox } from '@dhis2-ui/checkbox';
|
|
4
4
|
import cx from 'classnames';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import React from 'react';
|
|
@@ -11,10 +11,9 @@ const {
|
|
|
11
11
|
} = {
|
|
12
12
|
styles: /*#__PURE__*/React.createElement(_JSXStyle, {
|
|
13
13
|
id: "2013783366"
|
|
14
|
-
}, [
|
|
14
|
+
}, [`.jsx-2013783366{padding:${spacers.dp8} ${spacers.dp12};}`]),
|
|
15
15
|
className: "jsx-2013783366"
|
|
16
16
|
};
|
|
17
|
-
|
|
18
17
|
const MultiSelectOption = _ref => {
|
|
19
18
|
let {
|
|
20
19
|
label,
|
|
@@ -43,9 +42,8 @@ const MultiSelectOption = _ref => {
|
|
|
43
42
|
}), styles, /*#__PURE__*/React.createElement(_JSXStyle, {
|
|
44
43
|
id: "3813980210",
|
|
45
44
|
dynamic: [colors.grey200]
|
|
46
|
-
}, [
|
|
45
|
+
}, [`div.__jsx-style-dynamic-selector:hover{background-color:${colors.grey200};}`, "div.disabled.__jsx-style-dynamic-selector:hover{background-color:initial;}"]));
|
|
47
46
|
};
|
|
48
|
-
|
|
49
47
|
MultiSelectOption.defaultProps = {
|
|
50
48
|
dataTest: 'dhis2-uicore-multiselectoption'
|
|
51
49
|
};
|
|
@@ -1,31 +1,26 @@
|
|
|
1
1
|
var _this = this;
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* Returns a function, that, as long as it continues to be invoked, will not be triggered. The
|
|
5
4
|
* function will be called after it stops being called for N milliseconds. If `immediate` is
|
|
6
5
|
* passed, trigger the function on the leading edge, instead of the trailing.
|
|
7
6
|
*/
|
|
7
|
+
|
|
8
8
|
export const debounce = (func, wait, immediate) => {
|
|
9
9
|
let timeout;
|
|
10
10
|
return function () {
|
|
11
11
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
12
12
|
args[_key] = arguments[_key];
|
|
13
13
|
}
|
|
14
|
-
|
|
15
14
|
const context = _this;
|
|
16
|
-
|
|
17
15
|
const later = () => {
|
|
18
16
|
timeout = null;
|
|
19
|
-
|
|
20
17
|
if (!immediate) {
|
|
21
18
|
func.apply(context, args);
|
|
22
19
|
}
|
|
23
20
|
};
|
|
24
|
-
|
|
25
21
|
const callNow = immediate && !timeout;
|
|
26
22
|
clearTimeout(timeout);
|
|
27
23
|
timeout = setTimeout(later, wait);
|
|
28
|
-
|
|
29
24
|
if (callNow) {
|
|
30
25
|
func.apply(context, args);
|
|
31
26
|
}
|
package/build/es/select/empty.js
CHANGED
|
@@ -2,7 +2,6 @@ import _JSXStyle from "styled-jsx/style";
|
|
|
2
2
|
import { colors, spacers, theme } from '@dhis2/ui-constants';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import React from 'react';
|
|
5
|
-
|
|
6
5
|
const Empty = _ref => {
|
|
7
6
|
let {
|
|
8
7
|
message,
|
|
@@ -15,9 +14,8 @@ const Empty = _ref => {
|
|
|
15
14
|
}, message, /*#__PURE__*/React.createElement(_JSXStyle, {
|
|
16
15
|
id: "3788156646",
|
|
17
16
|
dynamic: [colors.grey700, theme.fonts, spacers.dp8, spacers.dp24]
|
|
18
|
-
}, [
|
|
17
|
+
}, [`div.__jsx-style-dynamic-selector{color:${colors.grey700};font-family:${theme.fonts};font-size:13px;line-height:16px;padding-block:${spacers.dp8};padding-inline:${spacers.dp24};text-align:center;}`]));
|
|
19
18
|
};
|
|
20
|
-
|
|
21
19
|
Empty.propTypes = {
|
|
22
20
|
dataTest: PropTypes.string.isRequired,
|
|
23
21
|
message: PropTypes.string.isRequired,
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import _JSXStyle from "styled-jsx/style";
|
|
2
|
-
import { Input } from '@dhis2-ui/input';
|
|
3
2
|
import { spacers, colors } from '@dhis2/ui-constants';
|
|
3
|
+
import { Input } from '@dhis2-ui/input';
|
|
4
4
|
import PropTypes from 'prop-types';
|
|
5
5
|
import React from 'react';
|
|
6
|
-
|
|
7
6
|
const FilterInput = _ref => {
|
|
8
7
|
let {
|
|
9
8
|
value,
|
|
@@ -26,9 +25,8 @@ const FilterInput = _ref => {
|
|
|
26
25
|
}), /*#__PURE__*/React.createElement(_JSXStyle, {
|
|
27
26
|
id: "730881408",
|
|
28
27
|
dynamic: [colors.white, spacers.dp8, spacers.dp8, spacers.dp4, spacers.dp8]
|
|
29
|
-
}, [
|
|
28
|
+
}, [`div.__jsx-style-dynamic-selector{position:-webkit-sticky;position:sticky;-webkit-inset-block-start:0;-ms-intb-rlock-start:0;inset-block-start:0;background:${colors.white};padding-block-start:${spacers.dp8};padding-inline-end:${spacers.dp8};padding-block-end:${spacers.dp4};padding-inline-start:${spacers.dp8};z-index:1;}`]));
|
|
30
29
|
};
|
|
31
|
-
|
|
32
30
|
FilterInput.propTypes = {
|
|
33
31
|
dataTest: PropTypes.string.isRequired,
|
|
34
32
|
value: PropTypes.string.isRequired,
|