grommet 2.35.0 → 2.36.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 (145) hide show
  1. package/components/Anchor/Anchor.js +1 -4
  2. package/components/Anchor/StyledAnchor.js +1 -1
  3. package/components/Box/Box.js +2 -2
  4. package/components/Box/StyledBox.js +18 -1
  5. package/components/Box/index.d.ts +1 -1
  6. package/components/Box/propTypes.js +4 -1
  7. package/components/Cards/stories/Simple.js +1 -4
  8. package/components/Data/stories/Cards.js +9 -19
  9. package/components/Data/stories/Complex.js +1 -4
  10. package/components/Data/stories/ComposedToolbar.js +74 -0
  11. package/components/Data/stories/Infinite.js +29 -64
  12. package/components/Data/stories/Inline.js +1 -9
  13. package/components/Data/stories/List.js +3 -9
  14. package/components/Data/stories/Properties.js +17 -22
  15. package/components/Data/stories/Simple.js +4 -10
  16. package/components/Data/stories/SpaceX.js +8 -7
  17. package/components/Data/stories/StarWars.js +6 -12
  18. package/components/Data/stories/Views.js +4 -11
  19. package/components/DataFilter/DataFilter.js +1 -0
  20. package/components/DataFilter/stories/Simple.js +2 -6
  21. package/components/DataFilters/stories/Drop.js +2 -6
  22. package/components/DataFilters/stories/Layer.js +2 -6
  23. package/components/DataFilters/stories/Simple.js +2 -6
  24. package/components/DataSearch/stories/Drop.js +6 -11
  25. package/components/DataSearch/stories/Responsive.js +6 -12
  26. package/components/DataSearch/stories/Simple.js +5 -10
  27. package/components/DataSearch/stories/UpdateOnSubmit.js +5 -7
  28. package/components/DataSort/stories/Drop.js +2 -6
  29. package/components/DataSort/stories/Simple.js +2 -6
  30. package/components/DataSummary/stories/Simple.js +2 -6
  31. package/components/DataTableColumns/stories/Simple.js +2 -6
  32. package/components/DataTableGroupBy/stories/Simple.js +5 -7
  33. package/components/DataView/stories/Simple.js +4 -6
  34. package/components/DateInput/DateInput.js +61 -17
  35. package/components/DateInput/index.d.ts +1 -0
  36. package/components/DateInput/propTypes.js +1 -0
  37. package/components/DateInput/stories/ReadOnly.js +36 -0
  38. package/components/DateInput/utils.js +2 -2
  39. package/components/Form/Form.js +34 -1
  40. package/components/FormField/FormField.js +20 -1
  41. package/components/FormField/README.md +1 -644
  42. package/components/FormField/index.d.ts +5 -1
  43. package/components/FormField/propTypes.js +4 -1
  44. package/components/FormField/stories/ThresholdValidation.js +51 -0
  45. package/components/Grommet/Grommet.js +1 -1
  46. package/components/Grommet/index.d.ts +12 -0
  47. package/components/Grommet/propTypes.js +12 -0
  48. package/components/Layer/LayerContainer.js +1 -1
  49. package/components/List/List.js +33 -30
  50. package/components/Pagination/Pagination.js +52 -9
  51. package/components/Pagination/PaginationStep.js +41 -0
  52. package/components/Pagination/PaginationSummary.js +33 -0
  53. package/components/Pagination/index.d.ts +2 -0
  54. package/components/Pagination/propTypes.js +3 -1
  55. package/components/Pagination/stories/Steps.js +40 -0
  56. package/components/RangeInput/RangeInput.js +19 -12
  57. package/components/TextInput/CopyButton.js +53 -0
  58. package/components/TextInput/StyledTextInput.js +13 -2
  59. package/components/TextInput/TextInput.js +46 -12
  60. package/components/TextInput/index.d.ts +1 -0
  61. package/components/TextInput/propTypes.js +1 -0
  62. package/components/TextInput/stories/ReadOnly.js +43 -0
  63. package/components/Toolbar/stories/Simple.js +1 -4
  64. package/es6/components/Anchor/Anchor.js +1 -4
  65. package/es6/components/Anchor/StyledAnchor.js +1 -1
  66. package/es6/components/Box/Box.js +2 -2
  67. package/es6/components/Box/StyledBox.js +18 -1
  68. package/es6/components/Box/index.d.ts +1 -1
  69. package/es6/components/Box/propTypes.js +4 -1
  70. package/es6/components/Cards/stories/Simple.js +2 -5
  71. package/es6/components/Data/stories/Cards.js +10 -20
  72. package/es6/components/Data/stories/Complex.js +2 -5
  73. package/es6/components/Data/stories/ComposedToolbar.js +69 -0
  74. package/es6/components/Data/stories/Infinite.js +32 -66
  75. package/es6/components/Data/stories/Inline.js +2 -10
  76. package/es6/components/Data/stories/List.js +4 -10
  77. package/es6/components/Data/stories/Properties.js +18 -23
  78. package/es6/components/Data/stories/Simple.js +5 -11
  79. package/es6/components/Data/stories/SpaceX.js +9 -8
  80. package/es6/components/Data/stories/StarWars.js +7 -13
  81. package/es6/components/Data/stories/Views.js +5 -12
  82. package/es6/components/DataFilter/DataFilter.js +1 -0
  83. package/es6/components/DataFilter/stories/Simple.js +2 -6
  84. package/es6/components/DataFilters/stories/Drop.js +2 -6
  85. package/es6/components/DataFilters/stories/Layer.js +2 -6
  86. package/es6/components/DataFilters/stories/Simple.js +2 -6
  87. package/es6/components/DataSearch/stories/Drop.js +7 -12
  88. package/es6/components/DataSearch/stories/Responsive.js +7 -13
  89. package/es6/components/DataSearch/stories/Simple.js +6 -11
  90. package/es6/components/DataSearch/stories/UpdateOnSubmit.js +6 -8
  91. package/es6/components/DataSort/stories/Drop.js +2 -6
  92. package/es6/components/DataSort/stories/Simple.js +2 -6
  93. package/es6/components/DataSummary/stories/Simple.js +2 -6
  94. package/es6/components/DataTableColumns/stories/Simple.js +2 -6
  95. package/es6/components/DataTableGroupBy/stories/Simple.js +5 -7
  96. package/es6/components/DataView/stories/Simple.js +6 -8
  97. package/es6/components/DateInput/DateInput.js +61 -17
  98. package/es6/components/DateInput/index.d.ts +1 -0
  99. package/es6/components/DateInput/propTypes.js +1 -0
  100. package/es6/components/DateInput/stories/ReadOnly.js +31 -0
  101. package/es6/components/DateInput/utils.js +2 -2
  102. package/es6/components/Form/Form.js +34 -1
  103. package/es6/components/FormField/FormField.js +21 -2
  104. package/es6/components/FormField/README.md +1 -644
  105. package/es6/components/FormField/index.d.ts +5 -1
  106. package/es6/components/FormField/propTypes.js +4 -1
  107. package/es6/components/FormField/stories/ThresholdValidation.js +46 -0
  108. package/es6/components/Grommet/Grommet.js +1 -1
  109. package/es6/components/Grommet/index.d.ts +12 -0
  110. package/es6/components/Grommet/propTypes.js +12 -0
  111. package/es6/components/Layer/LayerContainer.js +1 -1
  112. package/es6/components/List/List.js +33 -30
  113. package/es6/components/Pagination/Pagination.js +52 -9
  114. package/es6/components/Pagination/PaginationStep.js +35 -0
  115. package/es6/components/Pagination/PaginationSummary.js +27 -0
  116. package/es6/components/Pagination/index.d.ts +2 -0
  117. package/es6/components/Pagination/propTypes.js +3 -1
  118. package/es6/components/Pagination/stories/Steps.js +35 -0
  119. package/es6/components/RangeInput/RangeInput.js +19 -12
  120. package/es6/components/TextInput/CopyButton.js +48 -0
  121. package/es6/components/TextInput/StyledTextInput.js +14 -3
  122. package/es6/components/TextInput/TextInput.js +46 -12
  123. package/es6/components/TextInput/index.d.ts +1 -0
  124. package/es6/components/TextInput/propTypes.js +1 -0
  125. package/es6/components/TextInput/stories/ReadOnly.js +38 -0
  126. package/es6/components/Toolbar/stories/Simple.js +2 -5
  127. package/es6/languages/default.json +23 -0
  128. package/es6/themes/base.d.ts +8 -0
  129. package/es6/themes/base.js +12 -1
  130. package/es6/utils/index.js +1 -0
  131. package/es6/utils/readOnly.js +10 -0
  132. package/grommet.min.js +1 -1
  133. package/grommet.min.js.map +1 -1
  134. package/languages/default.json +23 -0
  135. package/package.json +31 -32
  136. package/themes/base.d.ts +8 -0
  137. package/themes/base.js +12 -1
  138. package/utils/index.js +6 -0
  139. package/utils/readOnly.js +14 -0
  140. package/components/Data/stories/Controlled.js +0 -92
  141. package/components/Data/stories/DataTable.js +0 -49
  142. package/components/DataFilters/stories/Inline.js +0 -53
  143. package/es6/components/Data/stories/Controlled.js +0 -86
  144. package/es6/components/Data/stories/DataTable.js +0 -44
  145. package/es6/components/DataFilters/stories/Inline.js +0 -48
