@dhis2-ui/select 10.9.1 → 10.10.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/build/cjs/index.js +18 -4
  2. package/build/cjs/locales/en/translations.json +7 -5
  3. package/build/cjs/simple-single-select/__stories__/DefaultPosition.js +38 -0
  4. package/build/cjs/simple-single-select/__stories__/Dense.js +22 -0
  5. package/build/cjs/simple-single-select/__stories__/Empty.js +20 -0
  6. package/build/cjs/simple-single-select/__stories__/EmptyWithEmptyNode.js +28 -0
  7. package/build/cjs/simple-single-select/__stories__/EmptyWithEmptyText.js +21 -0
  8. package/build/cjs/simple-single-select/__stories__/FlippedPosition.js +37 -0
  9. package/build/cjs/simple-single-select/__stories__/InfiniteLoading.js +61 -0
  10. package/build/cjs/simple-single-select/__stories__/Loading.js +20 -0
  11. package/build/cjs/simple-single-select/__stories__/ShiftedIntoView.js +28 -0
  12. package/build/cjs/simple-single-select/__stories__/WithClearButton.js +25 -0
  13. package/build/cjs/simple-single-select/__stories__/WithCustomLowMaxHeight.js +22 -0
  14. package/build/cjs/simple-single-select/__stories__/WithCustomOptions.js +48 -0
  15. package/build/cjs/simple-single-select/__stories__/WithDisabledOption.js +28 -0
  16. package/build/cjs/simple-single-select/__stories__/WithFilterField.js +36 -0
  17. package/build/cjs/simple-single-select/__stories__/WithInitialFocus.js +38 -0
  18. package/build/cjs/simple-single-select/__stories__/WithManyOptions.js +24 -0
  19. package/build/cjs/simple-single-select/__stories__/WithNoMatchText.js +30 -0
  20. package/build/cjs/simple-single-select/__stories__/WithOnBlur.js +23 -0
  21. package/build/cjs/simple-single-select/__stories__/WithOnFocus.js +23 -0
  22. package/build/cjs/simple-single-select/__stories__/WithOptionsAndDisabled.js +22 -0
  23. package/build/cjs/simple-single-select/__stories__/WithOptionsAndLoading.js +34 -0
  24. package/build/cjs/simple-single-select/__stories__/WithOptionsAndLoadingText.js +35 -0
  25. package/build/cjs/simple-single-select/__stories__/WithPlaceholder.js +23 -0
  26. package/build/cjs/simple-single-select/__stories__/WithPlaceholderAndSelection.js +25 -0
  27. package/build/cjs/simple-single-select/__stories__/WithPrefix.js +22 -0
  28. package/build/cjs/simple-single-select/__stories__/WithPrefixAndSelection.js +25 -0
  29. package/build/cjs/simple-single-select/__stories__/WithRTL.js +34 -0
  30. package/build/cjs/simple-single-select/__stories__/WithSelection.js +24 -0
  31. package/build/cjs/simple-single-select/__stories__/WithSelectionAndDisabled.js +25 -0
  32. package/build/cjs/simple-single-select/__stories__/WithoutOptionsAndLoading.js +21 -0
  33. package/build/cjs/simple-single-select/__stories__/WithoutSelection.js +22 -0
  34. package/build/cjs/simple-single-select/__stories__/options.js +77 -0
  35. package/build/cjs/simple-single-select/features/keyboard-interactions.test.e2e.js +441 -0
  36. package/build/cjs/simple-single-select/features/menu-positioning.test.e2e.js +152 -0
  37. package/build/cjs/simple-single-select/index.js +19 -0
  38. package/build/cjs/simple-single-select/is-option-hidden.js +22 -0
  39. package/build/cjs/simple-single-select/menu/empty.js +26 -0
  40. package/build/cjs/simple-single-select/menu/filter.js +60 -0
  41. package/build/cjs/simple-single-select/menu/index.js +12 -0
  42. package/build/cjs/simple-single-select/menu/loading.js +30 -0
  43. package/build/cjs/simple-single-select/menu/menu.js +158 -0
  44. package/build/cjs/simple-single-select/menu/no-match.js +28 -0
  45. package/build/cjs/simple-single-select/menu/option.js +120 -0
  46. package/build/cjs/simple-single-select/menu/options-list.js +97 -0
  47. package/build/cjs/simple-single-select/selected-value/clear-button.js +74 -0
  48. package/build/cjs/simple-single-select/selected-value/container.js +100 -0
  49. package/build/cjs/simple-single-select/selected-value/index.js +12 -0
  50. package/build/cjs/simple-single-select/selected-value/placeholder.js +30 -0
  51. package/build/cjs/simple-single-select/selected-value/prefix.js +30 -0
  52. package/build/cjs/simple-single-select/selected-value/selected-value.js +119 -0
  53. package/build/cjs/simple-single-select/shared-prop-types.js +14 -0
  54. package/build/cjs/simple-single-select/simple-single-select.e2e.stories.js +156 -0
  55. package/build/cjs/simple-single-select/simple-single-select.js +319 -0
  56. package/build/cjs/simple-single-select/simple-single-select.prod.stories.js +228 -0
  57. package/build/cjs/simple-single-select/simple-single-select.test.js +1106 -0
  58. package/build/cjs/simple-single-select/use-handle-key-press/index.js +19 -0
  59. package/build/cjs/simple-single-select/use-handle-key-press/use-focus-option.js +24 -0
  60. package/build/cjs/simple-single-select/use-handle-key-press/use-handle-key-press-on-combobox.js +177 -0
  61. package/build/cjs/simple-single-select/use-handle-key-press/use-handle-key-press-on-filter-input.js +106 -0
  62. package/build/cjs/simple-single-select/use-handle-key-press/use-handle-typing.js +81 -0
  63. package/build/cjs/simple-single-select/use-handle-key-press/use-highlight-first-option-on-previous-page.js +50 -0
  64. package/build/cjs/simple-single-select/use-handle-key-press/use-highlight-first-visible-option.js +30 -0
  65. package/build/cjs/simple-single-select/use-handle-key-press/use-highlight-last-option-on-next-page.js +50 -0
  66. package/build/cjs/simple-single-select/use-handle-key-press/use-highlight-last-visible-option.js +42 -0
  67. package/build/cjs/simple-single-select/use-handle-key-press/use-page-down.js +45 -0
  68. package/build/cjs/simple-single-select/use-handle-key-press/use-page-up.js +44 -0
  69. package/build/cjs/simple-single-select/use-handle-key-press/utils.js +46 -0
  70. package/build/cjs/simple-single-select-field/index.js +12 -0
  71. package/build/cjs/simple-single-select-field/simple-single-select-field.js +138 -0
  72. package/build/cjs/simple-single-select-field/simple-single-select-field.prod.stories.js +188 -0
  73. package/build/cjs/simple-single-select-field/simple-single-select-field.test.js +133 -0
  74. package/build/es/index.js +2 -0
  75. package/build/es/locales/en/translations.json +7 -5
  76. package/build/es/simple-single-select/__stories__/DefaultPosition.js +29 -0
  77. package/build/es/simple-single-select/__stories__/Dense.js +13 -0
  78. package/build/es/simple-single-select/__stories__/Empty.js +11 -0
  79. package/build/es/simple-single-select/__stories__/EmptyWithEmptyNode.js +19 -0
  80. package/build/es/simple-single-select/__stories__/EmptyWithEmptyText.js +12 -0
  81. package/build/es/simple-single-select/__stories__/FlippedPosition.js +28 -0
  82. package/build/es/simple-single-select/__stories__/InfiniteLoading.js +53 -0
  83. package/build/es/simple-single-select/__stories__/Loading.js +12 -0
  84. package/build/es/simple-single-select/__stories__/ShiftedIntoView.js +18 -0
  85. package/build/es/simple-single-select/__stories__/WithClearButton.js +16 -0
  86. package/build/es/simple-single-select/__stories__/WithCustomLowMaxHeight.js +13 -0
  87. package/build/es/simple-single-select/__stories__/WithCustomOptions.js +38 -0
  88. package/build/es/simple-single-select/__stories__/WithDisabledOption.js +19 -0
  89. package/build/es/simple-single-select/__stories__/WithFilterField.js +27 -0
  90. package/build/es/simple-single-select/__stories__/WithInitialFocus.js +29 -0
  91. package/build/es/simple-single-select/__stories__/WithManyOptions.js +15 -0
  92. package/build/es/simple-single-select/__stories__/WithNoMatchText.js +21 -0
  93. package/build/es/simple-single-select/__stories__/WithOnBlur.js +14 -0
  94. package/build/es/simple-single-select/__stories__/WithOnFocus.js +14 -0
  95. package/build/es/simple-single-select/__stories__/WithOptionsAndDisabled.js +13 -0
  96. package/build/es/simple-single-select/__stories__/WithOptionsAndLoading.js +25 -0
  97. package/build/es/simple-single-select/__stories__/WithOptionsAndLoadingText.js +26 -0
  98. package/build/es/simple-single-select/__stories__/WithPlaceholder.js +14 -0
  99. package/build/es/simple-single-select/__stories__/WithPlaceholderAndSelection.js +16 -0
  100. package/build/es/simple-single-select/__stories__/WithPrefix.js +13 -0
  101. package/build/es/simple-single-select/__stories__/WithPrefixAndSelection.js +16 -0
  102. package/build/es/simple-single-select/__stories__/WithRTL.js +25 -0
  103. package/build/es/simple-single-select/__stories__/WithSelection.js +15 -0
  104. package/build/es/simple-single-select/__stories__/WithSelectionAndDisabled.js +16 -0
  105. package/build/es/simple-single-select/__stories__/WithoutOptionsAndLoading.js +12 -0
  106. package/build/es/simple-single-select/__stories__/WithoutSelection.js +13 -0
  107. package/build/es/simple-single-select/__stories__/options.js +71 -0
  108. package/build/es/simple-single-select/features/keyboard-interactions.test.e2e.js +439 -0
  109. package/build/es/simple-single-select/features/menu-positioning.test.e2e.js +150 -0
  110. package/build/es/simple-single-select/index.js +2 -0
  111. package/build/es/simple-single-select/is-option-hidden.js +16 -0
  112. package/build/es/simple-single-select/menu/empty.js +19 -0
  113. package/build/es/simple-single-select/menu/filter.js +53 -0
  114. package/build/es/simple-single-select/menu/index.js +1 -0
  115. package/build/es/simple-single-select/menu/loading.js +23 -0
  116. package/build/es/simple-single-select/menu/menu.js +149 -0
  117. package/build/es/simple-single-select/menu/no-match.js +21 -0
  118. package/build/es/simple-single-select/menu/option.js +111 -0
  119. package/build/es/simple-single-select/menu/options-list.js +88 -0
  120. package/build/es/simple-single-select/selected-value/clear-button.js +68 -0
  121. package/build/es/simple-single-select/selected-value/container.js +91 -0
  122. package/build/es/simple-single-select/selected-value/index.js +1 -0
  123. package/build/es/simple-single-select/selected-value/placeholder.js +23 -0
  124. package/build/es/simple-single-select/selected-value/prefix.js +23 -0
  125. package/build/es/simple-single-select/selected-value/selected-value.js +112 -0
  126. package/build/es/simple-single-select/shared-prop-types.js +7 -0
  127. package/build/es/simple-single-select/simple-single-select.e2e.stories.js +142 -0
  128. package/build/es/simple-single-select/simple-single-select.js +310 -0
  129. package/build/es/simple-single-select/simple-single-select.prod.stories.js +36 -0
  130. package/build/es/simple-single-select/simple-single-select.test.js +1103 -0
  131. package/build/es/simple-single-select/use-handle-key-press/index.js +2 -0
  132. package/build/es/simple-single-select/use-handle-key-press/use-focus-option.js +18 -0
  133. package/build/es/simple-single-select/use-handle-key-press/use-handle-key-press-on-combobox.js +171 -0
  134. package/build/es/simple-single-select/use-handle-key-press/use-handle-key-press-on-filter-input.js +100 -0
  135. package/build/es/simple-single-select/use-handle-key-press/use-handle-typing.js +75 -0
  136. package/build/es/simple-single-select/use-handle-key-press/use-highlight-first-option-on-previous-page.js +44 -0
  137. package/build/es/simple-single-select/use-handle-key-press/use-highlight-first-visible-option.js +24 -0
  138. package/build/es/simple-single-select/use-handle-key-press/use-highlight-last-option-on-next-page.js +44 -0
  139. package/build/es/simple-single-select/use-handle-key-press/use-highlight-last-visible-option.js +36 -0
  140. package/build/es/simple-single-select/use-handle-key-press/use-page-down.js +39 -0
  141. package/build/es/simple-single-select/use-handle-key-press/use-page-up.js +38 -0
  142. package/build/es/simple-single-select/use-handle-key-press/utils.js +36 -0
  143. package/build/es/simple-single-select-field/index.js +1 -0
  144. package/build/es/simple-single-select-field/simple-single-select-field.js +131 -0
  145. package/build/es/simple-single-select-field/simple-single-select-field.prod.stories.js +172 -0
  146. package/build/es/simple-single-select-field/simple-single-select-field.test.js +130 -0
  147. package/package.json +15 -15
  148. package/types/index.d.ts +184 -1
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.findFirstOptionIndex = findFirstOptionIndex;
7
+ exports.findLastOptionIndex = findLastOptionIndex;
8
+ exports.findNextOptionIndex = findNextOptionIndex;
9
+ exports.findPrevOptionIndex = findPrevOptionIndex;
10
+ exports.isEnabled = isEnabled;
11
+ function isEnabled(_ref) {
12
+ let {
13
+ disabled
14
+ } = _ref;
15
+ return !disabled;
16
+ }
17
+ function findNextOptionIndex(_ref2) {
18
+ let {
19
+ options,
20
+ activeIndex
21
+ } = _ref2;
22
+ const startIndex = activeIndex + 1;
23
+ const optionsToSearch = options.slice(startIndex);
24
+
25
+ // Need to add back the count we removed by slicing the options array
26
+ return startIndex + optionsToSearch.findIndex(isEnabled);
27
+ }
28
+ function findPrevOptionIndex(_ref3) {
29
+ let {
30
+ options,
31
+ activeIndex
32
+ } = _ref3;
33
+ return options.slice(0, activeIndex).findLastIndex(isEnabled);
34
+ }
35
+ function findFirstOptionIndex(_ref4) {
36
+ let {
37
+ options
38
+ } = _ref4;
39
+ return options.findIndex(isEnabled);
40
+ }
41
+ function findLastOptionIndex(_ref5) {
42
+ let {
43
+ options
44
+ } = _ref5;
45
+ return options.findLastIndex(isEnabled);
46
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "SimpleSingleSelectField", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _simpleSingleSelectField.SimpleSingleSelectField;
10
+ }
11
+ });
12
+ var _simpleSingleSelectField = require("./simple-single-select-field.js");
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SimpleSingleSelectField = SimpleSingleSelectField;
7
+ var _propTypes = require("@dhis2/prop-types");
8
+ var _uiConstants = require("@dhis2/ui-constants");
9
+ var _field = require("@dhis2-ui/field");
10
+ var _propTypes2 = _interopRequireDefault(require("prop-types"));
11
+ var _react = _interopRequireDefault(require("react"));
12
+ var _index = require("../simple-single-select/index.js");
13
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
+ 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); }
15
+ function SimpleSingleSelectField(props) {
16
+ const {
17
+ className,
18
+ dataTest,
19
+ disabled,
20
+ error,
21
+ helpText,
22
+ label,
23
+ name,
24
+ required,
25
+ valid,
26
+ validationText,
27
+ warning
28
+ } = props;
29
+ const labelId = `${name}-label`;
30
+ return /*#__PURE__*/_react.default.createElement(_field.Field, {
31
+ className: className,
32
+ dataTest: dataTest,
33
+ disabled: disabled,
34
+ required: required,
35
+ labelId: labelId,
36
+ label: label,
37
+ helpText: helpText,
38
+ validationText: validationText,
39
+ error: error,
40
+ warning: warning,
41
+ valid: valid
42
+ }, /*#__PURE__*/_react.default.createElement(_index.SimpleSingleSelect, _extends({}, props, {
43
+ labelledBy: labelId
44
+ })));
45
+ }
46
+ SimpleSingleSelectField.propTypes = {
47
+ /** Label displayed above the input **/
48
+ label: _propTypes2.default.string.isRequired,
49
+ /** necessary for IDs that are required for accessibility **/
50
+ name: _propTypes2.default.string.isRequired,
51
+ /** An array of options **/
52
+ options: _propTypes2.default.arrayOf(_index.optionProp).isRequired,
53
+ /** A callback that will be called with the new value or an empty string **/
54
+ onChange: _propTypes2.default.func.isRequired,
55
+ /** Will focus the select initially **/
56
+ autoFocus: _propTypes2.default.bool,
57
+ /** Additional class names that will be applied to the root element **/
58
+ className: _propTypes2.default.string,
59
+ /** This will allow us to put an aria-label on the clear button **/
60
+ clearText: (0, _propTypes.requiredIf)(props => props.clearable, _propTypes2.default.string),
61
+ /** Whether a clear button should be displayed or not **/
62
+ clearable: _propTypes2.default.bool,
63
+ /** A value for a `data-test` attribute on the root element **/
64
+ dataTest: _propTypes2.default.string,
65
+ /** Renders a select with lower height **/
66
+ dense: _propTypes2.default.bool,
67
+ /** Disables all interactions with the select (except focussing) **/
68
+ disabled: _propTypes2.default.bool,
69
+ /** Text or component to display when there are no options **/
70
+ empty: _propTypes2.default.node,
71
+ /** Applies 'error' appearance for validation feedback. Mutually exclusive with `warning` and `valid` props **/
72
+ error: _uiConstants.sharedPropTypes.statusPropType,
73
+ /** Help text that will be displayed below the input **/
74
+ filterHelpText: _propTypes2.default.string,
75
+ /** Value will be used as aria-label attribute on the filter input **/
76
+ filterLabel: _propTypes2.default.string,
77
+ /** Placeholder for the filter input **/
78
+ filterPlaceholder: _propTypes2.default.string,
79
+ /** Value of the filter input **/
80
+ filterValue: _propTypes2.default.string,
81
+ /** Whether the select should display a filter input **/
82
+ filterable: _propTypes2.default.bool,
83
+ /** Help text, displayed below the input **/
84
+ helpText: _propTypes2.default.string,
85
+ /** Will show a loading indicator at the end of the options-list **/
86
+ loading: _propTypes2.default.bool,
87
+ /** Text that will be displayed next to the loading indicator **/
88
+ menuLoadingText: _propTypes2.default.string,
89
+ /** Allows to modify the max height of the menu **/
90
+ menuMaxHeight: _propTypes2.default.string,
91
+ /** String that will be displayed when the select is being filtered but the options array is empty **/
92
+ noMatchText: (0, _propTypes.requiredIf)(props => props.filterable, _propTypes2.default.string),
93
+ /** Allows to override what's rendered inside the `button[role="option"]`.
94
+ * Can be overriden on an individual option basis **/
95
+ optionComponent: _propTypes2.default.elementType,
96
+ /** For a11y: How aggressively the user should be updated about changes in options **/
97
+ optionUpdateStrategy: _propTypes2.default.oneOf(['off', 'polite', 'assertive']),
98
+ /** String to show when there's no value and no valueLabel **/
99
+ placeholder: _propTypes2.default.string,
100
+ /** String that will be displayed before the label of the selected option **/
101
+ prefix: _propTypes2.default.string,
102
+ /** Whether a value is required or not **/
103
+ required: _propTypes2.default.bool,
104
+ /** Standard HTML tab-index attribute that will be put on the combobox's root element **/
105
+ tabIndex: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.number]),
106
+ /** Applies 'valid' appearance for validation feedback. Mutually exclusive with `warning` and `valid` props **/
107
+ valid: _uiConstants.sharedPropTypes.statusPropType,
108
+ /** Text shown below input when `props.error` is true **/
109
+ validationText: _propTypes2.default.string,
110
+ /** As of now, this component does not support being uncontrolled **/
111
+ value: _propTypes2.default.string,
112
+ /**
113
+ * When the option is not in the options list (e.g. not loaded or list is
114
+ * filtered), but a selected value needs to be displayed, then this prop can
115
+ * be used to supply the text to be shown.
116
+ **/
117
+ valueLabel: (0, _propTypes.requiredIf)(props => {
118
+ if (props.options.find(_ref => {
119
+ let {
120
+ value
121
+ } = _ref;
122
+ return props.value === value;
123
+ })) {
124
+ return false;
125
+ }
126
+ return props.value;
127
+ }, _propTypes2.default.string),
128
+ /** Applies 'warning' appearance for validation feedback. Mutually exclusive with `warning` and `valid` props **/
129
+ warning: _uiConstants.sharedPropTypes.statusPropType,
130
+ /** Will be called when the combobox is loses focus **/
131
+ onBlur: _propTypes2.default.func,
132
+ /** Will be called when the last option is scrolled into the visible area **/
133
+ onEndReached: _propTypes2.default.func,
134
+ /** Will be called when the filter value changes **/
135
+ onFilterChange: _propTypes2.default.func,
136
+ /** Will be called when the combobox is being focused **/
137
+ onFocus: _propTypes2.default.func
138
+ };
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.WithHelpText = exports.StatusWarning = exports.StatusValid = exports.StatusError = exports.StatusDisabled = exports.Required = exports.InputWidth = exports.Default = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _index = require("./index.js");
9
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
10
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
+ const description = `
12
+ \`SimpleSingleSelectField\` is a wrapper around a \`SimpleSingleSelect\` component that adds a label, help text, validation text, and other features.
13
+
14
+ See the SimpleSingleSelect for more information, and read more at [Design System: Select](https://github.com/dhis2/design-system/blob/master/molecules/select.md).
15
+
16
+ \`\`\`js
17
+ import { SimpleSingleSelectField, SingleSelectOption } from '@dhis2/ui'
18
+ \`\`\`
19
+
20
+ _**Note**: The dropdowns in some of the following stories won't appear correctly on this page. View these demos in the 'Canvas' tab._
21
+ `;
22
+ const options = [{
23
+ value: '1',
24
+ label: 'one'
25
+ }, {
26
+ value: '2',
27
+ label: 'two'
28
+ }, {
29
+ value: '3',
30
+ label: 'three'
31
+ }, {
32
+ value: '4',
33
+ label: 'four'
34
+ }, {
35
+ value: '5',
36
+ label: 'five'
37
+ }, {
38
+ value: '6',
39
+ label: 'six'
40
+ }, {
41
+ value: '7',
42
+ label: 'seven'
43
+ }, {
44
+ value: '8',
45
+ label: 'eight'
46
+ }, {
47
+ value: '9',
48
+ label: 'nine'
49
+ }, {
50
+ value: '10',
51
+ label: 'ten'
52
+ }];
53
+ var _default = exports.default = {
54
+ title: 'SimpleSingleSelectField',
55
+ component: _index.SimpleSingleSelectField,
56
+ parameters: {
57
+ docs: {
58
+ description: {
59
+ component: description
60
+ }
61
+ }
62
+ }
63
+ };
64
+ const Default = () => {
65
+ var _options$find;
66
+ const [value, setValue] = (0, _react.useState)('3');
67
+ const valueLabel = value ? (_options$find = options.find(option => option.value === value)) === null || _options$find === void 0 ? void 0 : _options$find.label : '';
68
+ return /*#__PURE__*/_react.default.createElement(_index.SimpleSingleSelectField, {
69
+ name: "simple",
70
+ label: "This is the label",
71
+ value: value,
72
+ valueLabel: valueLabel,
73
+ onChange: nextValue => setValue(nextValue),
74
+ options: options
75
+ });
76
+ };
77
+ exports.Default = Default;
78
+ const WithHelpText = () => {
79
+ var _options$find2;
80
+ const [value, setValue] = (0, _react.useState)('3');
81
+ const valueLabel = value ? (_options$find2 = options.find(option => option.value === value)) === null || _options$find2 === void 0 ? void 0 : _options$find2.label : '';
82
+ return /*#__PURE__*/_react.default.createElement(_index.SimpleSingleSelectField, {
83
+ name: "simple",
84
+ label: "This is the label",
85
+ helpText: "This is the help text",
86
+ value: value,
87
+ valueLabel: valueLabel,
88
+ onChange: nextValue => setValue(nextValue),
89
+ options: options
90
+ });
91
+ };
92
+ exports.WithHelpText = WithHelpText;
93
+ const StatusValid = () => {
94
+ var _options$find3;
95
+ const [value, setValue] = (0, _react.useState)('3');
96
+ const valueLabel = value ? (_options$find3 = options.find(option => option.value === value)) === null || _options$find3 === void 0 ? void 0 : _options$find3.label : '';
97
+ return /*#__PURE__*/_react.default.createElement(_index.SimpleSingleSelectField, {
98
+ valid: true,
99
+ name: "simple",
100
+ label: "This is the label",
101
+ value: value,
102
+ valueLabel: valueLabel,
103
+ validationText: "Totally valid!",
104
+ onChange: nextValue => setValue(nextValue),
105
+ options: options
106
+ });
107
+ };
108
+ exports.StatusValid = StatusValid;
109
+ const StatusWarning = () => {
110
+ var _options$find4;
111
+ const [value, setValue] = (0, _react.useState)('3');
112
+ const valueLabel = value ? (_options$find4 = options.find(option => option.value === value)) === null || _options$find4 === void 0 ? void 0 : _options$find4.label : '';
113
+ return /*#__PURE__*/_react.default.createElement(_index.SimpleSingleSelectField, {
114
+ warning: true,
115
+ name: "simple",
116
+ label: "This is the label",
117
+ value: value,
118
+ valueLabel: valueLabel,
119
+ validationText: "Hm, not quite, I warn thee!",
120
+ onChange: nextValue => setValue(nextValue),
121
+ options: options
122
+ });
123
+ };
124
+ exports.StatusWarning = StatusWarning;
125
+ const StatusError = () => {
126
+ var _options$find5;
127
+ const [value, setValue] = (0, _react.useState)('3');
128
+ const valueLabel = value ? (_options$find5 = options.find(option => option.value === value)) === null || _options$find5 === void 0 ? void 0 : _options$find5.label : '';
129
+ return /*#__PURE__*/_react.default.createElement(_index.SimpleSingleSelectField, {
130
+ error: true,
131
+ name: "simple",
132
+ label: "This is the label",
133
+ value: value,
134
+ valueLabel: valueLabel,
135
+ validationText: "That value is wrong. Sorry!",
136
+ onChange: nextValue => setValue(nextValue),
137
+ options: options
138
+ });
139
+ };
140
+ exports.StatusError = StatusError;
141
+ const StatusDisabled = () => {
142
+ var _options$find6;
143
+ const [value, setValue] = (0, _react.useState)('3');
144
+ const valueLabel = value ? (_options$find6 = options.find(option => option.value === value)) === null || _options$find6 === void 0 ? void 0 : _options$find6.label : '';
145
+ return /*#__PURE__*/_react.default.createElement(_index.SimpleSingleSelectField, {
146
+ disabled: true,
147
+ name: "simple",
148
+ label: "This is the label",
149
+ value: value,
150
+ valueLabel: valueLabel,
151
+ onChange: nextValue => setValue(nextValue),
152
+ options: options
153
+ });
154
+ };
155
+ exports.StatusDisabled = StatusDisabled;
156
+ const Required = () => {
157
+ var _options$find7;
158
+ const [value, setValue] = (0, _react.useState)('3');
159
+ const valueLabel = value ? (_options$find7 = options.find(option => option.value === value)) === null || _options$find7 === void 0 ? void 0 : _options$find7.label : '';
160
+ return /*#__PURE__*/_react.default.createElement(_index.SimpleSingleSelectField, {
161
+ required: true,
162
+ name: "simple",
163
+ label: "This is the label",
164
+ value: value,
165
+ valueLabel: valueLabel,
166
+ onChange: nextValue => setValue(nextValue),
167
+ options: options
168
+ });
169
+ };
170
+ exports.Required = Required;
171
+ const InputWidth = () => {
172
+ var _options$find8;
173
+ const [value, setValue] = (0, _react.useState)('3');
174
+ const valueLabel = value ? (_options$find8 = options.find(option => option.value === value)) === null || _options$find8 === void 0 ? void 0 : _options$find8.label : '';
175
+ return /*#__PURE__*/_react.default.createElement("div", {
176
+ style: {
177
+ width: 200
178
+ }
179
+ }, /*#__PURE__*/_react.default.createElement(_index.SimpleSingleSelectField, {
180
+ name: "simple",
181
+ label: "A very long label indeed, well at least longer than the input field to show how it looks and works and stuff",
182
+ value: value,
183
+ valueLabel: valueLabel,
184
+ onChange: nextValue => setValue(nextValue),
185
+ options: options
186
+ }));
187
+ };
188
+ exports.InputWidth = InputWidth;
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+
3
+ require("@testing-library/jest-dom");
4
+ var _field = require("@dhis2-ui/field");
5
+ var _react = require("@testing-library/react");
6
+ var _react2 = _interopRequireDefault(require("react"));
7
+ var _simpleSingleSelect = require("../simple-single-select/simple-single-select.js");
8
+ var _simpleSingleSelectField = require("./simple-single-select-field.js");
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ jest.mock('../simple-single-select/simple-single-select.js', () => ({
11
+ SimpleSingleSelect: jest.fn(() => /*#__PURE__*/_react2.default.createElement("div", null))
12
+ }));
13
+ jest.mock('@dhis2-ui/field', () => ({
14
+ Field: jest.fn(_ref => {
15
+ let {
16
+ children
17
+ } = _ref;
18
+ return children;
19
+ })
20
+ }));
21
+ describe('<SimpleSingleSelectField />', () => {
22
+ afterEach(() => {
23
+ _field.Field.mockClear();
24
+ _simpleSingleSelect.SimpleSingleSelect.mockClear();
25
+ });
26
+ it('should forward props to the SimpleSingleSelect component', () => {
27
+ const options = [];
28
+ const optionComponent = () => null;
29
+ const onChange = () => null;
30
+ const onBlur = () => null;
31
+ const onEndReached = () => null;
32
+ const onFilterChange = () => null;
33
+ const onFocus = () => null;
34
+ (0, _react.render)(/*#__PURE__*/_react2.default.createElement(_simpleSingleSelectField.SimpleSingleSelectField, {
35
+ label: "Label text"
36
+ // Props that'll be passed to SimpleSingleSelect
37
+ ,
38
+ name: "foo",
39
+ options: options,
40
+ onChange: onChange,
41
+ autoFocus: false,
42
+ className: "",
43
+ clearText: "",
44
+ clearable: false,
45
+ optionComponent: optionComponent,
46
+ dataTest: "",
47
+ dense: false,
48
+ disabled: false,
49
+ empty: "",
50
+ filterHelpText: "",
51
+ filterLabel: "",
52
+ filterPlaceholder: "",
53
+ filterValue: "",
54
+ filterable: false,
55
+ loading: false,
56
+ menuLoadingText: "",
57
+ menuMaxHeight: "",
58
+ noMatchText: "",
59
+ optionUpdateStrategy: "off",
60
+ placeholder: "",
61
+ prefix: "",
62
+ tabIndex: "",
63
+ valid: true,
64
+ value: "",
65
+ valueLabel: "",
66
+ onBlur: onBlur,
67
+ onEndReached: onEndReached,
68
+ onFilterChange: onFilterChange,
69
+ onFocus: onFocus
70
+ }));
71
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].name).toBe('foo');
72
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].options).toBe(options);
73
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].onChange).toBe(onChange);
74
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].autoFocus).toBe(false);
75
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].className).toBe('');
76
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].clearText).toBe('');
77
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].clearable).toBe(false);
78
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].optionComponent).toBe(optionComponent);
79
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].dataTest).toBe('');
80
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].dense).toBe(false);
81
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].disabled).toBe(false);
82
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].empty).toBe('');
83
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].filterHelpText).toBe('');
84
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].filterLabel).toBe('');
85
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].filterPlaceholder).toBe('');
86
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].filterValue).toBe('');
87
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].filterable).toBe(false);
88
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].labelledBy).toBe('foo-label');
89
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].loading).toBe(false);
90
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].menuLoadingText).toBe('');
91
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].menuMaxHeight).toBe('');
92
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].noMatchText).toBe('');
93
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].optionUpdateStrategy).toBe('off');
94
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].placeholder).toBe('');
95
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].prefix).toBe('');
96
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].tabIndex).toBe('');
97
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].valid).toBe(true);
98
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].value).toBe('');
99
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].valueLabel).toBe('');
100
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].onBlur).toBe(onBlur);
101
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].onEndReached).toBe(onEndReached);
102
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].onFilterChange).toBe(onFilterChange);
103
+ expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].onFocus).toBe(onFocus);
104
+ });
105
+ it('should pass the right props to the Field component', () => {
106
+ (0, _react.render)(/*#__PURE__*/_react2.default.createElement(_simpleSingleSelectField.SimpleSingleSelectField, {
107
+ label: "Label text",
108
+ className: "class name",
109
+ dataTest: "data test",
110
+ disabled: true,
111
+ required: true,
112
+ helpText: "Help text",
113
+ validationText: "Validation text",
114
+ valid: true
115
+ // Props required by SimpleSingleSelect
116
+ ,
117
+ name: "foo",
118
+ options: [],
119
+ onChange: () => null
120
+ }));
121
+ expect(_field.Field.mock.calls[0][0].className).toBe('class name');
122
+ expect(_field.Field.mock.calls[0][0].dataTest).toBe('data test');
123
+ expect(_field.Field.mock.calls[0][0].disabled).toBe(true);
124
+ expect(_field.Field.mock.calls[0][0].required).toBe(true);
125
+ expect(_field.Field.mock.calls[0][0].labelId).toBe('foo-label');
126
+ expect(_field.Field.mock.calls[0][0].label).toBe('Label text');
127
+ expect(_field.Field.mock.calls[0][0].helpText).toBe('Help text');
128
+ expect(_field.Field.mock.calls[0][0].validationText).toBe('Validation text');
129
+ expect(_field.Field.mock.calls[0][0].error).toBe(undefined);
130
+ expect(_field.Field.mock.calls[0][0].warning).toBe(undefined);
131
+ expect(_field.Field.mock.calls[0][0].valid).toBe(true);
132
+ });
133
+ });
package/build/es/index.js CHANGED
@@ -2,5 +2,7 @@ export { MultiSelect } from './multi-select/index.js';
2
2
  export { MultiSelectField } from './multi-select-field/index.js';
