@dhis2-ui/select 10.9.2 → 10.10.0-alpha.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 +18 -4
- package/build/cjs/locales/en/translations.json +7 -5
- package/build/cjs/simple-single-select/__stories__/DefaultPosition.js +38 -0
- package/build/cjs/simple-single-select/__stories__/Dense.js +22 -0
- package/build/cjs/simple-single-select/__stories__/Empty.js +20 -0
- package/build/cjs/simple-single-select/__stories__/EmptyWithEmptyNode.js +28 -0
- package/build/cjs/simple-single-select/__stories__/EmptyWithEmptyText.js +21 -0
- package/build/cjs/simple-single-select/__stories__/FlippedPosition.js +37 -0
- package/build/cjs/simple-single-select/__stories__/InfiniteLoading.js +61 -0
- package/build/cjs/simple-single-select/__stories__/Loading.js +20 -0
- package/build/cjs/simple-single-select/__stories__/ShiftedIntoView.js +28 -0
- package/build/cjs/simple-single-select/__stories__/WithClearButton.js +25 -0
- package/build/cjs/simple-single-select/__stories__/WithCustomLowMaxHeight.js +22 -0
- package/build/cjs/simple-single-select/__stories__/WithCustomOptions.js +48 -0
- package/build/cjs/simple-single-select/__stories__/WithDisabledOption.js +28 -0
- package/build/cjs/simple-single-select/__stories__/WithFilterField.js +36 -0
- package/build/cjs/simple-single-select/__stories__/WithInitialFocus.js +38 -0
- package/build/cjs/simple-single-select/__stories__/WithManyOptions.js +24 -0
- package/build/cjs/simple-single-select/__stories__/WithNoMatchText.js +30 -0
- package/build/cjs/simple-single-select/__stories__/WithOnBlur.js +23 -0
- package/build/cjs/simple-single-select/__stories__/WithOnFocus.js +23 -0
- package/build/cjs/simple-single-select/__stories__/WithOptionsAndDisabled.js +22 -0
- package/build/cjs/simple-single-select/__stories__/WithOptionsAndLoading.js +34 -0
- package/build/cjs/simple-single-select/__stories__/WithOptionsAndLoadingText.js +35 -0
- package/build/cjs/simple-single-select/__stories__/WithPlaceholder.js +23 -0
- package/build/cjs/simple-single-select/__stories__/WithPlaceholderAndSelection.js +25 -0
- package/build/cjs/simple-single-select/__stories__/WithPrefix.js +22 -0
- package/build/cjs/simple-single-select/__stories__/WithPrefixAndSelection.js +25 -0
- package/build/cjs/simple-single-select/__stories__/WithRTL.js +34 -0
- package/build/cjs/simple-single-select/__stories__/WithScrollingParent.js +36 -0
- package/build/cjs/simple-single-select/__stories__/WithSelection.js +24 -0
- package/build/cjs/simple-single-select/__stories__/WithSelectionAndDisabled.js +25 -0
- package/build/cjs/simple-single-select/__stories__/WithoutOptionsAndLoading.js +21 -0
- package/build/cjs/simple-single-select/__stories__/WithoutSelection.js +22 -0
- package/build/cjs/simple-single-select/__stories__/options.js +77 -0
- package/build/cjs/simple-single-select/features/keyboard-interactions.test.e2e.js +441 -0
- package/build/cjs/simple-single-select/features/menu-positioning.test.e2e.js +152 -0
- package/build/cjs/simple-single-select/index.js +19 -0
- package/build/cjs/simple-single-select/is-option-hidden.js +22 -0
- package/build/cjs/simple-single-select/menu/empty.js +26 -0
- package/build/cjs/simple-single-select/menu/filter.js +60 -0
- package/build/cjs/simple-single-select/menu/index.js +12 -0
- package/build/cjs/simple-single-select/menu/loading.js +30 -0
- package/build/cjs/simple-single-select/menu/menu.js +158 -0
- package/build/cjs/simple-single-select/menu/no-match.js +28 -0
- package/build/cjs/simple-single-select/menu/option.js +120 -0
- package/build/cjs/simple-single-select/menu/options-list.js +97 -0
- package/build/cjs/simple-single-select/selected-value/clear-button.js +74 -0
- package/build/cjs/simple-single-select/selected-value/container.js +100 -0
- package/build/cjs/simple-single-select/selected-value/index.js +12 -0
- package/build/cjs/simple-single-select/selected-value/placeholder.js +30 -0
- package/build/cjs/simple-single-select/selected-value/prefix.js +30 -0
- package/build/cjs/simple-single-select/selected-value/selected-value.js +119 -0
- package/build/cjs/simple-single-select/shared-prop-types.js +14 -0
- package/build/cjs/simple-single-select/simple-single-select.e2e.stories.js +156 -0
- package/build/cjs/simple-single-select/simple-single-select.js +319 -0
- package/build/cjs/simple-single-select/simple-single-select.prod.stories.js +235 -0
- package/build/cjs/simple-single-select/simple-single-select.test.js +1106 -0
- package/build/cjs/simple-single-select/use-handle-key-press/index.js +19 -0
- package/build/cjs/simple-single-select/use-handle-key-press/use-focus-option.js +24 -0
- package/build/cjs/simple-single-select/use-handle-key-press/use-handle-key-press-on-combobox.js +183 -0
- package/build/cjs/simple-single-select/use-handle-key-press/use-handle-key-press-on-filter-input.js +106 -0
- package/build/cjs/simple-single-select/use-handle-key-press/use-handle-typing.js +81 -0
- package/build/cjs/simple-single-select/use-handle-key-press/use-highlight-first-option-on-previous-page.js +50 -0
- package/build/cjs/simple-single-select/use-handle-key-press/use-highlight-first-visible-option.js +30 -0
- package/build/cjs/simple-single-select/use-handle-key-press/use-highlight-last-option-on-next-page.js +50 -0
- package/build/cjs/simple-single-select/use-handle-key-press/use-highlight-last-visible-option.js +42 -0
- package/build/cjs/simple-single-select/use-handle-key-press/use-page-down.js +45 -0
- package/build/cjs/simple-single-select/use-handle-key-press/use-page-up.js +44 -0
- package/build/cjs/simple-single-select/use-handle-key-press/utils.js +46 -0
- package/build/cjs/simple-single-select-field/index.js +12 -0
- package/build/cjs/simple-single-select-field/simple-single-select-field.js +138 -0
- package/build/cjs/simple-single-select-field/simple-single-select-field.prod.stories.js +188 -0
- package/build/cjs/simple-single-select-field/simple-single-select-field.test.js +133 -0
- package/build/es/index.js +2 -0
- package/build/es/locales/en/translations.json +7 -5
- package/build/es/simple-single-select/__stories__/DefaultPosition.js +29 -0
- package/build/es/simple-single-select/__stories__/Dense.js +13 -0
- package/build/es/simple-single-select/__stories__/Empty.js +11 -0
- package/build/es/simple-single-select/__stories__/EmptyWithEmptyNode.js +19 -0
- package/build/es/simple-single-select/__stories__/EmptyWithEmptyText.js +12 -0
- package/build/es/simple-single-select/__stories__/FlippedPosition.js +28 -0
- package/build/es/simple-single-select/__stories__/InfiniteLoading.js +53 -0
- package/build/es/simple-single-select/__stories__/Loading.js +12 -0
- package/build/es/simple-single-select/__stories__/ShiftedIntoView.js +18 -0
- package/build/es/simple-single-select/__stories__/WithClearButton.js +16 -0
- package/build/es/simple-single-select/__stories__/WithCustomLowMaxHeight.js +13 -0
- package/build/es/simple-single-select/__stories__/WithCustomOptions.js +38 -0
- package/build/es/simple-single-select/__stories__/WithDisabledOption.js +19 -0
- package/build/es/simple-single-select/__stories__/WithFilterField.js +27 -0
- package/build/es/simple-single-select/__stories__/WithInitialFocus.js +29 -0
- package/build/es/simple-single-select/__stories__/WithManyOptions.js +15 -0
- package/build/es/simple-single-select/__stories__/WithNoMatchText.js +21 -0
- package/build/es/simple-single-select/__stories__/WithOnBlur.js +14 -0
- package/build/es/simple-single-select/__stories__/WithOnFocus.js +14 -0
- package/build/es/simple-single-select/__stories__/WithOptionsAndDisabled.js +13 -0
- package/build/es/simple-single-select/__stories__/WithOptionsAndLoading.js +25 -0
- package/build/es/simple-single-select/__stories__/WithOptionsAndLoadingText.js +26 -0
- package/build/es/simple-single-select/__stories__/WithPlaceholder.js +14 -0
- package/build/es/simple-single-select/__stories__/WithPlaceholderAndSelection.js +16 -0
- package/build/es/simple-single-select/__stories__/WithPrefix.js +13 -0
- package/build/es/simple-single-select/__stories__/WithPrefixAndSelection.js +16 -0
- package/build/es/simple-single-select/__stories__/WithRTL.js +25 -0
- package/build/es/simple-single-select/__stories__/WithScrollingParent.js +27 -0
- package/build/es/simple-single-select/__stories__/WithSelection.js +15 -0
- package/build/es/simple-single-select/__stories__/WithSelectionAndDisabled.js +16 -0
- package/build/es/simple-single-select/__stories__/WithoutOptionsAndLoading.js +12 -0
- package/build/es/simple-single-select/__stories__/WithoutSelection.js +13 -0
- package/build/es/simple-single-select/__stories__/options.js +71 -0
- package/build/es/simple-single-select/features/keyboard-interactions.test.e2e.js +439 -0
- package/build/es/simple-single-select/features/menu-positioning.test.e2e.js +150 -0
- package/build/es/simple-single-select/index.js +2 -0
- package/build/es/simple-single-select/is-option-hidden.js +16 -0
- package/build/es/simple-single-select/menu/empty.js +19 -0
- package/build/es/simple-single-select/menu/filter.js +53 -0
- package/build/es/simple-single-select/menu/index.js +1 -0
- package/build/es/simple-single-select/menu/loading.js +23 -0
- package/build/es/simple-single-select/menu/menu.js +149 -0
- package/build/es/simple-single-select/menu/no-match.js +21 -0
- package/build/es/simple-single-select/menu/option.js +111 -0
- package/build/es/simple-single-select/menu/options-list.js +88 -0
- package/build/es/simple-single-select/selected-value/clear-button.js +68 -0
- package/build/es/simple-single-select/selected-value/container.js +91 -0
- package/build/es/simple-single-select/selected-value/index.js +1 -0
- package/build/es/simple-single-select/selected-value/placeholder.js +23 -0
- package/build/es/simple-single-select/selected-value/prefix.js +23 -0
- package/build/es/simple-single-select/selected-value/selected-value.js +112 -0
- package/build/es/simple-single-select/shared-prop-types.js +7 -0
- package/build/es/simple-single-select/simple-single-select.e2e.stories.js +142 -0
- package/build/es/simple-single-select/simple-single-select.js +310 -0
- package/build/es/simple-single-select/simple-single-select.prod.stories.js +37 -0
- package/build/es/simple-single-select/simple-single-select.test.js +1103 -0
- package/build/es/simple-single-select/use-handle-key-press/index.js +2 -0
- package/build/es/simple-single-select/use-handle-key-press/use-focus-option.js +18 -0
- package/build/es/simple-single-select/use-handle-key-press/use-handle-key-press-on-combobox.js +177 -0
- package/build/es/simple-single-select/use-handle-key-press/use-handle-key-press-on-filter-input.js +100 -0
- package/build/es/simple-single-select/use-handle-key-press/use-handle-typing.js +75 -0
- package/build/es/simple-single-select/use-handle-key-press/use-highlight-first-option-on-previous-page.js +44 -0
- package/build/es/simple-single-select/use-handle-key-press/use-highlight-first-visible-option.js +24 -0
- package/build/es/simple-single-select/use-handle-key-press/use-highlight-last-option-on-next-page.js +44 -0
- package/build/es/simple-single-select/use-handle-key-press/use-highlight-last-visible-option.js +36 -0
- package/build/es/simple-single-select/use-handle-key-press/use-page-down.js +39 -0
- package/build/es/simple-single-select/use-handle-key-press/use-page-up.js +38 -0
- package/build/es/simple-single-select/use-handle-key-press/utils.js +36 -0
- package/build/es/simple-single-select-field/index.js +1 -0
- package/build/es/simple-single-select-field/simple-single-select-field.js +131 -0
- package/build/es/simple-single-select-field/simple-single-select-field.prod.stories.js +172 -0
- package/build/es/simple-single-select-field/simple-single-select-field.test.js +130 -0
- package/package.json +15 -15
- package/types/index.d.ts +184 -1
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
|
+
import { requiredIf } from '@dhis2/prop-types';
|
|
3
|
+
import { sharedPropTypes } from '@dhis2/ui-constants';
|
|
4
|
+
import { Field } from '@dhis2-ui/field';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import { SimpleSingleSelect, optionProp } from '../simple-single-select/index.js';
|
|
8
|
+
export function SimpleSingleSelectField(props) {
|
|
9
|
+
const {
|
|
10
|
+
className,
|
|
11
|
+
dataTest,
|
|
12
|
+
disabled,
|
|
13
|
+
error,
|
|
14
|
+
helpText,
|
|
15
|
+
label,
|
|
16
|
+
name,
|
|
17
|
+
required,
|
|
18
|
+
valid,
|
|
19
|
+
validationText,
|
|
20
|
+
warning
|
|
21
|
+
} = props;
|
|
22
|
+
const labelId = `${name}-label`;
|
|
23
|
+
return /*#__PURE__*/React.createElement(Field, {
|
|
24
|
+
className: className,
|
|
25
|
+
dataTest: dataTest,
|
|
26
|
+
disabled: disabled,
|
|
27
|
+
required: required,
|
|
28
|
+
labelId: labelId,
|
|
29
|
+
label: label,
|
|
30
|
+
helpText: helpText,
|
|
31
|
+
validationText: validationText,
|
|
32
|
+
error: error,
|
|
33
|
+
warning: warning,
|
|
34
|
+
valid: valid
|
|
35
|
+
}, /*#__PURE__*/React.createElement(SimpleSingleSelect, _extends({}, props, {
|
|
36
|
+
labelledBy: labelId
|
|
37
|
+
})));
|
|
38
|
+
}
|
|
39
|
+
SimpleSingleSelectField.propTypes = {
|
|
40
|
+
/** Label displayed above the input **/
|
|
41
|
+
label: PropTypes.string.isRequired,
|
|
42
|
+
/** necessary for IDs that are required for accessibility **/
|
|
43
|
+
name: PropTypes.string.isRequired,
|
|
44
|
+
/** An array of options **/
|
|
45
|
+
options: PropTypes.arrayOf(optionProp).isRequired,
|
|
46
|
+
/** A callback that will be called with the new value or an empty string **/
|
|
47
|
+
onChange: PropTypes.func.isRequired,
|
|
48
|
+
/** Will focus the select initially **/
|
|
49
|
+
autoFocus: PropTypes.bool,
|
|
50
|
+
/** Additional class names that will be applied to the root element **/
|
|
51
|
+
className: PropTypes.string,
|
|
52
|
+
/** This will allow us to put an aria-label on the clear button **/
|
|
53
|
+
clearText: requiredIf(props => props.clearable, PropTypes.string),
|
|
54
|
+
/** Whether a clear button should be displayed or not **/
|
|
55
|
+
clearable: PropTypes.bool,
|
|
56
|
+
/** A value for a `data-test` attribute on the root element **/
|
|
57
|
+
dataTest: PropTypes.string,
|
|
58
|
+
/** Renders a select with lower height **/
|
|
59
|
+
dense: PropTypes.bool,
|
|
60
|
+
/** Disables all interactions with the select (except focussing) **/
|
|
61
|
+
disabled: PropTypes.bool,
|
|
62
|
+
/** Text or component to display when there are no options **/
|
|
63
|
+
empty: PropTypes.node,
|
|
64
|
+
/** Applies 'error' appearance for validation feedback. Mutually exclusive with `warning` and `valid` props **/
|
|
65
|
+
error: sharedPropTypes.statusPropType,
|
|
66
|
+
/** Help text that will be displayed below the input **/
|
|
67
|
+
filterHelpText: PropTypes.string,
|
|
68
|
+
/** Value will be used as aria-label attribute on the filter input **/
|
|
69
|
+
filterLabel: PropTypes.string,
|
|
70
|
+
/** Placeholder for the filter input **/
|
|
71
|
+
filterPlaceholder: PropTypes.string,
|
|
72
|
+
/** Value of the filter input **/
|
|
73
|
+
filterValue: PropTypes.string,
|
|
74
|
+
/** Whether the select should display a filter input **/
|
|
75
|
+
filterable: PropTypes.bool,
|
|
76
|
+
/** Help text, displayed below the input **/
|
|
77
|
+
helpText: PropTypes.string,
|
|
78
|
+
/** Will show a loading indicator at the end of the options-list **/
|
|
79
|
+
loading: PropTypes.bool,
|
|
80
|
+
/** Text that will be displayed next to the loading indicator **/
|
|
81
|
+
menuLoadingText: PropTypes.string,
|
|
82
|
+
/** Allows to modify the max height of the menu **/
|
|
83
|
+
menuMaxHeight: PropTypes.string,
|
|
84
|
+
/** String that will be displayed when the select is being filtered but the options array is empty **/
|
|
85
|
+
noMatchText: requiredIf(props => props.filterable, PropTypes.string),
|
|
86
|
+
/** Allows to override what's rendered inside the `button[role="option"]`.
|
|
87
|
+
* Can be overriden on an individual option basis **/
|
|
88
|
+
optionComponent: PropTypes.elementType,
|
|
89
|
+
/** For a11y: How aggressively the user should be updated about changes in options **/
|
|
90
|
+
optionUpdateStrategy: PropTypes.oneOf(['off', 'polite', 'assertive']),
|
|
91
|
+
/** String to show when there's no value and no valueLabel **/
|
|
92
|
+
placeholder: PropTypes.string,
|
|
93
|
+
/** String that will be displayed before the label of the selected option **/
|
|
94
|
+
prefix: PropTypes.string,
|
|
95
|
+
/** Whether a value is required or not **/
|
|
96
|
+
required: PropTypes.bool,
|
|
97
|
+
/** Standard HTML tab-index attribute that will be put on the combobox's root element **/
|
|
98
|
+
tabIndex: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
99
|
+
/** Applies 'valid' appearance for validation feedback. Mutually exclusive with `warning` and `valid` props **/
|
|
100
|
+
valid: sharedPropTypes.statusPropType,
|
|
101
|
+
/** Text shown below input when `props.error` is true **/
|
|
102
|
+
validationText: PropTypes.string,
|
|
103
|
+
/** As of now, this component does not support being uncontrolled **/
|
|
104
|
+
value: PropTypes.string,
|
|
105
|
+
/**
|
|
106
|
+
* When the option is not in the options list (e.g. not loaded or list is
|
|
107
|
+
* filtered), but a selected value needs to be displayed, then this prop can
|
|
108
|
+
* be used to supply the text to be shown.
|
|
109
|
+
**/
|
|
110
|
+
valueLabel: requiredIf(props => {
|
|
111
|
+
if (props.options.find(_ref => {
|
|
112
|
+
let {
|
|
113
|
+
value
|
|
114
|
+
} = _ref;
|
|
115
|
+
return props.value === value;
|
|
116
|
+
})) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
return props.value;
|
|
120
|
+
}, PropTypes.string),
|
|
121
|
+
/** Applies 'warning' appearance for validation feedback. Mutually exclusive with `warning` and `valid` props **/
|
|
122
|
+
warning: sharedPropTypes.statusPropType,
|
|
123
|
+
/** Will be called when the combobox is loses focus **/
|
|
124
|
+
onBlur: PropTypes.func,
|
|
125
|
+
/** Will be called when the last option is scrolled into the visible area **/
|
|
126
|
+
onEndReached: PropTypes.func,
|
|
127
|
+
/** Will be called when the filter value changes **/
|
|
128
|
+
onFilterChange: PropTypes.func,
|
|
129
|
+
/** Will be called when the combobox is being focused **/
|
|
130
|
+
onFocus: PropTypes.func
|
|
131
|
+
};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { SimpleSingleSelectField } from './index.js';
|
|
3
|
+
const description = `
|
|
4
|
+
\`SimpleSingleSelectField\` is a wrapper around a \`SimpleSingleSelect\` component that adds a label, help text, validation text, and other features.
|
|
5
|
+
|
|
6
|
+
See the SimpleSingleSelect for more information, and read more at [Design System: Select](https://github.com/dhis2/design-system/blob/master/molecules/select.md).
|
|
7
|
+
|
|
8
|
+
\`\`\`js
|
|
9
|
+
import { SimpleSingleSelectField, SingleSelectOption } from '@dhis2/ui'
|
|
10
|
+
\`\`\`
|
|
11
|
+
|
|
12
|
+
_**Note**: The dropdowns in some of the following stories won't appear correctly on this page. View these demos in the 'Canvas' tab._
|
|
13
|
+
`;
|
|
14
|
+
const options = [{
|
|
15
|
+
value: '1',
|
|
16
|
+
label: 'one'
|
|
17
|
+
}, {
|
|
18
|
+
value: '2',
|
|
19
|
+
label: 'two'
|
|
20
|
+
}, {
|
|
21
|
+
value: '3',
|
|
22
|
+
label: 'three'
|
|
23
|
+
}, {
|
|
24
|
+
value: '4',
|
|
25
|
+
label: 'four'
|
|
26
|
+
}, {
|
|
27
|
+
value: '5',
|
|
28
|
+
label: 'five'
|
|
29
|
+
}, {
|
|
30
|
+
value: '6',
|
|
31
|
+
label: 'six'
|
|
32
|
+
}, {
|
|
33
|
+
value: '7',
|
|
34
|
+
label: 'seven'
|
|
35
|
+
}, {
|
|
36
|
+
value: '8',
|
|
37
|
+
label: 'eight'
|
|
38
|
+
}, {
|
|
39
|
+
value: '9',
|
|
40
|
+
label: 'nine'
|
|
41
|
+
}, {
|
|
42
|
+
value: '10',
|
|
43
|
+
label: 'ten'
|
|
44
|
+
}];
|
|
45
|
+
export default {
|
|
46
|
+
title: 'SimpleSingleSelectField',
|
|
47
|
+
component: SimpleSingleSelectField,
|
|
48
|
+
parameters: {
|
|
49
|
+
docs: {
|
|
50
|
+
description: {
|
|
51
|
+
component: description
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
export const Default = () => {
|
|
57
|
+
var _options$find;
|
|
58
|
+
const [value, setValue] = useState('3');
|
|
59
|
+
const valueLabel = value ? (_options$find = options.find(option => option.value === value)) === null || _options$find === void 0 ? void 0 : _options$find.label : '';
|
|
60
|
+
return /*#__PURE__*/React.createElement(SimpleSingleSelectField, {
|
|
61
|
+
name: "simple",
|
|
62
|
+
label: "This is the label",
|
|
63
|
+
value: value,
|
|
64
|
+
valueLabel: valueLabel,
|
|
65
|
+
onChange: nextValue => setValue(nextValue),
|
|
66
|
+
options: options
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
export const WithHelpText = () => {
|
|
70
|
+
var _options$find2;
|
|
71
|
+
const [value, setValue] = useState('3');
|
|
72
|
+
const valueLabel = value ? (_options$find2 = options.find(option => option.value === value)) === null || _options$find2 === void 0 ? void 0 : _options$find2.label : '';
|
|
73
|
+
return /*#__PURE__*/React.createElement(SimpleSingleSelectField, {
|
|
74
|
+
name: "simple",
|
|
75
|
+
label: "This is the label",
|
|
76
|
+
helpText: "This is the help text",
|
|
77
|
+
value: value,
|
|
78
|
+
valueLabel: valueLabel,
|
|
79
|
+
onChange: nextValue => setValue(nextValue),
|
|
80
|
+
options: options
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
export const StatusValid = () => {
|
|
84
|
+
var _options$find3;
|
|
85
|
+
const [value, setValue] = useState('3');
|
|
86
|
+
const valueLabel = value ? (_options$find3 = options.find(option => option.value === value)) === null || _options$find3 === void 0 ? void 0 : _options$find3.label : '';
|
|
87
|
+
return /*#__PURE__*/React.createElement(SimpleSingleSelectField, {
|
|
88
|
+
valid: true,
|
|
89
|
+
name: "simple",
|
|
90
|
+
label: "This is the label",
|
|
91
|
+
value: value,
|
|
92
|
+
valueLabel: valueLabel,
|
|
93
|
+
validationText: "Totally valid!",
|
|
94
|
+
onChange: nextValue => setValue(nextValue),
|
|
95
|
+
options: options
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
export const StatusWarning = () => {
|
|
99
|
+
var _options$find4;
|
|
100
|
+
const [value, setValue] = useState('3');
|
|
101
|
+
const valueLabel = value ? (_options$find4 = options.find(option => option.value === value)) === null || _options$find4 === void 0 ? void 0 : _options$find4.label : '';
|
|
102
|
+
return /*#__PURE__*/React.createElement(SimpleSingleSelectField, {
|
|
103
|
+
warning: true,
|
|
104
|
+
name: "simple",
|
|
105
|
+
label: "This is the label",
|
|
106
|
+
value: value,
|
|
107
|
+
valueLabel: valueLabel,
|
|
108
|
+
validationText: "Hm, not quite, I warn thee!",
|
|
109
|
+
onChange: nextValue => setValue(nextValue),
|
|
110
|
+
options: options
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
export const StatusError = () => {
|
|
114
|
+
var _options$find5;
|
|
115
|
+
const [value, setValue] = useState('3');
|
|
116
|
+
const valueLabel = value ? (_options$find5 = options.find(option => option.value === value)) === null || _options$find5 === void 0 ? void 0 : _options$find5.label : '';
|
|
117
|
+
return /*#__PURE__*/React.createElement(SimpleSingleSelectField, {
|
|
118
|
+
error: true,
|
|
119
|
+
name: "simple",
|
|
120
|
+
label: "This is the label",
|
|
121
|
+
value: value,
|
|
122
|
+
valueLabel: valueLabel,
|
|
123
|
+
validationText: "That value is wrong. Sorry!",
|
|
124
|
+
onChange: nextValue => setValue(nextValue),
|
|
125
|
+
options: options
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
export const StatusDisabled = () => {
|
|
129
|
+
var _options$find6;
|
|
130
|
+
const [value, setValue] = useState('3');
|
|
131
|
+
const valueLabel = value ? (_options$find6 = options.find(option => option.value === value)) === null || _options$find6 === void 0 ? void 0 : _options$find6.label : '';
|
|
132
|
+
return /*#__PURE__*/React.createElement(SimpleSingleSelectField, {
|
|
133
|
+
disabled: true,
|
|
134
|
+
name: "simple",
|
|
135
|
+
label: "This is the label",
|
|
136
|
+
value: value,
|
|
137
|
+
valueLabel: valueLabel,
|
|
138
|
+
onChange: nextValue => setValue(nextValue),
|
|
139
|
+
options: options
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
export const Required = () => {
|
|
143
|
+
var _options$find7;
|
|
144
|
+
const [value, setValue] = useState('3');
|
|
145
|
+
const valueLabel = value ? (_options$find7 = options.find(option => option.value === value)) === null || _options$find7 === void 0 ? void 0 : _options$find7.label : '';
|
|
146
|
+
return /*#__PURE__*/React.createElement(SimpleSingleSelectField, {
|
|
147
|
+
required: true,
|
|
148
|
+
name: "simple",
|
|
149
|
+
label: "This is the label",
|
|
150
|
+
value: value,
|
|
151
|
+
valueLabel: valueLabel,
|
|
152
|
+
onChange: nextValue => setValue(nextValue),
|
|
153
|
+
options: options
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
export const InputWidth = () => {
|
|
157
|
+
var _options$find8;
|
|
158
|
+
const [value, setValue] = useState('3');
|
|
159
|
+
const valueLabel = value ? (_options$find8 = options.find(option => option.value === value)) === null || _options$find8 === void 0 ? void 0 : _options$find8.label : '';
|
|
160
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
161
|
+
style: {
|
|
162
|
+
width: 200
|
|
163
|
+
}
|
|
164
|
+
}, /*#__PURE__*/React.createElement(SimpleSingleSelectField, {
|
|
165
|
+
name: "simple",
|
|
166
|
+
label: "A very long label indeed, well at least longer than the input field to show how it looks and works and stuff",
|
|
167
|
+
value: value,
|
|
168
|
+
valueLabel: valueLabel,
|
|
169
|
+
onChange: nextValue => setValue(nextValue),
|
|
170
|
+
options: options
|
|
171
|
+
}));
|
|
172
|
+
};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
2
|
+
import { Field } from '@dhis2-ui/field';
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { SimpleSingleSelect } from '../simple-single-select/simple-single-select.js';
|
|
6
|
+
import { SimpleSingleSelectField } from './simple-single-select-field.js';
|
|
7
|
+
jest.mock('../simple-single-select/simple-single-select.js', () => ({
|
|
8
|
+
SimpleSingleSelect: jest.fn(() => /*#__PURE__*/React.createElement("div", null))
|
|
9
|
+
}));
|
|
10
|
+
jest.mock('@dhis2-ui/field', () => ({
|
|
11
|
+
Field: jest.fn(_ref => {
|
|
12
|
+
let {
|
|
13
|
+
children
|
|
14
|
+
} = _ref;
|
|
15
|
+
return children;
|
|
16
|
+
})
|
|
17
|
+
}));
|
|
18
|
+
describe('<SimpleSingleSelectField />', () => {
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
Field.mockClear();
|
|
21
|
+
SimpleSingleSelect.mockClear();
|
|
22
|
+
});
|
|
23
|
+
it('should forward props to the SimpleSingleSelect component', () => {
|
|
24
|
+
const options = [];
|
|
25
|
+
const optionComponent = () => null;
|
|
26
|
+
const onChange = () => null;
|
|
27
|
+
const onBlur = () => null;
|
|
28
|
+
const onEndReached = () => null;
|
|
29
|
+
const onFilterChange = () => null;
|
|
30
|
+
const onFocus = () => null;
|
|
31
|
+
render(/*#__PURE__*/React.createElement(SimpleSingleSelectField, {
|
|
32
|
+
label: "Label text"
|
|
33
|
+
// Props that'll be passed to SimpleSingleSelect
|
|
34
|
+
,
|
|
35
|
+
name: "foo",
|
|
36
|
+
options: options,
|
|
37
|
+
onChange: onChange,
|
|
38
|
+
autoFocus: false,
|
|
39
|
+
className: "",
|
|
40
|
+
clearText: "",
|
|
41
|
+
clearable: false,
|
|
42
|
+
optionComponent: optionComponent,
|
|
43
|
+
dataTest: "",
|
|
44
|
+
dense: false,
|
|
45
|
+
disabled: false,
|
|
46
|
+
empty: "",
|
|
47
|
+
filterHelpText: "",
|
|
48
|
+
filterLabel: "",
|
|
49
|
+
filterPlaceholder: "",
|
|
50
|
+
filterValue: "",
|
|
51
|
+
filterable: false,
|
|
52
|
+
loading: false,
|
|
53
|
+
menuLoadingText: "",
|
|
54
|
+
menuMaxHeight: "",
|
|
55
|
+
noMatchText: "",
|
|
56
|
+
optionUpdateStrategy: "off",
|
|
57
|
+
placeholder: "",
|
|
58
|
+
prefix: "",
|
|
59
|
+
tabIndex: "",
|
|
60
|
+
valid: true,
|
|
61
|
+
value: "",
|
|
62
|
+
valueLabel: "",
|
|
63
|
+
onBlur: onBlur,
|
|
64
|
+
onEndReached: onEndReached,
|
|
65
|
+
onFilterChange: onFilterChange,
|
|
66
|
+
onFocus: onFocus
|
|
67
|
+
}));
|
|
68
|
+
expect(SimpleSingleSelect.mock.calls[0][0].name).toBe('foo');
|
|
69
|
+
expect(SimpleSingleSelect.mock.calls[0][0].options).toBe(options);
|
|
70
|
+
expect(SimpleSingleSelect.mock.calls[0][0].onChange).toBe(onChange);
|
|
71
|
+
expect(SimpleSingleSelect.mock.calls[0][0].autoFocus).toBe(false);
|
|
72
|
+
expect(SimpleSingleSelect.mock.calls[0][0].className).toBe('');
|
|
73
|
+
expect(SimpleSingleSelect.mock.calls[0][0].clearText).toBe('');
|
|
74
|
+
expect(SimpleSingleSelect.mock.calls[0][0].clearable).toBe(false);
|
|
75
|
+
expect(SimpleSingleSelect.mock.calls[0][0].optionComponent).toBe(optionComponent);
|
|
76
|
+
expect(SimpleSingleSelect.mock.calls[0][0].dataTest).toBe('');
|
|
77
|
+
expect(SimpleSingleSelect.mock.calls[0][0].dense).toBe(false);
|
|
78
|
+
expect(SimpleSingleSelect.mock.calls[0][0].disabled).toBe(false);
|
|
79
|
+
expect(SimpleSingleSelect.mock.calls[0][0].empty).toBe('');
|
|
80
|
+
expect(SimpleSingleSelect.mock.calls[0][0].filterHelpText).toBe('');
|
|
81
|
+
expect(SimpleSingleSelect.mock.calls[0][0].filterLabel).toBe('');
|
|
82
|
+
expect(SimpleSingleSelect.mock.calls[0][0].filterPlaceholder).toBe('');
|
|
83
|
+
expect(SimpleSingleSelect.mock.calls[0][0].filterValue).toBe('');
|
|
84
|
+
expect(SimpleSingleSelect.mock.calls[0][0].filterable).toBe(false);
|
|
85
|
+
expect(SimpleSingleSelect.mock.calls[0][0].labelledBy).toBe('foo-label');
|
|
86
|
+
expect(SimpleSingleSelect.mock.calls[0][0].loading).toBe(false);
|
|
87
|
+
expect(SimpleSingleSelect.mock.calls[0][0].menuLoadingText).toBe('');
|
|
88
|
+
expect(SimpleSingleSelect.mock.calls[0][0].menuMaxHeight).toBe('');
|
|
89
|
+
expect(SimpleSingleSelect.mock.calls[0][0].noMatchText).toBe('');
|
|
90
|
+
expect(SimpleSingleSelect.mock.calls[0][0].optionUpdateStrategy).toBe('off');
|
|
91
|
+
expect(SimpleSingleSelect.mock.calls[0][0].placeholder).toBe('');
|
|
92
|
+
expect(SimpleSingleSelect.mock.calls[0][0].prefix).toBe('');
|
|
93
|
+
expect(SimpleSingleSelect.mock.calls[0][0].tabIndex).toBe('');
|
|
94
|
+
expect(SimpleSingleSelect.mock.calls[0][0].valid).toBe(true);
|
|
95
|
+
expect(SimpleSingleSelect.mock.calls[0][0].value).toBe('');
|
|
96
|
+
expect(SimpleSingleSelect.mock.calls[0][0].valueLabel).toBe('');
|
|
97
|
+
expect(SimpleSingleSelect.mock.calls[0][0].onBlur).toBe(onBlur);
|
|
98
|
+
expect(SimpleSingleSelect.mock.calls[0][0].onEndReached).toBe(onEndReached);
|
|
99
|
+
expect(SimpleSingleSelect.mock.calls[0][0].onFilterChange).toBe(onFilterChange);
|
|
100
|
+
expect(SimpleSingleSelect.mock.calls[0][0].onFocus).toBe(onFocus);
|
|
101
|
+
});
|
|
102
|
+
it('should pass the right props to the Field component', () => {
|
|
103
|
+
render(/*#__PURE__*/React.createElement(SimpleSingleSelectField, {
|
|
104
|
+
label: "Label text",
|
|
105
|
+
className: "class name",
|
|
106
|
+
dataTest: "data test",
|
|
107
|
+
disabled: true,
|
|
108
|
+
required: true,
|
|
109
|
+
helpText: "Help text",
|
|
110
|
+
validationText: "Validation text",
|
|
111
|
+
valid: true
|
|
112
|
+
// Props required by SimpleSingleSelect
|
|
113
|
+
,
|
|
114
|
+
name: "foo",
|
|
115
|
+
options: [],
|
|
116
|
+
onChange: () => null
|
|
117
|
+
}));
|
|
118
|
+
expect(Field.mock.calls[0][0].className).toBe('class name');
|
|
119
|
+
expect(Field.mock.calls[0][0].dataTest).toBe('data test');
|
|
120
|
+
expect(Field.mock.calls[0][0].disabled).toBe(true);
|
|
121
|
+
expect(Field.mock.calls[0][0].required).toBe(true);
|
|
122
|
+
expect(Field.mock.calls[0][0].labelId).toBe('foo-label');
|
|
123
|
+
expect(Field.mock.calls[0][0].label).toBe('Label text');
|
|
124
|
+
expect(Field.mock.calls[0][0].helpText).toBe('Help text');
|
|
125
|
+
expect(Field.mock.calls[0][0].validationText).toBe('Validation text');
|
|
126
|
+
expect(Field.mock.calls[0][0].error).toBe(undefined);
|
|
127
|
+
expect(Field.mock.calls[0][0].warning).toBe(undefined);
|
|
128
|
+
expect(Field.mock.calls[0][0].valid).toBe(true);
|
|
129
|
+
});
|
|
130
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dhis2-ui/select",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.10.0-alpha.2",
|
|
4
4
|
"description": "UI Select",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,21 +33,21 @@
|
|
|
33
33
|
"styled-jsx": "^4"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@dhis2-ui/box": "10.
|
|
37
|
-
"@dhis2-ui/button": "10.
|
|
38
|
-
"@dhis2-ui/card": "10.
|
|
39
|
-
"@dhis2-ui/checkbox": "10.
|
|
40
|
-
"@dhis2-ui/chip": "10.
|
|
41
|
-
"@dhis2-ui/field": "10.
|
|
42
|
-
"@dhis2-ui/input": "10.
|
|
43
|
-
"@dhis2-ui/layer": "10.
|
|
44
|
-
"@dhis2-ui/loader": "10.
|
|
45
|
-
"@dhis2-ui/popper": "10.
|
|
46
|
-
"@dhis2-ui/status-icon": "10.
|
|
47
|
-
"@dhis2-ui/tooltip": "10.
|
|
36
|
+
"@dhis2-ui/box": "10.10.0-alpha.2",
|
|
37
|
+
"@dhis2-ui/button": "10.10.0-alpha.2",
|
|
38
|
+
"@dhis2-ui/card": "10.10.0-alpha.2",
|
|
39
|
+
"@dhis2-ui/checkbox": "10.10.0-alpha.2",
|
|
40
|
+
"@dhis2-ui/chip": "10.10.0-alpha.2",
|
|
41
|
+
"@dhis2-ui/field": "10.10.0-alpha.2",
|
|
42
|
+
"@dhis2-ui/input": "10.10.0-alpha.2",
|
|
43
|
+
"@dhis2-ui/layer": "10.10.0-alpha.2",
|
|
44
|
+
"@dhis2-ui/loader": "10.10.0-alpha.2",
|
|
45
|
+
"@dhis2-ui/popper": "10.10.0-alpha.2",
|
|
46
|
+
"@dhis2-ui/status-icon": "10.10.0-alpha.2",
|
|
47
|
+
"@dhis2-ui/tooltip": "10.10.0-alpha.2",
|
|
48
48
|
"@dhis2/prop-types": "^3.1.2",
|
|
49
|
-
"@dhis2/ui-constants": "10.
|
|
50
|
-
"@dhis2/ui-icons": "10.
|
|
49
|
+
"@dhis2/ui-constants": "10.10.0-alpha.2",
|
|
50
|
+
"@dhis2/ui-icons": "10.10.0-alpha.2",
|
|
51
51
|
"classnames": "^2.3.1",
|
|
52
52
|
"prop-types": "^15.7.2"
|
|
53
53
|
},
|