@@ -1,9 +1,9 @@
1
- var _excluded = ["buttonProps", "calendarProps", "defaultValue", "disabled", "dropProps", "format", "id", "icon", "inline", "inputProps", "name", "onChange", "onFocus", "plain", "reverse", "value", "messages"],
1
+ var _excluded = ["buttonProps", "calendarProps", "defaultValue", "disabled", "dropProps", "format", "id", "icon", "inline", "inputProps", "name", "onChange", "onFocus", "plain", "readOnly", "readOnlyCopy", "reverse", "value", "messages"],
2
2
  _excluded2 = ["icon"];
3
3
  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); }
4
4
  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; }
5
5
  import React, { useRef, forwardRef, useContext, useEffect, useMemo, useState, useCallback } from 'react';
6
- import { ThemeContext } from 'styled-components';
6
+ import styled, { ThemeContext } from 'styled-components';
7
7
  import { Calendar as CalendarIcon } from 'grommet-icons/icons/Calendar';
8
8
  import { defaultProps } from '../../default-props';
9
9
  import { AnnounceContext } from '../../contexts/AnnounceContext';
@@ -17,9 +17,17 @@ import { FormContext } from '../Form';
17
17
  import { Keyboard } from '../Keyboard';
18
18
  import { MaskedInput } from '../MaskedInput';