3
3
  export { MultiSelectOption } from './multi-select-option/index.js';
4
4
  export { SingleSelect } from './single-select/index.js';
5
+ export { SimpleSingleSelect } from './simple-single-select/index.js';
6
+ export { SimpleSingleSelectField } from './simple-single-select-field/index.js';
5
7
  export { SingleSelectField } from './single-select-field/index.js';
6
8
  export { SingleSelectOption } from './single-select-option/index.js';
@@ -1,7 +1,9 @@
1
1
  {
2
- "Clear": "",
3
- "No data found": "",
4
- "Type to filter options": "",
5
- "Loading options": "",
6
- "No options found": ""
2
+ "Clear": "Clear",
3
+ "No data found": "No data found",
4
+ "Type to filter options": "Type to filter options",
5
+ "Loading options": "Loading options",
6
+ "No options found": "No options found",
7
+ "Search options": "Search options",
8
+ "{{clearText}}": "{{clearText}}"
7
9
  }
@@ -0,0 +1,29 @@
1
+ import React, { useState } from 'react';
2
+ import { SimpleSingleSelect } from '../simple-single-select.js';
3
+ import { fiveOptions } from './options.js';
4
+ export const DefaultPosition = () => {
5
+ const [selected, setSelected] = useState({
6
+ label: 'ANC 1st visit',
7
+ value: 'anc_1st_visit'
8
+ });
9
+ return /*#__PURE__*/React.createElement("div", {
10
+ style: {
11
+ position: 'relative',
12
+ // Accounting for the padding on the body
13
+ height: 'calc(100vh - 32px)'
14
+ }
15
+ }, /*#__PURE__*/React.createElement("div", {
16
+ style: {
17
+ position: 'absolute',
18
+ top: '50%',
19
+ left: 0,
20
+ transform: 'translateY(-50%)',
21
+ width: '100%'
22
+ }
23
+ }, /*#__PURE__*/React.createElement(SimpleSingleSelect, {
24
+ name: "simple",
25
+ selected: selected,
26
+ onChange: setSelected,
27
+ options: fiveOptions
28
+ })));
29
+ };
@@ -0,0 +1,13 @@
1
+ import React, { useState } from 'react';
2
+ import { SimpleSingleSelect } from '../simple-single-select.js';
3
+ import { fiveOptions } from './options.js';
4
+ export const Dense = () => {
5
+ const [selected, setSelected] = useState(null);
6
+ return /*#__PURE__*/React.createElement(SimpleSingleSelect, {
7
+ dense: true,
8
+ name: "simple",
9
+ selected: selected,
10
+ onChange: setSelected,
11
+ options: fiveOptions
12
+ });
13
+ };
@@ -0,0 +1,11 @@
1
+ import React, { useState } from 'react';
2
+ import { SimpleSingleSelect } from '../simple-single-select.js';
3
+ export const Empty = () => {
4
+ const [selected, setSelected] = useState(null);
5
+ return /*#__PURE__*/React.createElement(SimpleSingleSelect, {
6
+ name: "simple",
7
+ selected: selected,
8
+ onChange: setSelected,
9
+ options: []
10
+ });
11
+ };
@@ -0,0 +1,19 @@
1
+ import React, { useState } from 'react';
2
+ import { SimpleSingleSelect } from '../simple-single-select.js';
3
+ export const EmptyWithEmptyNode = () => {
4
+ const [selected, setSelected] = useState(null);
5
+ const emptyNode = /*#__PURE__*/React.createElement("div", {
6
+ style: {
7
+ color: 'red',
8
+ textAlign: 'center',
9
+ padding: '10px 0'
10
+ }
11
+ }, "Custom empty text");
12
+ return /*#__PURE__*/React.createElement(SimpleSingleSelect, {
13
+ name: "simple",
14
+ selected: selected,
15
+ onChange: setSelected,
16
+ options: [],
17
+ empty: emptyNode
18
+ });
19
+ };
@@ -0,0 +1,12 @@
1
+ import React, { useState } from 'react';
2
+ import { SimpleSingleSelect } from '../simple-single-select.js';
3
+ export const EmptyWithEmptyText = () => {
4
+ const [selected, setSelected] = useState(null);
5
+ return /*#__PURE__*/React.createElement(SimpleSingleSelect, {
6
+ name: "simple",
7
+ selected: selected,
8
+ onChange: setSelected,
9
+ options: [],
10
+ empty: "Custom empty text"
11
+ });
12
+ };
@@ -0,0 +1,28 @@
1
+ import React, { useState } from 'react';
2
+ import { SimpleSingleSelect } from '../simple-single-select.js';
3
+ import { fiveOptions } from './options.js';
4
+ export const FlippedPosition = () => {
5
+ const [selected, setSelected] = useState({
6
+ label: 'ANC 1st visit',
7
+ value: 'anc_1st_visit'
8
+ });
9
+ return /*#__PURE__*/React.createElement("div", {
10
+ style: {
11
+ position: 'relative',
12
+ // Accounting for the padding on the body
13
+ height: 'calc(100vh - 32px)'
14
+ }
15
+ }, /*#__PURE__*/React.createElement("div", {
16
+ style: {
17
+ position: 'absolute',
18
+ bottom: 0,
19
+ left: 0,
20
+ width: '100%'
21
+ }
22
+ }, /*#__PURE__*/React.createElement(SimpleSingleSelect, {
23
+ name: "simple",
24
+ selected: selected,
25
+ onChange: setSelected,
26
+ options: fiveOptions
27
+ })));
28
+ };