@dhis2-ui/select 10.16.1 → 10.16.3-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 (278) hide show
  1. package/build/cjs/select/select.js +5 -2
  2. package/build/cjs/simple-single-select/use-handle-key-press/use-handle-key-press-on-filter-input.js +2 -2
  3. package/build/es/select/select.js +5 -2
  4. package/build/es/simple-single-select/use-handle-key-press/use-handle-key-press-on-filter-input.js +2 -2
  5. package/package.json +17 -16
  6. package/src/index.js +9 -0
  7. package/src/locales/ar/translations.json +7 -0
  8. package/src/locales/ar_IQ/translations.json +7 -0
  9. package/src/locales/ckb/translations.json +7 -0
  10. package/src/locales/cs/translations.json +7 -0
  11. package/src/locales/da/translations.json +7 -0
  12. package/src/locales/en/translations.json +11 -0
  13. package/src/locales/en_US/translations.json +9 -0
  14. package/src/locales/es/translations.json +7 -0
  15. package/src/locales/es_419/translations.json +7 -0
  16. package/src/locales/fr/translations.json +7 -0
  17. package/src/locales/hi_IN/translations.json +7 -0
  18. package/src/locales/id/translations.json +7 -0
  19. package/src/locales/index.js +80 -0
  20. package/src/locales/km/translations.json +7 -0
  21. package/src/locales/lo/translations.json +7 -0
  22. package/src/locales/my/translations.json +7 -0
  23. package/src/locales/nb/translations.json +7 -0
  24. package/src/locales/nl/translations.json +7 -0
  25. package/src/locales/prs/translations.json +7 -0
  26. package/src/locales/ps/translations.json +7 -0
  27. package/src/locales/pt/translations.json +7 -0
  28. package/src/locales/pt_BR/translations.json +7 -0
  29. package/src/locales/ru/translations.json +7 -0
  30. package/src/locales/sv/translations.json +7 -0
  31. package/src/locales/tet/translations.json +7 -0
  32. package/src/locales/tg/translations.json +7 -0
  33. package/src/locales/uk/translations.json +7 -0
  34. package/src/locales/ur/translations.json +7 -0
  35. package/src/locales/uz_Latn/translations.json +7 -0
  36. package/src/locales/uz_UZ_Cyrl/translations.json +7 -0
  37. package/src/locales/uz_UZ_Latn/translations.json +7 -0
  38. package/src/locales/vi/translations.json +7 -0
  39. package/src/locales/zh/translations.json +9 -0
  40. package/src/locales/zh_CN/translations.json +7 -0
  41. package/src/multi-select/__tests__/multi-select.test.js +23 -0
  42. package/src/multi-select/__tests__/selection-list.test.js +102 -0
  43. package/src/multi-select/features/accepts_blur_cb/index.js +14 -0
  44. package/src/multi-select/features/accepts_blur_cb.feature +8 -0
  45. package/src/multi-select/features/accepts_focus_cb/index.js +14 -0
  46. package/src/multi-select/features/accepts_focus_cb.feature +6 -0
  47. package/src/multi-select/features/accepts_initial_focus/index.js +5 -0
  48. package/src/multi-select/features/accepts_initial_focus.feature +5 -0
  49. package/src/multi-select/features/accepts_loading/index.js +22 -0
  50. package/src/multi-select/features/accepts_loading.feature +14 -0
  51. package/src/multi-select/features/accepts_max_height/index.js +31 -0
  52. package/src/multi-select/features/accepts_max_height.feature +11 -0
  53. package/src/multi-select/features/accepts_placeholder/index.js +25 -0
  54. package/src/multi-select/features/accepts_placeholder.feature +10 -0
  55. package/src/multi-select/features/accepts_prefix/index.js +19 -0
  56. package/src/multi-select/features/accepts_prefix.feature +10 -0
  57. package/src/multi-select/features/allows_invalid_options/index.js +27 -0
  58. package/src/multi-select/features/allows_invalid_options.feature +12 -0
  59. package/src/multi-select/features/allows_selecting/index.js +81 -0
  60. package/src/multi-select/features/allows_selecting.feature +44 -0
  61. package/src/multi-select/features/can_be_cleared/index.js +22 -0
  62. package/src/multi-select/features/can_be_cleared.feature +6 -0
  63. package/src/multi-select/features/can_be_disabled/index.js +36 -0
  64. package/src/multi-select/features/can_be_disabled.feature +32 -0
  65. package/src/multi-select/features/can_be_empty/index.js +28 -0
  66. package/src/multi-select/features/can_be_empty.feature +16 -0
  67. package/src/multi-select/features/can_be_filtered/index.js +23 -0
  68. package/src/multi-select/features/can_be_filtered.feature +14 -0
  69. package/src/multi-select/features/can_be_opened_and_closed/index.js +32 -0
  70. package/src/multi-select/features/can_be_opened_and_closed.feature +41 -0
  71. package/src/multi-select/features/common/index.js +49 -0
  72. package/src/multi-select/features/duplicate_option_values/index.js +21 -0
  73. package/src/multi-select/features/duplicate_option_values.feature +7 -0
  74. package/src/multi-select/features/menu_width_matches_input/index.js +53 -0
  75. package/src/multi-select/features/menu_width_matches_input.feature +11 -0
  76. package/src/multi-select/features/position/index.js +160 -0
  77. package/src/multi-select/features/position.feature +46 -0
  78. package/src/multi-select/features/shows_selections/index.js +18 -0
  79. package/src/multi-select/features/shows_selections.feature +9 -0
  80. package/src/multi-select/filterable-menu.js +43 -0
  81. package/src/multi-select/index.js +1 -0
  82. package/src/multi-select/input.js +129 -0
  83. package/src/multi-select/menu.js +91 -0
  84. package/src/multi-select/multi-select.e2e.stories.js +407 -0
  85. package/src/multi-select/multi-select.js +148 -0
  86. package/src/multi-select/multi-select.prod.stories.js +408 -0
  87. package/src/multi-select/selection-list.js +79 -0
  88. package/src/multi-select-field/__tests__/multi-select-field.test.js +29 -0
  89. package/src/multi-select-field/features/accepts_help_text/index.js +9 -0
  90. package/src/multi-select-field/features/accepts_help_text.feature +5 -0
  91. package/src/multi-select-field/features/accepts_label/index.js +9 -0
  92. package/src/multi-select-field/features/accepts_label.feature +5 -0
  93. package/src/multi-select-field/features/accepts_validation_text/index.js +9 -0
  94. package/src/multi-select-field/features/accepts_validation_text.feature +5 -0
  95. package/src/multi-select-field/features/can_be_required/index.js +11 -0
  96. package/src/multi-select-field/features/can_be_required.feature +5 -0
  97. package/src/multi-select-field/features/has_default_clear_text/index.js +16 -0
  98. package/src/multi-select-field/features/has_default_clear_text.feature +6 -0
  99. package/src/multi-select-field/features/has_default_empty_text/index.js +13 -0
  100. package/src/multi-select-field/features/has_default_empty_text.feature +6 -0
  101. package/src/multi-select-field/features/has_default_filter_nomatch_text/index.js +17 -0
  102. package/src/multi-select-field/features/has_default_filter_nomatch_text.feature +7 -0
  103. package/src/multi-select-field/features/has_default_filter_placeholder/index.js +15 -0
  104. package/src/multi-select-field/features/has_default_filter_placeholder.feature +6 -0
  105. package/src/multi-select-field/features/has_default_loading_text/index.js +13 -0
  106. package/src/multi-select-field/features/has_default_loading_text.feature +6 -0
  107. package/src/multi-select-field/index.js +1 -0
  108. package/src/multi-select-field/multi-select-field.e2e.stories.js +45 -0
  109. package/src/multi-select-field/multi-select-field.js +178 -0
  110. package/src/multi-select-field/multi-select-field.prod.stories.js +137 -0
  111. package/src/multi-select-option/index.js +1 -0
  112. package/src/multi-select-option/multi-select-option.js +70 -0
  113. package/src/select/__tests__/select.test.js +31 -0
  114. package/src/select/debounce/debounce.js +30 -0
  115. package/src/select/debounce/debounce.spec.js +35 -0
  116. package/src/select/empty.js +28 -0
  117. package/src/select/filter-input.js +42 -0
  118. package/src/select/filterable-menu.js +106 -0
  119. package/src/select/index.js +14 -0
  120. package/src/select/input-clear-button.js +66 -0
  121. package/src/select/input-placeholder.js +30 -0
  122. package/src/select/input-prefix.js +32 -0
  123. package/src/select/input-wrapper.js +114 -0
  124. package/src/select/loading.js +33 -0
  125. package/src/select/menu-wrapper.js +52 -0
  126. package/src/select/no-match.js +28 -0
  127. package/src/select/option-helpers.js +34 -0
  128. package/src/select/select.js +256 -0
  129. package/src/simple-single-select/__stories__/DefaultPosition.js +37 -0
  130. package/src/simple-single-select/__stories__/Dense.js +17 -0
  131. package/src/simple-single-select/__stories__/Empty.js +15 -0
  132. package/src/simple-single-select/__stories__/EmptyWithEmptyNode.js +27 -0
  133. package/src/simple-single-select/__stories__/EmptyWithEmptyText.js +16 -0
  134. package/src/simple-single-select/__stories__/FlippedPosition.js +36 -0
  135. package/src/simple-single-select/__stories__/InfiniteLoading.js +65 -0
  136. package/src/simple-single-select/__stories__/Loading.js +15 -0
  137. package/src/simple-single-select/__stories__/ShiftedIntoView.js +35 -0
  138. package/src/simple-single-select/__stories__/WithClearButton.js +26 -0
  139. package/src/simple-single-select/__stories__/WithCustomLowMaxHeight.js +17 -0
  140. package/src/simple-single-select/__stories__/WithCustomOptions.js +78 -0
  141. package/src/simple-single-select/__stories__/WithDisabledOption.js +25 -0
  142. package/src/simple-single-select/__stories__/WithFilterField.js +30 -0
  143. package/src/simple-single-select/__stories__/WithInitialFocus.js +29 -0
  144. package/src/simple-single-select/__stories__/WithManyOptions.js +19 -0
  145. package/src/simple-single-select/__stories__/WithMultipleSelectsAndScrollableParent.js +65 -0
  146. package/src/simple-single-select/__stories__/WithNoMatchText.js +25 -0
  147. package/src/simple-single-select/__stories__/WithOnBlur.js +22 -0
  148. package/src/simple-single-select/__stories__/WithOnFocus.js +22 -0
  149. package/src/simple-single-select/__stories__/WithOptionsAndDisabled.js +17 -0
  150. package/src/simple-single-select/__stories__/WithOptionsAndLoading.js +23 -0
  151. package/src/simple-single-select/__stories__/WithOptionsAndLoadingText.js +24 -0
  152. package/src/simple-single-select/__stories__/WithPlaceholder.js +18 -0
  153. package/src/simple-single-select/__stories__/WithPlaceholderAndSelection.js +20 -0
  154. package/src/simple-single-select/__stories__/WithPrefix.js +17 -0
  155. package/src/simple-single-select/__stories__/WithPrefixAndSelection.js +20 -0
  156. package/src/simple-single-select/__stories__/WithRTL.js +29 -0
  157. package/src/simple-single-select/__stories__/WithScrollingParent.js +51 -0
  158. package/src/simple-single-select/__stories__/WithSelection.js +19 -0
  159. package/src/simple-single-select/__stories__/WithSelectionAndDisabled.js +20 -0
  160. package/src/simple-single-select/__stories__/WithServerSideFilteringDemo.js +245 -0
  161. package/src/simple-single-select/__stories__/WithSimpleFilteringDemo.js +50 -0
  162. package/src/simple-single-select/__stories__/WithoutOptionsAndLoading.js +16 -0
  163. package/src/simple-single-select/__stories__/WithoutSelection.js +17 -0
  164. package/src/simple-single-select/__stories__/options.js +96 -0
  165. package/src/simple-single-select/__stories__/simple-single-select-server-side-filtering/CustomDataProvider.js +70 -0
  166. package/src/simple-single-select/__stories__/simple-single-select-server-side-filtering/dataElements.js +4271 -0
  167. package/src/simple-single-select/__stories__/simple-single-select-server-side-filtering/index.js +1 -0
  168. package/src/simple-single-select/features/keyboard-interactions.test.e2e.js +581 -0
  169. package/src/simple-single-select/features/menu-positioning.test.e2e.js +187 -0
  170. package/src/simple-single-select/index.js +2 -0
  171. package/src/simple-single-select/is-option-hidden.js +21 -0
  172. package/src/simple-single-select/menu/empty.js +27 -0
  173. package/src/simple-single-select/menu/filter.js +61 -0
  174. package/src/simple-single-select/menu/index.js +1 -0
  175. package/src/simple-single-select/menu/loading.js +38 -0
  176. package/src/simple-single-select/menu/menu.js +171 -0
  177. package/src/simple-single-select/menu/no-match.js +28 -0
  178. package/src/simple-single-select/menu/option.js +161 -0
  179. package/src/simple-single-select/menu/options-list.js +107 -0
  180. package/src/simple-single-select/selected-value/clear-button.js +71 -0
  181. package/src/simple-single-select/selected-value/container.js +146 -0
  182. package/src/simple-single-select/selected-value/index.js +1 -0
  183. package/src/simple-single-select/selected-value/placeholder.js +24 -0
  184. package/src/simple-single-select/selected-value/prefix.js +26 -0
  185. package/src/simple-single-select/selected-value/selected-value.js +174 -0
  186. package/src/simple-single-select/shared-prop-types.js +8 -0
  187. package/src/simple-single-select/simple-single-select.e2e.stories.js +216 -0
  188. package/src/simple-single-select/simple-single-select.js +389 -0
  189. package/src/simple-single-select/simple-single-select.prod.stories.js +41 -0
  190. package/src/simple-single-select/simple-single-select.test.js +1136 -0
  191. package/src/simple-single-select/use-handle-key-press/index.js +2 -0
  192. package/src/simple-single-select/use-handle-key-press/use-focus-option.js +24 -0
  193. package/src/simple-single-select/use-handle-key-press/use-handle-key-press-on-combobox.js +259 -0
  194. package/src/simple-single-select/use-handle-key-press/use-handle-key-press-on-filter-input.js +147 -0
  195. package/src/simple-single-select/use-handle-key-press/use-handle-typing.js +79 -0
  196. package/src/simple-single-select/use-handle-key-press/use-highlight-first-option-on-previous-page.js +62 -0
  197. package/src/simple-single-select/use-handle-key-press/use-highlight-first-visible-option.js +38 -0
  198. package/src/simple-single-select/use-handle-key-press/use-highlight-last-option-on-next-page.js +60 -0
  199. package/src/simple-single-select/use-handle-key-press/use-highlight-last-visible-option.js +52 -0
  200. package/src/simple-single-select/use-handle-key-press/use-page-down.js +50 -0
  201. package/src/simple-single-select/use-handle-key-press/use-page-up.js +50 -0
  202. package/src/simple-single-select/use-handle-key-press/utils.js +23 -0
  203. package/src/simple-single-select-field/index.js +1 -0
  204. package/src/simple-single-select-field/simple-single-select-field.js +198 -0
  205. package/src/simple-single-select-field/simple-single-select-field.prod.stories.js +188 -0
  206. package/src/simple-single-select-field/simple-single-select-field.test.js +144 -0
  207. package/src/single-select/__tests__/selection.test.js +102 -0
  208. package/src/single-select/__tests__/single-select.test.js +23 -0
  209. package/src/single-select/features/accepts_blur_cb/index.js +14 -0
  210. package/src/single-select/features/accepts_blur_cb.feature +8 -0
  211. package/src/single-select/features/accepts_focus_cb/index.js +14 -0
  212. package/src/single-select/features/accepts_focus_cb.feature +6 -0
  213. package/src/single-select/features/accepts_initial_focus/index.js +5 -0
  214. package/src/single-select/features/accepts_initial_focus.feature +5 -0
  215. package/src/single-select/features/accepts_loading/index.js +22 -0
  216. package/src/single-select/features/accepts_loading.feature +14 -0
  217. package/src/single-select/features/accepts_max_height/index.js +31 -0
  218. package/src/single-select/features/accepts_max_height.feature +11 -0
  219. package/src/single-select/features/accepts_placeholder/index.js +25 -0
  220. package/src/single-select/features/accepts_placeholder.feature +10 -0
  221. package/src/single-select/features/accepts_prefix/index.js +19 -0
  222. package/src/single-select/features/accepts_prefix.feature +10 -0
  223. package/src/single-select/features/allows_invalid_options/index.js +28 -0
  224. package/src/single-select/features/allows_invalid_options.feature +12 -0
  225. package/src/single-select/features/allows_selecting/index.js +38 -0
  226. package/src/single-select/features/allows_selecting.feature +21 -0
  227. package/src/single-select/features/can_be_cleared/index.js +22 -0
  228. package/src/single-select/features/can_be_cleared.feature +6 -0
  229. package/src/single-select/features/can_be_disabled/index.js +39 -0
  230. package/src/single-select/features/can_be_disabled.feature +32 -0
  231. package/src/single-select/features/can_be_empty/index.js +28 -0
  232. package/src/single-select/features/can_be_empty.feature +16 -0
  233. package/src/single-select/features/can_be_filtered/index.js +23 -0
  234. package/src/single-select/features/can_be_filtered.feature +14 -0
  235. package/src/single-select/features/can_be_opened_and_closed/index.js +32 -0
  236. package/src/single-select/features/can_be_opened_and_closed.feature +41 -0
  237. package/src/single-select/features/common/index.js +44 -0
  238. package/src/single-select/features/duplicate_option_values/index.js +26 -0
  239. package/src/single-select/features/duplicate_option_values.feature +7 -0
  240. package/src/single-select/features/menu_width_matches_input/index.js +53 -0
  241. package/src/single-select/features/menu_width_matches_input.feature +11 -0
  242. package/src/single-select/features/position/index.js +111 -0
  243. package/src/single-select/features/position.feature +26 -0
  244. package/src/single-select/features/shows_selections/index.js +9 -0
  245. package/src/single-select/features/shows_selections.feature +5 -0
  246. package/src/single-select/filterable-menu.js +41 -0
  247. package/src/single-select/index.js +1 -0
  248. package/src/single-select/input.js +101 -0
  249. package/src/single-select/menu.js +75 -0
  250. package/src/single-select/selection.js +60 -0
  251. package/src/single-select/single-select.e2e.stories.js +376 -0
  252. package/src/single-select/single-select.js +146 -0
  253. package/src/single-select/single-select.prod.stories.js +358 -0
  254. package/src/single-select-field/__tests__/single-select-field.test.js +29 -0
  255. package/src/single-select-field/features/accepts_help_text/index.js +9 -0
  256. package/src/single-select-field/features/accepts_help_text.feature +5 -0
  257. package/src/single-select-field/features/accepts_label/index.js +9 -0
  258. package/src/single-select-field/features/accepts_label.feature +5 -0
  259. package/src/single-select-field/features/accepts_validation_text/index.js +9 -0
  260. package/src/single-select-field/features/accepts_validation_text.feature +5 -0
  261. package/src/single-select-field/features/can_be_required/index.js +11 -0
  262. package/src/single-select-field/features/can_be_required.feature +5 -0
  263. package/src/single-select-field/features/has_default_clear_text/index.js +16 -0
  264. package/src/single-select-field/features/has_default_clear_text.feature +6 -0
  265. package/src/single-select-field/features/has_default_empty_text/index.js +13 -0
  266. package/src/single-select-field/features/has_default_empty_text.feature +6 -0
  267. package/src/single-select-field/features/has_default_filter_nomatch_text/index.js +17 -0
  268. package/src/single-select-field/features/has_default_filter_nomatch_text.feature +7 -0
  269. package/src/single-select-field/features/has_default_filter_placeholder/index.js +15 -0
  270. package/src/single-select-field/features/has_default_filter_placeholder.feature +6 -0
  271. package/src/single-select-field/features/has_default_loading_text/index.js +13 -0
  272. package/src/single-select-field/features/has_default_loading_text.feature +6 -0
  273. package/src/single-select-field/index.js +1 -0
  274. package/src/single-select-field/single-select-field.e2e.stories.js +45 -0
  275. package/src/single-select-field/single-select-field.js +178 -0
  276. package/src/single-select-field/single-select-field.prod.stories.js +146 -0
  277. package/src/single-select-option/index.js +1 -0
  278. 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 }