grommet 2.31.0 → 2.32.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) 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/Box/Box.js +14 -4
  6. package/components/Box/stories/Border.js +15 -1
  7. package/components/Button/BusyAnimation.js +51 -0
  8. package/components/Button/Button.js +64 -4
  9. package/components/Button/StyledButton.js +4 -2
  10. package/components/Button/StyledButtonKind.js +8 -4
  11. package/components/Button/index.d.ts +7 -0
  12. package/components/Button/propTypes.js +6 -0
  13. package/components/Button/stories/Busy.js +45 -0
  14. package/components/Calendar/stories/Dual.js +4 -6
  15. package/components/Chart/Chart.js +113 -57
  16. package/components/Chart/index.d.ts +3 -0
  17. package/components/Chart/propTypes.js +1 -0
  18. package/components/Chart/stories/Layout.js +6 -3
  19. package/components/Chart/stories/Pattern.js +1 -0
  20. package/components/Chart/stories/Vertical.js +41 -0
  21. package/components/Chart/utils.js +57 -10
  22. package/components/Data/Data.js +2 -1
  23. package/components/Data/DataForm.js +6 -2
  24. package/components/Data/filter.js +12 -1
  25. package/components/Data/stories/Complex.js +63 -6
  26. package/components/Data/stories/Inline.js +19 -2
  27. package/components/DataFilter/DataFilter.js +37 -22
  28. package/components/DataFilters/DataFilters.js +13 -10
  29. package/components/DataTable/Body.js +16 -13
  30. package/components/DataTable/DataTable.js +4 -1
  31. package/components/DataTable/GroupedBody.js +2 -1
  32. package/components/DataTable/Header.js +1 -0
  33. package/components/DataTable/buildState.js +13 -11
  34. package/components/DataTable/stories/Controlled.js +2 -1
  35. package/components/DataTable/stories/ControlledGrouped.js +2 -1
  36. package/components/DataTable/stories/CustomThemed/Custom.js +0 -1
  37. package/components/DataTable/stories/CustomThemed/Fill.js +2 -1
  38. package/components/DataTable/stories/GroupedOnSelect.js +2 -1
  39. package/components/DataTable/stories/NoPrimary.js +0 -1
  40. package/components/DataTable/stories/OnUpdate.js +2 -1
  41. package/components/DataTable/stories/Served.js +2 -1
  42. package/components/DataTable/stories/Tunable.js +2 -1
  43. package/components/DataTable/stories/rowDetails.js +2 -1
  44. package/components/DataTableColumns/DataTableColumns.js +5 -0
  45. package/components/DataTableColumns/stories/Simple.js +4 -3
  46. package/components/DataTableGroupBy/DataTableGroupBy.js +67 -0
  47. package/components/DataTableGroupBy/README.md +2 -0
  48. package/components/DataTableGroupBy/index.d.ts +20 -0
  49. package/components/DataTableGroupBy/index.js +6 -0
  50. package/components/DataTableGroupBy/propTypes.js +17 -0
  51. package/components/DataTableGroupBy/stories/Simple.js +50 -0
  52. package/components/DateInput/DateInput.js +1 -1
  53. package/components/Drop/DropContainer.js +5 -4
  54. package/components/DropButton/DropButton.js +2 -2
  55. package/components/FileInput/FileInput.js +82 -53
  56. package/components/Form/Form.js +95 -44
  57. package/components/Form/stories/TriggerValidationUsingFormField.js +109 -0
  58. package/components/FormField/FormField.js +4 -2
  59. package/components/FormField/index.d.ts +1 -0
  60. package/components/FormField/propTypes.js +2 -1
  61. package/components/Grid/stories/CustomThemed/Responsive.js +0 -1
  62. package/components/InfiniteScroll/InfiniteScroll.js +1 -0
  63. package/components/Layer/Layer.js +1 -1
  64. package/components/Layer/LayerContainer.js +2 -2
  65. package/components/List/index.d.ts +2 -2
  66. package/components/NameValueList/NameValueList.js +1 -1
  67. package/components/RadioButtonGroup/RadioButtonGroup.js +19 -4
  68. package/components/RadioButtonGroup/stories/typescript/Simple.tsx +6 -4
  69. package/components/SelectMultiple/SelectMultiple.js +13 -10
  70. package/components/SelectMultiple/SelectMultipleValue.js +1 -1
  71. package/components/Tip/stories/HeaderActions.js +0 -1
  72. package/components/index.d.ts +3 -1
  73. package/components/index.js +6 -0
  74. package/contexts/DataContext.js +2 -1
  75. package/es6/components/Accordion/Accordion.js +4 -2
  76. package/es6/components/Accordion/index.d.ts +1 -0
  77. package/es6/components/Accordion/propTypes.js +1 -0
  78. package/es6/components/AccordionPanel/AccordionPanel.js +2 -1
  79. package/es6/components/Box/Box.js +14 -4
  80. package/es6/components/Box/stories/Border.js +15 -1
  81. package/es6/components/Button/BusyAnimation.js +41 -0
  82. package/es6/components/Button/Button.js +64 -5
  83. package/es6/components/Button/StyledButton.js +4 -2
  84. package/es6/components/Button/StyledButtonKind.js +8 -4
  85. package/es6/components/Button/index.d.ts +7 -0
  86. package/es6/components/Button/propTypes.js +6 -0
  87. package/es6/components/Button/stories/Busy.js +37 -0
  88. package/es6/components/Calendar/stories/Dual.js +4 -6
  89. package/es6/components/Chart/Chart.js +113 -57
  90. package/es6/components/Chart/index.d.ts +3 -0
  91. package/es6/components/Chart/propTypes.js +1 -0
  92. package/es6/components/Chart/stories/Layout.js +6 -3
  93. package/es6/components/Chart/stories/Pattern.js +1 -0
  94. package/es6/components/Chart/stories/Vertical.js +35 -0
  95. package/es6/components/Chart/utils.js +57 -10
  96. package/es6/components/Data/Data.js +2 -1
  97. package/es6/components/Data/DataForm.js +4 -1
  98. package/es6/components/Data/filter.js +12 -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 +37 -22
  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 +2 -1
  106. package/es6/components/DataTable/buildState.js +13 -11
  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/DateInput/DateInput.js +1 -1
  116. package/es6/components/Drop/DropContainer.js +5 -4
  117. package/es6/components/DropButton/DropButton.js +2 -2
  118. package/es6/components/FileInput/FileInput.js +83 -53
  119. package/es6/components/Form/Form.js +95 -44
  120. package/es6/components/Form/stories/TriggerValidationUsingFormField.js +102 -0
  121. package/es6/components/FormField/FormField.js +4 -2
  122. package/es6/components/FormField/index.d.ts +1 -0
  123. package/es6/components/FormField/propTypes.js +2 -1
  124. package/es6/components/InfiniteScroll/InfiniteScroll.js +1 -0
  125. package/es6/components/Layer/Layer.js +1 -1
  126. package/es6/components/Layer/LayerContainer.js +2 -2
  127. package/es6/components/List/index.d.ts +2 -2
  128. package/es6/components/NameValueList/NameValueList.js +1 -1
  129. package/es6/components/RadioButtonGroup/RadioButtonGroup.js +19 -4
  130. package/es6/components/RadioButtonGroup/stories/typescript/Simple.tsx +6 -4
  131. package/es6/components/SelectMultiple/SelectMultiple.js +13 -10
  132. package/es6/components/SelectMultiple/SelectMultipleValue.js +1 -1
  133. package/es6/components/index.d.ts +3 -1
  134. package/es6/components/index.js +1 -0
  135. package/es6/contexts/DataContext.js +2 -1
  136. package/es6/index.d.ts +12 -0
  137. package/es6/index.js +2 -0
  138. package/es6/languages/default.json +15 -2
  139. package/es6/themes/base.js +1 -1
  140. package/es6/utils/index.d.ts +1 -1
  141. package/es6/utils/refs.js +1 -1
  142. package/grommet.min.js +1 -1
  143. package/grommet.min.js.map +1 -1
  144. package/index.d.ts +12 -0
  145. package/index.js +1 -0
  146. package/languages/default.json +15 -2
  147. package/package.json +46 -45
  148. package/themes/base.js +1 -1
  149. package/utils/index.d.ts +1 -1
  150. package/utils/refs.js +1 -1
