grommet 2.30.0 → 2.32.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 (162) hide show
  1. package/components/Accordion/Accordion.js +4 -2
  2. package/components/Accordion/index.d.ts +1 -0
  3. package/components/Accordion/propTypes.js +1 -0
  4. package/components/AccordionPanel/AccordionPanel.js +2 -1
  5. package/components/Anchor/Anchor.js +3 -2
  6. package/components/Box/Box.js +14 -4
  7. package/components/Box/stories/Border.js +15 -1
  8. package/components/Button/Badge.js +42 -43
  9. package/components/Button/BusyAnimation.js +51 -0
  10. package/components/Button/Button.js +78 -15
  11. package/components/Button/StyledButton.js +7 -3
  12. package/components/Button/StyledButtonKind.js +12 -6
  13. package/components/Button/index.d.ts +9 -0
  14. package/components/Button/propTypes.js +7 -0
  15. package/components/Button/stories/Busy.js +45 -0
  16. package/components/Calendar/stories/Dual.js +4 -6
  17. package/components/CheckBox/index.d.ts +1 -1
  18. package/components/Data/DataForm.js +45 -35
  19. package/components/Data/filter.js +9 -1
  20. package/components/Data/stories/Complex.js +63 -6
  21. package/components/Data/stories/Inline.js +19 -2
  22. package/components/DataFilter/DataFilter.js +11 -1
  23. package/components/DataFilters/DataFilters.js +13 -10
  24. package/components/DataTable/Body.js +16 -13
  25. package/components/DataTable/DataTable.js +4 -1
  26. package/components/DataTable/GroupedBody.js +1 -0
  27. package/components/DataTable/Header.js +1 -0
  28. package/components/DataTable/buildState.js +12 -10
  29. package/components/DataTable/stories/Controlled.js +2 -1
  30. package/components/DataTable/stories/ControlledGrouped.js +2 -1
  31. package/components/DataTable/stories/CustomThemed/Custom.js +0 -1
  32. package/components/DataTable/stories/CustomThemed/Fill.js +2 -1
  33. package/components/DataTable/stories/GroupedOnSelect.js +2 -1
  34. package/components/DataTable/stories/NoPrimary.js +0 -1
  35. package/components/DataTable/stories/OnUpdate.js +2 -1
  36. package/components/DataTable/stories/Served.js +2 -1
  37. package/components/DataTable/stories/Tunable.js +2 -1
  38. package/components/DataTable/stories/rowDetails.js +2 -1
  39. package/components/DataTableColumns/DataTableColumns.js +5 -0
  40. package/components/DataTableColumns/stories/Simple.js +4 -3
  41. package/components/DataTableGroupBy/DataTableGroupBy.js +67 -0
  42. package/components/DataTableGroupBy/README.md +2 -0
  43. package/components/DataTableGroupBy/index.d.ts +20 -0
  44. package/components/DataTableGroupBy/index.js +6 -0
  45. package/components/DataTableGroupBy/propTypes.js +17 -0
  46. package/components/DataTableGroupBy/stories/Simple.js +50 -0
  47. package/components/DataView/DataView.js +1 -1
  48. package/components/DateInput/DateInput.js +3 -2
  49. package/components/Drop/DropContainer.js +2 -2
  50. package/components/DropButton/DropButton.js +2 -2
  51. package/components/FileInput/FileInput.js +82 -53
  52. package/components/Form/Form.js +95 -44
  53. package/components/Form/stories/TriggerValidationUsingFormField.js +109 -0
  54. package/components/FormField/FormField.js +4 -3
  55. package/components/FormField/index.d.ts +1 -0
  56. package/components/FormField/propTypes.js +2 -1
  57. package/components/Grid/stories/CustomThemed/Responsive.js +0 -1
  58. package/components/InfiniteScroll/InfiniteScroll.js +1 -0
  59. package/components/Layer/Layer.js +1 -1
  60. package/components/Layer/LayerContainer.js +2 -2
  61. package/components/List/index.d.ts +2 -2
  62. package/components/MaskedInput/MaskedInput.js +3 -2
  63. package/components/MaskedInput/StyledMaskedInput.js +2 -1
  64. package/components/NameValueList/NameValueList.js +1 -1
  65. package/components/Notification/Notification.js +7 -3
  66. package/components/PageHeader/PageHeader.js +6 -4
  67. package/components/Pagination/StyledPageControl.js +3 -1
  68. package/components/Paragraph/Paragraph.js +2 -2
  69. package/components/Paragraph/stories/All.js +5 -1
  70. package/components/SelectMultiple/SelectMultiple.js +24 -20
  71. package/components/SelectMultiple/SelectMultipleContainer.js +16 -13
  72. package/components/SelectMultiple/SelectMultipleValue.js +1 -1
  73. package/components/SelectMultiple/stories/Help.js +49 -0
  74. package/components/Text/Text.js +2 -2
  75. package/components/TextInput/StyledTextInput.js +2 -1
  76. package/components/TextInput/TextInput.js +3 -2
  77. package/components/Tip/stories/HeaderActions.js +0 -1
  78. package/components/index.d.ts +1 -0
  79. package/components/index.js +6 -0
  80. package/es6/components/Accordion/Accordion.js +4 -2
  81. package/es6/components/Accordion/index.d.ts +1 -0
  82. package/es6/components/Accordion/propTypes.js +1 -0
  83. package/es6/components/AccordionPanel/AccordionPanel.js +2 -1
  84. package/es6/components/Anchor/Anchor.js +4 -3
  85. package/es6/components/Box/Box.js +14 -4
  86. package/es6/components/Box/stories/Border.js +15 -1
  87. package/es6/components/Button/Badge.js +43 -44
  88. package/es6/components/Button/BusyAnimation.js +41 -0
  89. package/es6/components/Button/Button.js +79 -17
  90. package/es6/components/Button/StyledButton.js +8 -4
  91. package/es6/components/Button/StyledButtonKind.js +13 -7
  92. package/es6/components/Button/index.d.ts +9 -0
  93. package/es6/components/Button/propTypes.js +8 -1
  94. package/es6/components/Button/stories/Busy.js +37 -0
  95. package/es6/components/Calendar/stories/Dual.js +4 -6
  96. package/es6/components/CheckBox/index.d.ts +1 -1
  97. package/es6/components/Data/DataForm.js +43 -34
  98. package/es6/components/Data/filter.js +9 -1
  99. package/es6/components/Data/stories/Complex.js +64 -7
  100. package/es6/components/Data/stories/Inline.js +20 -3
  101. package/es6/components/DataFilter/DataFilter.js +11 -1
  102. package/es6/components/DataFilters/DataFilters.js +13 -10
  103. package/es6/components/DataTable/Body.js +15 -13
  104. package/es6/components/DataTable/DataTable.js +4 -1
  105. package/es6/components/DataTable/GroupedBody.js +1 -0
  106. package/es6/components/DataTable/buildState.js +12 -10
  107. package/es6/components/DataTableColumns/DataTableColumns.js +5 -0
  108. package/es6/components/DataTableColumns/stories/Simple.js +5 -4
  109. package/es6/components/DataTableGroupBy/DataTableGroupBy.js +60 -0
  110. package/es6/components/DataTableGroupBy/README.md +2 -0
  111. package/es6/components/DataTableGroupBy/index.d.ts +20 -0
  112. package/es6/components/DataTableGroupBy/index.js +1 -0
  113. package/es6/components/DataTableGroupBy/propTypes.js +11 -0
  114. package/es6/components/DataTableGroupBy/stories/Simple.js +45 -0
  115. package/es6/components/DataView/DataView.js +1 -1
  116. package/es6/components/DateInput/DateInput.js +3 -2
  117. package/es6/components/Drop/DropContainer.js +2 -2
  118. package/es6/components/DropButton/DropButton.js +2 -2
  119. package/es6/components/FileInput/FileInput.js +83 -53
  120. package/es6/components/Form/Form.js +95 -44
  121. package/es6/components/Form/stories/TriggerValidationUsingFormField.js +102 -0
  122. package/es6/components/FormField/FormField.js +4 -3
  123. package/es6/components/FormField/index.d.ts +1 -0
  124. package/es6/components/FormField/propTypes.js +2 -1
  125. package/es6/components/InfiniteScroll/InfiniteScroll.js +1 -0
  126. package/es6/components/Layer/Layer.js +1 -1
  127. package/es6/components/Layer/LayerContainer.js +2 -2
  128. package/es6/components/List/index.d.ts +2 -2
  129. package/es6/components/MaskedInput/MaskedInput.js +4 -3
  130. package/es6/components/MaskedInput/StyledMaskedInput.js +2 -1
  131. package/es6/components/NameValueList/NameValueList.js +1 -1
  132. package/es6/components/Notification/Notification.js +7 -3
  133. package/es6/components/PageHeader/PageHeader.js +6 -4
  134. package/es6/components/Pagination/StyledPageControl.js +3 -1
  135. package/es6/components/Paragraph/Paragraph.js +2 -2
  136. package/es6/components/Paragraph/stories/All.js +5 -1
  137. package/es6/components/SelectMultiple/SelectMultiple.js +24 -20
  138. package/es6/components/SelectMultiple/SelectMultipleContainer.js +16 -13
  139. package/es6/components/SelectMultiple/SelectMultipleValue.js +1 -1
  140. package/es6/components/SelectMultiple/stories/Help.js +42 -0
  141. package/es6/components/Text/Text.js +2 -2
  142. package/es6/components/TextInput/StyledTextInput.js +2 -1
  143. package/es6/components/TextInput/TextInput.js +4 -3
  144. package/es6/components/index.d.ts +1 -0
  145. package/es6/components/index.js +1 -0
  146. package/es6/index.d.ts +1 -0
  147. package/es6/languages/default.json +15 -2
  148. package/es6/themes/base.d.ts +3 -0
  149. package/es6/themes/base.js +7 -1
  150. package/es6/utils/icon.js +7 -0
  151. package/es6/utils/index.js +1 -0
  152. package/es6/utils/styles.js +10 -0
  153. package/grommet.min.js +1 -1
  154. package/grommet.min.js.map +1 -1
  155. package/index.d.ts +1 -0
  156. package/languages/default.json +15 -2
  157. package/package.json +49 -48
  158. package/themes/base.d.ts +3 -0
  159. package/themes/base.js +7 -1
  160. package/utils/icon.js +12 -0
  161. package/utils/index.js +6 -0
  162. package/utils/styles.js +12 -1
