@pareto-engineering/design-system 4.0.0-alpha.62 → 4.0.0-alpha.63

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 (192) hide show
  1. package/dist/cjs/f/FormInput/FormInput.js +43 -13
  2. package/dist/cjs/f/common/V2/Description/Description.js +76 -0
  3. package/dist/cjs/f/common/V2/Description/index.js +13 -0
  4. package/dist/cjs/f/common/V2/Description/styles.scss +10 -0
  5. package/dist/cjs/f/common/V2/Label/Label.js +84 -0
  6. package/dist/cjs/f/common/V2/Label/index.js +13 -0
  7. package/dist/cjs/f/common/V2/Label/styles.scss +9 -0
  8. package/dist/cjs/f/common/V2/index.js +19 -0
  9. package/dist/cjs/f/common/index.js +12 -0
  10. package/dist/cjs/f/fields/V2/Checkbox/Checkbox.js +122 -0
  11. package/dist/cjs/f/fields/V2/Checkbox/index.js +13 -0
  12. package/dist/cjs/f/fields/V2/Checkbox/styles.scss +16 -0
  13. package/dist/cjs/f/fields/V2/ChoicesInput/ChoicesInput.js +154 -0
  14. package/dist/cjs/f/fields/V2/ChoicesInput/common/Choice/Choice.js +104 -0
  15. package/dist/cjs/f/fields/V2/ChoicesInput/common/Choice/index.js +13 -0
  16. package/dist/cjs/f/fields/V2/ChoicesInput/common/index.js +12 -0
  17. package/dist/cjs/f/fields/V2/ChoicesInput/index.js +13 -0
  18. package/dist/cjs/f/fields/V2/ChoicesInput/styles.scss +79 -0
  19. package/dist/cjs/f/fields/V2/EditorInput/EditorInput.js +197 -0
  20. package/dist/cjs/f/fields/V2/EditorInput/common/Toolbar.js +257 -0
  21. package/dist/cjs/f/fields/V2/EditorInput/common/TreeViewPlugin.js +18 -0
  22. package/dist/cjs/f/fields/V2/EditorInput/common/index.js +20 -0
  23. package/dist/cjs/f/fields/V2/EditorInput/index.js +13 -0
  24. package/dist/cjs/f/fields/V2/EditorInput/styles.scss +149 -0
  25. package/dist/cjs/f/fields/V2/LinkInput/LinkInput.js +156 -0
  26. package/dist/cjs/f/fields/V2/LinkInput/index.js +13 -0
  27. package/dist/cjs/f/fields/V2/LinkInput/styles.scss +90 -0
  28. package/dist/cjs/f/fields/V2/QueryChoices/QueryChoices.js +137 -0
  29. package/dist/cjs/f/fields/V2/QueryChoices/index.js +13 -0
  30. package/dist/cjs/f/fields/V2/QueryCombobox/QueryCombobox.js +229 -0
  31. package/dist/cjs/f/fields/V2/QueryCombobox/common/Combobox/Combobox.js +236 -0
  32. package/dist/cjs/f/fields/V2/QueryCombobox/common/Combobox/index.js +13 -0
  33. package/dist/cjs/f/fields/V2/QueryCombobox/common/Menu/Menu.js +83 -0
  34. package/dist/cjs/f/fields/V2/QueryCombobox/common/Menu/index.js +13 -0
  35. package/dist/cjs/f/fields/V2/QueryCombobox/common/MultipleCombobox/MultipleCombobox.js +300 -0
  36. package/dist/cjs/f/fields/V2/QueryCombobox/common/MultipleCombobox/index.js +13 -0
  37. package/dist/cjs/f/fields/V2/QueryCombobox/common/index.js +26 -0
  38. package/dist/cjs/f/fields/V2/QueryCombobox/index.js +13 -0
  39. package/dist/cjs/f/fields/V2/QueryCombobox/styles.scss +127 -0
  40. package/dist/cjs/f/fields/V2/QuerySelect/QuerySelect.js +198 -0
  41. package/dist/cjs/f/fields/V2/QuerySelect/index.js +13 -0
  42. package/dist/cjs/f/fields/V2/RatingsInput/RatingsInput.js +130 -0
  43. package/dist/cjs/f/fields/V2/RatingsInput/common/Rating/Rating.js +117 -0
  44. package/dist/cjs/f/fields/V2/RatingsInput/common/Rating/index.js +13 -0
  45. package/dist/cjs/f/fields/V2/RatingsInput/common/index.js +12 -0
  46. package/dist/cjs/f/fields/V2/RatingsInput/index.js +13 -0
  47. package/dist/cjs/f/fields/V2/RatingsInput/styles.scss +48 -0
  48. package/dist/cjs/f/fields/V2/SelectInput/SelectInput.js +154 -0
  49. package/dist/cjs/f/fields/V2/SelectInput/index.js +13 -0
  50. package/dist/cjs/f/fields/V2/SelectInput/styles.scss +87 -0
  51. package/dist/cjs/f/fields/V2/TextInput/TextInput.js +155 -0
  52. package/dist/cjs/f/fields/V2/TextInput/index.js +13 -0
  53. package/dist/cjs/f/fields/V2/TextInput/styles.scss +78 -0
  54. package/dist/cjs/f/fields/V2/TextareaInput/TextareaInput.js +152 -0
  55. package/dist/cjs/f/fields/V2/TextareaInput/index.js +13 -0
  56. package/dist/cjs/f/fields/V2/TextareaInput/styles.scss +53 -0
  57. package/dist/cjs/f/fields/V2/index.js +82 -0
  58. package/dist/cjs/f/fields/index.js +26 -1
  59. package/dist/es/f/FormInput/FormInput.js +33 -3
  60. package/dist/es/f/common/V2/Description/Description.js +68 -0
  61. package/dist/es/f/common/V2/Description/index.js +2 -0
  62. package/dist/es/f/common/V2/Description/styles.scss +10 -0
  63. package/dist/es/f/common/V2/Label/Label.js +76 -0
  64. package/dist/es/f/common/V2/Label/index.js +2 -0
  65. package/dist/es/f/common/V2/Label/styles.scss +9 -0
  66. package/dist/es/f/common/V2/index.js +2 -0
  67. package/dist/es/f/common/index.js +2 -1
  68. package/dist/es/f/fields/V2/Checkbox/Checkbox.js +114 -0
  69. package/dist/es/f/fields/V2/Checkbox/index.js +2 -0
  70. package/dist/es/f/fields/V2/Checkbox/styles.scss +16 -0
  71. package/dist/es/f/fields/V2/ChoicesInput/ChoicesInput.js +148 -0
  72. package/dist/es/f/fields/V2/ChoicesInput/common/Choice/Choice.js +97 -0
  73. package/dist/es/f/fields/V2/ChoicesInput/common/Choice/index.js +2 -0
  74. package/dist/es/f/fields/V2/ChoicesInput/common/index.js +1 -0
  75. package/dist/es/f/fields/V2/ChoicesInput/index.js +2 -0
  76. package/dist/es/f/fields/V2/ChoicesInput/styles.scss +79 -0
  77. package/dist/es/f/fields/V2/EditorInput/EditorInput.js +192 -0
  78. package/dist/es/f/fields/V2/EditorInput/common/Toolbar.js +246 -0
  79. package/dist/es/f/fields/V2/EditorInput/common/TreeViewPlugin.js +11 -0
  80. package/dist/es/f/fields/V2/EditorInput/common/index.js +2 -0
  81. package/dist/es/f/fields/V2/EditorInput/index.js +2 -0
  82. package/dist/es/f/fields/V2/EditorInput/styles.scss +149 -0
  83. package/dist/es/f/fields/V2/LinkInput/LinkInput.js +148 -0
  84. package/dist/es/f/fields/V2/LinkInput/index.js +2 -0
  85. package/dist/es/f/fields/V2/LinkInput/styles.scss +90 -0
  86. package/dist/es/f/fields/V2/QueryChoices/QueryChoices.js +126 -0
  87. package/dist/es/f/fields/V2/QueryChoices/index.js +2 -0
  88. package/dist/es/f/fields/V2/QueryCombobox/QueryCombobox.js +221 -0
  89. package/dist/es/f/fields/V2/QueryCombobox/common/Combobox/Combobox.js +229 -0
  90. package/dist/es/f/fields/V2/QueryCombobox/common/Combobox/index.js +2 -0
  91. package/dist/es/f/fields/V2/QueryCombobox/common/Menu/Menu.js +73 -0
  92. package/dist/es/f/fields/V2/QueryCombobox/common/Menu/index.js +2 -0
  93. package/dist/es/f/fields/V2/QueryCombobox/common/MultipleCombobox/MultipleCombobox.js +293 -0
  94. package/dist/es/f/fields/V2/QueryCombobox/common/MultipleCombobox/index.js +2 -0
  95. package/dist/es/f/fields/V2/QueryCombobox/common/index.js +3 -0
  96. package/dist/es/f/fields/V2/QueryCombobox/index.js +2 -0
  97. package/dist/es/f/fields/V2/QueryCombobox/styles.scss +127 -0
  98. package/dist/es/f/fields/V2/QuerySelect/QuerySelect.js +186 -0
  99. package/dist/es/f/fields/V2/QuerySelect/index.js +2 -0
  100. package/dist/es/f/fields/V2/RatingsInput/RatingsInput.js +124 -0
  101. package/dist/es/f/fields/V2/RatingsInput/common/Rating/Rating.js +109 -0
  102. package/dist/es/f/fields/V2/RatingsInput/common/Rating/index.js +2 -0
  103. package/dist/es/f/fields/V2/RatingsInput/common/index.js +1 -0
  104. package/dist/es/f/fields/V2/RatingsInput/index.js +2 -0
  105. package/dist/es/f/fields/V2/RatingsInput/styles.scss +48 -0
  106. package/dist/es/f/fields/V2/SelectInput/SelectInput.js +146 -0
  107. package/dist/es/f/fields/V2/SelectInput/index.js +2 -0
  108. package/dist/es/f/fields/V2/SelectInput/styles.scss +87 -0
  109. package/dist/es/f/fields/V2/TextInput/TextInput.js +147 -0
  110. package/dist/es/f/fields/V2/TextInput/index.js +2 -0
  111. package/dist/es/f/fields/V2/TextInput/styles.scss +78 -0
  112. package/dist/es/f/fields/V2/TextareaInput/TextareaInput.js +146 -0
  113. package/dist/es/f/fields/V2/TextareaInput/index.js +2 -0
  114. package/dist/es/f/fields/V2/TextareaInput/styles.scss +53 -0
  115. package/dist/es/f/fields/V2/index.js +11 -0
  116. package/dist/es/f/fields/index.js +2 -1
  117. package/package.json +3 -3
  118. package/src/stories/f/v2/Checkbox.stories.jsx +102 -0
  119. package/src/stories/f/v2/ChoicesInput.stories.jsx +139 -0
  120. package/src/stories/f/v2/EditorInput.stories.jsx +81 -0
  121. package/src/stories/f/v2/LinkInput.stories.jsx +93 -0
  122. package/src/stories/f/v2/QueryChoices.stories.jsx +144 -0
  123. package/src/stories/f/v2/QueryCombobox.stories.jsx +301 -0
  124. package/src/stories/f/v2/QuerySelect.stories.jsx +150 -0
  125. package/src/stories/f/v2/RatingsInput.stories.jsx +77 -0
  126. package/src/stories/f/v2/SelectInput.stories.jsx +95 -0
  127. package/src/stories/f/v2/TextInput.stories.jsx +120 -0
  128. package/src/stories/f/v2/TextareaInput.stories.jsx +107 -0
  129. package/src/stories/f/v2/__generated__/FormInputAllTaskStatusesQuery.graphql.js +122 -0
  130. package/src/stories/f/v2/__generated__/FormInputAllTeamsQuery.graphql.js +139 -0
  131. package/src/stories/f/v2/__generated__/QueryChoicesAllTaskStatusesQuery.graphql.js +122 -0
  132. package/src/stories/f/v2/__generated__/QueryComboboxAllTeamsQuery.graphql.js +139 -0
  133. package/src/stories/f/v2/__generated__/QuerySelectAllTaskStatusesQuery.graphql.js +122 -0
  134. package/src/ui/f/FormInput/FormInput.jsx +57 -12
  135. package/src/ui/f/common/V2/Description/Description.jsx +94 -0
  136. package/src/ui/f/common/V2/Description/index.js +2 -0
  137. package/src/ui/f/common/V2/Description/styles.scss +10 -0
  138. package/src/ui/f/common/V2/Label/Label.jsx +102 -0
  139. package/src/ui/f/common/V2/Label/index.js +2 -0
  140. package/src/ui/f/common/V2/Label/styles.scss +9 -0
  141. package/src/ui/f/common/V2/index.js +2 -0
  142. package/src/ui/f/common/index.js +1 -0
  143. package/src/ui/f/fields/V2/Checkbox/Checkbox.jsx +146 -0
  144. package/src/ui/f/fields/V2/Checkbox/index.js +2 -0
  145. package/src/ui/f/fields/V2/Checkbox/styles.scss +16 -0
  146. package/src/ui/f/fields/V2/ChoicesInput/ChoicesInput.jsx +183 -0
  147. package/src/ui/f/fields/V2/ChoicesInput/common/Choice/Choice.jsx +125 -0
  148. package/src/ui/f/fields/V2/ChoicesInput/common/Choice/index.js +2 -0
  149. package/src/ui/f/fields/V2/ChoicesInput/common/index.js +1 -0
  150. package/src/ui/f/fields/V2/ChoicesInput/index.js +2 -0
  151. package/src/ui/f/fields/V2/ChoicesInput/styles.scss +79 -0
  152. package/src/ui/f/fields/V2/EditorInput/EditorInput.jsx +244 -0
  153. package/src/ui/f/fields/V2/EditorInput/common/Toolbar.jsx +356 -0
  154. package/src/ui/f/fields/V2/EditorInput/common/TreeViewPlugin.jsx +16 -0
  155. package/src/ui/f/fields/V2/EditorInput/common/index.jsx +2 -0
  156. package/src/ui/f/fields/V2/EditorInput/index.js +2 -0
  157. package/src/ui/f/fields/V2/EditorInput/styles.scss +149 -0
  158. package/src/ui/f/fields/V2/LinkInput/LinkInput.jsx +187 -0
  159. package/src/ui/f/fields/V2/LinkInput/index.js +2 -0
  160. package/src/ui/f/fields/V2/LinkInput/styles.scss +90 -0
  161. package/src/ui/f/fields/V2/QueryChoices/QueryChoices.jsx +153 -0
  162. package/src/ui/f/fields/V2/QueryChoices/index.js +2 -0
  163. package/src/ui/f/fields/V2/QueryCombobox/QueryCombobox.jsx +254 -0
  164. package/src/ui/f/fields/V2/QueryCombobox/common/Combobox/Combobox.jsx +276 -0
  165. package/src/ui/f/fields/V2/QueryCombobox/common/Combobox/index.js +2 -0
  166. package/src/ui/f/fields/V2/QueryCombobox/common/Menu/Menu.jsx +103 -0
  167. package/src/ui/f/fields/V2/QueryCombobox/common/Menu/index.js +2 -0
  168. package/src/ui/f/fields/V2/QueryCombobox/common/MultipleCombobox/MultipleCombobox.jsx +362 -0
  169. package/src/ui/f/fields/V2/QueryCombobox/common/MultipleCombobox/index.js +2 -0
  170. package/src/ui/f/fields/V2/QueryCombobox/common/index.js +3 -0
  171. package/src/ui/f/fields/V2/QueryCombobox/index.js +2 -0
  172. package/src/ui/f/fields/V2/QueryCombobox/styles.scss +127 -0
  173. package/src/ui/f/fields/V2/QuerySelect/QuerySelect.jsx +220 -0
  174. package/src/ui/f/fields/V2/QuerySelect/index.js +2 -0
  175. package/src/ui/f/fields/V2/RatingsInput/RatingsInput.jsx +152 -0
  176. package/src/ui/f/fields/V2/RatingsInput/common/Rating/Rating.jsx +142 -0
  177. package/src/ui/f/fields/V2/RatingsInput/common/Rating/index.js +2 -0
  178. package/src/ui/f/fields/V2/RatingsInput/common/index.js +1 -0
  179. package/src/ui/f/fields/V2/RatingsInput/index.js +2 -0
  180. package/src/ui/f/fields/V2/RatingsInput/styles.scss +48 -0
  181. package/src/ui/f/fields/V2/SelectInput/SelectInput.jsx +187 -0
  182. package/src/ui/f/fields/V2/SelectInput/index.js +2 -0
  183. package/src/ui/f/fields/V2/SelectInput/styles.scss +87 -0
  184. package/src/ui/f/fields/V2/TextInput/TextInput.jsx +192 -0
  185. package/src/ui/f/fields/V2/TextInput/index.js +2 -0
  186. package/src/ui/f/fields/V2/TextInput/styles.scss +78 -0
  187. package/src/ui/f/fields/V2/TextareaInput/TextareaInput.jsx +180 -0
  188. package/src/ui/f/fields/V2/TextareaInput/index.js +2 -0
  189. package/src/ui/f/fields/V2/TextareaInput/styles.scss +53 -0
  190. package/src/ui/f/fields/V2/index.js +11 -0
  191. package/src/ui/f/fields/index.js +1 -0
  192. package/tests/__snapshots__/Storyshots.test.js.snap +5909 -0