19
19
  import { useForwardedRef, setHoursWithOffset } from '../../utils';
20
+ import { readOnlyStyle } from '../../utils/readOnly';
20
21
  import { formatToSchema, schemaToMask, valuesAreEqual, valueToText, textToValue, validateBounds } from './utils';
21
22
  import { DateInputPropTypes } from './propTypes';
22
23
  import { getOutputFormat } from '../Calendar/Calendar';
24
+ import { CopyButton } from '../TextInput/CopyButton';
25
+ var StyledDateInputContainer = styled(Box).withConfig({
26
+ displayName: "DateInput__StyledDateInputContainer",
27
+ componentId: "sc-1jfta23-0"
28
+ })(["", "};"], function (props) {
29
+ return props.readOnlyProp && readOnlyStyle(props.theme);
30
+ });
23
31
  var getReference = function getReference(value) {
24
32
  var adjustedDate;
25
33
  var res;
@@ -50,6 +58,8 @@ var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
50
58
  _onChange = _ref.onChange,
51
59
  _onFocus = _ref.onFocus,
52
60
  plain = _ref.plain,
61
+ readOnlyProp = _ref.readOnly,
62
+ readOnlyCopy = _ref.readOnlyCopy,
53
63
  _ref$reverse = _ref.reverse,
54
64
  reverseProp = _ref$reverse === void 0 ? false : _ref$reverse,
55
65
  valueArg = _ref.value,
@@ -64,6 +74,7 @@ var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
64
74
  useFormInput = _useContext2.useFormInput;
65
75
  var ref = useForwardedRef(refArg);
66
76
  var containerRef = useRef();
77
+ var readOnly = readOnlyProp || readOnlyCopy;
67
78
  var _useFormInput = useFormInput({
68
79
  name: name,
69
80
  value: valueArg,
@@ -106,6 +117,17 @@ var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
106
117
  var _useState3 = useState(schema ? valueToText(value, schema) : undefined),
107
118
  textValue = _useState3[0],
108
119
  setTextValue = _useState3[1];
120
+ var readOnlyCopyValidation = formatMessage({
121
+ id: 'input.readOnlyCopy.validation',
122
+ messages: messages
123
+ });
124
+ var readOnlyCopyPrompt = formatMessage({
125
+ id: 'input.readOnlyCopy.prompt',
126
+ messages: messages
127
+ });
128
+ var _useState4 = useState(readOnlyCopyPrompt),
129
+ tip = _useState4[0],
130
+ setTip = _useState4[1];
109
131
 
110
132
  // Setting the icon through `inputProps` is deprecated.
111
133
  // The `icon` prop should be used instead.
@@ -157,9 +179,9 @@ var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
157
179
  }, [schema, ref]);
158
180
 
159
181
  // when format and not inline, whether to show the Calendar in a Drop
160
- var _useState4 = useState(),
161
- open = _useState4[0],
162
- setOpen = _useState4[1];
182
+ var _useState5 = useState(),
183
+ open = _useState5[0],
184
+ setOpen = _useState5[1];
163
185
  var openCalendar = useCallback(function () {
164
186
  setOpen(true);
165
187
  announce(formatMessage({
@@ -233,7 +255,21 @@ var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
233
255
  })
234
256
  }, buttonProps));
235
257
  }
