@dhis2-ui/select 10.16.2 → 10.16.3
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/package.json +17 -16
- package/src/index.js +9 -0
- package/src/locales/ar/translations.json +7 -0
- package/src/locales/ar_IQ/translations.json +7 -0
- package/src/locales/ckb/translations.json +7 -0
- package/src/locales/cs/translations.json +7 -0
- package/src/locales/da/translations.json +7 -0
- package/src/locales/en/translations.json +11 -0
- package/src/locales/en_US/translations.json +9 -0
- package/src/locales/es/translations.json +7 -0
- package/src/locales/es_419/translations.json +7 -0
- package/src/locales/fr/translations.json +7 -0
- package/src/locales/hi_IN/translations.json +7 -0
- package/src/locales/id/translations.json +7 -0
- package/src/locales/index.js +80 -0
- package/src/locales/km/translations.json +7 -0
- package/src/locales/lo/translations.json +7 -0
- package/src/locales/my/translations.json +7 -0
- package/src/locales/nb/translations.json +7 -0
- package/src/locales/nl/translations.json +7 -0
- package/src/locales/prs/translations.json +7 -0
- package/src/locales/ps/translations.json +7 -0
- package/src/locales/pt/translations.json +7 -0
- package/src/locales/pt_BR/translations.json +7 -0
- package/src/locales/ru/translations.json +7 -0
- package/src/locales/sv/translations.json +7 -0
- package/src/locales/tet/translations.json +7 -0
- package/src/locales/tg/translations.json +7 -0
- package/src/locales/uk/translations.json +7 -0
- package/src/locales/ur/translations.json +7 -0
- package/src/locales/uz_Latn/translations.json +7 -0
- package/src/locales/uz_UZ_Cyrl/translations.json +7 -0
- package/src/locales/uz_UZ_Latn/translations.json +7 -0
- package/src/locales/vi/translations.json +7 -0
- package/src/locales/zh/translations.json +9 -0
- package/src/locales/zh_CN/translations.json +7 -0
- package/src/multi-select/__tests__/multi-select.test.js +23 -0
- package/src/multi-select/__tests__/selection-list.test.js +102 -0
- package/src/multi-select/features/accepts_blur_cb/index.js +14 -0
- package/src/multi-select/features/accepts_blur_cb.feature +8 -0
- package/src/multi-select/features/accepts_focus_cb/index.js +14 -0
- package/src/multi-select/features/accepts_focus_cb.feature +6 -0
- package/src/multi-select/features/accepts_initial_focus/index.js +5 -0
- package/src/multi-select/features/accepts_initial_focus.feature +5 -0
- package/src/multi-select/features/accepts_loading/index.js +22 -0
- package/src/multi-select/features/accepts_loading.feature +14 -0
- package/src/multi-select/features/accepts_max_height/index.js +31 -0
- package/src/multi-select/features/accepts_max_height.feature +11 -0
- package/src/multi-select/features/accepts_placeholder/index.js +25 -0
- package/src/multi-select/features/accepts_placeholder.feature +10 -0
- package/src/multi-select/features/accepts_prefix/index.js +19 -0
- package/src/multi-select/features/accepts_prefix.feature +10 -0
- package/src/multi-select/features/allows_invalid_options/index.js +27 -0
- package/src/multi-select/features/allows_invalid_options.feature +12 -0
- package/src/multi-select/features/allows_selecting/index.js +81 -0
- package/src/multi-select/features/allows_selecting.feature +44 -0
- package/src/multi-select/features/can_be_cleared/index.js +22 -0
- package/src/multi-select/features/can_be_cleared.feature +6 -0
- package/src/multi-select/features/can_be_disabled/index.js +36 -0
- package/src/multi-select/features/can_be_disabled.feature +32 -0
- package/src/multi-select/features/can_be_empty/index.js +28 -0
- package/src/multi-select/features/can_be_empty.feature +16 -0
- package/src/multi-select/features/can_be_filtered/index.js +23 -0
- package/src/multi-select/features/can_be_filtered.feature +14 -0
- package/src/multi-select/features/can_be_opened_and_closed/index.js +32 -0
- package/src/multi-select/features/can_be_opened_and_closed.feature +41 -0
- package/src/multi-select/features/common/index.js +49 -0
- package/src/multi-select/features/duplicate_option_values/index.js +21 -0
- package/src/multi-select/features/duplicate_option_values.feature +7 -0
- package/src/multi-select/features/menu_width_matches_input/index.js +53 -0
- package/src/multi-select/features/menu_width_matches_input.feature +11 -0
- package/src/multi-select/features/position/index.js +160 -0
- package/src/multi-select/features/position.feature +46 -0
- package/src/multi-select/features/shows_selections/index.js +18 -0
- package/src/multi-select/features/shows_selections.feature +9 -0
- package/src/multi-select/filterable-menu.js +43 -0
- package/src/multi-select/index.js +1 -0
- package/src/multi-select/input.js +129 -0
- package/src/multi-select/menu.js +91 -0
- package/src/multi-select/multi-select.e2e.stories.js +407 -0
- package/src/multi-select/multi-select.js +148 -0
- package/src/multi-select/multi-select.prod.stories.js +408 -0
- package/src/multi-select/selection-list.js +79 -0
- package/src/multi-select-field/__tests__/multi-select-field.test.js +29 -0
- package/src/multi-select-field/features/accepts_help_text/index.js +9 -0
- package/src/multi-select-field/features/accepts_help_text.feature +5 -0
- package/src/multi-select-field/features/accepts_label/index.js +9 -0
- package/src/multi-select-field/features/accepts_label.feature +5 -0
- package/src/multi-select-field/features/accepts_validation_text/index.js +9 -0
- package/src/multi-select-field/features/accepts_validation_text.feature +5 -0
- package/src/multi-select-field/features/can_be_required/index.js +11 -0
- package/src/multi-select-field/features/can_be_required.feature +5 -0
- package/src/multi-select-field/features/has_default_clear_text/index.js +16 -0
- package/src/multi-select-field/features/has_default_clear_text.feature +6 -0
- package/src/multi-select-field/features/has_default_empty_text/index.js +13 -0
- package/src/multi-select-field/features/has_default_empty_text.feature +6 -0
- package/src/multi-select-field/features/has_default_filter_nomatch_text/index.js +17 -0
- package/src/multi-select-field/features/has_default_filter_nomatch_text.feature +7 -0
- package/src/multi-select-field/features/has_default_filter_placeholder/index.js +15 -0
- package/src/multi-select-field/features/has_default_filter_placeholder.feature +6 -0
- package/src/multi-select-field/features/has_default_loading_text/index.js +13 -0
- package/src/multi-select-field/features/has_default_loading_text.feature +6 -0
- package/src/multi-select-field/index.js +1 -0
- package/src/multi-select-field/multi-select-field.e2e.stories.js +45 -0
- package/src/multi-select-field/multi-select-field.js +178 -0
- package/src/multi-select-field/multi-select-field.prod.stories.js +137 -0
- package/src/multi-select-option/index.js +1 -0
- package/src/multi-select-option/multi-select-option.js +70 -0
- package/src/select/__tests__/select.test.js +31 -0
- package/src/select/debounce/debounce.js +30 -0
- package/src/select/debounce/debounce.spec.js +35 -0
- package/src/select/empty.js +28 -0
- package/src/select/filter-input.js +42 -0
- package/src/select/filterable-menu.js +106 -0
- package/src/select/index.js +14 -0
- package/src/select/input-clear-button.js +66 -0
- package/src/select/input-placeholder.js +30 -0
- package/src/select/input-prefix.js +32 -0
- package/src/select/input-wrapper.js +114 -0
- package/src/select/loading.js +33 -0
- package/src/select/menu-wrapper.js +52 -0
- package/src/select/no-match.js +28 -0
- package/src/select/option-helpers.js +34 -0
- package/src/select/select.js +256 -0
- package/src/simple-single-select/__stories__/DefaultPosition.js +37 -0
- package/src/simple-single-select/__stories__/Dense.js +17 -0
- package/src/simple-single-select/__stories__/Empty.js +15 -0
- package/src/simple-single-select/__stories__/EmptyWithEmptyNode.js +27 -0
- package/src/simple-single-select/__stories__/EmptyWithEmptyText.js +16 -0
- package/src/simple-single-select/__stories__/FlippedPosition.js +36 -0
- package/src/simple-single-select/__stories__/InfiniteLoading.js +65 -0
- package/src/simple-single-select/__stories__/Loading.js +15 -0
- package/src/simple-single-select/__stories__/ShiftedIntoView.js +35 -0
- package/src/simple-single-select/__stories__/WithClearButton.js +26 -0
- package/src/simple-single-select/__stories__/WithCustomLowMaxHeight.js +17 -0
- package/src/simple-single-select/__stories__/WithCustomOptions.js +78 -0
- package/src/simple-single-select/__stories__/WithDisabledOption.js +25 -0
- package/src/simple-single-select/__stories__/WithFilterField.js +30 -0
- package/src/simple-single-select/__stories__/WithInitialFocus.js +29 -0
- package/src/simple-single-select/__stories__/WithManyOptions.js +19 -0
- package/src/simple-single-select/__stories__/WithMultipleSelectsAndScrollableParent.js +65 -0
- package/src/simple-single-select/__stories__/WithNoMatchText.js +25 -0
- package/src/simple-single-select/__stories__/WithOnBlur.js +22 -0
- package/src/simple-single-select/__stories__/WithOnFocus.js +22 -0
- package/src/simple-single-select/__stories__/WithOptionsAndDisabled.js +17 -0
- package/src/simple-single-select/__stories__/WithOptionsAndLoading.js +23 -0
- package/src/simple-single-select/__stories__/WithOptionsAndLoadingText.js +24 -0
- package/src/simple-single-select/__stories__/WithPlaceholder.js +18 -0
- package/src/simple-single-select/__stories__/WithPlaceholderAndSelection.js +20 -0
- package/src/simple-single-select/__stories__/WithPrefix.js +17 -0
- package/src/simple-single-select/__stories__/WithPrefixAndSelection.js +20 -0
- package/src/simple-single-select/__stories__/WithRTL.js +29 -0
- package/src/simple-single-select/__stories__/WithScrollingParent.js +51 -0
- package/src/simple-single-select/__stories__/WithSelection.js +19 -0
- package/src/simple-single-select/__stories__/WithSelectionAndDisabled.js +20 -0
- package/src/simple-single-select/__stories__/WithServerSideFilteringDemo.js +245 -0
- package/src/simple-single-select/__stories__/WithSimpleFilteringDemo.js +50 -0
- package/src/simple-single-select/__stories__/WithoutOptionsAndLoading.js +16 -0
- package/src/simple-single-select/__stories__/WithoutSelection.js +17 -0
- package/src/simple-single-select/__stories__/options.js +96 -0
- package/src/simple-single-select/__stories__/simple-single-select-server-side-filtering/CustomDataProvider.js +70 -0
- package/src/simple-single-select/__stories__/simple-single-select-server-side-filtering/dataElements.js +4271 -0
- package/src/simple-single-select/__stories__/simple-single-select-server-side-filtering/index.js +1 -0
- package/src/simple-single-select/features/keyboard-interactions.test.e2e.js +581 -0
- package/src/simple-single-select/features/menu-positioning.test.e2e.js +187 -0
- package/src/simple-single-select/index.js +2 -0
- package/src/simple-single-select/is-option-hidden.js +21 -0
- package/src/simple-single-select/menu/empty.js +27 -0
- package/src/simple-single-select/menu/filter.js +61 -0
- package/src/simple-single-select/menu/index.js +1 -0
- package/src/simple-single-select/menu/loading.js +38 -0
- package/src/simple-single-select/menu/menu.js +171 -0
- package/src/simple-single-select/menu/no-match.js +28 -0
- package/src/simple-single-select/menu/option.js +161 -0
- package/src/simple-single-select/menu/options-list.js +107 -0
- package/src/simple-single-select/selected-value/clear-button.js +71 -0
- package/src/simple-single-select/selected-value/container.js +146 -0
- package/src/simple-single-select/selected-value/index.js +1 -0
- package/src/simple-single-select/selected-value/placeholder.js +24 -0
- package/src/simple-single-select/selected-value/prefix.js +26 -0
- package/src/simple-single-select/selected-value/selected-value.js +174 -0
- package/src/simple-single-select/shared-prop-types.js +8 -0
- package/src/simple-single-select/simple-single-select.e2e.stories.js +216 -0
- package/src/simple-single-select/simple-single-select.js +389 -0
- package/src/simple-single-select/simple-single-select.prod.stories.js +41 -0
- package/src/simple-single-select/simple-single-select.test.js +1136 -0
- package/src/simple-single-select/use-handle-key-press/index.js +2 -0
- package/src/simple-single-select/use-handle-key-press/use-focus-option.js +24 -0
- package/src/simple-single-select/use-handle-key-press/use-handle-key-press-on-combobox.js +259 -0
- package/src/simple-single-select/use-handle-key-press/use-handle-key-press-on-filter-input.js +147 -0
- package/src/simple-single-select/use-handle-key-press/use-handle-typing.js +79 -0
- package/src/simple-single-select/use-handle-key-press/use-highlight-first-option-on-previous-page.js +62 -0
- package/src/simple-single-select/use-handle-key-press/use-highlight-first-visible-option.js +38 -0
- package/src/simple-single-select/use-handle-key-press/use-highlight-last-option-on-next-page.js +60 -0
- package/src/simple-single-select/use-handle-key-press/use-highlight-last-visible-option.js +52 -0
- package/src/simple-single-select/use-handle-key-press/use-page-down.js +50 -0
- package/src/simple-single-select/use-handle-key-press/use-page-up.js +50 -0
- package/src/simple-single-select/use-handle-key-press/utils.js +23 -0
- package/src/simple-single-select-field/index.js +1 -0
- package/src/simple-single-select-field/simple-single-select-field.js +198 -0
- package/src/simple-single-select-field/simple-single-select-field.prod.stories.js +188 -0
- package/src/simple-single-select-field/simple-single-select-field.test.js +144 -0
- package/src/single-select/__tests__/selection.test.js +102 -0
- package/src/single-select/__tests__/single-select.test.js +23 -0
- package/src/single-select/features/accepts_blur_cb/index.js +14 -0
- package/src/single-select/features/accepts_blur_cb.feature +8 -0
- package/src/single-select/features/accepts_focus_cb/index.js +14 -0
- package/src/single-select/features/accepts_focus_cb.feature +6 -0
- package/src/single-select/features/accepts_initial_focus/index.js +5 -0
- package/src/single-select/features/accepts_initial_focus.feature +5 -0
- package/src/single-select/features/accepts_loading/index.js +22 -0
- package/src/single-select/features/accepts_loading.feature +14 -0
- package/src/single-select/features/accepts_max_height/index.js +31 -0
- package/src/single-select/features/accepts_max_height.feature +11 -0
- package/src/single-select/features/accepts_placeholder/index.js +25 -0
- package/src/single-select/features/accepts_placeholder.feature +10 -0
- package/src/single-select/features/accepts_prefix/index.js +19 -0
- package/src/single-select/features/accepts_prefix.feature +10 -0
- package/src/single-select/features/allows_invalid_options/index.js +28 -0
- package/src/single-select/features/allows_invalid_options.feature +12 -0
- package/src/single-select/features/allows_selecting/index.js +38 -0
- package/src/single-select/features/allows_selecting.feature +21 -0
- package/src/single-select/features/can_be_cleared/index.js +22 -0
- package/src/single-select/features/can_be_cleared.feature +6 -0
- package/src/single-select/features/can_be_disabled/index.js +39 -0
- package/src/single-select/features/can_be_disabled.feature +32 -0
- package/src/single-select/features/can_be_empty/index.js +28 -0
- package/src/single-select/features/can_be_empty.feature +16 -0
- package/src/single-select/features/can_be_filtered/index.js +23 -0
- package/src/single-select/features/can_be_filtered.feature +14 -0
- package/src/single-select/features/can_be_opened_and_closed/index.js +32 -0
- package/src/single-select/features/can_be_opened_and_closed.feature +41 -0
- package/src/single-select/features/common/index.js +44 -0
- package/src/single-select/features/duplicate_option_values/index.js +26 -0
- package/src/single-select/features/duplicate_option_values.feature +7 -0
- package/src/single-select/features/menu_width_matches_input/index.js +53 -0
- package/src/single-select/features/menu_width_matches_input.feature +11 -0
- package/src/single-select/features/position/index.js +111 -0
- package/src/single-select/features/position.feature +26 -0
- package/src/single-select/features/shows_selections/index.js +9 -0
- package/src/single-select/features/shows_selections.feature +5 -0
- package/src/single-select/filterable-menu.js +41 -0
- package/src/single-select/index.js +1 -0
- package/src/single-select/input.js +101 -0
- package/src/single-select/menu.js +75 -0
- package/src/single-select/selection.js +60 -0
- package/src/single-select/single-select.e2e.stories.js +376 -0
- package/src/single-select/single-select.js +146 -0
- package/src/single-select/single-select.prod.stories.js +358 -0
- package/src/single-select-field/__tests__/single-select-field.test.js +29 -0
- package/src/single-select-field/features/accepts_help_text/index.js +9 -0
- package/src/single-select-field/features/accepts_help_text.feature +5 -0
- package/src/single-select-field/features/accepts_label/index.js +9 -0
- package/src/single-select-field/features/accepts_label.feature +5 -0
- package/src/single-select-field/features/accepts_validation_text/index.js +9 -0
- package/src/single-select-field/features/accepts_validation_text.feature +5 -0
- package/src/single-select-field/features/can_be_required/index.js +11 -0
- package/src/single-select-field/features/can_be_required.feature +5 -0
- package/src/single-select-field/features/has_default_clear_text/index.js +16 -0
- package/src/single-select-field/features/has_default_clear_text.feature +6 -0
- package/src/single-select-field/features/has_default_empty_text/index.js +13 -0
- package/src/single-select-field/features/has_default_empty_text.feature +6 -0
- package/src/single-select-field/features/has_default_filter_nomatch_text/index.js +17 -0
- package/src/single-select-field/features/has_default_filter_nomatch_text.feature +7 -0
- package/src/single-select-field/features/has_default_filter_placeholder/index.js +15 -0
- package/src/single-select-field/features/has_default_filter_placeholder.feature +6 -0
- package/src/single-select-field/features/has_default_loading_text/index.js +13 -0
- package/src/single-select-field/features/has_default_loading_text.feature +6 -0
- package/src/single-select-field/index.js +1 -0
- package/src/single-select-field/single-select-field.e2e.stories.js +45 -0
- package/src/single-select-field/single-select-field.js +178 -0
- package/src/single-select-field/single-select-field.prod.stories.js +146 -0
- package/src/single-select-option/index.js +1 -0
- package/src/single-select-option/single-select-option.js +84 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { sharedPropTypes } from '@dhis2/ui-constants'
|
|
2
|
+
import { Box } from '@dhis2-ui/box'
|
|
3
|
+
import { Field } from '@dhis2-ui/field'
|
|
4
|
+
import PropTypes from 'prop-types'
|
|
5
|
+
import React from 'react'
|
|
6
|
+
import i18n from '../locales/index.js'
|
|
7
|
+
import { SingleSelect } from '../single-select/index.js'
|
|
8
|
+
|
|
9
|
+
// TODO: translate
|
|
10
|
+
const translate = (prop, interpolationObject) => {
|
|
11
|
+
if (typeof prop === 'function') {
|
|
12
|
+
return prop(interpolationObject)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return prop
|
|
16
|
+
}
|
|
17
|
+
class SingleSelectField extends React.Component {
|
|
18
|
+
static defaultProps = {
|
|
19
|
+
dataTest: 'dhis2-uiwidgets-singleselectfield',
|
|
20
|
+
selected: '',
|
|
21
|
+
|
|
22
|
+
clearText: () => i18n.t('Clear'),
|
|
23
|
+
empty: () => i18n.t('No data found'),
|
|
24
|
+
filterPlaceholder: () => i18n.t('Type to filter options'),
|
|
25
|
+
loadingText: () => i18n.t('Loading options'),
|
|
26
|
+
noMatchText: () => i18n.t('No options found'),
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
render() {
|
|
30
|
+
const {
|
|
31
|
+
className,
|
|
32
|
+
onChange,
|
|
33
|
+
onFocus,
|
|
34
|
+
onKeyDown,
|
|
35
|
+
onBlur,
|
|
36
|
+
required,
|
|
37
|
+
label,
|
|
38
|
+
valid,
|
|
39
|
+
error,
|
|
40
|
+
warning,
|
|
41
|
+
disabled,
|
|
42
|
+
loading,
|
|
43
|
+
selected = SingleSelectField.defaultProps.selected,
|
|
44
|
+
tabIndex,
|
|
45
|
+
helpText,
|
|
46
|
+
validationText,
|
|
47
|
+
maxHeight,
|
|
48
|
+
inputMaxHeight,
|
|
49
|
+
inputWidth,
|
|
50
|
+
children,
|
|
51
|
+
clearable,
|
|
52
|
+
clearText = SingleSelectField.defaultProps.clearText,
|
|
53
|
+
filterable,
|
|
54
|
+
filterPlaceholder = SingleSelectField.defaultProps
|
|
55
|
+
.filterPlaceholder,
|
|
56
|
+
placeholder,
|
|
57
|
+
prefix,
|
|
58
|
+
empty = SingleSelectField.defaultProps.empty,
|
|
59
|
+
loadingText = SingleSelectField.defaultProps.loadingText,
|
|
60
|
+
noMatchText = SingleSelectField.defaultProps.noMatchText,
|
|
61
|
+
initialFocus,
|
|
62
|
+
dense,
|
|
63
|
+
dataTest = SingleSelectField.defaultProps.dataTest,
|
|
64
|
+
} = this.props
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<Field
|
|
68
|
+
className={className}
|
|
69
|
+
dataTest={dataTest}
|
|
70
|
+
disabled={disabled}
|
|
71
|
+
required={required}
|
|
72
|
+
label={label}
|
|
73
|
+
helpText={helpText}
|
|
74
|
+
validationText={validationText}
|
|
75
|
+
error={error}
|
|
76
|
+
warning={warning}
|
|
77
|
+
valid={valid}
|
|
78
|
+
>
|
|
79
|
+
<Box width={inputWidth} minWidth="100px">
|
|
80
|
+
<SingleSelect
|
|
81
|
+
selected={selected}
|
|
82
|
+
tabIndex={tabIndex}
|
|
83
|
+
maxHeight={maxHeight}
|
|
84
|
+
inputMaxHeight={inputMaxHeight}
|
|
85
|
+
onChange={onChange}
|
|
86
|
+
onFocus={onFocus}
|
|
87
|
+
onKeyDown={onKeyDown}
|
|
88
|
+
onBlur={onBlur}
|
|
89
|
+
loading={loading}
|
|
90
|
+
error={error}
|
|
91
|
+
warning={warning}
|
|
92
|
+
valid={valid}
|
|
93
|
+
disabled={disabled}
|
|
94
|
+
clearable={clearable}
|
|
95
|
+
clearText={translate(clearText)}
|
|
96
|
+
filterable={filterable}
|
|
97
|
+
filterPlaceholder={translate(filterPlaceholder)}
|
|
98
|
+
placeholder={placeholder}
|
|
99
|
+
prefix={prefix}
|
|
100
|
+
empty={translate(empty)}
|
|
101
|
+
loadingText={translate(loadingText)}
|
|
102
|
+
noMatchText={translate(noMatchText)}
|
|
103
|
+
initialFocus={initialFocus}
|
|
104
|
+
dense={dense}
|
|
105
|
+
>
|
|
106
|
+
{children}
|
|
107
|
+
</SingleSelect>
|
|
108
|
+
</Box>
|
|
109
|
+
</Field>
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
SingleSelectField.propTypes = {
|
|
115
|
+
/** Should be `SingleSelectOption` components */
|
|
116
|
+
children: PropTypes.node,
|
|
117
|
+
className: PropTypes.string,
|
|
118
|
+
/** Label for the button that clears selections */
|
|
119
|
+
clearText: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
|
120
|
+
/** Adds a button to the SingleSelect that clears selections when pressed */
|
|
121
|
+
clearable: PropTypes.bool,
|
|
122
|
+
dataTest: PropTypes.string,
|
|
123
|
+
/** Makes the SingleSelect smaller */
|
|
124
|
+
dense: PropTypes.bool,
|
|
125
|
+
/** Disables the SingleSelect */
|
|
126
|
+
disabled: PropTypes.bool,
|
|
127
|
+
/** Text to display when there are no options */
|
|
128
|
+
empty: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
129
|
+
/** Adds 'error' appearance for validation feedback. Mutually exclusive with 'valid' and 'warning' props */
|
|
130
|
+
error: sharedPropTypes.statusPropType,
|
|
131
|
+
/** Placeholder text to show in the filter field when it is empty */
|
|
132
|
+
filterPlaceholder: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
133
|
+
/** Adds a field to filter options */
|
|
134
|
+
filterable: PropTypes.bool,
|
|
135
|
+
/** Useful guiding text to display below the SingleSelect */
|
|
136
|
+
helpText: PropTypes.string,
|
|
137
|
+
/** Grabs initial focus on the page */
|
|
138
|
+
initialFocus: PropTypes.bool,
|
|
139
|
+
/** Constrains the height of the input */
|
|
140
|
+
inputMaxHeight: PropTypes.string,
|
|
141
|
+
/** Sets the width of the input. Can be any valid CSS measurement */
|
|
142
|
+
inputWidth: PropTypes.string,
|
|
143
|
+
/** Text for the label above the SingleSelect */
|
|
144
|
+
label: PropTypes.string,
|
|
145
|
+
/** Applies a loading appearance to the dropdown options */
|
|
146
|
+
loading: PropTypes.bool,
|
|
147
|
+
/** Text to display when `loading` is true */
|
|
148
|
+
loadingText: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
|
149
|
+
/** Constrains height of the SingleSelect */
|
|
150
|
+
maxHeight: PropTypes.string,
|
|
151
|
+
/** Text to display when there are no filter results */
|
|
152
|
+
noMatchText: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
|
153
|
+
/** Placeholder text when the SingleSelect is empty */
|
|
154
|
+
placeholder: PropTypes.string,
|
|
155
|
+
/** Leading text to prefix selections */
|
|
156
|
+
prefix: PropTypes.string,
|
|
157
|
+
/** Indicates that a selection is required */
|
|
158
|
+
required: PropTypes.bool,
|
|
159
|
+
/** Selected item in the SingleSelect (the string should refer to the item's `value` attribute) */
|
|
160
|
+
selected: PropTypes.string,
|
|
161
|
+
tabIndex: PropTypes.string,
|
|
162
|
+
/** Adds 'valid' appearance for validation feedback. Mutually exclusive with 'error' and 'warning' props */
|
|
163
|
+
valid: sharedPropTypes.statusPropType,
|
|
164
|
+
/** Text to provide form validation feedback. Receives styles according to validation status */
|
|
165
|
+
validationText: PropTypes.string,
|
|
166
|
+
/** Adds 'warning' appearance for validation feedback. Mutually exclusive with 'valid' and 'error' props */
|
|
167
|
+
warning: sharedPropTypes.statusPropType,
|
|
168
|
+
/** Called with signature `({ selected: string }, event)` */
|
|
169
|
+
onBlur: PropTypes.func,
|
|
170
|
+
/** Called with signature `({ selected: string }, event)` */
|
|
171
|
+
onChange: PropTypes.func,
|
|
172
|
+
/** Called with signature `({ selected: string }, event)` */
|
|
173
|
+
onFocus: PropTypes.func,
|
|
174
|
+
/** Called with signature `({ selected: string }, event)` */
|
|
175
|
+
onKeyDown: PropTypes.func,
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export { SingleSelectField }
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { sharedPropTypes } from '@dhis2/ui-constants'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { SingleSelectOption } from '../index.js'
|
|
4
|
+
import { SingleSelectField } from './index.js'
|
|
5
|
+
|
|
6
|
+
const description = `
|
|
7
|
+
\`SingleSelectField\` is a wrapper around a \`SingleSelect\` component that adds a label, help text, validation text, and other features.
|
|
8
|
+
|
|
9
|
+
See the SingleSelect for more information, and read more at [Design System: Select](https://github.com/dhis2/design-system/blob/master/molecules/select.md#multiple-selection).
|
|
10
|
+
|
|
11
|
+
\`\`\`js
|
|
12
|
+
import { SingleSelectField, SingleSelectOption } from '@dhis2/ui'
|
|
13
|
+
\`\`\`
|
|
14
|
+
|
|
15
|
+
_**Note**: The dropdowns in some of the following stories won't appear correctly on this page. View these demos in the 'Canvas' tab._
|
|
16
|
+
`
|
|
17
|
+
|
|
18
|
+
const onChange = (selected) =>
|
|
19
|
+
alert(`Selected changed to: ${JSON.stringify(selected, null, 2)}`)
|
|
20
|
+
|
|
21
|
+
const options = [
|
|
22
|
+
<SingleSelectOption key="1" value="1" label="one" />,
|
|
23
|
+
<SingleSelectOption key="2" value="2" label="two" />,
|
|
24
|
+
<SingleSelectOption key="3" value="3" label="three" />,
|
|
25
|
+
<SingleSelectOption key="4" value="4" label="four" />,
|
|
26
|
+
<SingleSelectOption key="5" value="5" label="five" />,
|
|
27
|
+
<SingleSelectOption key="6" value="6" label="six" />,
|
|
28
|
+
<SingleSelectOption key="7" value="7" label="seven" />,
|
|
29
|
+
<SingleSelectOption key="8" value="8" label="eight" />,
|
|
30
|
+
<SingleSelectOption key="9" value="9" label="nine" />,
|
|
31
|
+
<SingleSelectOption key="10" value="10" label="ten" />,
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
export default {
|
|
35
|
+
title: 'Single Select Field',
|
|
36
|
+
component: SingleSelectField,
|
|
37
|
+
subcomponents: { SingleSelectOption },
|
|
38
|
+
parameters: { docs: { description: { component: description } } },
|
|
39
|
+
// default args for stories
|
|
40
|
+
args: {
|
|
41
|
+
// Fix default prop issues - causes 'i18n is not defined' error
|
|
42
|
+
dataTest: 'dhis2-uiwidgets-singleselectfield',
|
|
43
|
+
selected: '',
|
|
44
|
+
|
|
45
|
+
clearText: 'Clear',
|
|
46
|
+
empty: 'No data found',
|
|
47
|
+
filterPlaceholder: 'Type to filter options',
|
|
48
|
+
loadingText: 'Loading options',
|
|
49
|
+
noMatchText: 'No options found',
|
|
50
|
+
|
|
51
|
+
label: 'Default label',
|
|
52
|
+
children: options,
|
|
53
|
+
onChange: onChange,
|
|
54
|
+
},
|
|
55
|
+
argTypes: {
|
|
56
|
+
valid: { ...sharedPropTypes.statusArgType },
|
|
57
|
+
warning: { ...sharedPropTypes.statusArgType },
|
|
58
|
+
error: { ...sharedPropTypes.statusArgType },
|
|
59
|
+
},
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const Template = (args) => <SingleSelectField {...args} />
|
|
63
|
+
|
|
64
|
+
export const Default = Template.bind({})
|
|
65
|
+
|
|
66
|
+
export const WithHelpText = Template.bind({})
|
|
67
|
+
WithHelpText.args = { helpText: 'Helpful text.' }
|
|
68
|
+
WithHelpText.parameters = {
|
|
69
|
+
docs: {
|
|
70
|
+
description: {
|
|
71
|
+
story: `_**Note**: The dropdowns in the following stories won't appear correctly on this page. View these demos in the 'Canvas' tab._`,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export const StatusValid = Template.bind({})
|
|
77
|
+
StatusValid.args = {
|
|
78
|
+
valid: true,
|
|
79
|
+
validationText: 'Totally valid!',
|
|
80
|
+
...WithHelpText.args,
|
|
81
|
+
}
|
|
82
|
+
StatusValid.storyName = 'Status: Valid'
|
|
83
|
+
|
|
84
|
+
export const StatusWarning = Template.bind({})
|
|
85
|
+
StatusWarning.args = {
|
|
86
|
+
warning: true,
|
|
87
|
+
validationText: 'Hm, not quite, I warn thee!',
|
|
88
|
+
...WithHelpText.args,
|
|
89
|
+
}
|
|
90
|
+
StatusWarning.storyName = 'Status: Warning'
|
|
91
|
+
|
|
92
|
+
export const StatusError = Template.bind({})
|
|
93
|
+
StatusError.args = {
|
|
94
|
+
error: true,
|
|
95
|
+
validationText: 'That value is wrong. Sorry!',
|
|
96
|
+
...WithHelpText.args,
|
|
97
|
+
}
|
|
98
|
+
StatusError.storyName = 'Status: Error'
|
|
99
|
+
|
|
100
|
+
export const StatusDisabled = Template.bind({})
|
|
101
|
+
StatusDisabled.args = {
|
|
102
|
+
disabled: true,
|
|
103
|
+
...WithHelpText.args,
|
|
104
|
+
}
|
|
105
|
+
StatusDisabled.storyName = 'Status: Disabled'
|
|
106
|
+
|
|
107
|
+
export const Required = Template.bind({})
|
|
108
|
+
Required.args = { required: true }
|
|
109
|
+
|
|
110
|
+
export const InputWidth = Template.bind({})
|
|
111
|
+
InputWidth.args = {
|
|
112
|
+
inputWidth: '200px',
|
|
113
|
+
label: 'A very long label indeed, well at least longer than the input field to show how it looks and works and stuff',
|
|
114
|
+
required: true,
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export const DefaultClearText = Template.bind({})
|
|
118
|
+
DefaultClearText.args = {
|
|
119
|
+
selected: '1',
|
|
120
|
+
clearable: true,
|
|
121
|
+
label: null,
|
|
122
|
+
children: (
|
|
123
|
+
<SingleSelectOption
|
|
124
|
+
key="1"
|
|
125
|
+
value="1"
|
|
126
|
+
label="Not translated, just for showing clear button"
|
|
127
|
+
/>
|
|
128
|
+
),
|
|
129
|
+
}
|
|
130
|
+
DefaultClearText.storyName = 'Default: clearText'
|
|
131
|
+
|
|
132
|
+
export const DefaultEmpty = Template.bind({})
|
|
133
|
+
DefaultEmpty.args = { children: null, label: null }
|
|
134
|
+
DefaultEmpty.storyName = 'Default: empty'
|
|
135
|
+
|
|
136
|
+
export const DefaultFilterPlaceholderAndNoMatchText = Template.bind({})
|
|
137
|
+
DefaultFilterPlaceholderAndNoMatchText.args = {
|
|
138
|
+
filterable: true,
|
|
139
|
+
...DefaultEmpty.args,
|
|
140
|
+
}
|
|
141
|
+
DefaultFilterPlaceholderAndNoMatchText.storyName =
|
|
142
|
+
'Default: filterPlaceholder and noMatchText'
|
|
143
|
+
|
|
144
|
+
export const DefaultLoadingText = Template.bind({})
|
|
145
|
+
DefaultLoadingText.args = { loading: true, ...DefaultEmpty.args }
|
|
146
|
+
DefaultLoadingText.storyName = 'Default: loadingText'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SingleSelectOption } from './single-select-option.js'
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { colors, spacers } from '@dhis2/ui-constants'
|
|
2
|
+
import cx from 'classnames'
|
|
3
|
+
import PropTypes from 'prop-types'
|
|
4
|
+
import React from 'react'
|
|
5
|
+
|
|
6
|
+
const SingleSelectOption = ({
|
|
7
|
+
label,
|
|
8
|
+
active,
|
|
9
|
+
disabled,
|
|
10
|
+
onClick,
|
|
11
|
+
className,
|
|
12
|
+
dataTest = 'dhis2-uicore-singleselectoption',
|
|
13
|
+
value,
|
|
14
|
+
}) => (
|
|
15
|
+
<div
|
|
16
|
+
className={cx(className, {
|
|
17
|
+
disabled,
|
|
18
|
+
active,
|
|
19
|
+
})}
|
|
20
|
+
onClick={(e) => onClick({}, e)}
|
|
21
|
+
data-test={dataTest}
|
|
22
|
+
data-value={value}
|
|
23
|
+
data-label={label}
|
|
24
|
+
>
|
|
25
|
+
<span className="checkmark" aria-hidden="true"></span>
|
|
26
|
+
<span className="content">{label}</span>
|
|
27
|
+
<style jsx>{`
|
|
28
|
+
div {
|
|
29
|
+
display: flex;
|
|
30
|
+
align-items: center;
|
|
31
|
+
cursor: pointer;
|
|
32
|
+
font-size: 14px;
|
|
33
|
+
text-decoration: none;
|
|
34
|
+
color: ${colors.grey900};
|
|
35
|
+
padding-block: ${spacers.dp8};
|
|
36
|
+
padding-inline: 6px ${spacers.dp12};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
div:hover {
|
|
40
|
+
background-color: ${colors.grey200};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
div:active,
|
|
44
|
+
div.active {
|
|
45
|
+
background-color: ${colors.teal050};
|
|
46
|
+
cursor: auto;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
div.disabled {
|
|
50
|
+
color: ${colors.grey500};
|
|
51
|
+
cursor: not-allowed;
|
|
52
|
+
user-select: none;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
div.disabled:hover {
|
|
56
|
+
background-color: initial;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
div .checkmark {
|
|
60
|
+
width: 16px;
|
|
61
|
+
height: 16px;
|
|
62
|
+
margin-inline-end: 6px;
|
|
63
|
+
flex-shrink: 0;
|
|
64
|
+
background-size: contain;
|
|
65
|
+
background-repeat: no-repeat;
|
|
66
|
+
background-image: ${active
|
|
67
|
+
? `url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTMuNjMyMDkgNy44MzIxNEMzLjI3MjA5IDcuNDcyMTQgMi43MjAwOSA3LjQ3MjE0IDIuMzYwMDkgNy44MzIxNEMyLjAwMDA5IDguMTkyMTQgMi4wMDAwOSA4Ljc0NDE0IDIuMzYwMDkgOS4xMDQxNEw1LjYyNDA5IDEyLjM2ODFDNS45ODQwOSAxMi43MjgxIDYuNTM2MDkgMTIuNzI4MSA2Ljg5NjA5IDEyLjM2ODFMMTQuNjQ4MSA0LjY0MDE0QzE1LjAwODEgNC4yODAxNCAxNS4wMDgxIDMuNzI4MTQgMTQuNjQ4MSAzLjM2ODE0QzE0LjI4ODEgMy4wMDgxNCAxMy43MzYxIDMuMDA4MTQgMTMuMzUyMSAzLjM2ODE0TDYuMjcyMDkgMTAuNDcyMUwzLjYzMjA5IDcuODMyMTRaIiBmaWxsPSIjMDA2OTVDIi8+Cjwvc3ZnPgo=')`
|
|
68
|
+
: 'none'};
|
|
69
|
+
}
|
|
70
|
+
`}</style>
|
|
71
|
+
</div>
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
SingleSelectOption.propTypes = {
|
|
75
|
+
label: PropTypes.string.isRequired,
|
|
76
|
+
value: PropTypes.string.isRequired,
|
|
77
|
+
active: PropTypes.bool,
|
|
78
|
+
className: PropTypes.string,
|
|
79
|
+
dataTest: PropTypes.string,
|
|
80
|
+
disabled: PropTypes.bool,
|
|
81
|
+
onClick: PropTypes.func,
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export { SingleSelectOption }
|