grommet 2.19.1 → 2.21.0

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 (530) hide show
  1. package/components/Accordion/Accordion.js +26 -23
  2. package/components/Accordion/stories/CustomHeader.js +36 -34
  3. package/components/Accordion/stories/CustomThemed/Custom.js +2 -9
  4. package/components/Accordion/stories/{typescript → CustomThemed}/Rich.tsx +2 -2
  5. package/components/Accordion/stories/DarkNoAnimation.js +34 -32
  6. package/components/Accordion/stories/Multiple.js +32 -30
  7. package/components/Accordion/stories/Simple.js +33 -31
  8. package/components/Anchor/propTypes.js +1 -1
  9. package/components/Anchor/stories/Color.js +1 -5
  10. package/components/Anchor/stories/Default.js +2 -6
  11. package/components/Anchor/stories/Disabled.js +2 -6
  12. package/components/Anchor/stories/Gap.js +2 -6
  13. package/components/Anchor/stories/Inline.js +2 -6
  14. package/components/Anchor/stories/Size.js +2 -6
  15. package/components/Anchor/stories/Weight.js +2 -6
  16. package/components/Avatar/Avatar.js +12 -11
  17. package/components/Avatar/stories/Basic.js +23 -21
  18. package/components/Avatar/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
  19. package/components/Avatar/stories/Round.js +35 -33
  20. package/components/Avatar/stories/Sizes.js +80 -78
  21. package/components/Avatar/stories/typescript/Stacked.tsx +10 -11
  22. package/components/Button/Button.js +3 -3
  23. package/components/Button/StyledButton.js +3 -1
  24. package/components/Button/StyledButtonKind.js +5 -9
  25. package/components/Calendar/Calendar.js +113 -87
  26. package/components/Calendar/StyledCalendar.js +1 -1
  27. package/components/Calendar/index.d.ts +4 -0
  28. package/components/Calendar/stories/ActiveDate.js +35 -34
  29. package/components/Calendar/stories/CustomDay.js +69 -67
  30. package/components/Calendar/stories/CustomHeader.js +39 -37
  31. package/{es6/components/Calendar/stories/typescript → components/Calendar/stories/CustomThemed}/CustomDate.tsx +1 -1
  32. package/components/Calendar/stories/{CustomSizeHeading.js → CustomThemed/CustomSizeHeading.js} +1 -1
  33. package/components/Calendar/stories/DaylightSavings.js +55 -53
  34. package/components/Calendar/stories/Dual.js +86 -84
  35. package/components/Calendar/stories/Fill.js +16 -14
  36. package/components/Calendar/stories/Multiple.js +26 -24
  37. package/components/Calendar/stories/Range.js +13 -11
  38. package/components/Calendar/stories/ShowAdjacentDays.js +36 -34
  39. package/components/Calendar/stories/Simple.js +24 -22
  40. package/components/Calendar/stories/SundayFirstDay.js +13 -11
  41. package/components/Calendar/utils.js +60 -10
  42. package/components/Card/stories/{Clickable.js → CustomThemed/Clickable.js} +2 -2
  43. package/components/Card/stories/{Stacked.js → CustomThemed/Stacked.js} +2 -2
  44. package/components/Card/stories/{Themed.js → CustomThemed/Themed.js} +2 -2
  45. package/components/Card/stories/Simple.js +26 -23
  46. package/components/Carousel/Carousel.js +145 -93
  47. package/components/Carousel/CarouselChild.js +17 -27
  48. package/components/Carousel/StyledCarousel.js +44 -0
  49. package/components/Carousel/index.d.ts +5 -0
  50. package/components/Carousel/propTypes.js +13 -9
  51. package/components/Carousel/stories/Autoplay.js +52 -0
  52. package/components/Carousel/stories/ControlVariations.js +170 -0
  53. package/components/Carousel/stories/Controlled.js +43 -37
  54. package/components/Carousel/stories/{Custom.js → CustomThemed/Custom.js} +1 -1
  55. package/components/Carousel/stories/CustomThemed/Icons.tsx +50 -0
  56. package/components/Carousel/stories/InteractiveChild.js +73 -0
  57. package/components/Carousel/stories/Multiple.js +7 -1
  58. package/components/Carousel/stories/Simple.js +25 -19
  59. package/components/Chart/Chart.js +16 -7
  60. package/components/Chart/calcs.js +1 -1
  61. package/components/Chart/utils.js +1 -1
  62. package/components/CheckBox/StyledCheckBox.js +1 -1
  63. package/components/Clock/Clock.js +1 -1
  64. package/components/Clock/StyledClock.js +1 -1
  65. package/components/Collapsible/stories/Horizontal.js +54 -50
  66. package/components/Collapsible/stories/Nested.js +78 -76
  67. package/components/Collapsible/stories/Simple.js +24 -22
  68. package/components/DataChart/DataChart.js +84 -21
  69. package/components/DataChart/Detail.js +8 -0
  70. package/components/DataChart/XAxis.js +19 -10
  71. package/components/DataChart/index.d.ts +10 -2
  72. package/components/DataChart/propTypes.js +2 -1
  73. package/components/DataChart/stories/Offset.js +82 -0
  74. package/components/DataChart/stories/StackedAreas.js +77 -0
  75. package/components/DataChart/stories/StackedLines.js +73 -0
  76. package/components/DataChart/utils.js +1 -1
  77. package/components/DataTable/DataTable.js +1 -1
  78. package/components/DataTable/StyledDataTable.js +1 -1
  79. package/components/DataTable/buildState.js +3 -2
  80. package/components/DataTable/index.d.ts +3 -3
  81. package/components/DataTable/stories/ColumnSize.js +63 -61
  82. package/components/DataTable/stories/Controlled.js +34 -32
  83. package/components/DataTable/stories/ControlledGrouped.js +16 -14
  84. package/components/DataTable/stories/{Fill.js → CustomThemed/Fill.js} +2 -2
  85. package/components/DataTable/stories/Grouped.js +15 -13
  86. package/components/DataTable/stories/GroupedOnSelect.js +16 -14
  87. package/components/DataTable/stories/InfiniteScrollDataTable.js +22 -20
  88. package/components/DataTable/stories/MultiplePin.js +48 -44
  89. package/components/DataTable/stories/NoPrimary.js +15 -13
  90. package/components/DataTable/stories/OnUpdate.js +24 -22
  91. package/components/DataTable/stories/Placeholder.js +27 -25
  92. package/components/DataTable/stories/ResizableColumns.js +17 -15
  93. package/components/DataTable/stories/Served.js +18 -16
  94. package/components/DataTable/stories/Show.js +29 -23
  95. package/components/DataTable/stories/Simple.js +14 -12
  96. package/components/DataTable/stories/Sized.js +14 -12
  97. package/components/DataTable/stories/Sort.js +20 -18
  98. package/components/DataTable/stories/SpaceX.js +36 -34
  99. package/components/DataTable/stories/SpaceXUngrouped.js +26 -24
  100. package/components/DataTable/stories/Styled.js +43 -41
  101. package/components/DataTable/stories/Tunable.js +19 -17
  102. package/components/DataTable/stories/Units.js +16 -14
  103. package/components/DataTable/stories/data.js +1 -1
  104. package/components/DataTable/stories/rowDetails.js +40 -38
  105. package/components/DataTable/stories/typescript/Clickable.tsx +30 -29
  106. package/components/DataTable/stories/typescript/OnSelect.tsx +13 -13
  107. package/components/DataTable/stories/typescript/Paginated.tsx +15 -15
  108. package/components/DateInput/DateInput.js +85 -30
  109. package/components/DateInput/index.d.ts +1 -0
  110. package/components/DateInput/propTypes.js +1 -0
  111. package/components/DateInput/stories/FormatInline.js +172 -16
  112. package/components/DateInput/stories/ResetDate.js +1 -1
  113. package/components/DateInput/utils.js +20 -17
  114. package/components/Drop/DropContainer.js +16 -9
  115. package/components/Drop/stories/AllNotStretched.js +166 -164
  116. package/components/Drop/stories/{Lazy.js → CustomThemed/Lazy.js} +1 -1
  117. package/components/Drop/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
  118. package/components/Drop/stories/Meter.js +35 -30
  119. package/components/Drop/stories/Multiple.js +56 -52
  120. package/components/Drop/stories/Overflow.js +54 -50
  121. package/components/Drop/stories/Plain.js +30 -26
  122. package/components/Drop/stories/Progressive.js +52 -48
  123. package/components/Drop/stories/Simple.js +28 -24
  124. package/components/Drop/stories/Styled.js +45 -41
  125. package/components/Drop/stories/TrapFocus.js +21 -16
  126. package/components/DropButton/stories/Menu.js +5 -7
  127. package/components/DropButton/stories/Simple.js +2 -6
  128. package/components/DropButton/stories/typescript/Calendar.tsx +17 -20
  129. package/components/FileInput/stories/CustomThemed/Custom.js +5 -7
  130. package/components/Footer/stories/data.js +1 -1
  131. package/components/Form/Form.js +321 -265
  132. package/components/Form/stories/ArrayOfFormFields.js +161 -0
  133. package/components/Form/stories/FieldBorderPosition.js +1 -0
  134. package/components/Form/stories/FieldWithChildren.js +4 -4
  135. package/components/FormField/FormField.js +5 -1
  136. package/components/Grommet/Grommet.js +8 -1
  137. package/components/Layer/LayerContainer.js +9 -4
  138. package/components/Layer/StyledLayer.js +1 -1
  139. package/components/List/List.js +11 -2
  140. package/components/List/index.d.ts +1 -0
  141. package/components/List/propTypes.js +1 -0
  142. package/components/Markdown/Markdown.js +4 -2
  143. package/components/MaskedInput/StyledMaskedInput.js +1 -1
  144. package/components/Menu/Menu.js +39 -12
  145. package/components/Menu/stories/BottomControlButton.js +2 -6
  146. package/components/Menu/stories/{typescript → CustomThemed}/Themed.tsx +1 -1
  147. package/components/Menu/stories/ItemWithIcon.js +2 -6
  148. package/components/Menu/stories/Justify.js +2 -6
  149. package/components/Menu/stories/Reverse.js +2 -6
  150. package/components/Menu/stories/Simple.js +2 -6
  151. package/components/Menu/stories/typescript/Children.tsx +10 -13
  152. package/components/Meter/utils.js +1 -1
  153. package/components/NameValueList/NameValueList.js +8 -5
  154. package/components/NameValueList/stories/CustomValue.js +1 -1
  155. package/components/NameValueList/stories/data.js +1 -1
  156. package/components/NameValuePair/NameValuePair.js +1 -4
  157. package/components/Nav/stories/Collapsable.js +39 -37
  158. package/components/Nav/stories/{CustomAnchor.js → CustomThemed/CustomAnchor.js} +2 -2
  159. package/components/Nav/stories/{JustifySidebar.js → CustomThemed/JustifySidebar.js} +1 -1
  160. package/components/Nav/stories/OnHeader.js +29 -27
  161. package/components/Nav/stories/Sidebar.js +24 -18
  162. package/components/Nav/stories/Simple.js +15 -13
  163. package/components/Notification/Notification.js +17 -6
  164. package/components/Notification/index.d.ts +7 -1
  165. package/components/Notification/propTypes.js +4 -1
  166. package/components/Pagination/StyledPageControl.js +2 -2
  167. package/components/RadioButton/StyledRadioButton.js +1 -1
  168. package/components/RadioButtonGroup/RadioButtonGroup.js +3 -1
  169. package/components/RangeInput/StyledRangeInput.js +1 -1
  170. package/components/RangeInput/stories/SimpleRange.js +2 -6
  171. package/components/Select/Select.js +45 -12
  172. package/components/Select/SelectContainer.js +22 -6
  173. package/components/Select/stories/ChildrenRender.js +37 -33
  174. package/components/Select/stories/Clear.js +7 -3
  175. package/components/Select/stories/Controlled.js +32 -28
  176. package/components/Select/stories/{CustomSearch.js → CustomThemed/CustomSearch.js} +2 -2
  177. package/components/Select/stories/Disabled.js +29 -25
  178. package/components/Select/stories/InsideFormField.js +29 -27
  179. package/components/Select/stories/LazyLoadingOptions.js +27 -25
  180. package/components/Select/stories/ManyOptions.js +47 -43
  181. package/components/Select/stories/Multiple.js +25 -21
  182. package/components/Select/stories/ObjectOptions.js +27 -25
  183. package/components/Select/stories/Search.js +62 -58
  184. package/components/Select/stories/Simple.js +26 -22
  185. package/components/Select/stories/Uncontrolled.js +24 -20
  186. package/components/Select/stories/ValueLabel.js +40 -36
  187. package/components/Select/stories/typescript/CreateOption.tsx +34 -30
  188. package/components/Sidebar/stories/Labels.js +25 -19
  189. package/components/Sidebar/stories/typescript/Simple.tsx +17 -12
  190. package/components/SkipLinks/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
  191. package/components/SkipLinks/stories/Simple.js +82 -78
  192. package/components/Stack/stories/Fill.js +15 -11
  193. package/components/Stack/stories/Simple.js +15 -9
  194. package/components/Tab/Tab.js +6 -1
  195. package/components/Table/StyledTable.js +1 -1
  196. package/components/Table/stories/Default.js +30 -28
  197. package/components/Table/stories/InfiniteScrollInTable.js +39 -35
  198. package/components/Table/stories/MeterInTable.js +26 -24
  199. package/components/Table/stories/data.js +1 -1
  200. package/components/Tabs/StyledTabs.js +1 -1
  201. package/components/Tabs/Tabs.js +23 -19
  202. package/components/Tabs/stories/{AlignControls.js → CustomThemed/AlignControls.js} +1 -1
  203. package/components/Tabs/stories/{Custom.js → CustomThemed/Custom.js} +3 -3
  204. package/components/Tabs/stories/{Icon.js → CustomThemed/Icon.js} +1 -1
  205. package/components/Tabs/stories/{States.js → CustomThemed/States.js} +1 -1
  206. package/components/Tabs/stories/Plain.js +45 -41
  207. package/components/Tabs/stories/Responsive.js +191 -189
  208. package/components/Tabs/stories/Rich.js +30 -28
  209. package/components/Tabs/stories/Scrollable.js +32 -28
  210. package/components/Tabs/stories/Uncontrolled.js +45 -41
  211. package/components/Tabs/stories/typescript/Controlled.tsx +21 -21
  212. package/components/Tag/README.md +2 -0
  213. package/components/Tag/StyledTag.js +35 -0
  214. package/components/Tag/Tag.js +94 -0
  215. package/components/Tag/index.d.ts +35 -0
  216. package/components/Tag/index.js +8 -0
  217. package/components/Tag/propTypes.js +28 -0
  218. package/components/Tag/stories/OnClick.js +34 -0
  219. package/components/Tag/stories/OnRemove.js +38 -0
  220. package/components/Tag/stories/Simple.js +32 -0
  221. package/components/Tag/stories/Size.js +45 -0
  222. package/components/Text/Text.js +23 -9
  223. package/components/TextArea/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
  224. package/components/TextArea/stories/Fill.js +18 -16
  225. package/components/TextArea/stories/InsideFormField.js +43 -41
  226. package/components/TextArea/stories/NonResizable.js +13 -11
  227. package/components/TextArea/stories/Simple.js +13 -11
  228. package/components/TextInput/StyledTextInput.js +1 -1
  229. package/components/TextInput/TextInput.js +13 -4
  230. package/components/TextInput/index.d.ts +6 -1
  231. package/{es6/components/TextInput/stories/typescript → components/TextInput/stories/CustomThemed}/CustomSuggestions.tsx +1 -1
  232. package/components/TextInput/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
  233. package/components/TextInput/stories/DefaultSuggestion.js +20 -19
  234. package/components/TextInput/stories/Icon.js +22 -21
  235. package/components/TextInput/stories/InsideFormField.js +32 -30
  236. package/components/TextInput/stories/OnSelect.js +20 -19
  237. package/components/TextInput/stories/Password.js +30 -29
  238. package/components/TextInput/stories/Simple.js +17 -16
  239. package/components/TextInput/stories/StyledPlaceholder.js +10 -9
  240. package/components/TextInput/stories/Suggestions.js +19 -18
  241. package/components/TextInput/stories/Uncontrolled.js +18 -17
  242. package/components/TextInput/stories/WithTags.js +19 -18
  243. package/components/Tip/stories/Caret.js +37 -31
  244. package/components/Tip/stories/{ResponsiveTip.js → CustomThemed/ResponsiveTip.js} +1 -1
  245. package/components/Tip/stories/{SidebarTip.js → CustomThemed/SidebarTip.js} +1 -1
  246. package/{es6/components/Tip/stories/typescript → components/Tip/stories/CustomThemed}/Themed.tsx +1 -1
  247. package/components/Tip/stories/HeaderActions.js +66 -60
  248. package/components/Tip/stories/InfoTip.js +59 -56
  249. package/components/Tip/stories/typescript/Animated.tsx +26 -21
  250. package/components/Tip/stories/typescript/Children.tsx +52 -51
  251. package/components/Tip/stories/typescript/Simple.tsx +12 -7
  252. package/components/Video/Video.js +98 -38
  253. package/components/Video/index.d.ts +15 -2
  254. package/components/Video/propTypes.js +8 -1
  255. package/components/Video/stories/typescript/TheaterMode.tsx +46 -0
  256. package/components/index.d.ts +1 -0
  257. package/components/index.js +8 -0
  258. package/contexts/MessageContext/MessageContext.js +3 -2
  259. package/contexts/MessageContext/index.js +1 -1
  260. package/es6/components/Accordion/Accordion.js +26 -23
  261. package/es6/components/Accordion/stories/CustomHeader.js +37 -34
  262. package/es6/components/Accordion/stories/CustomThemed/Custom.js +2 -9
  263. package/es6/components/Accordion/stories/{typescript → CustomThemed}/Rich.tsx +2 -2
  264. package/es6/components/Accordion/stories/DarkNoAnimation.js +35 -32
  265. package/es6/components/Accordion/stories/Multiple.js +33 -30
  266. package/es6/components/Accordion/stories/Simple.js +34 -31
  267. package/es6/components/Anchor/propTypes.js +1 -1
  268. package/es6/components/Anchor/stories/Color.js +2 -5
  269. package/es6/components/Anchor/stories/Default.js +3 -6
  270. package/es6/components/Anchor/stories/Disabled.js +3 -6
  271. package/es6/components/Anchor/stories/Gap.js +3 -6
  272. package/es6/components/Anchor/stories/Inline.js +3 -6
  273. package/es6/components/Anchor/stories/Size.js +3 -6
  274. package/es6/components/Anchor/stories/Weight.js +3 -6
  275. package/es6/components/Avatar/Avatar.js +13 -12
  276. package/es6/components/Avatar/stories/Basic.js +24 -21
  277. package/es6/components/Avatar/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
  278. package/es6/components/Avatar/stories/Round.js +36 -33
  279. package/es6/components/Avatar/stories/Sizes.js +81 -78
  280. package/es6/components/Avatar/stories/typescript/Stacked.tsx +10 -11
  281. package/es6/components/Button/Button.js +3 -3
  282. package/es6/components/Button/StyledButton.js +3 -1
  283. package/es6/components/Button/StyledButtonKind.js +5 -9
  284. package/es6/components/Calendar/Calendar.js +114 -88
  285. package/es6/components/Calendar/index.d.ts +4 -0
  286. package/es6/components/Calendar/stories/ActiveDate.js +36 -34
  287. package/es6/components/Calendar/stories/CustomDay.js +70 -67
  288. package/es6/components/Calendar/stories/CustomHeader.js +40 -37
  289. package/{components/Calendar/stories/typescript → es6/components/Calendar/stories/CustomThemed}/CustomDate.tsx +1 -1
  290. package/es6/components/Calendar/stories/{CustomSizeHeading.js → CustomThemed/CustomSizeHeading.js} +1 -1
  291. package/es6/components/Calendar/stories/DaylightSavings.js +56 -53
  292. package/es6/components/Calendar/stories/Dual.js +87 -84
  293. package/es6/components/Calendar/stories/Fill.js +17 -14
  294. package/es6/components/Calendar/stories/Multiple.js +25 -22
  295. package/es6/components/Calendar/stories/Range.js +14 -11
  296. package/es6/components/Calendar/stories/ShowAdjacentDays.js +37 -34
  297. package/es6/components/Calendar/stories/Simple.js +25 -22
  298. package/es6/components/Calendar/stories/SundayFirstDay.js +14 -11
  299. package/es6/components/Calendar/utils.js +48 -4
  300. package/es6/components/Card/stories/{Clickable.js → CustomThemed/Clickable.js} +2 -2
  301. package/es6/components/Card/stories/{Stacked.js → CustomThemed/Stacked.js} +2 -2
  302. package/es6/components/Card/stories/{Themed.js → CustomThemed/Themed.js} +2 -2
  303. package/es6/components/Card/stories/Simple.js +27 -24
  304. package/es6/components/Carousel/Carousel.js +145 -94
  305. package/es6/components/Carousel/CarouselChild.js +17 -25
  306. package/es6/components/Carousel/StyledCarousel.js +31 -0
  307. package/es6/components/Carousel/index.d.ts +5 -0
  308. package/es6/components/Carousel/propTypes.js +13 -9
  309. package/es6/components/Carousel/stories/Autoplay.js +41 -0
  310. package/es6/components/Carousel/stories/ControlVariations.js +161 -0
  311. package/es6/components/Carousel/stories/Controlled.js +44 -38
  312. package/es6/components/Carousel/stories/{Custom.js → CustomThemed/Custom.js} +1 -1
  313. package/es6/components/Carousel/stories/CustomThemed/Icons.tsx +50 -0
  314. package/es6/components/Carousel/stories/InteractiveChild.js +61 -0
  315. package/es6/components/Carousel/stories/Multiple.js +8 -2
  316. package/es6/components/Carousel/stories/Simple.js +26 -20
  317. package/es6/components/Chart/Chart.js +16 -7
  318. package/es6/components/Clock/Clock.js +1 -1
  319. package/es6/components/Collapsible/stories/Horizontal.js +55 -50
  320. package/es6/components/Collapsible/stories/Nested.js +79 -76
  321. package/es6/components/Collapsible/stories/Simple.js +25 -22
  322. package/es6/components/DataChart/DataChart.js +84 -21
  323. package/es6/components/DataChart/Detail.js +7 -0
  324. package/es6/components/DataChart/XAxis.js +19 -10
  325. package/es6/components/DataChart/index.d.ts +10 -2
  326. package/es6/components/DataChart/propTypes.js +2 -1
  327. package/es6/components/DataChart/stories/Offset.js +70 -0
  328. package/es6/components/DataChart/stories/StackedAreas.js +65 -0
  329. package/es6/components/DataChart/stories/StackedLines.js +61 -0
  330. package/es6/components/DataTable/DataTable.js +1 -1
  331. package/es6/components/DataTable/buildState.js +2 -1
  332. package/es6/components/DataTable/index.d.ts +3 -3
  333. package/es6/components/DataTable/stories/ColumnSize.js +64 -61
  334. package/es6/components/DataTable/stories/Controlled.js +35 -32
  335. package/es6/components/DataTable/stories/ControlledGrouped.js +17 -14
  336. package/es6/components/DataTable/stories/{Fill.js → CustomThemed/Fill.js} +2 -2
  337. package/es6/components/DataTable/stories/Grouped.js +16 -13
  338. package/es6/components/DataTable/stories/GroupedOnSelect.js +17 -14
  339. package/es6/components/DataTable/stories/InfiniteScrollDataTable.js +23 -20
  340. package/es6/components/DataTable/stories/MultiplePin.js +49 -45
  341. package/es6/components/DataTable/stories/NoPrimary.js +16 -13
  342. package/es6/components/DataTable/stories/OnUpdate.js +25 -22
  343. package/es6/components/DataTable/stories/Placeholder.js +28 -25
  344. package/es6/components/DataTable/stories/ResizableColumns.js +18 -15
  345. package/es6/components/DataTable/stories/Served.js +19 -16
  346. package/es6/components/DataTable/stories/Show.js +27 -21
  347. package/es6/components/DataTable/stories/Simple.js +15 -12
  348. package/es6/components/DataTable/stories/Sized.js +15 -12
  349. package/es6/components/DataTable/stories/Sort.js +21 -18
  350. package/es6/components/DataTable/stories/SpaceX.js +37 -34
  351. package/es6/components/DataTable/stories/SpaceXUngrouped.js +27 -24
  352. package/es6/components/DataTable/stories/Styled.js +44 -41
  353. package/es6/components/DataTable/stories/Tunable.js +20 -17
  354. package/es6/components/DataTable/stories/Units.js +17 -14
  355. package/es6/components/DataTable/stories/rowDetails.js +41 -38
  356. package/es6/components/DataTable/stories/typescript/Clickable.tsx +30 -29
  357. package/es6/components/DataTable/stories/typescript/OnSelect.tsx +13 -13
  358. package/es6/components/DataTable/stories/typescript/Paginated.tsx +15 -15
  359. package/es6/components/DateInput/DateInput.js +80 -28
  360. package/es6/components/DateInput/index.d.ts +1 -0
  361. package/es6/components/DateInput/propTypes.js +1 -0
  362. package/es6/components/DateInput/stories/FormatInline.js +169 -16
  363. package/es6/components/DateInput/utils.js +18 -13
  364. package/es6/components/Drop/DropContainer.js +15 -9
  365. package/es6/components/Drop/stories/AllNotStretched.js +167 -164
  366. package/es6/components/Drop/stories/{Lazy.js → CustomThemed/Lazy.js} +1 -1
  367. package/es6/components/Drop/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
  368. package/es6/components/Drop/stories/Meter.js +36 -30
  369. package/es6/components/Drop/stories/Multiple.js +57 -52
  370. package/es6/components/Drop/stories/Overflow.js +55 -50
  371. package/es6/components/Drop/stories/Plain.js +31 -26
  372. package/es6/components/Drop/stories/Progressive.js +53 -48
  373. package/es6/components/Drop/stories/Simple.js +29 -24
  374. package/es6/components/Drop/stories/Styled.js +46 -41
  375. package/es6/components/Drop/stories/TrapFocus.js +22 -17
  376. package/es6/components/DropButton/stories/Menu.js +6 -7
  377. package/es6/components/DropButton/stories/Simple.js +3 -6
  378. package/es6/components/DropButton/stories/typescript/Calendar.tsx +17 -20
  379. package/es6/components/FileInput/stories/CustomThemed/Custom.js +5 -7
  380. package/es6/components/Form/Form.js +321 -265
  381. package/es6/components/Form/stories/ArrayOfFormFields.js +147 -0
  382. package/es6/components/Form/stories/FieldBorderPosition.js +1 -0
  383. package/es6/components/Form/stories/FieldWithChildren.js +4 -4
  384. package/es6/components/FormField/FormField.js +6 -2
  385. package/es6/components/Grommet/Grommet.js +8 -1
  386. package/es6/components/Layer/LayerContainer.js +9 -4
  387. package/es6/components/List/List.js +11 -2
  388. package/es6/components/List/index.d.ts +1 -0
  389. package/es6/components/List/propTypes.js +1 -0
  390. package/es6/components/Markdown/Markdown.js +4 -2
  391. package/es6/components/Menu/Menu.js +40 -13
  392. package/es6/components/Menu/stories/BottomControlButton.js +3 -6
  393. package/es6/components/Menu/stories/{typescript → CustomThemed}/Themed.tsx +1 -1
  394. package/es6/components/Menu/stories/ItemWithIcon.js +3 -6
  395. package/es6/components/Menu/stories/Justify.js +3 -6
  396. package/es6/components/Menu/stories/Reverse.js +3 -6
  397. package/es6/components/Menu/stories/Simple.js +3 -6
  398. package/es6/components/Menu/stories/typescript/Children.tsx +10 -13
  399. package/es6/components/NameValueList/NameValueList.js +9 -6
  400. package/es6/components/NameValueList/stories/CustomValue.js +1 -1
  401. package/es6/components/NameValuePair/NameValuePair.js +1 -4
  402. package/es6/components/Nav/stories/Collapsable.js +40 -37
  403. package/es6/components/Nav/stories/{CustomAnchor.js → CustomThemed/CustomAnchor.js} +2 -2
  404. package/es6/components/Nav/stories/{JustifySidebar.js → CustomThemed/JustifySidebar.js} +1 -1
  405. package/es6/components/Nav/stories/OnHeader.js +30 -27
  406. package/es6/components/Nav/stories/Sidebar.js +25 -19
  407. package/es6/components/Nav/stories/Simple.js +16 -13
  408. package/es6/components/Notification/Notification.js +18 -7
  409. package/es6/components/Notification/index.d.ts +7 -1
  410. package/es6/components/Notification/propTypes.js +4 -1
  411. package/es6/components/Pagination/StyledPageControl.js +1 -1
  412. package/es6/components/RadioButtonGroup/RadioButtonGroup.js +3 -1
  413. package/es6/components/RangeInput/StyledRangeInput.js +1 -1
  414. package/es6/components/RangeInput/stories/SimpleRange.js +3 -6
  415. package/es6/components/Select/Select.js +45 -12
  416. package/es6/components/Select/SelectContainer.js +22 -6
  417. package/es6/components/Select/stories/ChildrenRender.js +38 -33
  418. package/es6/components/Select/stories/Clear.js +8 -4
  419. package/es6/components/Select/stories/Controlled.js +33 -28
  420. package/es6/components/Select/stories/{CustomSearch.js → CustomThemed/CustomSearch.js} +2 -2
  421. package/es6/components/Select/stories/Disabled.js +30 -25
  422. package/es6/components/Select/stories/InsideFormField.js +30 -27
  423. package/es6/components/Select/stories/LazyLoadingOptions.js +28 -25
  424. package/es6/components/Select/stories/ManyOptions.js +48 -43
  425. package/es6/components/Select/stories/Multiple.js +26 -21
  426. package/es6/components/Select/stories/ObjectOptions.js +28 -25
  427. package/es6/components/Select/stories/Search.js +63 -58
  428. package/es6/components/Select/stories/Simple.js +27 -22
  429. package/es6/components/Select/stories/Uncontrolled.js +25 -20
  430. package/es6/components/Select/stories/ValueLabel.js +41 -36
  431. package/es6/components/Select/stories/typescript/CreateOption.tsx +34 -30
  432. package/es6/components/Sidebar/stories/Labels.js +26 -20
  433. package/es6/components/Sidebar/stories/typescript/Simple.tsx +17 -12
  434. package/es6/components/SkipLinks/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
  435. package/es6/components/SkipLinks/stories/Simple.js +83 -79
  436. package/es6/components/Stack/stories/Fill.js +16 -11
  437. package/es6/components/Stack/stories/Simple.js +16 -10
  438. package/es6/components/Tab/Tab.js +6 -1
  439. package/es6/components/Table/stories/Default.js +31 -28
  440. package/es6/components/Table/stories/InfiniteScrollInTable.js +40 -36
  441. package/es6/components/Table/stories/MeterInTable.js +27 -24
  442. package/es6/components/Tabs/Tabs.js +23 -20
  443. package/es6/components/Tabs/stories/{AlignControls.js → CustomThemed/AlignControls.js} +1 -1
  444. package/es6/components/Tabs/stories/{Custom.js → CustomThemed/Custom.js} +3 -3
  445. package/es6/components/Tabs/stories/{Icon.js → CustomThemed/Icon.js} +1 -1
  446. package/es6/components/Tabs/stories/{States.js → CustomThemed/States.js} +1 -1
  447. package/es6/components/Tabs/stories/Plain.js +45 -40
  448. package/es6/components/Tabs/stories/Responsive.js +191 -188
  449. package/es6/components/Tabs/stories/Rich.js +30 -27
  450. package/es6/components/Tabs/stories/Scrollable.js +32 -27
  451. package/es6/components/Tabs/stories/Uncontrolled.js +45 -40
  452. package/es6/components/Tabs/stories/typescript/Controlled.tsx +21 -21
  453. package/es6/components/Tag/README.md +2 -0
  454. package/es6/components/Tag/StyledTag.js +22 -0
  455. package/es6/components/Tag/Tag.js +77 -0
  456. package/es6/components/Tag/index.d.ts +35 -0
  457. package/es6/components/Tag/index.js +1 -0
  458. package/es6/components/Tag/propTypes.js +18 -0
  459. package/es6/components/Tag/stories/OnClick.js +22 -0
  460. package/es6/components/Tag/stories/OnRemove.js +26 -0
  461. package/es6/components/Tag/stories/Simple.js +20 -0
  462. package/es6/components/Tag/stories/Size.js +33 -0
  463. package/es6/components/Text/Text.js +23 -10
  464. package/es6/components/TextArea/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
  465. package/es6/components/TextArea/stories/Fill.js +19 -16
  466. package/es6/components/TextArea/stories/InsideFormField.js +44 -41
  467. package/es6/components/TextArea/stories/NonResizable.js +14 -11
  468. package/es6/components/TextArea/stories/Simple.js +14 -11
  469. package/es6/components/TextInput/TextInput.js +13 -4
  470. package/es6/components/TextInput/index.d.ts +6 -1
  471. package/{components/TextInput/stories/typescript → es6/components/TextInput/stories/CustomThemed}/CustomSuggestions.tsx +1 -1
  472. package/es6/components/TextInput/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
  473. package/es6/components/TextInput/stories/DefaultSuggestion.js +21 -19
  474. package/es6/components/TextInput/stories/Icon.js +23 -21
  475. package/es6/components/TextInput/stories/InsideFormField.js +33 -30
  476. package/es6/components/TextInput/stories/OnSelect.js +21 -19
  477. package/es6/components/TextInput/stories/Password.js +31 -29
  478. package/es6/components/TextInput/stories/Simple.js +18 -16
  479. package/es6/components/TextInput/stories/StyledPlaceholder.js +11 -9
  480. package/es6/components/TextInput/stories/Suggestions.js +20 -18
  481. package/es6/components/TextInput/stories/Uncontrolled.js +19 -17
  482. package/es6/components/TextInput/stories/WithTags.js +20 -18
  483. package/es6/components/Tip/stories/Caret.js +38 -32
  484. package/es6/components/Tip/stories/{ResponsiveTip.js → CustomThemed/ResponsiveTip.js} +1 -1
  485. package/es6/components/Tip/stories/{SidebarTip.js → CustomThemed/SidebarTip.js} +1 -1
  486. package/{components/Tip/stories/typescript → es6/components/Tip/stories/CustomThemed}/Themed.tsx +1 -1
  487. package/es6/components/Tip/stories/HeaderActions.js +67 -61
  488. package/es6/components/Tip/stories/InfoTip.js +60 -57
  489. package/es6/components/Tip/stories/typescript/Animated.tsx +26 -21
  490. package/es6/components/Tip/stories/typescript/Children.tsx +52 -51
  491. package/es6/components/Tip/stories/typescript/Simple.tsx +12 -7
  492. package/es6/components/Video/Video.js +99 -39
  493. package/es6/components/Video/index.d.ts +15 -2
  494. package/es6/components/Video/propTypes.js +8 -1
  495. package/es6/components/Video/stories/typescript/TheaterMode.tsx +46 -0
  496. package/es6/components/index.d.ts +1 -0
  497. package/es6/components/index.js +1 -0
  498. package/es6/contexts/MessageContext/MessageContext.js +2 -1
  499. package/es6/index.d.ts +1 -0
  500. package/es6/languages/default.json +11 -3
  501. package/es6/themes/base.d.ts +59 -12
  502. package/es6/themes/base.js +60 -2
  503. package/es6/utils/DOM.js +13 -3
  504. package/es6/utils/background.js +2 -1
  505. package/grommet.min.js +1 -1
  506. package/grommet.min.js.map +1 -1
  507. package/index.d.ts +1 -0
  508. package/languages/default.json +11 -3
  509. package/package.json +59 -58
  510. package/themes/base.d.ts +59 -12
  511. package/themes/base.js +61 -3
  512. package/themes/index.js +1 -1
  513. package/utils/DOM.js +20 -4
  514. package/utils/animation.js +1 -1
  515. package/utils/background.js +3 -2
  516. package/utils/border.js +1 -1
  517. package/utils/colors.js +1 -1
  518. package/utils/general-prop-types.js +1 -1
  519. package/utils/graphics.js +1 -1
  520. package/utils/mixins.js +1 -1
  521. package/utils/object.js +1 -1
  522. package/utils/responsive.js +1 -1
  523. package/utils/styles.js +1 -1
  524. package/utils/use-isomorphic-layout-effect.js +1 -1
  525. package/components/Carousel/stories/InitialChild.js +0 -43
  526. package/components/Carousel/stories/WithClickableChild.js +0 -51
  527. package/components/Carousel/stories/WithoutControls.js +0 -44
  528. package/es6/components/Carousel/stories/InitialChild.js +0 -32
  529. package/es6/components/Carousel/stories/WithClickableChild.js +0 -40
  530. package/es6/components/Carousel/stories/WithoutControls.js +0 -33
