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.
- package/components/Anchor/Anchor.js +1 -4
- package/components/Anchor/StyledAnchor.js +1 -1
- package/components/Box/Box.js +2 -2
- package/components/Box/StyledBox.js +18 -1
- package/components/Box/index.d.ts +1 -1
- package/components/Box/propTypes.js +4 -1
- package/components/Cards/stories/Simple.js +1 -4
- package/components/Data/stories/Cards.js +9 -19
- package/components/Data/stories/Complex.js +1 -4
- package/components/Data/stories/ComposedToolbar.js +74 -0
- package/components/Data/stories/Infinite.js +29 -64
- package/components/Data/stories/Inline.js +1 -9
- package/components/Data/stories/List.js +3 -9
- package/components/Data/stories/Properties.js +17 -22
- package/components/Data/stories/Simple.js +4 -10
- package/components/Data/stories/SpaceX.js +8 -7
- package/components/Data/stories/StarWars.js +6 -12
- package/components/Data/stories/Views.js +4 -11
- package/components/DataFilter/DataFilter.js +1 -0
- package/components/DataFilter/stories/Simple.js +2 -6
- package/components/DataFilters/stories/Drop.js +2 -6
- package/components/DataFilters/stories/Layer.js +2 -6
- package/components/DataFilters/stories/Simple.js +2 -6
- package/components/DataSearch/stories/Drop.js +6 -11
- package/components/DataSearch/stories/Responsive.js +6 -12
- package/components/DataSearch/stories/Simple.js +5 -10
- package/components/DataSearch/stories/UpdateOnSubmit.js +5 -7
- package/components/DataSort/stories/Drop.js +2 -6
- package/components/DataSort/stories/Simple.js +2 -6
- package/components/DataSummary/stories/Simple.js +2 -6
- package/components/DataTableColumns/stories/Simple.js +2 -6
- package/components/DataTableGroupBy/stories/Simple.js +5 -7
- package/components/DataView/stories/Simple.js +4 -6
- package/components/DateInput/DateInput.js +61 -17
- package/components/DateInput/index.d.ts +1 -0
- package/components/DateInput/propTypes.js +1 -0
- package/components/DateInput/stories/ReadOnly.js +36 -0
- package/components/DateInput/utils.js +2 -2
- package/components/Form/Form.js +34 -1
- package/components/FormField/FormField.js +20 -1
- package/components/FormField/README.md +1 -644
- package/components/FormField/index.d.ts +5 -1
- package/components/FormField/propTypes.js +4 -1
- package/components/FormField/stories/ThresholdValidation.js +51 -0
- package/components/Grommet/Grommet.js +1 -1
- package/components/Grommet/index.d.ts +12 -0
- package/components/Grommet/propTypes.js +12 -0
- package/components/Layer/LayerContainer.js +1 -1
- package/components/List/List.js +33 -30
- package/components/Pagination/Pagination.js +52 -9
- package/components/Pagination/PaginationStep.js +41 -0
- package/components/Pagination/PaginationSummary.js +33 -0
- package/components/Pagination/index.d.ts +2 -0
- package/components/Pagination/propTypes.js +3 -1
- package/components/Pagination/stories/Steps.js +40 -0
- package/components/RangeInput/RangeInput.js +19 -12
- package/components/TextInput/CopyButton.js +53 -0
- package/components/TextInput/StyledTextInput.js +13 -2
- package/components/TextInput/TextInput.js +46 -12
- package/components/TextInput/index.d.ts +1 -0
- package/components/TextInput/propTypes.js +1 -0
- package/components/TextInput/stories/ReadOnly.js +43 -0
- package/components/Toolbar/stories/Simple.js +1 -4
- package/es6/components/Anchor/Anchor.js +1 -4
- package/es6/components/Anchor/StyledAnchor.js +1 -1
- package/es6/components/Box/Box.js +2 -2
- package/es6/components/Box/StyledBox.js +18 -1
- package/es6/components/Box/index.d.ts +1 -1
- package/es6/components/Box/propTypes.js +4 -1
- package/es6/components/Cards/stories/Simple.js +2 -5
- package/es6/components/Data/stories/Cards.js +10 -20
- package/es6/components/Data/stories/Complex.js +2 -5
- package/es6/components/Data/stories/ComposedToolbar.js +69 -0
- package/es6/components/Data/stories/Infinite.js +32 -66
- package/es6/components/Data/stories/Inline.js +2 -10
- package/es6/components/Data/stories/List.js +4 -10
- package/es6/components/Data/stories/Properties.js +18 -23
- package/es6/components/Data/stories/Simple.js +5 -11
- package/es6/components/Data/stories/SpaceX.js +9 -8
- package/es6/components/Data/stories/StarWars.js +7 -13
- package/es6/components/Data/stories/Views.js +5 -12
- package/es6/components/DataFilter/DataFilter.js +1 -0
- package/es6/components/DataFilter/stories/Simple.js +2 -6
- package/es6/components/DataFilters/stories/Drop.js +2 -6
- package/es6/components/DataFilters/stories/Layer.js +2 -6
- package/es6/components/DataFilters/stories/Simple.js +2 -6
- package/es6/components/DataSearch/stories/Drop.js +7 -12
- package/es6/components/DataSearch/stories/Responsive.js +7 -13
- package/es6/components/DataSearch/stories/Simple.js +6 -11
- package/es6/components/DataSearch/stories/UpdateOnSubmit.js +6 -8
- package/es6/components/DataSort/stories/Drop.js +2 -6
- package/es6/components/DataSort/stories/Simple.js +2 -6
- package/es6/components/DataSummary/stories/Simple.js +2 -6
- package/es6/components/DataTableColumns/stories/Simple.js +2 -6
- package/es6/components/DataTableGroupBy/stories/Simple.js +5 -7
- package/es6/components/DataView/stories/Simple.js +6 -8
- package/es6/components/DateInput/DateInput.js +61 -17
- package/es6/components/DateInput/index.d.ts +1 -0
- package/es6/components/DateInput/propTypes.js +1 -0
- package/es6/components/DateInput/stories/ReadOnly.js +31 -0
- package/es6/components/DateInput/utils.js +2 -2
- package/es6/components/Form/Form.js +34 -1
- package/es6/components/FormField/FormField.js +21 -2
- package/es6/components/FormField/README.md +1 -644
- package/es6/components/FormField/index.d.ts +5 -1
- package/es6/components/FormField/propTypes.js +4 -1
- package/es6/components/FormField/stories/ThresholdValidation.js +46 -0
- package/es6/components/Grommet/Grommet.js +1 -1
- package/es6/components/Grommet/index.d.ts +12 -0
- package/es6/components/Grommet/propTypes.js +12 -0
- package/es6/components/Layer/LayerContainer.js +1 -1
- package/es6/components/List/List.js +33 -30
- package/es6/components/Pagination/Pagination.js +52 -9
- package/es6/components/Pagination/PaginationStep.js +35 -0
- package/es6/components/Pagination/PaginationSummary.js +27 -0
- package/es6/components/Pagination/index.d.ts +2 -0
- package/es6/components/Pagination/propTypes.js +3 -1
- package/es6/components/Pagination/stories/Steps.js +35 -0
- package/es6/components/RangeInput/RangeInput.js +19 -12
- package/es6/components/TextInput/CopyButton.js +48 -0
- package/es6/components/TextInput/StyledTextInput.js +14 -3
- package/es6/components/TextInput/TextInput.js +46 -12
- package/es6/components/TextInput/index.d.ts +1 -0
- package/es6/components/TextInput/propTypes.js +1 -0
- package/es6/components/TextInput/stories/ReadOnly.js +38 -0
- package/es6/components/Toolbar/stories/Simple.js +2 -5
- package/es6/languages/default.json +23 -0
- package/es6/themes/base.d.ts +8 -0
- package/es6/themes/base.js +12 -1
- package/es6/utils/index.js +1 -0
- package/es6/utils/readOnly.js +10 -0
- package/grommet.min.js +1 -1
- package/grommet.min.js.map +1 -1
- package/languages/default.json +23 -0
- package/package.json +31 -32
- package/themes/base.d.ts +8 -0
- package/themes/base.js +12 -1
- package/utils/index.js +6 -0
- package/utils/readOnly.js +14 -0
- package/components/Data/stories/Controlled.js +0 -92
- package/components/Data/stories/DataTable.js +0 -49
- package/components/DataFilters/stories/Inline.js +0 -53
- package/es6/components/Data/stories/Controlled.js +0 -86
- package/es6/components/Data/stories/DataTable.js +0 -44
- 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
|
|
161
|
-
open =
|
|
162
|
-
setOpen =
|
|
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
|
|
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
|
-
|
|
259
|
-
|
|
294
|
+
if (!readOnlyCopy) {
|
|
295
|
+
event.preventDefault();
|
|
296
|
+
if (!readOnly) openCalendar();
|
|
297
|
+
}
|
|
260
298
|
}
|
|
261
|
-
}, /*#__PURE__*/React.createElement(
|
|
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 &&
|
|
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
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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 &&
|
|
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() {
|
|
@@ -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(
|
|
2
|
-
function _isNativeReflectConstruct() {
|
|
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 (
|
|
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) {
|