@@ -28,11 +28,10 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
28
28
  // If there are any files selected, we need to show the buttons to remove them.
29
29
  // So, we offset the <input /> from the right by the appropriate width.
30
30
  // We don't use Stack because of how we need to control the positioning.
31
-
32
31
  var ContentsBox = (0, _styledComponents["default"])(_Box.Box).withConfig({
33
32
  displayName: "FileInput__ContentsBox",
34
33
  componentId: "sc-1jzq7im-0"
35
- })(["cursor:pointer;position:relative;", " ", ";", ";", ";"], function (props) {
34
+ })(["cursor:pointer;position:relative;", " ", ";", ";", ";", ";", ";"], function (props) {
36
35
  return props.disabled && (0, _utils.disabledStyle)();
37
36
  }, function (props) {
38
37
  return props.theme.fileInput && props.theme.fileInput.extend;
@@ -40,6 +39,10 @@ var ContentsBox = (0, _styledComponents["default"])(_Box.Box).withConfig({
40
39
  return props.hover && props.theme.fileInput && props.theme.fileInput.hover && props.theme.fileInput.hover.extend;
41
40
  }, function (props) {
42
41
  return props.dragOver && props.theme.fileInput && props.theme.fileInput.dragOver && props.theme.fileInput.dragOver.extend;
42
+ }, function (props) {
43
+ return props.focus && (0, _utils.focusStyle)();
44
+ }, function (props) {
45
+ return !props.focus && (0, _utils.unfocusStyle)();
43
46
  });
44
47
  var Label = (0, _styledComponents["default"])(_Text.Text).withConfig({
45
48
  displayName: "FileInput__Label",
@@ -85,6 +88,9 @@ var FileInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
85
88
  var _React$useState2 = _react["default"].useState(),
86
89
  dragOver = _React$useState2[0],
87
90
  setDragOver = _React$useState2[1];
91
+ var _React$useState3 = _react["default"].useState(),
92
+ focus = _React$useState3[0],
93
+ setFocus = _React$useState3[1];
88
94
  var _useState = (0, _react.useState)(false),
89
95
  showRemoveConfirmation = _useState[0],
90
96
  setShowRemoveConfirmation = _useState[1];
@@ -98,6 +104,7 @@ var FileInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
98
104
  var removeRef = (0, _react.useRef)();
99
105
  var ConfirmRemove = confirmRemove;
100
106
  var RemoveIcon = theme.fileInput.icons.remove;
107
+ var usingKeyboard = (0, _utils.useKeyboard)();
101
108
  var _formContext$useFormI = formContext.useFormInput({
102
109
  name: name,
103
110
  value: valueProp,
@@ -247,8 +254,54 @@ var FileInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
247
254
  onMouseOut: disabled ? undefined : function () {
248
255
  return setHover(false);
249
256
  },
250
- dragOver: dragOver
251
- }, (!files.length || files.length > 1) && /*#__PURE__*/_react["default"].createElement(_Box.Box, {
257
+ dragOver: dragOver,
258
+ focus: usingKeyboard && focus
259
+ }, /*#__PURE__*/_react["default"].createElement(_StyledFileInput.StyledFileInput, _extends({
260
+ ref: inputRef,
261
+ type: "file",
262
+ id: id,
263
+ name: name,
264
+ maxSize: maxSize,
265
+ multiple: multiple,
266
+ disabled: disabled,
267
+ plain: true,
268
+ rightOffset: rightOffset
269
+ }, rest, {
270
+ onDragOver: function onDragOver() {
271
+ return setDragOver(true);
272
+ },
273
+ onDragLeave: function onDragLeave() {
274
+ return setDragOver(false);
275
+ },
276
+ onChange: function onChange(event) {
277
+ event.persist();
278
+ var fileList = event.target.files;
279
+ var nextFiles = multiple ? [].concat(files) : [];
280
+ var _loop = function _loop(i) {
281
+ // avoid duplicates
282
+ var existing = nextFiles.filter(function (file) {
283
+ return file.name === fileList[i].name && file.size === fileList[i].size;
284
+ }).length > 0;
285
+ if (!existing) {
286
+ nextFiles.push(fileList[i]);
287
+ }
288
+ };
289
+ for (var i = 0; i < fileList.length; i += 1) {
290
+ _loop(i);
291
+ }
292
+ setFiles(nextFiles);
293
+ setDragOver(false);
294
+ if (_onChange) _onChange(event, {
295
+ files: nextFiles
296
+ });
297
+ },
298
+ onBlur: function onBlur() {
299
+ return setFocus(false);
300
+ },
301
+ onFocus: function onFocus() {
302
+ return setFocus(true);
303
+ }
304
+ })), (!files.length || files.length > 1) && /*#__PURE__*/_react["default"].createElement(_Box.Box, {
252
305
  align: "center",
253
306
  fill: "horizontal",
254
307
  direction: "row",
@@ -261,7 +314,10 @@ var FileInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
261
314
  onEnter: function onEnter(event) {
262
315
  if (controlRef.current === event.target) inputRef.current.click();
263
316
  }
264
- }, theme.fileInput.button ? /*#__PURE__*/_react["default"].createElement(_Button.Button, {
317
+ }, theme.fileInput.button ? /*#__PURE__*/_react["default"].createElement(_Button.Button
318
+ // The focus here is redundant for keyboard users
319
+ , {
320
+ tabIndex: -1,
265
321
  ref: controlRef,
266
322
  kind: theme.fileInput.button,
267
323
  label: format({
@@ -272,8 +328,10 @@ var FileInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
272
328
  inputRef.current.click();
273
329
  inputRef.current.focus();
274
330
  }
275
- }) : /*#__PURE__*/_react["default"].createElement(_Anchor.Anchor, {
276
- tabIndex: 0,
331
+ }) : /*#__PURE__*/_react["default"].createElement(_Anchor.Anchor
332
+ // The focus here is redundant for keyboard users
333
+ , {
334
+ tabIndex: -1,
277
335
  alignSelf: "center",
278
336
  ref: controlRef,
279
337
  margin: "small",
@@ -321,7 +379,10 @@ var FileInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
321
379
  onEnter: function onEnter(event) {
322
380
  if (controlRef.current === event.target) inputRef.current.click();
323
381
  }
324
- }, theme.fileInput.button ? /*#__PURE__*/_react["default"].createElement(_Button.Button, {
382
+ }, theme.fileInput.button ? /*#__PURE__*/_react["default"].createElement(_Button.Button
383
+ // The focus here is redundant for keyboard users
384
+ , {
385
+ tabIndex: -1,
325
386
  ref: controlRef,
326
387
  kind: theme.fileInput.button,
327
388
  label: format({
@@ -332,8 +393,10 @@ var FileInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
332
393
  inputRef.current.click();
333
394
  inputRef.current.focus();
334
395
  }
335
- }) : /*#__PURE__*/_react["default"].createElement(_Anchor.Anchor, {
336
- tabIndex: 0,
396
+ }) : /*#__PURE__*/_react["default"].createElement(_Anchor.Anchor
397
+ // The focus here is redundant for keyboard users
398
+ , {
399
+ tabIndex: -1,
337
400
  alignSelf: "center",
338
401
  ref: controlRef,
339
402
  margin: "small",
@@ -387,7 +450,10 @@ var FileInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
387
450
  onEnter: function onEnter(event) {
388
451
  if (controlRef.current === event.target) inputRef.current.click();
389
452
  }
390
- }, theme.fileInput.button ? /*#__PURE__*/_react["default"].createElement(_Button.Button, {
453
+ }, theme.fileInput.button ? /*#__PURE__*/_react["default"].createElement(_Button.Button
454
+ // The focus here is redundant for keyboard users
455
+ , {
456
+ tabIndex: -1,
391
457
  ref: controlRef,
392
458
  kind: theme.fileInput.button,
393
459
  label: format({
@@ -398,8 +464,10 @@ var FileInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
398
464
  inputRef.current.click();
399
465
  inputRef.current.focus();
400
466
  }
401
- }) : /*#__PURE__*/_react["default"].createElement(_Anchor.Anchor, {
402
- tabIndex: 0,
467
+ }) : /*#__PURE__*/_react["default"].createElement(_Anchor.Anchor
468
+ // The focus here is redundant for keyboard users
469
+ , {
470
+ tabIndex: -1,
403
471
  ref: controlRef,
404
472
  margin: "small",
405
473
  onClick: function onClick() {
@@ -411,46 +479,7 @@ var FileInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
411
479
  messages: messages
412
480
  })
413
481
  }))));
414
- }), /*#__PURE__*/_react["default"].createElement(_StyledFileInput.StyledFileInput, _extends({
415
- ref: inputRef,
416
- type: "file",
417
- id: id,
418
- name: name,
419
- maxSize: maxSize,
420
- multiple: multiple,
421
- disabled: disabled,
422
- plain: true,
423
- rightOffset: rightOffset
424
- }, rest, {
425
- onDragOver: function onDragOver() {
426
- return setDragOver(true);
427
- },
428
- onDragLeave: function onDragLeave() {
429
- return setDragOver(false);
430
- },
431
- onChange: function onChange(event) {
432
- event.persist();
433
- var fileList = event.target.files;
434
- var nextFiles = multiple ? [].concat(files) : [];
435
- var _loop = function _loop(i) {
436
- // avoid duplicates
437
- var existing = nextFiles.filter(function (file) {
438
- return file.name === fileList[i].name && file.size === fileList[i].size;
439
- }).length > 0;
440
- if (!existing) {
441
- nextFiles.push(fileList[i]);
442
- }
443
- };
444
- for (var i = 0; i < fileList.length; i += 1) {
445
- _loop(i);
446
- }
447
- setFiles(nextFiles);
448
- setDragOver(false);
449
- if (_onChange) _onChange(event, {
450
- files: nextFiles
451
- });
452
- }
453
- }))), showRemoveConfirmation && /*#__PURE__*/_react["default"].createElement(ConfirmRemove, {
482
+ })), showRemoveConfirmation && /*#__PURE__*/_react["default"].createElement(ConfirmRemove, {
454
483
  onConfirm: function onConfirm() {
455
484
  removeFile(pendingRemoval.index);
456
485
  setPendingRemoval(defaultPendingRemoval);
@@ -135,11 +135,13 @@ var validateForm = function validateForm(validationRules, formValue, format, mes
135
135
  var name = _ref[0],
136
136
  _ref$ = _ref[1],
137
137
  field = _ref$.field,
138
- input = _ref$.input;
138
+ input = _ref$.input,
139
+ validateOn = _ref$.validateOn;
139
140
  if (!omitValid) {
140
141
  nextErrors[name] = undefined;
141
142
  nextInfos[name] = undefined;
142
143
  }
144
+ if (!validateOn) return;
143
145
  var result;
144
146
  if (input) {
145
147
  // input() a validation function supplied through useFormInput()
@@ -163,6 +165,9 @@ var validateForm = function validateForm(validationRules, formValue, format, mes
163
165
  });
164
166
  return [nextErrors, nextInfos];
165
167
  };
168
+ var isInstantValidate = function isInstantValidate(validateOn) {
169
+ return ['blur', 'change'].includes(validateOn);
170
+ };
166
171
  var Form = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref) {
167
172
  var children = _ref2.children,
168
173
  _ref2$errors = _ref2.errors,
@@ -176,7 +181,7 @@ var Form = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref) {
176
181
  _onSubmit = _ref2.onSubmit,
177
182
  onValidate = _ref2.onValidate,
178
183
  _ref2$validate = _ref2.validate,
179
- validateOn = _ref2$validate === void 0 ? 'submit' : _ref2$validate,
184
+ validateOnProp = _ref2$validate === void 0 ? 'submit' : _ref2$validate,
180
185
  valueProp = _ref2.value,
181
186
  rest = _objectWithoutPropertiesLoose(_ref2, _excluded);
182
187
  var formRef = (0, _utils.useForwardedRef)(ref);
@@ -191,12 +196,15 @@ var Form = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref) {
191
196
  var _useState2 = (0, _react.useState)(defaultTouched),
192
197
  touched = _useState2[0],
193
198
  setTouched = _useState2[1];
194
- var _useState3 = (0, _react.useState)({
199
+ var _useState3 = (0, _react.useState)(validateOnProp),
200
+ validateOn = _useState3[0],
201
+ setValidateOn = _useState3[1];
202
+ var _useState4 = (0, _react.useState)({
195
203
  errors: errorsProp,
196
204
  infos: infosProp
197
205
  }),
198
- validationResults = _useState3[0],
199
- setValidationResults = _useState3[1];
206
+ validationResults = _useState4[0],
207
+ setValidationResults = _useState4[1];
200
208
  // maintain a copy of validationResults in a ref for useEffects
201
209
  // which can't depend on validationResults directly without
202
210
  // causing infinite renders.
@@ -204,16 +212,16 @@ var Form = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref) {
204
212
  // Simulated onMount state. Consider Form to be mounted once it has
205
213
  // accounted for values originating from controlled inputs (available
206
214
  // at second rendering).
207
- var _useState4 = (0, _react.useState)('unmounted'),
208
- mounted = _useState4[0],
209
- setMounted = _useState4[1];
215
+ var _useState5 = (0, _react.useState)('unmounted'),
216
+ mounted = _useState5[0],
217
+ setMounted = _useState5[1];
210
218
  (0, _react.useEffect)(function () {
211
219
  if (!mounted) setMounted('mounting');else if (mounted === 'mounting') setMounted('mounted');
212
220
  }, [mounted]);
213
221
  // `pendingValidation` is the name of the FormField awaiting validation.
214
- var _useState5 = (0, _react.useState)(undefined),
215
- pendingValidation = _useState5[0],
216
- setPendingValidation = _useState5[1];
222
+ var _useState6 = (0, _react.useState)(undefined),
223
+ pendingValidation = _useState6[0],
224
+ setPendingValidation = _useState6[1];
217
225
  var validationRulesRef = (0, _react.useRef)({});
218
226
  var requiredFields = (0, _react.useRef)([]);
219
227
  var analyticsRef = (0, _react.useRef)({
@@ -285,16 +293,20 @@ var Form = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref) {
285
293
  var validationRules = Object.entries(validationRulesRef.current);
286
294
  // Use simulated onMount state to account for values provided by
287
295
  // controlled inputs.
288
- if (mounted !== 'mounted' && ['blur', 'change'].includes(validateOn) && Object.keys(value).length > 0 && Object.keys(touched).length === 0) {
289
- applyValidationRules(validationRules.filter(function (_ref3) {
290
- var n = _ref3[0];
291
- return value[n];
296
+ if (mounted !== 'mounted' && (isInstantValidate(validateOn) || validationRules.some(function (_ref3) {
297
+ var v = _ref3[1];
298
+ return isInstantValidate(v.validateOn);
299
+ })) && Object.keys(value).length > 0 && Object.keys(touched).length === 0) {
300
+ applyValidationRules(validationRules.filter(function (_ref4) {
301
+ var n = _ref4[0],
302
+ v = _ref4[1];
303
+ return getFieldValue(n, value) && v.validateOn;
292
304
  })
293
305
  // Exlude empty arrays which may be initial values in
294
306
  // an input such as DateInput.
295
- .filter(function (_ref4) {
296
- var n = _ref4[0];
297
- return !(Array.isArray(value[n]) && value[n].length === 0);
307
+ .filter(function (_ref5) {
308
+ var n = _ref5[0];
309
+ return !(Array.isArray(getFieldValue(n, value)) && getFieldValue(n, value).length === 0);
298
310
  }));
299
311
  }
300
312
  }, [applyValidationRules, mounted, touched, validateOn, value]);
@@ -304,10 +316,14 @@ var Form = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref) {
304
316
  (0, _react.useEffect)(function () {
305
317
  var validationRules = Object.entries(validationRulesRef.current);
306
318
  var timer = setTimeout(function () {
307
- if (pendingValidation && ['blur', 'change'].includes(validateOn)) {
308
- applyValidationRules(validationRules.filter(function (_ref5) {
309
- var n = _ref5[0];
310
- return touched[n] || pendingValidation.includes(n);
319
+ if (pendingValidation && (isInstantValidate(validateOn) || validationRules.some(function (_ref6) {
320
+ var v = _ref6[1];
321
+ return isInstantValidate(v.validateOn);
322
+ }))) {
323
+ applyValidationRules(validationRules.filter(function (_ref7) {
324
+ var n = _ref7[0],
325
+ v = _ref7[1];
326
+ return (touched[n] || pendingValidation.includes(n)) && v.validateOn;
311
327
  }));
312
328
  setPendingValidation(undefined);
313
329
  }
@@ -329,8 +345,8 @@ var Form = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref) {
329
345
  var _validationResultsRef2;
330
346
  var validationRules = Object.entries(validationRulesRef.current);
331
347
  if ((_validationResultsRef2 = validationResultsRef.current) != null && _validationResultsRef2.errors && Object.keys(validationResultsRef.current.errors).length > 0) {
332
- applyValidationRules(validationRules.filter(function (_ref6) {
333
- var n = _ref6[0];
348
+ applyValidationRules(validationRules.filter(function (_ref8) {
349
+ var n = _ref8[0];
334
350
  return touched[n] && validationResultsRef.current.errors[n];
335
351
  }));
336
352
  }
@@ -390,14 +406,14 @@ var Form = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref) {
390
406
  // they can have access to it.
391
407
  //
392
408
  var formContextValue = (0, _react.useMemo)(function () {
393
- var useFormInput = function useFormInput(_ref7) {
394
- var name = _ref7.name,
395
- componentValue = _ref7.value,
396
- initialValue = _ref7.initialValue,
397
- validateArg = _ref7.validate;
398
- var _useState6 = (0, _react.useState)(initialValue),
399
- inputValue = _useState6[0],
400
- setInputValue = _useState6[1];
409
+ var useFormInput = function useFormInput(_ref9) {
410
+ var name = _ref9.name,
411
+ componentValue = _ref9.value,
412
+ initialValue = _ref9.initialValue,
413
+ validateArg = _ref9.validate;
414
+ var _useState7 = (0, _react.useState)(initialValue),
415
+ inputValue = _useState7[0],
416
+ setInputValue = _useState7[1];
401
417
  var formValue = name ? getFieldValue(name, value) : undefined;
402
418
  // for dynamic forms, we need to track when an input has been added to
403
419
  // the form value. if the input is unmounted, we will delete its
@@ -489,15 +505,26 @@ var Form = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref) {
489
505
  if (initialValue !== undefined) setInputValue(nextComponentValue);
490
506
  }];
491
507
  };
492
- var useFormField = function useFormField(_ref8) {
493
- var errorArg = _ref8.error,
494
- infoArg = _ref8.info,
495
- name = _ref8.name,
496
- required = _ref8.required,
497
- disabled = _ref8.disabled,
498
- validateArg = _ref8.validate;
508
+ var useFormField = function useFormField(_ref10) {
509
+ var errorArg = _ref10.error,
510
+ infoArg = _ref10.info,
511
+ name = _ref10.name,
512
+ required = _ref10.required,
513
+ disabled = _ref10.disabled,
514
+ validateArg = _ref10.validate,
515
+ validateOnArg = _ref10.validateOn;
499
516
  var error = disabled ? undefined : errorArg || validationResults.errors[name];
500
517
  var info = infoArg || validationResults.infos[name];
518
+ (0, _react.useEffect)(function () {
519
+ setValidateOn(function (prevValues) {
520
+ var _extends2;
521
+ if (typeof prevValues === 'string') {
522
+ var _ref11;
523
+ return _ref11 = {}, _ref11[name] = validateOnArg || validateOnProp, _ref11;
524
+ }
525
+ return _extends({}, prevValues, (_extends2 = {}, _extends2[name] = validateOnArg || validateOnProp, _extends2));
526
+ });
527
+ }, [validateOnArg, name]);
501
528
 
502
529
  // Create validation rules for field
503
530
  (0, _react.useEffect)(function () {
@@ -510,8 +537,21 @@ var Form = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref) {
510
537
  validationRulesRef.current[name] = {};
511
538
  }
512
539
  validationRulesRef.current[name].field = validateName(validateArg, required);
540
+
541
+ // priority is given to validateOn prop on formField, if it is
542
+ // undefined, then we will use the validate prop value of Form.
543
+ // The reason we don't want to add validateOn = "submit" here is
544
+ // because we don't want to trigger validation of "submit" field
545
+ // when the user is typing in the instant (blur, change)
546
+ // validation fields.
547
+ if (validateOnArg && validateOnArg !== 'submit') {
548
+ validationRulesRef.current[name].validateOn = validateOnArg;
549
+ } else if (!validateOnArg && validateOnProp !== 'submit') {
550
+ validationRulesRef.current[name].validateOn = validateOnProp;
551
+ }
513
552
  return function () {
514
553
  delete validationRulesRef.current[name].field;
554
+ delete validationRulesRef.current[name].validateOn;
515
555
  var requiredFieldIndex = requiredFields.current.indexOf(name);
516
556
  if (requiredFieldIndex !== -1) {
517
557
  requiredFields.current.splice(requiredFieldIndex, 1);
@@ -519,15 +559,15 @@ var Form = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref) {
519
559
  };
520
560
  }
521
561
  return undefined;
522
- }, [error, name, required, validateArg, disabled]);
562
+ }, [error, name, required, validateArg, disabled, validateOnArg]);
523
563
  return {
524
564
  error: error,
525
565
  info: info,
526
566
  inForm: true,
527
- onBlur: validateOn === 'blur' ? function () {
567
+ onBlur: validateOnArg === 'blur' || validateOn[name] === 'blur' ? function () {
528
568
  return setPendingValidation(pendingValidation ? [].concat(pendingValidation, [name]) : [name]);
529
569
  } : undefined,
530
- onChange: validateOn === 'change' ? function () {
570
+ onChange: validateOnArg === 'change' || validateOn[name] === 'change' ? function () {
531
571
  return setPendingValidation(pendingValidation ? [].concat(pendingValidation, [name]) : [name]);
532
572
  } : undefined
533
573
  };
@@ -537,7 +577,7 @@ var Form = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref) {
537
577
  useFormInput: useFormInput,
538
578
  kind: kind
539
579
  };
540
- }, [onChange, kind, pendingValidation, touched, validateOn, validationResults.errors, validationResults.infos, value, valueProp]);
580
+ }, [onChange, kind, pendingValidation, touched, validateOn, validationResults.errors, validationResults.infos, value, valueProp, validateOnProp]);
541
581
  return /*#__PURE__*/_react["default"].createElement("form", _extends({
542
582
  ref: formRef
543
583
  }, rest, {
@@ -575,7 +615,18 @@ var Form = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref) {
575
615
  // otherwise.
576
616
  event.preventDefault();
577
617
  setPendingValidation(undefined);
578
- var _validateForm2 = validateForm(Object.entries(validationRulesRef.current), value, format, messages, true),
618
+ // adding validateOn: "submit" prop to the undefined validateOn fields
619
+ // as we want to trigger "submit" validation once form is submitted
620
+ var newValidationRulesRef = Object.keys(validationRulesRef.current).reduce(function (acc, key) {
621
+ acc[key] = validationRulesRef.current[key];
622
+ if (!acc[key].validateOn) {
623
+ acc[key] = _extends({}, validationRulesRef.current[key], {
624
+ validateOn: 'submit'
625
+ });
626
+ }
627
+ return acc;
628
+ }, {});
629
+ var _validateForm2 = validateForm(Object.entries(newValidationRulesRef), value, format, messages, true),
579
630
  nextErrors = _validateForm2[0],
580
631
  nextInfos = _validateForm2[1];
581
632
  setValidationResults(function () {
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports["default"] = exports.TriggerValidationUsingFormField = void 0;
5
+ var _react = _interopRequireDefault(require("react"));
6
+ var _grommetIcons = require("grommet-icons");
7
+ var _grommet = require("grommet");
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
+ var TriggerValidationUsingFormField = function TriggerValidationUsingFormField() {
10
+ return /*#__PURE__*/_react["default"].createElement(_grommet.Box, {
11
+ fill: true,
12
+ align: "center",
13
+ justify: "center"
14
+ }, /*#__PURE__*/_react["default"].createElement(_grommet.Box, {
15
+ width: "medium"
16
+ }, /*#__PURE__*/_react["default"].createElement(_grommet.Heading, {
17
+ alignSelf: "center",
18
+ level: "2"
19
+ }, "Validate On"), /*#__PURE__*/_react["default"].createElement(_grommet.Form, {
20
+ onReset: function onReset(event) {
21
+ return console.log(event);
22
+ },
23
+ onSubmit: function onSubmit(_ref) {
24
+ var value = _ref.value;
25
+ return console.log('Submit', value);
26
+ }
27
+ }, /*#__PURE__*/_react["default"].createElement(_grommet.FormField, {
28
+ label: "Blur",
29
+ name: "blur",
30
+ "aria-label": "blur",
31
+ required: true,
32
+ validate: [{
33
+ regexp: /^[a-z]/i
34
+ }, function (name) {
35
+ if (name && name.length === 1) return 'must be >1 character';
36
+ return undefined;
37
+ }, function (name) {
38
+ if (name === 'good') return {
39
+ message: /*#__PURE__*/_react["default"].createElement(_grommet.Box, {
40
+ align: "end"
41
+ }, /*#__PURE__*/_react["default"].createElement(_grommetIcons.StatusGood, null)),
42
+ status: 'info'
43
+ };
44
+ return undefined;
45
+ }],
46
+ validateOn: "blur"
47
+ }), /*#__PURE__*/_react["default"].createElement(_grommet.FormField, {
48
+ label: "Submit",
49
+ name: "submit",
50
+ "aria-label": "submit",
51
+ required: true,
52
+ validate: [{
53
+ regexp: /^[a-z]/i
54
+ }, function (name) {
55
+ if (name && name.length === 1) return 'must be >1 character';
56
+ return undefined;
57
+ }, function (name) {
58
+ if (name === 'good') return {
59
+ message: /*#__PURE__*/_react["default"].createElement(_grommet.Box, {
60
+ align: "end"
61
+ }, /*#__PURE__*/_react["default"].createElement(_grommetIcons.StatusGood, null)),
62
+ status: 'info'
63
+ };
64
+ return undefined;
65
+ }],
66
+ validateOn: "submit"
67
+ }), /*#__PURE__*/_react["default"].createElement(_grommet.FormField, {
68
+ label: "Change",
69
+ name: "change",
70
+ "aria-label": "change",
71
+ required: true,
72
+ validate: [{
73
+ regexp: /^[a-z]/i
74
+ }, function (name) {
75
+ if (name && name.length === 1) return 'must be >1 character';
76
+ return undefined;
77
+ }, function (name) {
78
+ if (name === 'good') return {
79
+ message: /*#__PURE__*/_react["default"].createElement(_grommet.Box, {
80
+ align: "end"
81
+ }, /*#__PURE__*/_react["default"].createElement(_grommetIcons.StatusGood, null)),
82
+ status: 'info'
83
+ };
84
+ return undefined;
85
+ }],
86
+ validateOn: "change"
87
+ }), /*#__PURE__*/_react["default"].createElement(_grommet.Box, {
88
+ direction: "row",
89
+ justify: "between",
90
+ margin: {
91
+ top: 'medium'
92
+ }
93
+ }, /*#__PURE__*/_react["default"].createElement(_grommet.Button, {
94
+ label: "Cancel"
95
+ }), /*#__PURE__*/_react["default"].createElement(_grommet.Button, {
96
+ type: "reset",
97
+ label: "Reset"
98
+ }), /*#__PURE__*/_react["default"].createElement(_grommet.Button, {
99
+ type: "submit",
100
+ label: "Update",
101
+ primary: true
102
+ })))));
103
+ };
104
+ exports.TriggerValidationUsingFormField = TriggerValidationUsingFormField;
105
+ TriggerValidationUsingFormField.storyName = 'Trigger Validation using Form Field';
106
+ var _default = {
107
+ title: 'Input/Form/Trigger Validation using Form Field'
108
+ };
109
+ exports["default"] = _default;
@@ -19,7 +19,7 @@ var _FormContext = require("../Form/FormContext");
19
19
  var _propTypes = require("./propTypes");
20
20
  var _excluded = ["error", "info", "message", "type"],
21
21
  _excluded2 = ["component", "disabled", "invalid", "name", "onChange"],
22
- _excluded3 = ["children", "className", "component", "contentProps", "disabled", "error", "help", "htmlFor", "info", "label", "margin", "name", "onBlur", "onChange", "onFocus", "pad", "required", "style", "validate"];
22
+ _excluded3 = ["children", "className", "component", "contentProps", "disabled", "error", "help", "htmlFor", "info", "label", "margin", "name", "onBlur", "onChange", "onFocus", "pad", "required", "style", "validate", "validateOn"];
23
23
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
24
24
  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; }
25
25
  function _extends() { _extends = Object.assign ? Object.assign.bind() : 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); }
@@ -159,6 +159,7 @@ var FormField = /*#__PURE__*/(0, _react.forwardRef)(function (_ref3, ref) {
159
159
  required = _ref3.required,
160
160
  style = _ref3.style,
161
161
  validate = _ref3.validate,
162
+ validateOn = _ref3.validateOn,
162
163
  rest = _objectWithoutPropertiesLoose(_ref3, _excluded3);
163
164
  var theme = (0, _react.useContext)(_styledComponents.ThemeContext) || _defaultProps.defaultProps.theme;
164
165
  var formContext = (0, _react.useContext)(_FormContext.FormContext);
@@ -168,7 +169,8 @@ var FormField = /*#__PURE__*/(0, _react.forwardRef)(function (_ref3, ref) {
168
169
  info: infoProp,
169
170
  name: name,
170
171
  required: required,
171
- validate: validate
172
+ validate: validate,
173
+ validateOn: validateOn
172
174
  }),
173
175
  error = _formContext$useFormF.error,
174
176
  info = _formContext$useFormF.info,
@@ -338,7 +340,6 @@ var FormField = /*#__PURE__*/(0, _react.forwardRef)(function (_ref3, ref) {
338
340
  return /*#__PURE__*/_react["default"].createElement(FormFieldBox, _extends({
339
341
  ref: formFieldRef,
340
342
  className: className,
341
- flex: false,
342
343
  background: outerBackground,
343
344
  margin: abut ? abutMargin : margin || _extends({}, formFieldTheme.margin)
344
345
  }, outerProps, {
@@ -33,6 +33,7 @@ export interface FormFieldProps {
33
33
  }
34
34
  | ((...args: any[]) => any)
35
35
  )[];
36
+ validateOn?: 'blur' | 'submit' | 'change';
36
37
  }
37
38
 
38
39
  type inputProps = Omit<
@@ -33,7 +33,8 @@ if (process.env.NODE_ENV !== 'production') {
33
33
  // regular expression
34
34
  message: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].node]),
35
35
  status: _propTypes["default"].oneOf(['error', 'info'])
36
- }), _propTypes["default"].func]))])
36
+ }), _propTypes["default"].func]))]),
37
+ validateOn: _propTypes["default"].oneOf(['blur', 'submit', 'change'])
37
38
  };
38
39
  }
39
40
  var FormFieldPropTypes = PropType;
@@ -13,7 +13,6 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
13
13
  // Two responsive grids
14
14
  // - First one with a known number of elements
15
15
  // - Second one with an unknown number of elements
16
-
17
16
  // set custom breakpoints so we can see the changes
18
17
  var customBreakpoints = (0, _utils.deepMerge)(_themes.grommet, {
19
18
  global: {
@@ -211,6 +211,7 @@ var InfiniteScroll = function InfiniteScroll(_ref) {
211
211
  while (replace && i <= lastPage) {
212
212
  if (!pageHeights[i] && pageHeights[i] !== pageHeights[0]) {
213
213
  if (!nextPageHeights) nextPageHeights = [].concat(pageHeights || []);
214
+ // set to first page height
214
215
  var _nextPageHeights = nextPageHeights;
215
216
  nextPageHeights[i] = _nextPageHeights[0];
216
217
  }