236
- var calendarButton = /*#__PURE__*/React.createElement(Button, {
258
+ var onClickCopy = function onClickCopy() {
259
+ global.navigator.clipboard.writeText(textValue);
260
+ announce(readOnlyCopyValidation, 'assertive');
261
+ setTip(readOnlyCopyValidation);
262
+ };
263
+ var onBlurCopy = function onBlurCopy() {
264
+ if (tip === readOnlyCopyValidation) setTip(readOnlyCopyPrompt);
265
+ };
266
+ var DateInputButton = readOnlyCopy ? /*#__PURE__*/React.createElement(CopyButton, {
267
+ onBlurCopy: onBlurCopy,
268
+ onClickCopy: onClickCopy,
269
+ readOnlyCopyPrompt: readOnlyCopyPrompt,
270
+ tip: tip,
271
+ value: value
272
+ }) : /*#__PURE__*/React.createElement(Button, {
237
273
  onClick: open ? closeCalendar : openCalendar,
238
274
  plain: true,
239
275
  icon: icon || MaskedInputIcon || /*#__PURE__*/React.createElement(CalendarIcon, {
@@ -255,16 +291,22 @@ var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
255
291
  return closeCalendar();
256
292
  } : undefined,
257
293
  onSpace: function onSpace(event) {
258
- event.preventDefault();
259
- openCalendar();
294
+ if (!readOnlyCopy) {
295
+ event.preventDefault();
296
+ if (!readOnly) openCalendar();
297
+ }
260
298
  }
261
- }, /*#__PURE__*/React.createElement(Box, {
299
+ }, /*#__PURE__*/React.createElement(StyledDateInputContainer, {
262
300
  ref: containerRef,
263
301
  border: !plain,
264
302
  round: theme.dateInput.container.round,
265
- direction: "row",
303
+ direction: "row"
304
+ // readOnly prop shouldn't get passed to the dom here
305
+ ,
306
+ readOnlyProp: readOnly,
266
307
  fill: true
267
- }, reverse && calendarButton, /*#__PURE__*/React.createElement(MaskedInput, _extends({
308
+ }, reverse && (!readOnly || readOnlyCopy) && DateInputButton, /*#__PURE__*/React.createElement(MaskedInput, _extends({
309
+ readOnly: readOnly,
268
310
  ref: ref,
269
311
  id: id,
270
312
  name: name,
@@ -293,17 +335,19 @@ var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
293
335
  }
294
336
  },
295
337
  onFocus: function onFocus(event) {
296
- announce(formatMessage({
297
- id: 'dateInput.openCalendar',
298
- messages: messages
299
- }));
338
+ if (!readOnly) {
339
+ announce(formatMessage({
340
+ id: 'dateInput.openCalendar',
341
+ messages: messages
342
+ }));
343
+ }
300
344
  if (_onFocus) _onFocus(event);
301
345
  }
302
- })), !reverse && calendarButton)));
346
+ })), !reverse && (!readOnly || readOnlyCopy) && DateInputButton)));
303
347
  if (inline) {
304
348
  return /*#__PURE__*/React.createElement(Box, null, input, calendar);
305
349
  }