@@ -0,0 +1,254 @@
1
+ /* @pareto-engineering/generator-front 1.0.12 */
2
+ import * as React from 'react'
3
+
4
+ import { useState, useInsertionEffect } from 'react'
5
+
6
+ import { useField } from 'formik'
7
+
8
+ import { useRelayEnvironment, fetchQuery } from 'react-relay'
9
+
10
+ import PropTypes from 'prop-types'
11
+
12
+ // Local Definitions
13
+
14
+ import { Combobox, MultipleCombobox } from './common'
15
+
16
+ /**
17
+ * This is the component description.
18
+ */
19
+ const QueryCombobox = ({
20
+ id,
21
+ style,
22
+ className,
23
+ query,
24
+ multiple,
25
+ name,
26
+ label,
27
+ labelColor,
28
+ color,
29
+ optional,
30
+ description,
31
+ disabled,
32
+ debounceMs,
33
+ searchVariable,
34
+ extraVariables,
35
+ optionsKeyMap,
36
+ minLength,
37
+ transformSearch,
38
+ validate,
39
+ placeholder,
40
+ promptCreateNewOption,
41
+ // ...otherProps
42
+ }) => {
43
+ useInsertionEffect(() => {
44
+ import('./styles.scss')
45
+ }, [])
46
+
47
+ const [, meta, helpers] = useField({ name, validate })
48
+
49
+ const { setValue, setError } = helpers
50
+
51
+ const { value } = meta
52
+
53
+ const environment = useRelayEnvironment()
54
+
55
+ const [isFetching, setIsFetching] = useState(false)
56
+
57
+ const [options, setOptions] = useState([])
58
+
59
+ const { graphql, accessor } = query
60
+
61
+ const getOptions = (inputValue) => {
62
+ if (isFetching) return
63
+
64
+ let variables = { [searchVariable]: inputValue }
65
+
66
+ if (extraVariables) {
67
+ variables = {
68
+ ...variables,
69
+ ...extraVariables,
70
+ }
71
+ }
72
+
73
+ fetchQuery(
74
+ environment,
75
+ graphql,
76
+ variables,
77
+ )
78
+ .subscribe({
79
+ start:() => {
80
+ setIsFetching(true)
81
+ },
82
+ complete:() => {
83
+ setIsFetching(false)
84
+ },
85
+ error:(fetchError) => {
86
+ setIsFetching(false)
87
+ if (setError)setError(fetchError.message)
88
+ },
89
+ next:(data) => {
90
+ setOptions(data[accessor].edges.map(({ node }) => ({
91
+ value:node[optionsKeyMap.value],
92
+ label:optionsKeyMap.getLabel(node),
93
+ })))
94
+ },
95
+ })
96
+ }
97
+
98
+ const comboboxProps = {
99
+ id,
100
+ style,
101
+ options,
102
+ getOptions,
103
+ setOptions,
104
+ debounceMs,
105
+ disabled,
106
+ name,
107
+ label,
108
+ labelColor,
109
+ optional,
110
+ description,
111
+ setValue,
112
+ value,
113
+ color,
114
+ isFetching,
115
+ className,
116
+ minLength,
117
+ transformSearch,
118
+ placeholder,
119
+ promptCreateNewOption,
120
+ }
121
+
122
+ const Input = multiple ? MultipleCombobox : Combobox
123
+
124
+ return <Input {...comboboxProps} />
125
+ }
126
+
127
+ QueryCombobox.propTypes = {
128
+ /**
129
+ * The HTML id for this element
130
+ */
131
+ id:PropTypes.string,
132
+
133
+ /**
134
+ * The HTML class names for this element
135
+ */
136
+ className:PropTypes.string,
137
+
138
+ /**
139
+ * The React-written, css properties for this element.
140
+ */
141
+ style:PropTypes.objectOf(PropTypes.string),
142
+
143
+ /**
144
+ * The name of the custom select input
145
+ */
146
+ name:PropTypes.string,
147
+
148
+ /**
149
+ * The label of the custom select input
150
+ */
151
+ label:PropTypes.string,
152
+
153
+ /**
154
+ * The label color of the custom select input
155
+ */
156
+ labelColor:PropTypes.string,
157
+
158
+ /**
159
+ * The custom select input description
160
+ */
161
+ description:PropTypes.string,
162
+
163
+ /**
164
+ * Whether the input should be disabled
165
+ */
166
+ disabled:PropTypes.bool,
167
+
168
+ /**
169
+ * The base color of the tiles
170
+ */
171
+ color:PropTypes.string,
172
+
173
+ /**
174
+ * The debounce time in milliseconds
175
+ */
176
+ debounceMs:PropTypes.number,
177
+
178
+ /**
179
+ * The graphql query to fetch the options and the accessor to destructure the results from
180
+ */
181
+ query:PropTypes.shape({
182
+ accessor:PropTypes.string,
183
+ graphql :PropTypes.oneOfType([
184
+ PropTypes.string,
185
+ PropTypes.object,
186
+ ]).isRequired,
187
+ }),
188
+
189
+ /**
190
+ * The extra variables required to be used in the query.
191
+ */
192
+ extraVariables:PropTypes.objectOf(PropTypes.string),
193
+
194
+ /**
195
+ * The select option keys to be used to map the data to the select options.
196
+ * i.e `{ value: 'id', label: 'name' }`
197
+ */
198
+ optionsKeyMap:PropTypes.shape({
199
+ value :PropTypes.string.isRequired,
200
+ getLabel:PropTypes.func.isRequired,
201
+ }),
202
+
203
+ /**
204
+ * Whether to allow multiple items selection
205
+ */
206
+ multiple:PropTypes.bool,
207
+
208
+ /**
209
+ * The variable to be used to search the data
210
+ */
211
+ searchVariable:PropTypes.string,
212
+
213
+ /**
214
+ * The minimum length of the search input to start fetching the options
215
+ */
216
+ minLength:PropTypes.number,
217
+
218
+ /**
219
+ * The function to transform the search input
220
+ */
221
+ transformSearch:PropTypes.func,
222
+
223
+ /**
224
+ * The query combobox field validator function
225
+ */
226
+ validate:PropTypes.func,
227
+
228
+ /*
229
+ * Whether the input is optional or not
230
+ */
231
+ optional:PropTypes.bool,
232
+
233
+ /**
234
+ * Whether to prompt the user to create a new option if the search input
235
+ * does not match any of the options
236
+ */
237
+ promptCreateNewOption:PropTypes.bool,
238
+ }
239
+
240
+ QueryCombobox.defaultProps = {
241
+ optionsKeyMap:{
242
+ value :'id',
243
+ getLabel:(node) => node.name,
244
+ },
245
+ multiple :false,
246
+ color :'interactive',
247
+ searchVariable :'search',
248
+ transformSearch :(search) => search,
249
+ minLength :2,
250
+ disabled :false,
251
+ promptCreateNewOption:false,
252
+ }
253
+
254
+ export default QueryCombobox
@@ -0,0 +1,276 @@
1
+ /* @pareto-engineering/generator-front 1.0.12 */
2
+ import * as React from 'react'
3
+
4
+ import { useEffect, useRef } from 'react'
5
+
6
+ import PropTypes from 'prop-types'
7
+
8
+ import { useCombobox } from 'downshift'
9
+
10
+ import styleNames from '@pareto-engineering/bem/exports'
11
+
12
+ import { FormLabelV2, FormDescriptionV2 } from 'ui/f'
13
+
14
+ import { Popover, LoadingCircle } from 'ui/a'
15
+
16
+ import { Button } from 'ui/b'
17
+
18
+ import { lookUpInputValueFromFetchedOptions } from '../../../../../common'
19
+
20
+ // Local Definitions
21
+
22
+ import { Menu } from '../Menu'
23
+
24
+ const baseClassName = styleNames.base
25
+
26
+ const componentClassName = 'combobox'
27
+
28
+ /**
29
+ * This is the component description.
30
+ */
31
+ const Combobox = ({
32
+ id,
33
+ className:userClassName,
34
+ style,
35
+ label,
36
+ labelColor,
37
+ name,
38
+ options:items,
39
+ getOptions,
40
+ setOptions,
41
+ setValue,
42
+ description,
43
+ value,
44
+ color,
45
+ minLength,
46
+ isFetching,
47
+ transformSearch,
48
+ disabled,
49
+ optional,
50
+ placeholder,
51
+ promptCreateNewOption,
52
+ // ...otherProps
53
+ }) => {
54
+ const {
55
+ isOpen,
56
+ selectItem,
57
+ selectedItem,
58
+ inputValue,
59
+ setInputValue,
60
+ getLabelProps,
61
+ getMenuProps,
62
+ getInputProps,
63
+ highlightedIndex,
64
+ getComboboxProps,
65
+ getItemProps,
66
+ } = useCombobox({
67
+ items,
68
+ initialSelectedItem:value,
69
+ itemToString :(item) => (item ? item.label : ''),
70
+ onInputValueChange :({ inputValue:searchInputValue }) => {
71
+ const transformedInput = transformSearch(searchInputValue)
72
+ if (transformedInput.length > minLength) {
73
+ getOptions(transformedInput)
74
+ }
75
+ },
76
+ })
77
+
78
+ useEffect(() => {
79
+ if (promptCreateNewOption) {
80
+ lookUpInputValueFromFetchedOptions({
81
+ items, inputValue, setOptions, minLength,
82
+ })
83
+ }
84
+ }, [inputValue, items, promptCreateNewOption])
85
+
86
+ // If the user has selected an item, we'll set the value of the field
87
+ // or if the combobox state has a selected item, we'll set the value to the formik state
88
+ useEffect(() => {
89
+ if (selectedItem) {
90
+ setValue(selectedItem)
91
+ }
92
+ }, [selectedItem])
93
+
94
+ // If the formik state has a value, we'll set the selected item to the combobox state
95
+ useEffect(() => {
96
+ if (value?.value !== selectedItem?.value) {
97
+ selectItem(value)
98
+ }
99
+ }, [value])
100
+
101
+ const parentRef = useRef(null)
102
+
103
+ const resetInputValue = () => setInputValue('')
104
+
105
+ return (
106
+ <div
107
+ id={id}
108
+ className={[
109
+ baseClassName,
110
+ componentClassName,
111
+ userClassName,
112
+ `y-${color}`,
113
+ ]
114
+ .filter((e) => e)
115
+ .join(' ')}
116
+ style={style}
117
+ ref={parentRef}
118
+ {...getComboboxProps()}
119
+ >
120
+ <FormLabelV2
121
+ {...getLabelProps()}
122
+ name={name}
123
+ optional={optional}
124
+ color={labelColor}
125
+ >
126
+ {label}
127
+ </FormLabelV2>
128
+ <input {...getInputProps()} className="input" disabled={disabled} placeholder={placeholder} />
129
+ {isFetching && (
130
+ <LoadingCircle className="x-main" />
131
+ )}
132
+ {inputValue.length > minLength && !isFetching && (
133
+ <Button isSimple isCompact color="heading" onClick={resetInputValue}>
134
+ <span className="icon">
135
+ Y
136
+ </span>
137
+ </Button>
138
+ )}
139
+ <FormDescriptionV2 className="s-1" description={description} name={name} />
140
+ <Popover
141
+ isOpen={isOpen}
142
+ parentRef={parentRef}
143
+ >
144
+ <Menu
145
+ className={`y-${color}`}
146
+ isOpen={isOpen}
147
+ getItemProps={getItemProps}
148
+ highlightedIndex={highlightedIndex}
149
+ items={items}
150
+ {...getMenuProps()}
151
+ />
152
+ </Popover>
153
+ </div>
154
+ )
155
+ }
156
+
157
+ Combobox.propTypes = {
158
+ /**
159
+ * The HTML id for this element
160
+ */
161
+ id:PropTypes.string,
162
+
163
+ /**
164
+ * The HTML class names for this element
165
+ */
166
+ className:PropTypes.string,
167
+
168
+ /**
169
+ * The React-written, css properties for this element.
170
+ */
171
+ style:PropTypes.objectOf(PropTypes.string),
172
+
173
+ /**
174
+ * The label of the custom select input
175
+ */
176
+ label:PropTypes.string,
177
+
178
+ /**
179
+ * The custom select input options from the backend
180
+ */
181
+ options:PropTypes.arrayOf(
182
+ PropTypes.shape({
183
+ value:PropTypes.string,
184
+ label:PropTypes.string,
185
+ }),
186
+ ),
187
+
188
+ /**
189
+ * The name of the custom select input
190
+ */
191
+ name:PropTypes.string,
192
+
193
+ /**
194
+ * The function to fetch the options from the backend
195
+ */
196
+ getOptions:PropTypes.func,
197
+
198
+ /**
199
+ * The function to set the value of the custom select input
200
+ */
201
+ setValue:PropTypes.func.isRequired,
202
+
203
+ /**
204
+ * The custom select input description
205
+ */
206
+ description:PropTypes.string,
207
+
208
+ /**
209
+ * The value of the custom select input
210
+ */
211
+ value:PropTypes.shape({
212
+ value:PropTypes.string,
213
+ label:PropTypes.string,
214
+ }),
215
+
216
+ /**
217
+ * The base color of the combobox custom select input
218
+ */
219
+ color:PropTypes.string,
220
+
221
+ /**
222
+ * Whether the query getting the combobox options is inFlight
223
+ */
224
+ isFetching:PropTypes.bool.isRequired,
225
+
226
+ /**
227
+ * The minimum length of the search input to start fetching the options
228
+ */
229
+ minLength:PropTypes.number,
230
+
231
+ /**
232
+ * The function to transform the search input
233
+ */
234
+ transformSearch:PropTypes.func,
235
+
236
+ /**
237
+ * Whether the input filed shpuld be disabled
238
+ */
239
+ disabled:PropTypes.bool,
240
+
241
+ /**
242
+ * The number of columns the label should span
243
+ */
244
+ labelSpan:PropTypes.number,
245
+
246
+ /**
247
+ * The number of columns the input should span
248
+ */
249
+ inputSpan:PropTypes.number,
250
+
251
+ /**
252
+ * The number of columns the label should span on desktop
253
+ */
254
+ desktopLabelSpan:PropTypes.number,
255
+
256
+ /**
257
+ * The number of columns the input should span on desktop
258
+ */
259
+ desktopInputSpan:PropTypes.number,
260
+
261
+ /**
262
+ * Whether the input is optional or not
263
+ */
264
+ optional:PropTypes.bool,
265
+
266
+ /**
267
+ * The placeholder text for the input
268
+ */
269
+ placeholder:PropTypes.string,
270
+ }
271
+
272
+ Combobox.defaultProps = {
273
+ // someProp: false
274
+ }
275
+
276
+ export default Combobox
@@ -0,0 +1,2 @@
1
+ /* @pareto-engineering/generator-front 1.0.12 */
2
+ export { default as Combobox } from './Combobox'
@@ -0,0 +1,103 @@
1
+ /* @pareto-engineering/generator-front 1.0.12 */
2
+ import * as React from 'react'
3
+
4
+ import PropTypes from 'prop-types'
5
+
6
+ import styleNames from '@pareto-engineering/bem/exports'
7
+
8
+ // Local Definitions
9
+
10
+ const baseClassName = styleNames.base
11
+
12
+ const componentClassName = 'menu'
13
+
14
+ /**
15
+ * This is the component description.
16
+ */
17
+ const Menu = React.forwardRef(({
18
+ id,
19
+ className:userClassName,
20
+ style,
21
+ items,
22
+ isOpen,
23
+ highlightedIndex,
24
+ getItemProps,
25
+ ...otherProps
26
+ }, ref) => (
27
+ <ul
28
+ id={id}
29
+ className={[
30
+
31
+ baseClassName,
32
+
33
+ componentClassName,
34
+ userClassName,
35
+ ]
36
+ .filter((e) => e)
37
+ .join(' ')}
38
+ style={style}
39
+ ref={ref}
40
+ {...otherProps}
41
+ >
42
+ {isOpen && items.map((item, index) => (
43
+ <li
44
+ key={item.label}
45
+ {...getItemProps({ item, index })}
46
+ className={[
47
+ 'item',
48
+ highlightedIndex === index && styleNames.modifierActive,
49
+ ].filter(Boolean)
50
+ .join(' ')}
51
+ >
52
+ <p>
53
+ {item.label}
54
+ </p>
55
+ </li>
56
+ ))}
57
+ </ul>
58
+ ))
59
+ Menu.propTypes = {
60
+ /**
61
+ * The HTML id for this element
62
+ */
63
+ id:PropTypes.string,
64
+
65
+ /**
66
+ * The HTML class names for this element
67
+ */
68
+ className:PropTypes.string,
69
+
70
+ /**
71
+ * The React-written, css properties for this element.
72
+ */
73
+ style:PropTypes.objectOf(PropTypes.string),
74
+
75
+ /**
76
+ * The items to be displayed in the menu
77
+ */
78
+ items:PropTypes.arrayOf(PropTypes.shape({
79
+ value:PropTypes.string,
80
+ label:PropTypes.string,
81
+ })),
82
+
83
+ /**
84
+ * Whether or not the menu is open
85
+ */
86
+ isOpen:PropTypes.bool,
87
+
88
+ /**
89
+ * The index of the highlighted item
90
+ */
91
+ highlightedIndex:PropTypes.number,
92
+
93
+ /**
94
+ * The function to get the item props
95
+ */
96
+ getItemProps:PropTypes.func,
97
+ }
98
+
99
+ Menu.defaultProps = {
100
+ // someProp:false
101
+ }
102
+
103
+ export default Menu
@@ -0,0 +1,2 @@
1
+ /* @pareto-engineering/generator-front 1.0.12 */
2
+ export { default as Menu } from './Menu'