@@ -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,
@@ -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
  }
@@ -60,7 +60,7 @@ var Layer = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
60
60
  }
61
61
  setTimeout(function () {
62
62
  // we add the id and query here so the unit tests work
63
- var clone = containerTarget === document.body ? document.getElementById('layerClone') : containerTarget.getElementById('layerClone');
63
+ var clone = containerTarget.getRootNode().getElementById('layerClone');
64
64
  if (clone) {
65
65
  containerTarget.removeChild(clone);
66
66
  layerContainer.remove();
@@ -110,8 +110,8 @@ var LayerContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
110
110
  var onClickDocument = function onClickDocument(event) {
111
111
  // determine which portal id the target is in, if any
112
112
  var clickedPortalId = null;
113
- var node = containerTarget === document.body ? event.target : event == null ? void 0 : event.composedPath()[0];
114
- while (clickedPortalId === null && node !== document && node !== null) {
113
+ var node = event.composed && event.composedPath()[0] || event.target;
114
+ while (clickedPortalId === null && node && node !== document && !(node instanceof ShadowRoot)) {
115
115
  // check if user click occurred within the layer
116
116
  var attr = node.getAttribute('data-g-portal-id');
117
117
  if (attr !== null && attr !== '') clickedPortalId = parseInt(attr, 10);
@@ -43,7 +43,7 @@ export interface ListProps<ListItemType> {
43
43
  | string[]
44
44
  | { light: string | string[]; dark: string | string[] };
45
45
  border?: BorderType;
46
- children?: React.ReactNode;
46
+ children?: (...args: any[]) => any;
47
47
  data?: ListItemType[];
48
48
  disabled?: string[];
49
49
  gridArea?: GridAreaType;
@@ -69,7 +69,7 @@ export interface ListProps<ListItemType> {
69
69
  action?: (item: ListItemType, index: number) => void;
70
70
  }
71
71
 
72
- type ulProps = JSX.IntrinsicElements['ul'];
72
+ type ulProps = Omit<JSX.IntrinsicElements['ul'], 'children'>;
73
73
 
74
74
  export interface ListExtendedProps<ListItemType>
75
75
  extends ListProps<ListItemType>,
@@ -53,9 +53,9 @@ var NameValueList = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
53
53
  }, /*#__PURE__*/_react["default"].createElement(_Grid.Grid, _extends({
54
54
  as: "dl",
55
55
  ref: ref,
56
+ align: align,
56
57
  columns: columns,
57
58
  gap: gap,
58
- fill: layout === 'grid',
59
59
  margin: "none" // override browser default margin for dl
60
60
  }, rest)));
61
61
  });
@@ -23,7 +23,7 @@ var RadioButtonGroup = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref)
23
23
  _ref$focusIndicator = _ref.focusIndicator,
24
24
  focusIndicator = _ref$focusIndicator === void 0 ? true : _ref$focusIndicator,
25
25
  name = _ref.name,
26
- _onChange = _ref.onChange,
26
+ onChange = _ref.onChange,
27
27
  optionsProp = _ref.options,
28
28
  valueProp = _ref.value,
29
29
  gap = _ref.gap,
@@ -46,7 +46,7 @@ var RadioButtonGroup = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref)
46
46
  var _formContext$useFormI = formContext.useFormInput({
47
47
  name: name,
48
48
  value: valueProp,
49
- initialValue: defaultValue || ''
49
+ initialValue: defaultValue != null ? defaultValue : ''
50
50
  }),
51
51
  value = _formContext$useFormI[0],
52
52
  setValue = _formContext$useFormI[1];
@@ -96,6 +96,18 @@ var RadioButtonGroup = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref)
96
96
  setFocus(true);