306
- if (open) {
350
+ if (open && !readOnly) {
307
351
  return [input, /*#__PURE__*/React.createElement(Keyboard, {
308
352
  key: "drop",
309
353
  onEsc: function onEsc() {
@@ -22,6 +22,7 @@ export interface DateInputProps {
22
22
  };
23
23
  name?: string;
24
24
  onChange?: (event: { value: string | string[] }) => void;
25
+ readOnlyCopy?: boolean;
25
26
  size?:
26
27
  | 'xsmall'
27
28
  | 'small'
@@ -11,6 +11,7 @@ if (process.env.NODE_ENV !== 'production') {
11
11
  id: PropTypes.string,
12
12
  inline: PropTypes.bool,
13
13
  reverse: PropTypes.bool,
14
+ readOnlyCopy: PropTypes.bool,
14
15
  inputProps: PropTypes.shape({}),
15
16
  name: PropTypes.string,
16
17
  onChange: PropTypes.func,
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+ import { Box, DateInput } from 'grommet';
3
+ export var ReadOnly = function ReadOnly() {
4
+ return (
5
+ /*#__PURE__*/
6
+ // Uncomment <Grommet> lines when using outside of storybook
7
+ // <Grommet theme={...}>
8
+ React.createElement(Box, {
9
+ fill: true,
10
+ align: "center",
11
+ pad: "large"
12
+ }, /*#__PURE__*/React.createElement(Box, {
13
+ width: "medium",
14
+ gap: "medium"
15
+ }, /*#__PURE__*/React.createElement(DateInput, {
16
+ value: "02/11/2024",
17
+ "aria-label": "read only",
18
+ readOnly: true,
19
+ format: "mm/dd/yyyy"
20
+ }), /*#__PURE__*/React.createElement(DateInput, {
21
+ value: "02/11/2024",
22
+ "aria-label": "read only copy",
23
+ readOnlyCopy: true,
24
+ format: "mm/dd/yyyy"
25
+ })))
26
+ // </Grommet>
27
+ );
28
+ };
29
+ export default {
30
+ title: 'Input/DateInput/ReadOnly'
31
+ };
@@ -1,5 +1,5 @@
1
- function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
2
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
1
+ function _construct(t, e, r) { if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments); var o = [null]; o.push.apply(o, e); var p = new (t.bind.apply(t, o))(); return r && _setPrototypeOf(p, r.prototype), p; }
2
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
3
3
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
4
4
  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); }
5
5
  import { setHoursWithOffset } from '../../utils';
@@ -13,6 +13,7 @@ var defaultValidationResults = {
13
13
  errors: {},
14
14
  infos: {}
15
15
  };
16
+ var defaultThreshold = 0.5;
16
17
  var stringToArray = function stringToArray(string) {
17
18
  var match = string == null ? void 0 : string.match(/^(.+)\[([0-9]+)\]\.(.*)$/);
18
19
  if (match) {
@@ -72,6 +73,36 @@ var setFieldValue = function setFieldValue(name, componentValue, prevValue) {
72
73
  }
73
74
  return nextValue;
74
75
  };
76
+ var validateCharacterCount = function validateCharacterCount(format, rule, value) {
77
+ var max = rule.max,
78
+ threshold = rule.threshold;
79
+ var getMessage = function getMessage() {
80
+ var charactersRemaining = function charactersRemaining(plural) {
81
+ return {
82
+ id: "formField.maxCharacters.remaining." + (plural ? 'plural' : 'singular'),
83
+ values: {
84
+ number: max - value.length
85
+ }
86
+ };
87
+ };
88
+ var charactersOverLimit = function charactersOverLimit(plural) {
89
+ return {
90
+ id: "formField.maxCharacters.overLimit." + (plural ? 'plural' : 'singular'),
91
+ values: {
92
+ number: value.length - max
93
+ }
94
+ };
95
+ };
96
+ if (max - value.length >= 0) {
97
+ return format(charactersRemaining(max - value.length > 1));
98
+ }
99
+ return format(charactersOverLimit(value.length - max > 1));
100
+ };
101
+ return value.length / max > (threshold != null ? threshold : defaultThreshold) ? {
102
+ status: max - value.length >= 0 ? 'info' : 'error',
103
+ message: getMessage()
104
+ } : undefined;
105
+ };
75
106
 
76
107
  // Apply validation rule to field value and send correct messaging.
77
108
  var validate = function validate(rule, fieldValue, formValue, format, messages) {
@@ -91,6 +122,8 @@ var validate = function validate(rule, fieldValue, formValue, format, messages)
91
122
  };
92
123
  }
93
124
  }
125
+ } else if (rule.max) {
126
+ result = validateCharacterCount(format, rule, fieldValue);
94
127
  }
95
128
  return result;
96
129
  };
@@ -615,7 +648,7 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
615
648
  // bubbles up to the "outer" form even though in the DOM the portal
616
649
  // doesn't render as child of the "outer" form.
617
650
  // https://legacy.reactjs.org/docs/portals.html#event-bubbling-through-portals
618
- if (formRef.current && event.target === formRef.current) {
651
+ if (formRef.current && (event.target === formRef.current || event.target.form === formRef.current)) {
619
652
  setPendingValidation(undefined);
620
653
  // adding validateOn: "submit" prop to the undefined validateOn
621
654
  // fields as we want to trigger "submit" validation once form
@@ -3,7 +3,7 @@ var _excluded = ["error", "info", "message", "type"],
3
3
  _excluded3 = ["children", "className", "component", "contentProps", "disabled", "error", "help", "htmlFor", "info", "label", "margin", "name", "onBlur", "onChange", "onFocus", "pad", "required", "style", "validate", "validateOn"];
4
4
  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); }
5
5
  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; }
