@pareto-engineering/design-system 2.0.0-alpha.5 → 2.0.0-alpha.52

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 (309) hide show
  1. package/.env.scripts.example +4 -0
  2. package/.eslintrc.js +25 -1
  3. package/babel.config.js +1 -0
  4. package/dist/cjs/a/BackgroundGradient/BackgroundGradient.js +77 -0
  5. package/dist/cjs/a/BackgroundGradient/index.js +15 -0
  6. package/dist/cjs/a/BackgroundGradient/styles.scss +16 -0
  7. package/dist/cjs/a/ContentTree/ContentTree.js +83 -0
  8. package/dist/cjs/a/ContentTree/common/Tree/Tree.js +116 -0
  9. package/dist/cjs/a/ContentTree/common/Tree/index.js +15 -0
  10. package/dist/cjs/a/ContentTree/common/index.js +31 -0
  11. package/dist/cjs/a/ContentTree/common/useContentTree.js +82 -0
  12. package/dist/cjs/a/ContentTree/common/useFirstVisibleNode.js +65 -0
  13. package/dist/cjs/a/ContentTree/index.js +15 -0
  14. package/dist/cjs/a/ContentTree/styles.scss +33 -0
  15. package/dist/cjs/a/Conversation/Conversation.js +14 -8
  16. package/dist/cjs/a/Conversation/common/Message/Message.js +32 -6
  17. package/dist/cjs/a/Conversation/styles.scss +132 -33
  18. package/dist/cjs/a/OvalIllustration/OvalIllustration.js +133 -0
  19. package/dist/cjs/a/OvalIllustration/index.js +15 -0
  20. package/dist/cjs/a/OvalIllustration/styles.scss +102 -0
  21. package/dist/cjs/a/Popover/Popover.js +134 -0
  22. package/dist/cjs/a/Popover/common/Divider/Divider.js +67 -0
  23. package/dist/cjs/a/Popover/common/Divider/index.js +15 -0
  24. package/dist/cjs/a/Popover/common/Item/Item.js +67 -0
  25. package/dist/cjs/a/Popover/common/Item/index.js +15 -0
  26. package/dist/cjs/a/Popover/common/index.js +21 -0
  27. package/dist/cjs/a/Popover/index.js +15 -0
  28. package/dist/cjs/a/Popover/styles.scss +33 -0
  29. package/dist/cjs/a/Shapes/Shapes.js +39 -9
  30. package/dist/cjs/a/Shapes/styles.scss +79 -23
  31. package/dist/cjs/a/SnapScroller/SnapScroller.js +77 -0
  32. package/dist/cjs/a/SnapScroller/index.js +15 -0
  33. package/dist/cjs/a/SnapScroller/styles.scss +38 -0
  34. package/dist/cjs/a/index.js +41 -1
  35. package/dist/cjs/b/Button/Button.js +10 -4
  36. package/dist/cjs/b/Button/styles.scss +55 -10
  37. package/dist/cjs/b/Logo/Logo.js +41 -41
  38. package/dist/cjs/b/Logo/styles.scss +0 -138
  39. package/dist/cjs/b/Page/common/Section/Section.js +35 -7
  40. package/dist/cjs/c/ContentSlides/common/HorizontalMenu/HorizontalMenu.js +16 -9
  41. package/dist/cjs/c/ContentSlides/common/Navigator/Navigator.js +4 -3
  42. package/dist/cjs/c/ContentSlides/styles.scss +10 -4
  43. package/dist/cjs/c/SocialMediaShareButton/SocialMediaShareButton.js +111 -0
  44. package/dist/cjs/c/SocialMediaShareButton/index.js +15 -0
  45. package/dist/cjs/c/SocialMediaShareButton/styles.scss +39 -0
  46. package/dist/cjs/c/index.js +9 -1
  47. package/dist/cjs/f/FormInput/FormInput.js +20 -3
  48. package/dist/cjs/f/FormInput/styles.scss +11 -0
  49. package/dist/cjs/f/common/Debugger/Debugger.js +1 -1
  50. package/dist/cjs/f/common/Label/Label.js +1 -1
  51. package/dist/cjs/f/common/Label/styles.scss +1 -1
  52. package/dist/cjs/f/fields/ChoicesInput/ChoicesInput.js +1 -1
  53. package/dist/cjs/f/fields/ChoicesInput/styles.scss +17 -2
  54. package/dist/cjs/f/fields/QueryCombobox/QueryCombobox.js +236 -0
  55. package/dist/cjs/f/fields/QueryCombobox/common/Combobox/Combobox.js +205 -0
  56. package/dist/cjs/f/fields/QueryCombobox/common/Combobox/index.js +15 -0
  57. package/dist/cjs/f/fields/QueryCombobox/common/Menu/Menu.js +103 -0
  58. package/dist/cjs/f/fields/QueryCombobox/common/Menu/index.js +15 -0
  59. package/dist/cjs/f/fields/QueryCombobox/common/MultipleCombobox/MultipleCombobox.js +304 -0
  60. package/dist/cjs/f/fields/QueryCombobox/common/MultipleCombobox/index.js +15 -0
  61. package/dist/cjs/f/fields/QueryCombobox/common/index.js +29 -0
  62. package/dist/cjs/f/fields/QueryCombobox/index.js +15 -0
  63. package/dist/cjs/f/fields/QueryCombobox/styles.scss +90 -0
  64. package/dist/cjs/f/fields/QuerySelect/QuerySelect.js +201 -0
  65. package/dist/cjs/f/fields/QuerySelect/index.js +15 -0
  66. package/dist/cjs/f/fields/QuerySelect/styles.scss +21 -0
  67. package/dist/cjs/f/fields/RatingsInput/RatingsInput.js +39 -6
  68. package/dist/cjs/f/fields/RatingsInput/styles.scss +29 -20
  69. package/dist/cjs/f/fields/SelectInput/SelectInput.js +50 -13
  70. package/dist/cjs/f/fields/SelectInput/styles.scss +33 -13
  71. package/dist/cjs/f/fields/TaskRecommendationInput/TaskRecommendationInput.js +1 -1
  72. package/dist/cjs/f/fields/TextInput/TextInput.js +35 -7
  73. package/dist/cjs/f/fields/TextInput/styles.scss +16 -7
  74. package/dist/cjs/f/fields/TextareaInput/TextareaInput.js +15 -8
  75. package/dist/cjs/f/fields/TextareaInput/styles.scss +19 -6
  76. package/dist/cjs/f/fields/index.js +15 -23
  77. package/dist/cjs/form-reset.scss +1 -1
  78. package/dist/cjs/index.js +26 -0
  79. package/dist/cjs/test/QueryLoader/QueryLoader.js +41 -0
  80. package/dist/cjs/test/QueryLoader/__generated__/QueryLoaderHelloQuery.graphql.js +71 -0
  81. package/dist/cjs/test/QueryLoader/common/PreloadedTestData/PreloadedTestData.js +49 -0
  82. package/dist/cjs/test/QueryLoader/common/PreloadedTestData/index.js +15 -0
  83. package/dist/cjs/test/QueryLoader/common/index.js +13 -0
  84. package/dist/cjs/test/QueryLoader/index.js +15 -0
  85. package/dist/cjs/test/QueryLoader/styles.scss +9 -0
  86. package/dist/cjs/test/index.js +13 -0
  87. package/dist/cjs/utils/hooks/index.js +23 -0
  88. package/dist/cjs/utils/hooks/useDynamicPosition.js +107 -0
  89. package/dist/cjs/utils/hooks/useWindowSize.js +39 -0
  90. package/dist/cjs/utils/index.js +19 -0
  91. package/dist/es/a/BackgroundGradient/BackgroundGradient.js +55 -0
  92. package/dist/es/a/BackgroundGradient/index.js +2 -0
  93. package/dist/es/a/BackgroundGradient/styles.scss +16 -0
  94. package/dist/es/a/ContentTree/ContentTree.js +67 -0
  95. package/dist/es/a/ContentTree/common/Tree/Tree.js +98 -0
  96. package/dist/es/a/ContentTree/common/Tree/index.js +2 -0
  97. package/dist/es/a/ContentTree/common/index.js +3 -0
  98. package/dist/es/a/ContentTree/common/useContentTree.js +74 -0
  99. package/dist/es/a/ContentTree/common/useFirstVisibleNode.js +54 -0
  100. package/dist/es/a/ContentTree/index.js +2 -0
  101. package/dist/es/a/ContentTree/styles.scss +33 -0
  102. package/dist/es/a/Conversation/Conversation.js +14 -8
  103. package/dist/es/a/Conversation/common/Message/Message.js +32 -6
  104. package/dist/es/a/Conversation/styles.scss +132 -33
  105. package/dist/es/a/OvalIllustration/OvalIllustration.js +111 -0
  106. package/dist/es/a/OvalIllustration/index.js +2 -0
  107. package/dist/es/a/OvalIllustration/styles.scss +102 -0
  108. package/dist/es/a/Popover/Popover.js +118 -0
  109. package/dist/es/a/Popover/common/Divider/Divider.js +47 -0
  110. package/dist/es/a/Popover/common/Divider/index.js +2 -0
  111. package/dist/es/a/Popover/common/Item/Item.js +47 -0
  112. package/dist/es/a/Popover/common/Item/index.js +2 -0
  113. package/dist/es/a/Popover/common/index.js +2 -0
  114. package/dist/es/a/Popover/index.js +2 -0
  115. package/dist/es/a/Popover/styles.scss +33 -0
  116. package/dist/es/a/Shapes/Shapes.js +39 -9
  117. package/dist/es/a/Shapes/styles.scss +79 -23
  118. package/dist/es/a/SnapScroller/SnapScroller.js +61 -0
  119. package/dist/es/a/SnapScroller/index.js +2 -0
  120. package/dist/es/a/SnapScroller/styles.scss +38 -0
  121. package/dist/es/a/index.js +6 -1
  122. package/dist/es/b/Button/Button.js +8 -2
  123. package/dist/es/b/Button/styles.scss +55 -10
  124. package/dist/es/b/Logo/Logo.js +41 -41
  125. package/dist/es/b/Logo/styles.scss +0 -138
  126. package/dist/es/b/Page/common/Section/Section.js +34 -6
  127. package/dist/es/c/ContentSlides/common/HorizontalMenu/HorizontalMenu.js +16 -9
  128. package/dist/es/c/ContentSlides/common/Navigator/Navigator.js +4 -3
  129. package/dist/es/c/ContentSlides/styles.scss +10 -4
  130. package/dist/es/c/SocialMediaShareButton/SocialMediaShareButton.js +95 -0
  131. package/dist/es/c/SocialMediaShareButton/index.js +2 -0
  132. package/dist/es/c/SocialMediaShareButton/styles.scss +39 -0
  133. package/dist/es/c/index.js +2 -1
  134. package/dist/es/f/FormInput/FormInput.js +20 -3
  135. package/dist/es/f/FormInput/styles.scss +11 -0
  136. package/dist/es/f/common/Debugger/Debugger.js +1 -1
  137. package/dist/es/f/common/Label/Label.js +1 -1
  138. package/dist/es/f/common/Label/styles.scss +1 -1
  139. package/dist/es/f/fields/ChoicesInput/ChoicesInput.js +1 -1
  140. package/dist/es/f/fields/ChoicesInput/styles.scss +17 -2
  141. package/dist/es/f/fields/QueryCombobox/QueryCombobox.js +213 -0
  142. package/dist/es/f/fields/QueryCombobox/common/Combobox/Combobox.js +185 -0
  143. package/dist/es/f/fields/QueryCombobox/common/Combobox/index.js +2 -0
  144. package/dist/es/f/fields/QueryCombobox/common/Menu/Menu.js +77 -0
  145. package/dist/es/f/fields/QueryCombobox/common/Menu/index.js +2 -0
  146. package/dist/es/f/fields/QueryCombobox/common/MultipleCombobox/MultipleCombobox.js +276 -0
  147. package/dist/es/f/fields/QueryCombobox/common/MultipleCombobox/index.js +2 -0
  148. package/dist/es/f/fields/QueryCombobox/common/index.js +3 -0
  149. package/dist/es/f/fields/QueryCombobox/index.js +2 -0
  150. package/dist/es/f/fields/QueryCombobox/styles.scss +90 -0
  151. package/dist/es/f/fields/QuerySelect/QuerySelect.js +179 -0
  152. package/dist/es/f/fields/QuerySelect/index.js +2 -0
  153. package/dist/es/f/fields/QuerySelect/styles.scss +21 -0
  154. package/dist/es/f/fields/RatingsInput/RatingsInput.js +38 -6
  155. package/dist/es/f/fields/RatingsInput/styles.scss +29 -20
  156. package/dist/es/f/fields/SelectInput/SelectInput.js +49 -13
  157. package/dist/es/f/fields/SelectInput/styles.scss +33 -13
  158. package/dist/es/f/fields/TaskRecommendationInput/TaskRecommendationInput.js +1 -1
  159. package/dist/es/f/fields/TextInput/TextInput.js +35 -7
  160. package/dist/es/f/fields/TextInput/styles.scss +16 -7
  161. package/dist/es/f/fields/TextareaInput/TextareaInput.js +15 -8
  162. package/dist/es/f/fields/TextareaInput/styles.scss +19 -6
  163. package/dist/es/f/fields/index.js +3 -4
  164. package/dist/es/form-reset.scss +1 -1
  165. package/dist/es/index.js +3 -1
  166. package/dist/es/test/QueryLoader/QueryLoader.js +29 -0
  167. package/dist/es/test/QueryLoader/__generated__/QueryLoaderHelloQuery.graphql.js +71 -0
  168. package/dist/es/test/QueryLoader/common/PreloadedTestData/PreloadedTestData.js +31 -0
  169. package/dist/es/test/QueryLoader/common/PreloadedTestData/index.js +2 -0
  170. package/dist/es/test/QueryLoader/common/index.js +1 -0
  171. package/dist/es/test/QueryLoader/index.js +2 -0
  172. package/dist/es/test/QueryLoader/styles.scss +9 -0
  173. package/dist/es/test/index.js +1 -0
  174. package/dist/es/utils/hooks/index.js +2 -0
  175. package/dist/es/utils/hooks/useDynamicPosition.js +93 -0
  176. package/dist/es/utils/hooks/useWindowSize.js +27 -0
  177. package/dist/es/utils/index.js +1 -0
  178. package/package.json +18 -4
  179. package/relay.config.js +12 -0
  180. package/schema.graphql +4075 -0
  181. package/scripts/fetchSchema.js +74 -0
  182. package/src/__snapshots__/Storyshots.test.js.snap +7018 -3507
  183. package/src/local.scss +4 -2
  184. package/src/stories/StyleGuide/Sprites.stories.mdx +25 -0
  185. package/src/stories/StyleGuide/helpers.js +16 -0
  186. package/src/stories/a/BackgroundGradient.stories.jsx +38 -0
  187. package/src/stories/a/ContentTree.stories.jsx +662 -0
  188. package/src/stories/a/Conversation.stories.jsx +78 -1
  189. package/src/stories/a/OvalIllustration.stories.jsx +59 -0
  190. package/src/stories/a/Popover.stories.jsx +106 -0
  191. package/src/stories/a/Shapes.stories.jsx +74 -43
  192. package/src/stories/a/SnapScroller.stories.jsx +98 -0
  193. package/src/stories/b/Button.stories.jsx +27 -4
  194. package/src/stories/b/Logo.stories.jsx +17 -9
  195. package/src/stories/b/Page.stories.jsx +27 -2
  196. package/src/stories/c/ContentSlides.stories.jsx +154 -2
  197. package/src/stories/c/SocialMediaShareButton.stories.jsx +25 -0
  198. package/src/stories/f/FormInput.stories.jsx +233 -0
  199. package/src/stories/f/QueryCombobox.stories.jsx +269 -0
  200. package/src/stories/f/QuerySelect.stories.jsx +134 -0
  201. package/src/stories/f/RatingsInput.stories.jsx +3 -2
  202. package/src/stories/f/SelectInput.stories.jsx +36 -5
  203. package/src/stories/f/TextInput.stories.jsx +15 -4
  204. package/src/stories/f/TextareaInput.stories.jsx +42 -6
  205. package/src/stories/f/__generated__/FormInputAllTaskStatusesQuery.graphql.js +122 -0
  206. package/src/stories/f/__generated__/FormInputAllTeamsQuery.graphql.js +139 -0
  207. package/src/stories/f/__generated__/QueryComboboxAllTeamsQuery.graphql.js +139 -0
  208. package/src/stories/f/__generated__/QuerySelectAllTaskStatusesQuery.graphql.js +122 -0
  209. package/src/stories/test/QueryLoader.stories.jsx +36 -0
  210. package/src/stories/utils/generateNodeId.js +12 -0
  211. package/src/stories/utils/lorem.js +15 -0
  212. package/src/stories/utils/relay/EnvironmentProvider.jsx +14 -0
  213. package/src/stories/utils/relay/environment.js +5 -0
  214. package/src/stories/utils/relay/index.js +4 -0
  215. package/src/stories/utils/relay/mockRelayOperation.js +14 -0
  216. package/src/stories/utils/relay/mockResolvers.js +299 -0
  217. package/src/stories/utils/testData.js +63 -0
  218. package/src/ui/a/BackgroundGradient/BackgroundGradient.jsx +76 -0
  219. package/src/ui/a/BackgroundGradient/index.js +2 -0
  220. package/src/ui/a/BackgroundGradient/styles.scss +16 -0
  221. package/src/ui/a/ContentTree/ContentTree.jsx +88 -0
  222. package/src/ui/a/ContentTree/common/Tree/Tree.jsx +138 -0
  223. package/src/ui/a/ContentTree/common/Tree/index.js +2 -0
  224. package/src/ui/a/ContentTree/common/index.js +3 -0
  225. package/src/ui/a/ContentTree/common/useContentTree.js +83 -0
  226. package/src/ui/a/ContentTree/common/useFirstVisibleNode.js +59 -0
  227. package/src/ui/a/ContentTree/index.js +2 -0
  228. package/src/ui/a/ContentTree/styles.scss +33 -0
  229. package/src/ui/a/Conversation/Conversation.jsx +15 -7
  230. package/src/ui/a/Conversation/common/Message/Message.jsx +38 -6
  231. package/src/ui/a/Conversation/styles.scss +132 -33
  232. package/src/ui/a/OvalIllustration/OvalIllustration.jsx +134 -0
  233. package/src/ui/a/OvalIllustration/index.js +2 -0
  234. package/src/ui/a/OvalIllustration/styles.scss +102 -0
  235. package/src/ui/a/Popover/Popover.jsx +157 -0
  236. package/src/ui/a/Popover/index.js +2 -0
  237. package/src/ui/a/Popover/styles.scss +33 -0
  238. package/src/ui/a/Shapes/Shapes.jsx +44 -7
  239. package/src/ui/a/Shapes/styles.scss +79 -23
  240. package/src/ui/a/SnapScroller/SnapScroller.jsx +83 -0
  241. package/src/ui/a/SnapScroller/index.js +2 -0
  242. package/src/ui/a/SnapScroller/styles.scss +38 -0
  243. package/src/ui/a/index.js +5 -0
  244. package/src/ui/b/Button/Button.jsx +9 -1
  245. package/src/ui/b/Button/styles.scss +55 -10
  246. package/src/ui/b/Logo/Logo.jsx +41 -41
  247. package/src/ui/b/Logo/styles.scss +0 -138
  248. package/src/ui/b/Page/common/Section/Section.jsx +39 -5
  249. package/src/ui/c/ContentSlides/common/HorizontalMenu/HorizontalMenu.jsx +12 -5
  250. package/src/ui/c/ContentSlides/common/Navigator/Navigator.jsx +3 -2
  251. package/src/ui/c/ContentSlides/styles.scss +10 -4
  252. package/src/ui/c/SocialMediaShareButton/SocialMediaShareButton.jsx +121 -0
  253. package/src/ui/c/SocialMediaShareButton/index.js +2 -0
  254. package/src/ui/c/SocialMediaShareButton/styles.scss +39 -0
  255. package/src/ui/c/index.js +1 -0
  256. package/src/ui/f/FormInput/FormInput.jsx +26 -1
  257. package/src/ui/f/FormInput/styles.scss +11 -0
  258. package/src/ui/f/common/Debugger/Debugger.jsx +1 -1
  259. package/src/ui/f/common/Label/Label.jsx +1 -1
  260. package/src/ui/f/common/Label/styles.scss +1 -1
  261. package/src/ui/f/fields/ChoicesInput/ChoicesInput.jsx +1 -1
  262. package/src/ui/f/fields/ChoicesInput/styles.scss +17 -2
  263. package/src/ui/f/fields/QueryCombobox/QueryCombobox.jsx +227 -0
  264. package/src/ui/f/fields/QueryCombobox/common/Combobox/Combobox.jsx +222 -0
  265. package/src/ui/f/fields/QueryCombobox/common/Combobox/index.js +2 -0
  266. package/src/ui/f/fields/QueryCombobox/common/Menu/Menu.jsx +103 -0
  267. package/src/ui/f/fields/QueryCombobox/common/Menu/index.js +2 -0
  268. package/src/ui/f/fields/QueryCombobox/common/MultipleCombobox/MultipleCombobox.jsx +318 -0
  269. package/src/ui/f/fields/QueryCombobox/common/MultipleCombobox/index.js +2 -0
  270. package/src/ui/f/fields/QueryCombobox/common/index.js +3 -0
  271. package/src/ui/f/fields/QueryCombobox/index.js +2 -0
  272. package/src/ui/f/fields/QueryCombobox/styles.scss +90 -0
  273. package/src/ui/f/fields/QuerySelect/QuerySelect.jsx +200 -0
  274. package/src/ui/f/fields/QuerySelect/index.js +2 -0
  275. package/src/ui/f/fields/RatingsInput/RatingsInput.jsx +54 -19
  276. package/src/ui/f/fields/RatingsInput/styles.scss +29 -20
  277. package/src/ui/f/fields/SelectInput/SelectInput.jsx +59 -8
  278. package/src/ui/f/fields/SelectInput/styles.scss +33 -13
  279. package/src/ui/f/fields/TextInput/TextInput.jsx +31 -3
  280. package/src/ui/f/fields/TextInput/styles.scss +16 -7
  281. package/src/ui/f/fields/TextareaInput/TextareaInput.jsx +24 -13
  282. package/src/ui/f/fields/TextareaInput/styles.scss +19 -6
  283. package/src/ui/f/fields/index.js +2 -3
  284. package/src/ui/form-reset.scss +1 -1
  285. package/src/ui/index.js +2 -0
  286. package/src/ui/test/QueryLoader/QueryLoader.jsx +41 -0
  287. package/src/ui/test/QueryLoader/__generated__/QueryLoaderHelloQuery.graphql.js +68 -0
  288. package/src/ui/test/QueryLoader/common/PreloadedTestData/PreloadedTestData.jsx +51 -0
  289. package/src/ui/test/QueryLoader/common/PreloadedTestData/index.js +2 -0
  290. package/src/ui/test/QueryLoader/common/index.js +1 -0
  291. package/src/ui/test/QueryLoader/index.js +2 -0
  292. package/src/ui/test/index.js +1 -0
  293. package/src/ui/utils/hooks/index.js +2 -0
  294. package/src/ui/utils/hooks/useDynamicPosition.js +104 -0
  295. package/src/ui/utils/hooks/useWindowSize.js +32 -0
  296. package/src/ui/utils/index.js +1 -0
  297. package/stylelint.config.js +13 -13
  298. package/src/stories/f/CheckboxInput.stories.jsx +0 -37
  299. package/src/stories/f/RadioInput.stories.jsx +0 -37
  300. package/src/stories/f/TaskRecommendationInput.stories.jsx +0 -38
  301. package/src/ui/f/fields/CheckboxInput/CheckboxInput.jsx +0 -107
  302. package/src/ui/f/fields/CheckboxInput/index.js +0 -2
  303. package/src/ui/f/fields/CheckboxInput/styles.scss +0 -28
  304. package/src/ui/f/fields/RadioInput/RadioInput.jsx +0 -112
  305. package/src/ui/f/fields/RadioInput/index.js +0 -2
  306. package/src/ui/f/fields/RadioInput/styles.scss +0 -26
  307. package/src/ui/f/fields/TaskRecommendationInput/TaskRecommendationInput.jsx +0 -130
  308. package/src/ui/f/fields/TaskRecommendationInput/index.js +0 -2
  309. package/src/ui/f/fields/TaskRecommendationInput/styles.scss +0 -41