@@ -17,33 +17,91 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
17
17
 
18
18
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
19
 
20
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
21
-
22
20
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
23
21
 
22
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
23
+
24
24
  var defaultValue = {};
25
25
  var defaultTouched = {};
26
26
  var defaultValidationResults = {
27
27
  errors: {},
28
28
  infos: {}
29
- }; // Validating nameValues with the validator and sending correct messaging
29
+ };
30
+
31
+ var stringToArray = function stringToArray(string) {
32
+ var match = string == null ? void 0 : string.match(/^(.+)\[([0-9]+)\]\.(.*)$/);
33
+
34
+ if (match) {
35
+ var arrayName = match[1],
36
+ indexOfArray = match[2],
37
+ arrayObjName = match[3];
38
+ return {
39
+ indexOfArray: indexOfArray,
40
+ arrayName: arrayName,
41
+ arrayObjName: arrayObjName
42
+ };
43
+ }
44
+
45
+ return undefined;
46
+ };
47
+
48
+ var getFieldValue = function getFieldValue(name, value) {
49
+ var isArrayField = stringToArray(name);
50
+
51
+ if (isArrayField) {
52
+ var _value$arrayName;
53
+
54
+ var indexOfArray = isArrayField.indexOfArray,
55
+ arrayName = isArrayField.arrayName,
56
+ arrayObjName = isArrayField.arrayObjName;
57
+ var obj = (_value$arrayName = value[arrayName]) == null ? void 0 : _value$arrayName[indexOfArray];
58
+ return arrayObjName ? obj == null ? void 0 : obj[arrayObjName] : obj;
59
+ }
60
+
61
+ return value[name];
62
+ };
63
+
64
+ var setFieldValue = function setFieldValue(name, componentValue, prevValue) {
65
+ var nextValue = _extends({}, prevValue);
66
+
67
+ var isArrayField = stringToArray(name);
68
+
69
+ if (isArrayField) {
70
+ var indexOfArray = isArrayField.indexOfArray,
71
+ arrayName = isArrayField.arrayName,
72
+ arrayObjName = isArrayField.arrayObjName;
73
+ if (!nextValue[arrayName]) nextValue[arrayName] = [];
30
74
 
31
- var validate = function validate(validator, nameValue, formValue, format, messages) {
75
+ if (arrayObjName) {
76
+ var _nextValue$arrayName$;
77
+
78
+ if (!nextValue[arrayName][indexOfArray]) nextValue[arrayName][indexOfArray] = (_nextValue$arrayName$ = {}, _nextValue$arrayName$[arrayObjName] = componentValue, _nextValue$arrayName$);
79
+ nextValue[arrayName][indexOfArray][arrayObjName] = componentValue;
80
+ } else nextValue[arrayName][indexOfArray] = componentValue;
81
+ } else {
82
+ nextValue[name] = componentValue;
83
+ }
84
+
85
+ return nextValue;
86
+ }; // Apply validation rule to field value and send correct messaging.
87
+
88
+
89
+ var validate = function validate(rule, fieldValue, formValue, format, messages) {
32
90
  var result;
33
91
 
34
- if (typeof validator === 'function') {
35
- result = validator(nameValue, formValue);
36
- } else if (validator.regexp) {
37
- if (!validator.regexp.test(nameValue)) {
38
- result = validator.message || format({
92
+ if (typeof rule === 'function') {
93
+ result = rule(fieldValue, formValue);
94
+ } else if (rule.regexp) {
95
+ if (!rule.regexp.test(fieldValue)) {
96
+ result = rule.message || format({
39
97
  id: 'form.invalid',
40
98
  messages: messages
41
99
  });
42
100
 
43
- if (validator.status) {
101
+ if (rule.status) {
44
102
  result = {
45
103
  message: result,
46
- status: validator.status
104
+ status: rule.status
47
105
  };
48
106
  }
49
107
  }
@@ -53,39 +111,37 @@ var validate = function validate(validator, nameValue, formValue, format, messag
53
111
  }; // Validates particular key in formValue
54
112
 
55
113
 
56
- var validateName = function validateName(nameValidators, required) {
114
+ var validateName = function validateName(validationRules, required) {
57
115
  return function (name, formValue, format, messages) {
58
- var nameValue = formValue[name];
59
- var result; // ValidateArg is something that gets passed in from a FormField component
60
- // See 'validate' prop in FormField
116
+ var fieldValue = getFieldValue(name, formValue);
117
+ var validationResult;
61
118
 
62
- if (required && (nameValue === undefined || nameValue === '' || nameValue === false || Array.isArray(nameValue) && !nameValue.length)) {
63
- // There is no value at that name, and one is required
64
- result = format({
119
+ if (required && ( // false is for CheckBox
120
+ fieldValue === undefined || fieldValue === '' || fieldValue === false || Array.isArray(fieldValue) && !fieldValue.length)) {
121
+ validationResult = format({
65
122
  id: 'form.required',
66
123
  messages: messages
67
124
  });
68
- } else if (nameValidators) {
69
- if (Array.isArray(nameValidators)) {
70
- nameValidators.some(function (validator) {
71
- result = validate(validator, nameValue, formValue, format, messages);
72
- return !!result;
125
+ } else if (validationRules) {
126
+ if (Array.isArray(validationRules)) {
127
+ validationRules.some(function (rule) {
128
+ validationResult = validate(rule, fieldValue, formValue, format, messages);
129
+ return !!validationResult;
73
130
  });
74
131
  } else {
75
- result = validate(nameValidators, nameValue, formValue, format, messages);
132
+ validationResult = validate(validationRules, fieldValue, formValue, format, messages);
76
133
  }
77
134
  }
78
135
 
79
- return result;
136
+ return validationResult;
80
137
  };
81
- }; // validations is an array from Object.entries()
82
- // Validates all keys in formValue
138
+ }; // Validates all keys in formValue
83
139
 
84
140
 
85
- var validateForm = function validateForm(validations, formValue, format, messages, omitValid) {
141
+ var validateForm = function validateForm(validationRules, formValue, format, messages, omitValid) {
86
142
  var nextErrors = {};
87
143
  var nextInfos = {};
88
- validations.forEach(function (_ref) {
144
+ validationRules.forEach(function (_ref) {
89
145
  var name = _ref[0],
90
146
  _ref$ = _ref[1],
91
147
  field = _ref$.field,
@@ -99,12 +155,12 @@ var validateForm = function validateForm(validations, formValue, format, message
99
155
  var result;
100
156
 
101
157
  if (input) {
102
- // input() are validations supplied through useFormInput()
158
+ // input() a validation function supplied through useFormInput()
103
159
  result = input(name, formValue, format, messages);
104
160
  }
105
161
 
106
162
  if (field && !result) {
107
- // field() are validations supplied through useFormField()
163
+ // field() a validation function supplied through useFormField()
108
164
  result = field(name, formValue, format, messages);
109
165
  } // typeof error === 'object' is implied for both cases of error with
110
166
  // a status message and for an error object that is a react node
@@ -154,147 +210,138 @@ var Form = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref) {
154
210
  touched = _useState2[0],
155
211
  setTouched = _useState2[1];
156
212
 
157
- var _useState3 = (0, _react.useState)(defaultValidationResults),
213
+ var _useState3 = (0, _react.useState)({
214
+ errors: errorsProp,
215
+ infos: infosProp
216
+ }),
158
217
  validationResults = _useState3[0],
159
- setValidationResults = _useState3[1]; // when onBlur input validation is triggered, we need to complete any
160
- // potential click events before running the onBlur validation.
161
- // otherwise, click events like reset, etc. may not be registered.
162
- // for a detailed scenario/discussion,
163
- // see: https://github.com/grommet/grommet/issues/4863
164
- // the value of pendingValidation is the name of the FormField
165
- // awaiting validation.
218
+ setValidationResults = _useState3[1]; // maintain a copy of validationResults in a ref for useEffects
219
+ // which can't depend on validationResults directly without
220
+ // causing infinite renders.
166
221
 
167
222
 
168
- var _useState4 = (0, _react.useState)(undefined),
169
- pendingValidation = _useState4[0],
170
- setPendingValidation = _useState4[1];
223
+ var validationResultsRef = (0, _react.useRef)({}); // Simulated onMount state. Consider Form to be mounted once it has
224
+ // accounted for values originating from controlled inputs (available
225
+ // at second rendering).
226
+
227
+ var _useState4 = (0, _react.useState)('unmounted'),
228
+ mounted = _useState4[0],
229
+ setMounted = _useState4[1];
171
230
 
172
231
  (0, _react.useEffect)(function () {
173
- setPendingValidation(undefined);
174
- setValidationResults({
175
- errors: errorsProp,
176
- infos: infosProp
177
- });
178
- }, [errorsProp, infosProp]);
179
- var validations = (0, _react.useRef)({});
232
+ if (!mounted) setMounted('mounting');else if (mounted === 'mounting') setMounted('mounted');
233
+ }, [mounted]); // `pendingValidation` is the name of the FormField awaiting validation.
234
+
235
+ var _useState5 = (0, _react.useState)(undefined),
236
+ pendingValidation = _useState5[0],
237
+ setPendingValidation = _useState5[1];
238
+
239
+ var validationRulesRef = (0, _react.useRef)({});
180
240
  var requiredFields = (0, _react.useRef)([]);
181
241
  var buildValid = (0, _react.useCallback)(function (nextErrors) {
182
242
  var valid = false;
183
243
  valid = requiredFields.current.filter(function (n) {
184
- return Object.keys(validations.current).includes(n);
244
+ return Object.keys(validationRulesRef.current).includes(n);
185
245
  }).every(function (field) {
186
246
  return value[field] && (value[field] !== '' || value[field] !== false);
187
247
  });
188
248
  if (Object.keys(nextErrors).length > 0) valid = false;
189
249
  return valid;
190
- }, [value]); // Remove any errors that we don't have any validations for anymore.
191
-
192
- var filterErrorValidations = function filterErrorValidations(errors) {
193
- var nextErrors = errors;
194
- return Object.keys(nextErrors).filter(function (n) {
195
- return !validations.current[n] || nextErrors[n] === undefined;
250
+ }, [value]); // Only keep validation results for current form fields. In the case of a
251
+ // dynamic form, a field possessing an error may have been removed from the
252
+ // form; need to clean up any previous related validation results.
253
+
254
+ var filterRemovedFields = function filterRemovedFields(prevValidations) {
255
+ var nextValidations = prevValidations;
256
+ return Object.keys(nextValidations).filter(function (n) {
257
+ return !validationRulesRef.current[n] || nextValidations[n] === undefined;
196
258
  }).forEach(function (n) {
197
- return delete nextErrors[n];
259
+ return delete nextValidations[n];
198
260
  });
199
- }; // Remove any infos that we don't have any validations for anymore.
261
+ };
200
262
 
263
+ var applyValidationRules = (0, _react.useCallback)(function (validationRules) {
264
+ var _validateForm = validateForm(validationRules, value, format, messages),
265
+ validatedErrors = _validateForm[0],
266
+ validatedInfos = _validateForm[1];
201
267
 
202
- var filterInfoValidations = function filterInfoValidations(infos) {
203
- var nextInfos = infos;
204
- return Object.keys(nextInfos).filter(function (n) {
205
- return !validations.current[n] || nextInfos[n] === undefined;
206
- }).forEach(function (n) {
207
- return delete nextInfos[n];
208
- });
209
- }; // On initial mount, when validateOn is change or blur,
210
- // set validation results for any set fields and calculate whether
211
- // the form is valid overall.
212
-
268
+ setValidationResults(function (prevValidationResults) {
269
+ // Keep any previous errors and infos for untouched keys,
270
+ // these may have come from a Submit.
271
+ var nextErrors = _extends({}, prevValidationResults.errors, validatedErrors);
213
272
 
214
- (0, _react.useEffect)(function () {
215
- var validationsForSetFields = Object.entries(validations.current).filter(function (_ref3) {
216
- var n = _ref3[0];
217
- return value[n];
218
- });
273
+ var nextInfos = _extends({}, prevValidationResults.infos, validatedInfos); // Remove previous errors and infos for keys no longer in the
274
+ // form, these may have been fields removed from a dynamic form.
219
275
 
220
- if (validationsForSetFields.length > 0 && validateOn !== 'submit') {
221
- var _validateForm = validateForm(validationsForSetFields, value, format, messages),
222
- errors = _validateForm[0],
223
- infos = _validateForm[1];
224
276
 
225
- filterErrorValidations(errors);
226
- filterInfoValidations(infos);
277
+ filterRemovedFields(nextErrors);
278
+ filterRemovedFields(nextInfos);
227
279
  var nextValidationResults = {
228
- errors: errors,
229
- infos: infos,
230
- valid: buildValid(errors)
280
+ errors: nextErrors,
281
+ infos: nextInfos
231
282
  };
232
- if (onValidate) onValidate(nextValidationResults);
233
- setValidationResults(nextValidationResults);
234
- } // We only want to run this for the value we have on initial mount.
235
- // We don't want subsequent changes to the value to re-run this.
236
- // eslint-disable-next-line react-hooks/exhaustive-deps
283
+ if (onValidate) onValidate(_extends({}, nextValidationResults, {
284
+ valid: buildValid(nextErrors)
285
+ }));
286
+ validationResultsRef.current = nextValidationResults;
287
+ return nextValidationResults;
288
+ });
289
+ }, [buildValid, format, messages, onValidate, value]); // Validate all fields holding values onMount if set to
290
+ // validate when blur or change.
237
291
 
238
- }, []); // Currently, onBlur validation will trigger after a timeout of 120ms.
292
+ (0, _react.useEffect)(function () {
293
+ var validationRules = Object.entries(validationRulesRef.current); // Use simulated onMount state to account for values provided by
294
+ // controlled inputs.
295
+
296
+ if (mounted !== 'mounted' && ['blur', 'change'].includes(validateOn) && Object.keys(value).length > 0 && Object.keys(touched).length === 0) {
297
+ applyValidationRules(validationRules.filter(function (_ref3) {
298
+ var n = _ref3[0];
299
+ return value[n];
300
+ }) // Exlude empty arrays which may be initial values in
301
+ // an input such as DateInput.
302
+ .filter(function (_ref4) {
303
+ var n = _ref4[0];
304
+ return !(Array.isArray(value[n]) && value[n].length === 0);
305
+ }));
306
+ }
307
+ }, [applyValidationRules, mounted, touched, validateOn, value]); // Run validation against fields with pendingValidations from onBlur
308
+ // and/or onChange.
239
309
 
240
310
  (0, _react.useEffect)(function () {
311
+ var validationRules = Object.entries(validationRulesRef.current);
241
312
  var timer = setTimeout(function () {
242
- if (pendingValidation) {
243
- // run validations on the pending one and any other touched fields
244
- var _validateForm2 = validateForm(Object.entries(validations.current).filter(function (_ref4) {
245
- var n = _ref4[0];
313
+ if (pendingValidation && ['blur', 'change'].includes(validateOn)) {
314
+ applyValidationRules(validationRules.filter(function (_ref5) {
315
+ var n = _ref5[0];
246
316
  return touched[n] || pendingValidation.includes(n);
247
- }), value, format, messages),
248
- validatedErrors = _validateForm2[0],
249
- validatedInfos = _validateForm2[1];
250
-
317
+ }));
251
318
  setPendingValidation(undefined);
252
- setValidationResults(function (prevValidationResults) {
253
- // keep any previous errors and infos for untouched keys,
254
- // these may have come from a submit
255
- var nextErrors = _extends({}, prevValidationResults.errors, validatedErrors);
256
-
257
- var nextInfos = _extends({}, prevValidationResults.infos, validatedInfos);
258
-
259
- filterErrorValidations(nextErrors);
260
- filterInfoValidations(nextInfos);
261
- var nextValidationResults = {
262
- errors: nextErrors,
263
- infos: nextInfos,
264
- valid: buildValid(nextErrors)
265
- };
266
- if (onValidate) onValidate(nextValidationResults);
267
- return nextValidationResults;
268
- });
269
- } // a timeout is needed to ensure that a click event (like one on a reset
270
- // button) completes prior to running the validation. without a timeout,
271
- // the blur will always complete and trigger a validation prematurely
272
- // The following values have been empirically tested, but 120 was
273
- // selected because it is the largest value
319
+ } // Complete any potential click events before running onBlur validation.
320
+ // Otherwise, click events like reset, etc. may not be registered. For a
321
+ // detailed scenario/discussion, see: https://github.com/grommet/grommet/issues/4863
322
+ // Values empirically tested; 120 was selected because it is the largest
274
323
  // Chrome: 100, Safari: 120, Firefox: 80
275
324
 
276
325
  }, 120);
277
326
  return function () {
278
327
  return clearTimeout(timer);
279
328
  };
280
- }, [buildValid, format, messages, pendingValidation, onValidate, touched, value, requiredFields]); // clear any errors when value changes
329
+ }, [applyValidationRules, pendingValidation, touched, validateOn]); // Re-run validation rules for all fields with prior errors.
330
+ // if validate=blur this helps re-validate if there are errors
331
+ // as the user fixes them (basically act like validate=change for that)
281
332
 
282
333
  (0, _react.useEffect)(function () {
283
- if (validateOn !== 'change') setPendingValidation(undefined);
284
- setValidationResults(function (prevValidationResults) {
285
- var _validateForm3 = validateForm(Object.entries(validations.current).filter(function (_ref5) {
286
- var n = _ref5[0];
287
- return prevValidationResults.errors[n] || prevValidationResults.infos[n];
288
- }), value, format, messages),
289
- nextErrors = _validateForm3[0],
290
- nextInfos = _validateForm3[1];
334
+ var _validationResultsRef;
291
335
 
292
- return {
293
- errors: _extends({}, prevValidationResults.errors, nextErrors),
294
- infos: _extends({}, prevValidationResults.infos, nextInfos)
295
- };
296
- });
297
- }, [format, messages, touched, validateOn, value]); // There are three basic patterns of handling form input value state:
336
+ var validationRules = Object.entries(validationRulesRef.current);
337
+
338
+ if ((_validationResultsRef = validationResultsRef.current) != null && _validationResultsRef.errors && Object.keys(validationResultsRef.current.errors).length > 0) {
339
+ applyValidationRules(validationRules.filter(function (_ref6) {
340
+ var n = _ref6[0];
341
+ return touched[n] && validationResultsRef.current.errors[n];
342
+ }));
343
+ }
344
+ }, [applyValidationRules, touched]); // There are three basic patterns of handling form input value state:
298
345
  //
299
346
  // 1 - form controlled
300
347
  //
@@ -327,144 +374,155 @@ var Form = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref) {
327
374
  // they can have access to it.
328
375
  //
329
376
 
330
- var useFormInput = function useFormInput(_ref6) {
331
- var name = _ref6.name,
332
- componentValue = _ref6.value,
333
- initialValue = _ref6.initialValue,
334
- validateArg = _ref6.validate;
335
-
336
- var _useState5 = (0, _react.useState)(initialValue),
337
- inputValue = _useState5[0],
338
- setInputValue = _useState5[1];
339
-
340
- var formValue = name ? value[name] : undefined; // for dynamic forms, we need to track when an input has been added to
341
- // the form value. if the input is unmounted, we will delete its key/value
342
- // from the form value.
343
-
344
- var keyCreated = (0, _react.useRef)(false); // This effect is for pattern #2, where the controlled input
345
- // component is driving the value via componentValue.
346
-
347
- (0, _react.useEffect)(function () {
348
- if (name && // we have somewhere to put this
349
- componentValue !== undefined && // input driving
350
- componentValue !== formValue // don't already have it
351
- ) {
352
- setValueState(function (prevValue) {
353
- var nextValue = _extends({}, prevValue);
354
-
355
- nextValue[name] = componentValue;
356
- return nextValue;
357
- }); // don't onChange on programmatic changes
358
- }
359
- }, [componentValue, formValue, name]); // on unmount, if the form is uncontrolled, remove the key/value
360
- // from the form value
361
-
362
- (0, _react.useEffect)(function () {
363
- return function () {
364
- if (keyCreated.current) {
365
- keyCreated.current = false;
377
+ var formContextValue = (0, _react.useMemo)(function () {
378
+ var useFormInput = function useFormInput(_ref7) {
379
+ var name = _ref7.name,
380
+ componentValue = _ref7.value,
381
+ initialValue = _ref7.initialValue,
382
+ validateArg = _ref7.validate;
383
+
384
+ var _useState6 = (0, _react.useState)(initialValue),
385
+ inputValue = _useState6[0],
386
+ setInputValue = _useState6[1];
387
+
388
+ var formValue = name ? getFieldValue(name, value) : undefined; // for dynamic forms, we need to track when an input has been added to
389
+ // the form value. if the input is unmounted, we will delete its
390
+ // key/value from the form value.
391
+
392
+ var keyCreated = (0, _react.useRef)(false); // This effect is for pattern #2, where the controlled input
393
+ // component is driving the value via componentValue.
394
+
395
+ (0, _react.useEffect)(function () {
396
+ if (name && // we have somewhere to put this
397
+ componentValue !== undefined && // input driving
398
+ componentValue !== formValue // don't already have it
399
+ ) {
366
400
  setValueState(function (prevValue) {
367
- var nextValue = _extends({}, prevValue);
368
-
369
- delete nextValue[name];
370
- return nextValue;
371
- });
372
- }
373
- };
374
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
375
- [] // only run onmount and unmount
376
- );
377
- (0, _react.useEffect)(function () {
378
- if (validateArg) {
379
- if (!validations.current[name]) {
380
- validations.current[name] = {};
401
+ return setFieldValue(name, componentValue, prevValue);
402
+ }); // don't onChange on programmatic changes
381
403
  }
404
+ }, [componentValue, formValue, name]); // on unmount, if the form is uncontrolled, remove the key/value
405
+ // from the form value
382
406
 
383
- validations.current[name].input = validateName(validateArg);
407
+ (0, _react.useEffect)(function () {
384
408
  return function () {
385
- return delete validations.current[name].input;
409
+ if (keyCreated.current) {
410
+ keyCreated.current = false;
411
+ setValueState(function (prevValue) {
412
+ var nextValue = _extends({}, prevValue);
413
+
414
+ var isArrayField = stringToArray(name);
415
+
416
+ if (isArrayField) {
417
+ var arrayName = isArrayField.arrayName;
418
+ delete nextValue[arrayName];
419
+ } else {
420
+ delete nextValue[name];
421
+ }
422
+
423
+ return nextValue;
424
+ });
425
+ }
386
426
  };
387
- }
388
-
389
- return undefined;
390
- }, [validateArg, name]);
391
- var useValue;
392
- if (componentValue !== undefined) // input component drives, pattern #2
393
- useValue = componentValue;else if (valueProp && name && formValue !== undefined) // form drives, pattern #1
394
- useValue = formValue;else if (formValue === undefined && name) // form has reset, so reset input value as well
395
- useValue = initialValue;else useValue = inputValue;
396
- return [useValue, function (nextComponentValue) {
397
- if (name) {
398
- // we have somewhere to put this
399
- var nextTouched = _extends({}, touched);
400
-
401
- nextTouched[name] = true;
402
-
403
- if (!touched[name]) {
404
- // don't update if not needed
405
- setTouched(nextTouched);
427
+ }, // eslint-disable-next-line react-hooks/exhaustive-deps
428
+ [] // only run onmount and unmount
429
+ ); // Create validation rules for fields
430
+
431
+ (0, _react.useEffect)(function () {
432
+ if (validateArg) {
433
+ if (!validationRulesRef.current[name]) {
434
+ validationRulesRef.current[name] = {};
435
+ }
436
+
437
+ validationRulesRef.current[name].input = validateName(validateArg);
438
+ return function () {
439
+ return delete validationRulesRef.current[name].input;
440
+ };
406
441
  }
407
442
 
408
- var nextValue = _extends({}, value); // if nextValue doesn't have a key for name, this must be
409
- // uncontrolled form. we will flag this field was added so
410
- // we know to remove its value from the form if it is dynamically
411
- // removed
412
-
413
-
414
- if (!(name in nextValue)) keyCreated.current = true;
415
- nextValue[name] = nextComponentValue;
416
- setValueState(nextValue);
417
- if (onChange) onChange(nextValue, {
418
- touched: nextTouched
419
- });
420
- }
443
+ return undefined;
444
+ }, [validateArg, name]);
445
+ var useValue;
446
+ if (componentValue !== undefined) // input component drives, pattern #2
447
+ useValue = componentValue;else if (valueProp && name && formValue !== undefined) // form drives, pattern #1
448
+ useValue = formValue;else if (formValue === undefined && name) // form has reset, so reset input value as well
449
+ useValue = initialValue;else useValue = inputValue;
450
+ return [useValue, function (nextComponentValue) {
451
+ if (name) {
452
+ // we have somewhere to put this
453
+ var nextTouched = _extends({}, touched);
454
+
455
+ nextTouched[name] = true;
456
+
457
+ if (!touched[name]) {
458
+ // don't update if not needed
459
+ setTouched(nextTouched);
460
+ } // if nextValue doesn't have a key for name, this must be
461
+ // uncontrolled form. we will flag this field was added so
462
+ // we know to remove its value from the form if it is dynamically
463
+ // removed
464
+
465
+
466
+ if (!(name in value)) keyCreated.current = true;
467
+ var nextValue = setFieldValue(name, nextComponentValue, value);
468
+ setValueState(nextValue);
469
+ if (onChange) onChange(nextValue, {
470
+ touched: nextTouched
471
+ });
472
+ }
421
473
 
422
- if (initialValue !== undefined) setInputValue(nextComponentValue);
423
- }];
424
- };
474
+ if (initialValue !== undefined) setInputValue(nextComponentValue);
475
+ }];
476
+ };
425
477
 
426
- var useFormField = function useFormField(_ref7) {
427
- var errorArg = _ref7.error,
428
- infoArg = _ref7.info,
429
- name = _ref7.name,
430
- required = _ref7.required,
431
- disabled = _ref7.disabled,
432
- validateArg = _ref7.validate;
433
- var error = disabled ? undefined : errorArg || validationResults.errors[name];
434
- var info = infoArg || validationResults.infos[name];
435
- (0, _react.useEffect)(function () {
436
- var index = requiredFields.current.indexOf(name);
437
-
438
- if (required) {
439
- if (index === -1) requiredFields.current.push(name);
440
- } else if (index !== -1) requiredFields.current.splice(index, 1);
441
-
442
- if (validateArg || required) {
443
- if (!validations.current[name]) {
444
- validations.current[name] = {};
478
+ var useFormField = function useFormField(_ref8) {
479
+ var errorArg = _ref8.error,
480
+ infoArg = _ref8.info,
481
+ name = _ref8.name,
482
+ required = _ref8.required,
483
+ disabled = _ref8.disabled,
484
+ validateArg = _ref8.validate;
485
+ var error = disabled ? undefined : errorArg || validationResults.errors[name];
486
+ var info = infoArg || validationResults.infos[name]; // Create validation rules for field
487
+
488
+ (0, _react.useEffect)(function () {
489
+ var index = requiredFields.current.indexOf(name);
490
+
491
+ if (required) {
492
+ if (index === -1) requiredFields.current.push(name);
493
+ } else if (index !== -1) requiredFields.current.splice(index, 1);
494
+
495
+ if (validateArg || required) {
496
+ if (!validationRulesRef.current[name]) {
497
+ validationRulesRef.current[name] = {};
498
+ }
499
+
500
+ validationRulesRef.current[name].field = validateName(validateArg, required);
501
+ return function () {
502
+ return delete validationRulesRef.current[name].field;
503
+ };
445
504
  }
446
505
 
447
- validations.current[name].field = validateName(validateArg, required);
448
- return function () {
449
- return delete validations.current[name].field;
450
- };
451
- }
506
+ return undefined;
507
+ }, [error, name, required, validateArg, disabled]);
508
+ return {
509
+ error: error,
510
+ info: info,
511
+ inForm: true,
512
+ onBlur: validateOn === 'blur' ? function () {
513
+ return setPendingValidation(pendingValidation ? [].concat(pendingValidation, [name]) : [name]);
514
+ } : undefined,
515
+ onChange: validateOn === 'change' ? function () {
516
+ return setPendingValidation(pendingValidation ? [].concat(pendingValidation, [name]) : [name]);
517
+ } : undefined
518
+ };
519
+ };
452
520
 
453
- return undefined;
454
- }, [error, name, required, validateArg, disabled]);
455
521
  return {
456
- error: error,
457
- info: info,
458
- inForm: true,
459
- onBlur: validateOn === 'blur' ? function () {
460
- return setPendingValidation(pendingValidation ? [].concat(pendingValidation, [name]) : [name]);
461
- } : undefined,
462
- onChange: validateOn === 'change' ? function () {
463
- return setPendingValidation(pendingValidation ? [].concat(pendingValidation, [name]) : [name]);
464
- } : undefined
522
+ useFormField: useFormField,
523
+ useFormInput: useFormInput
465
524
  };
466
- };
467
-
525
+ }, [onChange, pendingValidation, touched, validateOn, validationResults.errors, validationResults.infos, value, valueProp]);
468
526
  return /*#__PURE__*/_react["default"].createElement("form", _extends({
469
527
  ref: ref
470
528
  }, rest, {
@@ -497,9 +555,9 @@ var Form = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref) {
497
555
  event.preventDefault();
498
556
  setPendingValidation(undefined);
499
557
 
500
- var _validateForm4 = validateForm(Object.entries(validations.current), value, format, messages, true),
501
- nextErrors = _validateForm4[0],
502
- nextInfos = _validateForm4[1];
558
+ var _validateForm2 = validateForm(Object.entries(validationRulesRef.current), value, format, messages, true),
559
+ nextErrors = _validateForm2[0],
560
+ nextInfos = _validateForm2[1];
503
561
 
504
562
  setValidationResults(function () {
505
563
  var nextValidationResults = {
@@ -509,6 +567,7 @@ var Form = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref) {
509
567
  valid: buildValid(nextErrors)
510
568
  };
511
569
  if (onValidate) onValidate(nextValidationResults);
570
+ validationResultsRef.current = nextValidationResults;
512
571
  return nextValidationResults;
513
572
  });
514
573
 
@@ -523,10 +582,7 @@ var Form = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref) {
523
582
  }
524
583
  }
525
584
  }), /*#__PURE__*/_react["default"].createElement(_FormContext.FormContext.Provider, {
526
- value: {
527
- useFormField: useFormField,
528
- useFormInput: useFormInput
529
- }
585
+ value: formContextValue
530
586
  }, children));
531
587
  });
532
588
  exports.Form = Form;