97
97
  }, 1);
98
98
  };
99
+ var onRadioButtonChange = function onRadioButtonChange(event, optionValue) {
100
+ setValue(optionValue);
101
+ if (onChange) {
102
+ event.persist(); // extract from React synthetic event pool
103
+ // event.target.value gives value as a string which needs to be
104
+ // manually typecasted according to the type of original option value.
105
+ // return the original option value attached with the event.
106
+ var adjustedEvent = event;
107
+ adjustedEvent.value = optionValue;
108
+ onChange(adjustedEvent);
109
+ }
110
+ };
99
111
  var onBlur = function onBlur() {
100
112
  return setFocus(false);
101
113
  };
@@ -122,6 +134,10 @@ var RadioButtonGroup = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref)
122
134
  // when nothing has been selected, show focus
123
135
  // on the first radiobutton
124
136
  value === '' && index === 0;
137
+ if (optionRest.checked) {
138
+ console.warn( // eslint-disable-next-line max-len
139
+ "'checked' prop of an individual RadioButton shouldn't be used in a RadioButtonGroup component. Use the RadioButtonGroup 'value' prop instead.");
140
+ }
125
141
  return /*#__PURE__*/_react["default"].createElement(_RadioButton.RadioButton, _extends({
126
142
  ref: function ref(aRef) {
127
143
  optionRefs.current[index] = aRef;
@@ -144,8 +160,7 @@ var RadioButtonGroup = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref)
144
160
  onFocus: onFocus,
145
161
  onBlur: onBlur,
146
162
  onChange: function onChange(event) {
147
- setValue(optionValue);
148
- if (_onChange) _onChange(event);
163
+ return onRadioButtonChange(event, optionValue);
149
164
  },
150
165
  tabIndex: focusable ? '0' : '-1' // necessary for Firefox
151
166
  }, optionRest), children ? function (state) {
@@ -1,7 +1,9 @@
1
- import React, { useState } from 'react';
1
+ import React, { ChangeEvent, useState } from 'react';
2
2
 
3
3
  import { Box, RadioButtonGroup } from 'grommet';
4
4
 
5
+ type EventWithValueProp = ChangeEvent<HTMLInputElement> & {value: string | number};
6
+
5
7
  export const Simple = () => {
6
8
  const postMethods = [
7
9
  { label: 'FTP', value: 'FTP' },
@@ -16,8 +18,8 @@ export const Simple = () => {
16
18
  ];
17
19
 
18
20
  // Type arguments can only be used in TypeScript files.
19
- // Remove <string | object> if you are not using Typescript.
20
- const [value, setValue] = useState<string | object>(postMethods[0]);
21
+ // Remove <string | number> if you are not using Typescript.
22
+ const [value, setValue] = useState<string | number>(postMethods[0].value);
21
23
 
22
24
  return (
23
25
  <Box align="center" pad="large">
@@ -25,7 +27,7 @@ export const Simple = () => {
25
27
  name="radio"
26
28
  options={postMethods}
27
29
  value={value}
28
- onChange={(event) => setValue(event.target.value)}
30
+ onChange={(event: EventWithValueProp) => setValue(event.value)}
29
31
  />
30
32
  </Box>
31
33
  );
@@ -44,7 +44,7 @@ var SelectMultiple = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
44
44
  defaultValue = _ref.defaultValue,
45
45
  disabled = _ref.disabled,
46
46
  disabledKey = _ref.disabledKey,
47
- dropAlign = _ref.dropAlign,
47
+ dropAlignProp = _ref.dropAlign,
48
48
  dropHeight = _ref.dropHeight,
49
49
  dropProps = _ref.dropProps,
50
50
  dropTarget = _ref.dropTarget,
@@ -92,6 +92,16 @@ var SelectMultiple = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
92
92
  var selectBoxRef = (0, _react.useRef)();
93
93
  var dropButtonRef = (0, _utils.useForwardedRef)(ref);
94
94
  var usingKeyboard = (0, _utils.useKeyboard)();
95
+ var dropAlign = (0, _react.useMemo)(function () {
96
+ return dropAlignProp || (showSelectedInline ? {
97
+ top: 'top',
98
+ right: 'right',
99
+ left: 'left'
100
+ } : {
101
+ top: 'bottom',
102
+ left: 'left'
103
+ });
104
+ }, [dropAlignProp, showSelectedInline]);
95
105
 
96
106
  // value is used for what we receive in valueProp and the basis for
97
107
  // what we send with onChange
@@ -355,11 +365,7 @@ var SelectMultiple = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
355
365
  fill: "horizontal",
356
366
  alignSelf: "start"
357
367
  }, dropButtonProps, {
358
- dropAlign: dropAlign || {
359
- top: 'top',
360
- right: 'right',
361
- left: 'left'
362
- },
368
+ dropAlign: dropAlign,
363
369
  dropTarget: dropTarget || selectBoxRef.current
364
370
  }), selectValue || displayLabelKey ? /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_Box.Box, {
365
371
  direction: "row"
@@ -402,10 +408,7 @@ var SelectMultiple = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
402
408
  }, rest)), displaySelectIcon)), !open && (value == null ? void 0 : value.length) > 0 && (selectValue || displayLabelKey))) : /*#__PURE__*/_react["default"].createElement(_Box.Box, {
403
409
  width: width
404
410
  }, /*#__PURE__*/_react["default"].createElement(_StyledSelect.StyledSelectDropButton, _extends({}, dropButtonProps, {
405
- dropAlign: dropAlign || {
406
- top: 'bottom',
407
- left: 'left'
408
- },
411
+ dropAlign: dropAlign,
409
412
  dropTarget: dropTarget,
410
413
  alignSelf: alignSelf,
411
414
  tabIndex: "0"
@@ -60,7 +60,7 @@ var SelectMultipleValue = function SelectMultipleValue(_ref) {
60
60
  onSelectChange(event, {
61
61
  option: optionValue,
62
62
  value: intermediate.filter(function (v) {
63
- return typeof v === 'object' ? (0, _utils.applyKey)(v, valueKey || labelKey) === (0, _utils.applyKey)(optionValue, valueKey || labelKey) : v !== optionValue;
63
+ return typeof v === 'object' ? (0, _utils.applyKey)(v, valueKey || labelKey) !== (0, _utils.applyKey)(optionValue, valueKey || labelKey) : v !== optionValue;
64
64
  })
65
65
  });
66
66
  if (valueIndex !== intermediate.length - 1) {
@@ -10,7 +10,6 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
10
10
  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; }
11
11
  // Source code for the data can be found here
12
12
  // https://github.com/grommet/grommet/blob/master/src/js/components/DataTable/stories/data.js
13
-
14
13
  var TipContent = function TipContent(_ref) {
15
14
  var message = _ref.message,
16
15
  icon = _ref.icon;