@@ -0,0 +1,222 @@
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'
11
+
12
+ import { FormLabel, FormDescription } from 'ui/f'
13
+
14
+ import { Popover, LoadingCircle } from 'ui/a'
15
+
16
+ // Local Definitions
17
+
18
+ import { Menu } from '../Menu'
19
+
20
+ const baseClassName = styleNames.base
21
+
22
+ const componentClassName = 'combobox'
23
+
24
+ /**
25
+ * This is the component description.
26
+ */
27
+ const Combobox = ({
28
+ id,
29
+ className:userClassName,
30
+ style,
31
+ label,
32
+ name,
33
+ options:items,
34
+ getOptions,
35
+ setValue,
36
+ error,
37
+ description,
38
+ value,
39
+ color,
40
+ minLength,
41
+ isFetching,
42
+ transformSearch,
43
+ // ...otherProps
44
+ }) => {
45
+ const {
46
+ isOpen,
47
+ selectItem,
48
+ selectedItem,
49
+ getLabelProps,
50
+ getMenuProps,
51
+ getInputProps,
52
+ highlightedIndex,
53
+ getComboboxProps,
54
+ getItemProps,
55
+ } = useCombobox({
56
+ items,
57
+ initialSelectedItem:value,
58
+ itemToString :(item) => (item ? item.label : ''),
59
+ onInputValueChange :({ inputValue }) => {
60
+ const transformedInput = transformSearch(inputValue)
61
+ if (transformedInput.length > minLength) {
62
+ getOptions(transformedInput)
63
+ }
64
+ },
65
+ })
66
+
67
+ // If the user has selected an item, we'll set the value of the field
68
+ // or if the combobox state has a selected item, we'll set the value to the formik state
69
+ useEffect(() => {
70
+ if (selectedItem) {
71
+ setValue(selectedItem)
72
+ }
73
+ }, [selectedItem])
74
+
75
+ // If the formik state has a value, we'll set the selected item to the combobox state
76
+ useEffect(() => {
77
+ if (value?.value !== selectedItem?.value) {
78
+ selectItem(value)
79
+ }
80
+ }, [value])
81
+
82
+ const parentRef = useRef(null)
83
+
84
+ return (
85
+ <div
86
+ id={id}
87
+ className={[
88
+
89
+ baseClassName,
90
+
91
+ componentClassName,
92
+ userClassName,
93
+ `y-${color}`,
94
+ ]
95
+ .filter((e) => e)
96
+ .join(' ')}
97
+ style={style}
98
+ ref={parentRef}
99
+ >
100
+ <FormLabel {...getLabelProps()} name={name}>
101
+ {label}
102
+ </FormLabel>
103
+
104
+ <div {...getComboboxProps()} className="input-wrapper">
105
+ <input {...getInputProps()} className="input" />
106
+ {isFetching && (
107
+ <LoadingCircle className="x-main2" />
108
+ )}
109
+ </div>
110
+
111
+ <Popover
112
+ isOpen={isOpen}
113
+ parentRef={parentRef}
114
+ >
115
+ <Menu
116
+ isOpen={isOpen}
117
+ getItemProps={getItemProps}
118
+ highlightedIndex={highlightedIndex}
119
+ items={items}
120
+ {...getMenuProps()}
121
+ />
122
+ </Popover>
123
+
124
+ {(description || error) && (
125
+ <FormDescription isError={!!error}>
126
+ { error || description }
127
+ </FormDescription>
128
+ )}
129
+ </div>
130
+ )
131
+ }
132
+
133
+ Combobox.propTypes = {
134
+ /**
135
+ * The HTML id for this element
136
+ */
137
+ id:PropTypes.string,
138
+
139
+ /**
140
+ * The HTML class names for this element
141
+ */
142
+ className:PropTypes.string,
143
+
144
+ /**
145
+ * The React-written, css properties for this element.
146
+ */
147
+ style:PropTypes.objectOf(PropTypes.string),
148
+
149
+ /**
150
+ * The label of the custom select input
151
+ */
152
+ label:PropTypes.string,
153
+
154
+ /**
155
+ * The custom select input options from the backend
156
+ */
157
+ options:PropTypes.arrayOf(
158
+ PropTypes.shape({
159
+ value:PropTypes.string,
160
+ label:PropTypes.string,
161
+ }),
162
+ ),
163
+
164
+ /**
165
+ * The name of the custom select input
166
+ */
167
+ name:PropTypes.string,
168
+
169
+ /**
170
+ * The function to fetch the options from the backend
171
+ */
172
+ getOptions:PropTypes.func,
173
+
174
+ /**
175
+ * The function to set the value of the custom select input
176
+ */
177
+ setValue:PropTypes.func.isRequired,
178
+
179
+ /**
180
+ * The custom select input description
181
+ */
182
+ description:PropTypes.string,
183
+
184
+ /**
185
+ * The error object
186
+ */
187
+ error:PropTypes.objectOf(PropTypes.string),
188
+
189
+ /**
190
+ * The value of the custom select input
191
+ */
192
+ value:PropTypes.shape({
193
+ value:PropTypes.string,
194
+ label:PropTypes.string,
195
+ }),
196
+
197
+ /**
198
+ * The base color of the combobox custom select input
199
+ */
200
+ color:PropTypes.string,
201
+
202
+ /**
203
+ * Whether the query getting the combobox options is inFlight
204
+ */
205
+ isFetching:PropTypes.bool.isRequired,
206
+
207
+ /**
208
+ * The minimum length of the search input to start fetching the options
209
+ */
210
+ minLength:PropTypes.number,
211
+
212
+ /**
213
+ * The function to transform the search input
214
+ */
215
+ transformSearch:PropTypes.func,
216
+ }
217
+
218
+ Combobox.defaultProps = {
219
+ // someProp: false
220
+ }
221
+
222
+ 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'
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'
@@ -0,0 +1,318 @@
1
+ /* @pareto-engineering/generator-front 1.0.12 */
2
+ import * as React from 'react'
3
+
4
+ import { useState, useEffect, useRef } from 'react'
5
+
6
+ import PropTypes from 'prop-types'
7
+
8
+ import styleNames from '@pareto-engineering/bem'
9
+
10
+ import { useCombobox, useMultipleSelection } from 'downshift'
11
+
12
+ import { Button } from 'ui/b'
13
+
14
+ import { Popover, LoadingCircle } from 'ui/a'
15
+
16
+ import { FormDescription, FormLabel } from 'ui/f'
17
+
18
+ // Local Definitions
19
+
20
+ import { Menu } from '../Menu'
21
+
22
+ const baseClassName = styleNames.base
23
+
24
+ const componentClassName = 'multiple-combobox'
25
+
26
+ /**
27
+ * @param {Array[Object]} first - first array to check if it has an item not in the second array.
28
+ * @param {Array[Object]} second - second array to check against the first array.
29
+ *
30
+ * @returns {Boolean} - true if the first array has an item not in the second array.
31
+ */
32
+ const testIfArraysAreUnique = (first, second) => first
33
+ .filter((objInFirstArray) => !second
34
+ .some((objInSecondArray) => objInFirstArray.value === objInSecondArray.value))
35
+ .length > 0
36
+
37
+ /**
38
+ * This is the component description.
39
+ */
40
+ const MultipleCombobox = ({
41
+ id,
42
+ className:userClassName,
43
+ style,
44
+ label,
45
+ name,
46
+ options:items,
47
+ getOptions,
48
+ setValue,
49
+ error,
50
+ description,
51
+ value,
52
+ color,
53
+ isFetching,
54
+ minLength,
55
+ transformSearch,
56
+ // ...otherProps
57
+ }) => {
58
+ const [searchInputValue, setSearchInputValue] = useState('')
59
+ const {
60
+ getSelectedItemProps,
61
+ getDropdownProps,
62
+ addSelectedItem,
63
+ removeSelectedItem,
64
+ setSelectedItems,
65
+ selectedItems,
66
+ } = useMultipleSelection({
67
+ initialSelectedItems:value || [],
68
+ })
69
+
70
+ /**
71
+ * @returns {Boolean} - Unique items from the options array so that the combobox
72
+ * shows only the options that are not yet selected.
73
+ */
74
+ const getFilteredItems = () => items
75
+ .filter((item) => selectedItems
76
+ .findIndex((e) => e.label === item.label) < 0)
77
+
78
+ const {
79
+ isOpen,
80
+ getLabelProps,
81
+ getMenuProps,
82
+ getInputProps,
83
+ getComboboxProps,
84
+ highlightedIndex,
85
+ getItemProps,
86
+ } = useCombobox({
87
+ searchInputValue,
88
+ defaultHighlightedIndex:0, // after selection, highlight the first item.
89
+ selectedItem :null,
90
+ items :getFilteredItems(),
91
+ circularNavigation :true,
92
+ stateReducer :(state, actionAndChanges) => {
93
+ const { changes, type } = actionAndChanges
94
+ switch (type) {
95
+ case useCombobox.stateChangeTypes.InputKeyDownEnter:
96
+ case useCombobox.stateChangeTypes.ItemClick:
97
+ return {
98
+ ...changes,
99
+ isOpen:true, // keep the menu open after selection.
100
+ }
101
+ default:
102
+ break
103
+ }
104
+ return changes
105
+ },
106
+ onStateChange:({ inputValue:newSearchInputValue, type, selectedItem }) => {
107
+ switch (type) {
108
+ case useCombobox.stateChangeTypes.InputChange: {
109
+ const transformedInput = transformSearch(newSearchInputValue)
110
+ if (transformedInput.length > minLength) {
111
+ getOptions(transformedInput)
112
+ }
113
+ setSearchInputValue(newSearchInputValue)
114
+ break
115
+ }
116
+ case useCombobox.stateChangeTypes.InputKeyDownEnter:
117
+ case useCombobox.stateChangeTypes.ItemClick:
118
+ case useCombobox.stateChangeTypes.InputBlur:
119
+ if (selectedItem) {
120
+ setSearchInputValue('')
121
+ addSelectedItem(selectedItem)
122
+ }
123
+ break
124
+ default:
125
+ break
126
+ }
127
+ },
128
+ })
129
+
130
+ useEffect(() => {
131
+ if (selectedItems?.length > 0) {
132
+ setValue(selectedItems)
133
+ }
134
+ }, [selectedItems])
135
+
136
+ useEffect(() => {
137
+ if (value?.length > 0 && (
138
+ testIfArraysAreUnique(value, selectedItems)
139
+ || testIfArraysAreUnique(selectedItems, value)
140
+ )) {
141
+ setSelectedItems(value)
142
+ }
143
+ }, [value])
144
+
145
+ const parentRef = useRef(null)
146
+
147
+ return (
148
+ <div
149
+ id={id}
150
+ className={[
151
+
152
+ baseClassName,
153
+
154
+ componentClassName,
155
+ userClassName,
156
+ `y-${color}`,
157
+ ]
158
+ .filter((e) => e)
159
+ .join(' ')}
160
+ style={style}
161
+ >
162
+
163
+ <FormLabel {...getLabelProps()} name={name}>
164
+ {label}
165
+ </FormLabel>
166
+
167
+ {selectedItems?.length > 0 && (
168
+ <div className="selected-items">
169
+ {selectedItems.map((selectedItem, index) => (
170
+ <div
171
+ key={selectedItem.label}
172
+ {...getSelectedItemProps({ selectedItem, index })}
173
+ className="item"
174
+ >
175
+ <Button
176
+ onClick={(e) => {
177
+ e.stopPropagation()
178
+ removeSelectedItem(selectedItem)
179
+ }}
180
+ isCompact
181
+ isSimple
182
+ color={color}
183
+ >
184
+ <span className="v25 mr-v">{selectedItem.label}</span>
185
+ <span className="f-icons close">Y</span>
186
+ </Button>
187
+ </div>
188
+ ))}
189
+ </div>
190
+ )}
191
+ <div {...getComboboxProps()} className="input-wrapper">
192
+ <input
193
+ {...getInputProps(
194
+ getDropdownProps({ preventKeyAction: isOpen }),
195
+ )}
196
+ className="input"
197
+ />
198
+ {isFetching && (
199
+ <LoadingCircle className="x-main2" />
200
+ )}
201
+ </div>
202
+
203
+ <Popover
204
+ isOpen={isOpen}
205
+ parentRef={parentRef}
206
+ >
207
+ <Menu
208
+ isOpen={isOpen}
209
+ getItemProps={getItemProps}
210
+ highlightedIndex={highlightedIndex}
211
+ items={getFilteredItems()}
212
+ {...getMenuProps()}
213
+ />
214
+ </Popover>
215
+
216
+ {(description || error) && (
217
+ <FormDescription isError={!!error}>
218
+ { error || description }
219
+ </FormDescription>
220
+ )}
221
+
222
+ </div>
223
+ )
224
+ }
225
+
226
+ MultipleCombobox.propTypes = {
227
+ /**
228
+ * The HTML id for this element
229
+ */
230
+ id:PropTypes.string,
231
+
232
+ /**
233
+ * The HTML class names for this element
234
+ */
235
+ className:PropTypes.string,
236
+
237
+ /**
238
+ * The React-written, css properties for this element.
239
+ */
240
+ style:PropTypes.objectOf(PropTypes.string),
241
+
242
+ /**
243
+ * The label of the custom select input
244
+ */
245
+ label:PropTypes.string,
246
+
247
+ /**
248
+ * The custom select input options from the backend
249
+ */
250
+ options:PropTypes.arrayOf(
251
+ PropTypes.shape({
252
+ value:PropTypes.string,
253
+ label:PropTypes.string,
254
+ }),
255
+ ),
256
+
257
+ /**
258
+ * The name of the custom select input
259
+ */
260
+ name:PropTypes.string,
261
+
262
+ /**
263
+ * The function to fetch the options from the backend
264
+ */
265
+ getOptions:PropTypes.func,
266
+
267
+ /**
268
+ * The function to set the value of the custom select input
269
+ */
270
+ setValue:PropTypes.func.isRequired,
271
+
272
+ /**
273
+ * The custom select input description
274
+ */
275
+ description:PropTypes.string,
276
+
277
+ /**
278
+ * The error object
279
+ */
280
+ error:PropTypes.objectOf(PropTypes.string),
281
+
282
+ /**
283
+ * The value of the custom select input
284
+ */
285
+ value:PropTypes.arrayOf(
286
+ PropTypes.shape({
287
+ value:PropTypes.string,
288
+ label:PropTypes.string,
289
+ }),
290
+ ),
291
+
292
+ /**
293
+ * The base color of the custom select input
294
+ */
295
+ color:PropTypes.string,
296
+
297
+ /**
298
+ * Whether the query getting the combobox options is inFlight
299
+ */
300
+ isFetching:PropTypes.bool.isRequired,
301
+
302
+ /**
303
+ * The minimum length of the search input to start fetching the options
304
+ */
305
+ minLength:PropTypes.number,
306
+
307
+ /**
308
+ * The function to transform the search input
309
+ */
310
+ transformSearch:PropTypes.func,
311
+
312
+ }
313
+
314
+ MultipleCombobox.defaultProps = {
315
+ // someProp: false
316
+ }
317
+
318
+ export default MultipleCombobox
@@ -0,0 +1,2 @@
1
+ /* @pareto-engineering/generator-front 1.0.12 */
2
+ export { default as MultipleCombobox } from './MultipleCombobox'
@@ -0,0 +1,3 @@
1
+ export { Menu } from './Menu'
2
+ export { Combobox } from './Combobox'
3
+ export { MultipleCombobox } from './MultipleCombobox'
@@ -0,0 +1,2 @@
1
+ /* @pareto-engineering/generator-front 1.0.12 */
2
+ export { default as QueryCombobox } from './QueryCombobox'