6
- import React, { Children, cloneElement, forwardRef, useContext, useState } from 'react';
6
+ import React, { Children, cloneElement, forwardRef, useContext, useMemo, useState } from 'react';
7
7
  import styled, { ThemeContext } from 'styled-components';
8
8
  import { defaultProps } from '../../default-props';
9
9
  import { containsFocus, shouldKeepFocus, withinDropPortal, PortalContext } from '../../utils';
@@ -119,6 +119,7 @@ var Input = function Input(_ref2) {
119
119
  }, rest, extraProps));
120
120
  };
121
121
  var FormField = /*#__PURE__*/forwardRef(function (_ref3, ref) {
122
+ var _theme$global$input;
122
123
  var children = _ref3.children,
123
124
  className = _ref3.className,
124
125
  component = _ref3.component,
@@ -165,6 +166,18 @@ var FormField = /*#__PURE__*/forwardRef(function (_ref3, ref) {
165
166
  var themeBorder = formFieldTheme.border;
166
167
  var debounce = useDebounce();
167
168
  var portalContext = useContext(PortalContext);
169
+ var readOnlyField = useMemo(function () {
170
+ var readOnly = false;
171
+ if (children) {
172
+ Children.map(children, function (child) {
173
+ var _child$props, _child$props2;
174
+ if ((((_child$props = child.props) == null ? void 0 : _child$props.readOnly) === true || ((_child$props2 = child.props) == null ? void 0 : _child$props2.readOnlyCopy) === true) && child.type && ('TextInput'.indexOf(child.type.displayName) !== -1 || 'DateInput'.indexOf(child.type.displayName) !== -1)) {
175
+ readOnly = true;
176
+ }
177
+ });
178
+ }
179
+ return readOnly;
180
+ }, [children]);
168
181
 
169
182
  // This is here for backwards compatibility. In case the child is a grommet
170
183
  // input component, set plain and focusIndicator props, if they aren't
@@ -202,7 +215,10 @@ var FormField = /*#__PURE__*/forwardRef(function (_ref3, ref) {
202
215
  themeContentProps.pad = undefined;
203
216
  }
204
217
  if (themeBorder && themeBorder.position === 'inner') {
205
- if (error && formFieldTheme.error) {
218
+ if (readOnlyField) {
219
+ var _theme$global$input$r;
220
+ themeContentProps.background = (_theme$global$input$r = theme.global.input.readOnly) == null ? void 0 : _theme$global$input$r.background;
221
+ } else if (error && formFieldTheme.error) {
206
222
  themeContentProps.background = formFieldTheme.error.background;
207
223
  } else if (disabled && formFieldTheme.disabled) {
208
224
  themeContentProps.background = formFieldTheme.disabled.background;
@@ -224,6 +240,9 @@ var FormField = /*#__PURE__*/forwardRef(function (_ref3, ref) {
224
240
  var borderColor;
225
241
  if (disabled && formFieldTheme.disabled.border && formFieldTheme.disabled.border.color) {
226
242
  borderColor = formFieldTheme.disabled.border.color;
243
+ } else if (readOnlyField && (_theme$global$input = theme.global.input) != null && (_theme$global$input = _theme$global$input.readOnly) != null && (_theme$global$input = _theme$global$input.border) != null && _theme$global$input.color) {
244
+ var _theme$global$input2;
245
+ borderColor = (_theme$global$input2 = theme.global.input) == null || (_theme$global$input2 = _theme$global$input2.readOnly) == null || (_theme$global$input2 = _theme$global$input2.border) == null ? void 0 : _theme$global$input2.color;
227
246
  } else if (
228
247
  // backward compatibility check
229
248
  error && themeBorder && themeBorder.error.color || error && formFieldTheme.error && formFieldTheme.error.border) {