grommet 2.30.0 → 2.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/Accordion/Accordion.js +4 -2
- package/components/Accordion/index.d.ts +1 -0
- package/components/Accordion/propTypes.js +1 -0
- package/components/AccordionPanel/AccordionPanel.js +2 -1
- package/components/Anchor/Anchor.js +3 -2
- package/components/Box/Box.js +14 -4
- package/components/Box/stories/Border.js +15 -1
- package/components/Button/Badge.js +42 -43
- package/components/Button/BusyAnimation.js +51 -0
- package/components/Button/Button.js +78 -15
- package/components/Button/StyledButton.js +7 -3
- package/components/Button/StyledButtonKind.js +12 -6
- package/components/Button/index.d.ts +9 -0
- package/components/Button/propTypes.js +7 -0
- package/components/Button/stories/Busy.js +45 -0
- package/components/Calendar/stories/Dual.js +4 -6
- package/components/CheckBox/index.d.ts +1 -1
- package/components/Data/DataForm.js +45 -35
- package/components/Data/filter.js +9 -1
- package/components/Data/stories/Complex.js +63 -6
- package/components/Data/stories/Inline.js +19 -2
- package/components/DataFilter/DataFilter.js +11 -1
- package/components/DataFilters/DataFilters.js +13 -10
- package/components/DataTable/Body.js +16 -13
- package/components/DataTable/DataTable.js +4 -1
- package/components/DataTable/GroupedBody.js +1 -0
- package/components/DataTable/Header.js +1 -0
- package/components/DataTable/buildState.js +12 -10
- package/components/DataTable/stories/Controlled.js +2 -1
- package/components/DataTable/stories/ControlledGrouped.js +2 -1
- package/components/DataTable/stories/CustomThemed/Custom.js +0 -1
- package/components/DataTable/stories/CustomThemed/Fill.js +2 -1
- package/components/DataTable/stories/GroupedOnSelect.js +2 -1
- package/components/DataTable/stories/NoPrimary.js +0 -1
- package/components/DataTable/stories/OnUpdate.js +2 -1
- package/components/DataTable/stories/Served.js +2 -1
- package/components/DataTable/stories/Tunable.js +2 -1
- package/components/DataTable/stories/rowDetails.js +2 -1
- package/components/DataTableColumns/DataTableColumns.js +5 -0
- package/components/DataTableColumns/stories/Simple.js +4 -3
- package/components/DataTableGroupBy/DataTableGroupBy.js +67 -0
- package/components/DataTableGroupBy/README.md +2 -0
- package/components/DataTableGroupBy/index.d.ts +20 -0
- package/components/DataTableGroupBy/index.js +6 -0
- package/components/DataTableGroupBy/propTypes.js +17 -0
- package/components/DataTableGroupBy/stories/Simple.js +50 -0
- package/components/DataView/DataView.js +1 -1
- package/components/DateInput/DateInput.js +3 -2
- package/components/Drop/DropContainer.js +2 -2
- package/components/DropButton/DropButton.js +2 -2
- package/components/FileInput/FileInput.js +82 -53
- package/components/Form/Form.js +95 -44
- package/components/Form/stories/TriggerValidationUsingFormField.js +109 -0
- package/components/FormField/FormField.js +4 -3
- package/components/FormField/index.d.ts +1 -0
- package/components/FormField/propTypes.js +2 -1
- package/components/Grid/stories/CustomThemed/Responsive.js +0 -1
- package/components/InfiniteScroll/InfiniteScroll.js +1 -0
- package/components/Layer/Layer.js +1 -1
- package/components/Layer/LayerContainer.js +2 -2
- package/components/List/index.d.ts +2 -2
- package/components/MaskedInput/MaskedInput.js +3 -2
- package/components/MaskedInput/StyledMaskedInput.js +2 -1
- package/components/NameValueList/NameValueList.js +1 -1
- package/components/Notification/Notification.js +7 -3
- package/components/PageHeader/PageHeader.js +6 -4
- package/components/Pagination/StyledPageControl.js +3 -1
- package/components/Paragraph/Paragraph.js +2 -2
- package/components/Paragraph/stories/All.js +5 -1
- package/components/SelectMultiple/SelectMultiple.js +24 -20
- package/components/SelectMultiple/SelectMultipleContainer.js +16 -13
- package/components/SelectMultiple/SelectMultipleValue.js +1 -1
- package/components/SelectMultiple/stories/Help.js +49 -0
- package/components/Text/Text.js +2 -2
- package/components/TextInput/StyledTextInput.js +2 -1
- package/components/TextInput/TextInput.js +3 -2
- package/components/Tip/stories/HeaderActions.js +0 -1
- package/components/index.d.ts +1 -0
- package/components/index.js +6 -0
- package/es6/components/Accordion/Accordion.js +4 -2
- package/es6/components/Accordion/index.d.ts +1 -0
- package/es6/components/Accordion/propTypes.js +1 -0
- package/es6/components/AccordionPanel/AccordionPanel.js +2 -1
- package/es6/components/Anchor/Anchor.js +4 -3
- package/es6/components/Box/Box.js +14 -4
- package/es6/components/Box/stories/Border.js +15 -1
- package/es6/components/Button/Badge.js +43 -44
- package/es6/components/Button/BusyAnimation.js +41 -0
- package/es6/components/Button/Button.js +79 -17
- package/es6/components/Button/StyledButton.js +8 -4
- package/es6/components/Button/StyledButtonKind.js +13 -7
- package/es6/components/Button/index.d.ts +9 -0
- package/es6/components/Button/propTypes.js +8 -1
- package/es6/components/Button/stories/Busy.js +37 -0
- package/es6/components/Calendar/stories/Dual.js +4 -6
- package/es6/components/CheckBox/index.d.ts +1 -1
- package/es6/components/Data/DataForm.js +43 -34
- package/es6/components/Data/filter.js +9 -1
- package/es6/components/Data/stories/Complex.js +64 -7
- package/es6/components/Data/stories/Inline.js +20 -3
- package/es6/components/DataFilter/DataFilter.js +11 -1
- package/es6/components/DataFilters/DataFilters.js +13 -10
- package/es6/components/DataTable/Body.js +15 -13
- package/es6/components/DataTable/DataTable.js +4 -1
- package/es6/components/DataTable/GroupedBody.js +1 -0
- package/es6/components/DataTable/buildState.js +12 -10
- package/es6/components/DataTableColumns/DataTableColumns.js +5 -0
- package/es6/components/DataTableColumns/stories/Simple.js +5 -4
- package/es6/components/DataTableGroupBy/DataTableGroupBy.js +60 -0
- package/es6/components/DataTableGroupBy/README.md +2 -0
- package/es6/components/DataTableGroupBy/index.d.ts +20 -0
- package/es6/components/DataTableGroupBy/index.js +1 -0
- package/es6/components/DataTableGroupBy/propTypes.js +11 -0
- package/es6/components/DataTableGroupBy/stories/Simple.js +45 -0
- package/es6/components/DataView/DataView.js +1 -1
- package/es6/components/DateInput/DateInput.js +3 -2
- package/es6/components/Drop/DropContainer.js +2 -2
- package/es6/components/DropButton/DropButton.js +2 -2
- package/es6/components/FileInput/FileInput.js +83 -53
- package/es6/components/Form/Form.js +95 -44
- package/es6/components/Form/stories/TriggerValidationUsingFormField.js +102 -0
- package/es6/components/FormField/FormField.js +4 -3
- package/es6/components/FormField/index.d.ts +1 -0
- package/es6/components/FormField/propTypes.js +2 -1
- package/es6/components/InfiniteScroll/InfiniteScroll.js +1 -0
- package/es6/components/Layer/Layer.js +1 -1
- package/es6/components/Layer/LayerContainer.js +2 -2
- package/es6/components/List/index.d.ts +2 -2
- package/es6/components/MaskedInput/MaskedInput.js +4 -3
- package/es6/components/MaskedInput/StyledMaskedInput.js +2 -1
- package/es6/components/NameValueList/NameValueList.js +1 -1
- package/es6/components/Notification/Notification.js +7 -3
- package/es6/components/PageHeader/PageHeader.js +6 -4
- package/es6/components/Pagination/StyledPageControl.js +3 -1
- package/es6/components/Paragraph/Paragraph.js +2 -2
- package/es6/components/Paragraph/stories/All.js +5 -1
- package/es6/components/SelectMultiple/SelectMultiple.js +24 -20
- package/es6/components/SelectMultiple/SelectMultipleContainer.js +16 -13
- package/es6/components/SelectMultiple/SelectMultipleValue.js +1 -1
- package/es6/components/SelectMultiple/stories/Help.js +42 -0
- package/es6/components/Text/Text.js +2 -2
- package/es6/components/TextInput/StyledTextInput.js +2 -1
- package/es6/components/TextInput/TextInput.js +4 -3
- package/es6/components/index.d.ts +1 -0
- package/es6/components/index.js +1 -0
- package/es6/index.d.ts +1 -0
- package/es6/languages/default.json +15 -2
- package/es6/themes/base.d.ts +3 -0
- package/es6/themes/base.js +7 -1
- package/es6/utils/icon.js +7 -0
- package/es6/utils/index.js +1 -0
- package/es6/utils/styles.js +10 -0
- package/grommet.min.js +1 -1
- package/grommet.min.js.map +1 -1
- package/index.d.ts +1 -0
- package/languages/default.json +15 -2
- package/package.json +49 -48
- package/themes/base.d.ts +3 -0
- package/themes/base.js +7 -1
- package/utils/icon.js +12 -0
- package/utils/index.js +6 -0
- package/utils/styles.js +12 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DataTableGroupBy } from './DataTableGroupBy';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
var PropType = {};
|
|
3
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
4
|
+
PropType = {
|
|
5
|
+
options: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.arrayOf(PropTypes.shape({
|
|
6
|
+
label: PropTypes.string,
|
|
7
|
+
property: PropTypes.string
|
|
8
|
+
}))])
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export var DataTableGroupByPropTypes = PropType;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Box, Data, DataTable, Notification, Toolbar } from 'grommet';
|
|
3
|
+
import { DataTableGroupBy } from '../DataTableGroupBy';
|
|
4
|
+
import { columns, DATA } from '../../DataTable/stories/data';
|
|
5
|
+
|
|
6
|
+
// simplify option label for name property
|
|
7
|
+
var options = columns.filter(function (_ref) {
|
|
8
|
+
var property = _ref.property;
|
|
9
|
+
return ['location', 'percent'].includes(property);
|
|
10
|
+
}).map(function (_ref2) {
|
|
11
|
+
var header = _ref2.header,
|
|
12
|
+
property = _ref2.property;
|
|
13
|
+
return {
|
|
14
|
+
property: property,
|
|
15
|
+
label: header
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
export var Simple = function Simple() {
|
|
19
|
+
return (
|
|
20
|
+
/*#__PURE__*/
|
|
21
|
+
// Uncomment <Grommet> lines when using outside of storybook
|
|
22
|
+
// <Grommet theme={...}>
|
|
23
|
+
React.createElement(Box, {
|
|
24
|
+
align: "center",
|
|
25
|
+
justify: "start",
|
|
26
|
+
pad: "large",
|
|
27
|
+
gap: "medium"
|
|
28
|
+
}, /*#__PURE__*/React.createElement(Notification, {
|
|
29
|
+
status: "info",
|
|
30
|
+
message: "Data is in 'beta'. The API surface is subject to change."
|
|
31
|
+
}), /*#__PURE__*/React.createElement(Data, {
|
|
32
|
+
data: DATA
|
|
33
|
+
}, /*#__PURE__*/React.createElement(Toolbar, null, /*#__PURE__*/React.createElement(DataTableGroupBy, {
|
|
34
|
+
options: options
|
|
35
|
+
})), /*#__PURE__*/React.createElement(DataTable, null)))
|
|
36
|
+
// </Grommet>
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
Simple.args = {
|
|
41
|
+
full: true
|
|
42
|
+
};
|
|
43
|
+
export default {
|
|
44
|
+
title: 'Data/DataTableGroupBy/Simple'
|
|
45
|
+
};
|
|
@@ -44,7 +44,7 @@ export var DataView = function DataView(_ref) {
|
|
|
44
44
|
id: id,
|
|
45
45
|
name: "_view",
|
|
46
46
|
showSelectedInline: true,
|
|
47
|
-
placeholder: noForm ? 'Select view
|
|
47
|
+
placeholder: noForm ? 'Select view' : undefined,
|
|
48
48
|
options: names,
|
|
49
49
|
value: view == null ? void 0 : view.name
|
|
50
50
|
}, rest));
|
|
@@ -34,6 +34,7 @@ var getReference = function getReference(value) {
|
|
|
34
34
|
return adjustedDate;
|
|
35
35
|
};
|
|
36
36
|
var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
|
|
37
|
+
var _theme$icon, _theme$dateInput$icon;
|
|
37
38
|
var buttonProps = _ref.buttonProps,
|
|
38
39
|
calendarProps = _ref.calendarProps,
|
|
39
40
|
defaultValue = _ref.defaultValue,
|
|
@@ -58,7 +59,7 @@ var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
|
|
|
58
59
|
var announce = useContext(AnnounceContext);
|
|
59
60
|
var _useContext = useContext(MessageContext),
|
|
60
61
|
formatMessage = _useContext.format;
|
|
61
|
-
var iconSize = theme.
|
|
62
|
+
var iconSize = ((_theme$icon = theme.icon) == null ? void 0 : _theme$icon.matchSize) && rest.size || ((_theme$dateInput$icon = theme.dateInput.icon) == null ? void 0 : _theme$dateInput$icon.size) || 'medium';
|
|
62
63
|
var _useContext2 = useContext(FormContext),
|
|
63
64
|
useFormInput = _useContext2.useFormInput;
|
|
64
65
|
var ref = useForwardedRef(refArg);
|
|
@@ -173,7 +174,7 @@ var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
|
|
|
173
174
|
if (range && Array.isArray(nextValue)) {
|
|
174
175
|
normalizedValue = nextValue[0];
|
|
175
176
|
} // clicking an edge date removes it
|
|
176
|
-
else if (range) normalizedValue = [nextValue, nextValue];else normalizedValue = nextValue;
|
|
177
|
+
else if (range && nextValue) normalizedValue = [nextValue, nextValue];else normalizedValue = nextValue;
|
|
177
178
|
if (schema) setTextValue(valueToText(normalizedValue, schema));
|
|
178
179
|
setValue(normalizedValue);
|
|
179
180
|
setReference(getReference(nextValue));
|
|
@@ -60,8 +60,8 @@ var DropContainer = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
60
60
|
var onClickDocument = function onClickDocument(event) {
|
|
61
61
|
// determine which portal id the target is in, if any
|
|
62
62
|
var clickedPortalId = null;
|
|
63
|
-
var node =
|
|
64
|
-
while (clickedPortalId === null && node !== document) {
|
|
63
|
+
var node = event.composed && event.composedPath()[0] || event.target;
|
|
64
|
+
while (clickedPortalId === null && node && node !== document && !(node instanceof ShadowRoot)) {
|
|
65
65
|
var attr = node.getAttribute('data-g-portal-id');
|
|
66
66
|
if (attr !== null) clickedPortalId = parseInt(attr, 10);
|
|
67
67
|
node = node.parentNode;
|
|
@@ -38,8 +38,8 @@ var DropButton = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
38
38
|
var onDropClose = useCallback(function (event) {
|
|
39
39
|
// if the user has clicked on our Button, don't do anything here,
|
|
40
40
|
// handle that in onClickInternal() below.
|
|
41
|
-
var node = event.target;
|
|
42
|
-
while (node !== document && node !== buttonRef.current) {
|
|
41
|
+
var node = event.composed && event.composedPath()[0] || event.target;
|
|
42
|
+
while (node && node !== document && !(node instanceof ShadowRoot) && node !== buttonRef.current) {
|
|
43
43
|
node = node.parentNode;
|
|
44
44
|
}
|
|
45
45
|
if (node !== buttonRef.current) {
|
|
@@ -6,7 +6,7 @@ import styled, { ThemeContext } from 'styled-components';
|
|
|
6
6
|
import { CircleAlert } from 'grommet-icons/icons/CircleAlert';
|
|
7
7
|
import { MessageContext } from '../../contexts/MessageContext';
|
|
8
8
|
import { defaultProps } from '../../default-props';
|
|
9
|
-
import { disabledStyle, parseMetricToNum, useForwardedRef } from '../../utils';
|
|
9
|
+
import { disabledStyle, focusStyle, parseMetricToNum, unfocusStyle, useForwardedRef, useKeyboard } from '../../utils';
|
|
10
10
|
import { Anchor } from '../Anchor';
|
|
11
11
|
import { Box } from '../Box';
|
|
12
12
|
import { Button } from '../Button';
|
|
@@ -26,7 +26,7 @@ import { formatBytes } from './utils/formatBytes';
|
|
|
26
26
|
var ContentsBox = styled(Box).withConfig({
|
|
27
27
|
displayName: "FileInput__ContentsBox",
|
|
28
28
|
componentId: "sc-1jzq7im-0"
|
|
29
|
-
})(["cursor:pointer;position:relative;", " ", ";", ";", ";"], function (props) {
|
|
29
|
+
})(["cursor:pointer;position:relative;", " ", ";", ";", ";", ";", ";"], function (props) {
|
|
30
30
|
return props.disabled && disabledStyle();
|
|
31
31
|
}, function (props) {
|
|
32
32
|
return props.theme.fileInput && props.theme.fileInput.extend;
|
|
@@ -34,6 +34,10 @@ var ContentsBox = styled(Box).withConfig({
|
|
|
34
34
|
return props.hover && props.theme.fileInput && props.theme.fileInput.hover && props.theme.fileInput.hover.extend;
|
|
35
35
|
}, function (props) {
|
|
36
36
|
return props.dragOver && props.theme.fileInput && props.theme.fileInput.dragOver && props.theme.fileInput.dragOver.extend;
|
|
37
|
+
}, function (props) {
|
|
38
|
+
return props.focus && focusStyle();
|
|
39
|
+
}, function (props) {
|
|
40
|
+
return !props.focus && unfocusStyle();
|
|
37
41
|
});
|
|
38
42
|
var Label = styled(Text).withConfig({
|
|
39
43
|
displayName: "FileInput__Label",
|
|
@@ -79,6 +83,9 @@ var FileInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
79
83
|
var _React$useState2 = React.useState(),
|
|
80
84
|
dragOver = _React$useState2[0],
|
|
81
85
|
setDragOver = _React$useState2[1];
|
|
86
|
+
var _React$useState3 = React.useState(),
|
|
87
|
+
focus = _React$useState3[0],
|
|
88
|
+
setFocus = _React$useState3[1];
|
|
82
89
|
var _useState = useState(false),
|
|
83
90
|
showRemoveConfirmation = _useState[0],
|
|
84
91
|
setShowRemoveConfirmation = _useState[1];
|
|
@@ -92,6 +99,7 @@ var FileInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
92
99
|
var removeRef = useRef();
|
|
93
100
|
var ConfirmRemove = confirmRemove;
|
|
94
101
|
var RemoveIcon = theme.fileInput.icons.remove;
|
|
102
|
+
var usingKeyboard = useKeyboard();
|
|
95
103
|
var _formContext$useFormI = formContext.useFormInput({
|
|
96
104
|
name: name,
|
|
97
105
|
value: valueProp,
|
|
@@ -241,8 +249,54 @@ var FileInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
241
249
|
onMouseOut: disabled ? undefined : function () {
|
|
242
250
|
return setHover(false);
|
|
243
251
|
},
|
|
244
|
-
dragOver: dragOver
|
|
245
|
-
|
|
252
|
+
dragOver: dragOver,
|
|
253
|
+
focus: usingKeyboard && focus
|
|
254
|
+
}, /*#__PURE__*/React.createElement(StyledFileInput, _extends({
|
|
255
|
+
ref: inputRef,
|
|
256
|
+
type: "file",
|
|
257
|
+
id: id,
|
|
258
|
+
name: name,
|
|
259
|
+
maxSize: maxSize,
|
|
260
|
+
multiple: multiple,
|
|
261
|
+
disabled: disabled,
|
|
262
|
+
plain: true,
|
|
263
|
+
rightOffset: rightOffset
|
|
264
|
+
}, rest, {
|
|
265
|
+
onDragOver: function onDragOver() {
|
|
266
|
+
return setDragOver(true);
|
|
267
|
+
},
|
|
268
|
+
onDragLeave: function onDragLeave() {
|
|
269
|
+
return setDragOver(false);
|
|
270
|
+
},
|
|
271
|
+
onChange: function onChange(event) {
|
|
272
|
+
event.persist();
|
|
273
|
+
var fileList = event.target.files;
|
|
274
|
+
var nextFiles = multiple ? [].concat(files) : [];
|
|
275
|
+
var _loop = function _loop(i) {
|
|
276
|
+
// avoid duplicates
|
|
277
|
+
var existing = nextFiles.filter(function (file) {
|
|
278
|
+
return file.name === fileList[i].name && file.size === fileList[i].size;
|
|
279
|
+
}).length > 0;
|
|
280
|
+
if (!existing) {
|
|
281
|
+
nextFiles.push(fileList[i]);
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
for (var i = 0; i < fileList.length; i += 1) {
|
|
285
|
+
_loop(i);
|
|
286
|
+
}
|
|
287
|
+
setFiles(nextFiles);
|
|
288
|
+
setDragOver(false);
|
|
289
|
+
if (_onChange) _onChange(event, {
|
|
290
|
+
files: nextFiles
|
|
291
|
+
});
|
|
292
|
+
},
|
|
293
|
+
onBlur: function onBlur() {
|
|
294
|
+
return setFocus(false);
|
|
295
|
+
},
|
|
296
|
+
onFocus: function onFocus() {
|
|
297
|
+
return setFocus(true);
|
|
298
|
+
}
|
|
299
|
+
})), (!files.length || files.length > 1) && /*#__PURE__*/React.createElement(Box, {
|
|
246
300
|
align: "center",
|
|
247
301
|
fill: "horizontal",
|
|
248
302
|
direction: "row",
|
|
@@ -255,7 +309,10 @@ var FileInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
255
309
|
onEnter: function onEnter(event) {
|
|
256
310
|
if (controlRef.current === event.target) inputRef.current.click();
|
|
257
311
|
}
|
|
258
|
-
}, theme.fileInput.button ? /*#__PURE__*/React.createElement(Button
|
|
312
|
+
}, theme.fileInput.button ? /*#__PURE__*/React.createElement(Button
|
|
313
|
+
// The focus here is redundant for keyboard users
|
|
314
|
+
, {
|
|
315
|
+
tabIndex: -1,
|
|
259
316
|
ref: controlRef,
|
|
260
317
|
kind: theme.fileInput.button,
|
|
261
318
|
label: format({
|
|
@@ -266,8 +323,10 @@ var FileInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
266
323
|
inputRef.current.click();
|
|
267
324
|
inputRef.current.focus();
|
|
268
325
|
}
|
|
269
|
-
}) : /*#__PURE__*/React.createElement(Anchor
|
|
270
|
-
|
|
326
|
+
}) : /*#__PURE__*/React.createElement(Anchor
|
|
327
|
+
// The focus here is redundant for keyboard users
|
|
328
|
+
, {
|
|
329
|
+
tabIndex: -1,
|
|
271
330
|
alignSelf: "center",
|
|
272
331
|
ref: controlRef,
|
|
273
332
|
margin: "small",
|
|
@@ -315,7 +374,10 @@ var FileInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
315
374
|
onEnter: function onEnter(event) {
|
|
316
375
|
if (controlRef.current === event.target) inputRef.current.click();
|
|
317
376
|
}
|
|
318
|
-
}, theme.fileInput.button ? /*#__PURE__*/React.createElement(Button
|
|
377
|
+
}, theme.fileInput.button ? /*#__PURE__*/React.createElement(Button
|
|
378
|
+
// The focus here is redundant for keyboard users
|
|
379
|
+
, {
|
|
380
|
+
tabIndex: -1,
|
|
319
381
|
ref: controlRef,
|
|
320
382
|
kind: theme.fileInput.button,
|
|
321
383
|
label: format({
|
|
@@ -326,8 +388,10 @@ var FileInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
326
388
|
inputRef.current.click();
|
|
327
389
|
inputRef.current.focus();
|
|
328
390
|
}
|
|
329
|
-
}) : /*#__PURE__*/React.createElement(Anchor
|
|
330
|
-
|
|
391
|
+
}) : /*#__PURE__*/React.createElement(Anchor
|
|
392
|
+
// The focus here is redundant for keyboard users
|
|
393
|
+
, {
|
|
394
|
+
tabIndex: -1,
|
|
331
395
|
alignSelf: "center",
|
|
332
396
|
ref: controlRef,
|
|
333
397
|
margin: "small",
|
|
@@ -381,7 +445,10 @@ var FileInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
381
445
|
onEnter: function onEnter(event) {
|
|
382
446
|
if (controlRef.current === event.target) inputRef.current.click();
|
|
383
447
|
}
|
|
384
|
-
}, theme.fileInput.button ? /*#__PURE__*/React.createElement(Button
|
|
448
|
+
}, theme.fileInput.button ? /*#__PURE__*/React.createElement(Button
|
|
449
|
+
// The focus here is redundant for keyboard users
|
|
450
|
+
, {
|
|
451
|
+
tabIndex: -1,
|
|
385
452
|
ref: controlRef,
|
|
386
453
|
kind: theme.fileInput.button,
|
|
387
454
|
label: format({
|
|
@@ -392,8 +459,10 @@ var FileInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
392
459
|
inputRef.current.click();
|
|
393
460
|
inputRef.current.focus();
|
|
394
461
|
}
|
|
395
|
-
}) : /*#__PURE__*/React.createElement(Anchor
|
|
396
|
-
|
|
462
|
+
}) : /*#__PURE__*/React.createElement(Anchor
|
|
463
|
+
// The focus here is redundant for keyboard users
|
|
464
|
+
, {
|
|
465
|
+
tabIndex: -1,
|
|
397
466
|
ref: controlRef,
|
|
398
467
|
margin: "small",
|
|
399
468
|
onClick: function onClick() {
|
|
@@ -405,46 +474,7 @@ var FileInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
405
474
|
messages: messages
|
|
406
475
|
})
|
|
407
476
|
}))));
|
|
408
|
-
}), /*#__PURE__*/React.createElement(
|
|
409
|
-
ref: inputRef,
|
|
410
|
-
type: "file",
|
|
411
|
-
id: id,
|
|
412
|
-
name: name,
|
|
413
|
-
maxSize: maxSize,
|
|
414
|
-
multiple: multiple,
|
|
415
|
-
disabled: disabled,
|
|
416
|
-
plain: true,
|
|
417
|
-
rightOffset: rightOffset
|
|
418
|
-
}, rest, {
|
|
419
|
-
onDragOver: function onDragOver() {
|
|
420
|
-
return setDragOver(true);
|
|
421
|
-
},
|
|
422
|
-
onDragLeave: function onDragLeave() {
|
|
423
|
-
return setDragOver(false);
|
|
424
|
-
},
|
|
425
|
-
onChange: function onChange(event) {
|
|
426
|
-
event.persist();
|
|
427
|
-
var fileList = event.target.files;
|
|
428
|
-
var nextFiles = multiple ? [].concat(files) : [];
|
|
429
|
-
var _loop = function _loop(i) {
|
|
430
|
-
// avoid duplicates
|
|
431
|
-
var existing = nextFiles.filter(function (file) {
|
|
432
|
-
return file.name === fileList[i].name && file.size === fileList[i].size;
|
|
433
|
-
}).length > 0;
|
|
434
|
-
if (!existing) {
|
|
435
|
-
nextFiles.push(fileList[i]);
|
|
436
|
-
}
|
|
437
|
-
};
|
|
438
|
-
for (var i = 0; i < fileList.length; i += 1) {
|
|
439
|
-
_loop(i);
|
|
440
|
-
}
|
|
441
|
-
setFiles(nextFiles);
|
|
442
|
-
setDragOver(false);
|
|
443
|
-
if (_onChange) _onChange(event, {
|
|
444
|
-
files: nextFiles
|
|
445
|
-
});
|
|
446
|
-
}
|
|
447
|
-
}))), showRemoveConfirmation && /*#__PURE__*/React.createElement(ConfirmRemove, {
|
|
477
|
+
})), showRemoveConfirmation && /*#__PURE__*/React.createElement(ConfirmRemove, {
|
|
448
478
|
onConfirm: function onConfirm() {
|
|
449
479
|
removeFile(pendingRemoval.index);
|
|
450
480
|
setPendingRemoval(defaultPendingRemoval);
|
|
@@ -129,11 +129,13 @@ var validateForm = function validateForm(validationRules, formValue, format, mes
|
|
|
129
129
|
var name = _ref[0],
|
|
130
130
|
_ref$ = _ref[1],
|
|
131
131
|
field = _ref$.field,
|
|
132
|
-
input = _ref$.input
|
|
132
|
+
input = _ref$.input,
|
|
133
|
+
validateOn = _ref$.validateOn;
|
|
133
134
|
if (!omitValid) {
|
|
134
135
|
nextErrors[name] = undefined;
|
|
135
136
|
nextInfos[name] = undefined;
|
|
136
137
|
}
|
|
138
|
+
if (!validateOn) return;
|
|
137
139
|
var result;
|
|
138
140
|
if (input) {
|
|
139
141
|
// input() a validation function supplied through useFormInput()
|
|
@@ -157,6 +159,9 @@ var validateForm = function validateForm(validationRules, formValue, format, mes
|
|
|
157
159
|
});
|
|
158
160
|
return [nextErrors, nextInfos];
|
|
159
161
|
};
|
|
162
|
+
var isInstantValidate = function isInstantValidate(validateOn) {
|
|
163
|
+
return ['blur', 'change'].includes(validateOn);
|
|
164
|
+
};
|
|
160
165
|
var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
161
166
|
var children = _ref2.children,
|
|
162
167
|
_ref2$errors = _ref2.errors,
|
|
@@ -170,7 +175,7 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
170
175
|
_onSubmit = _ref2.onSubmit,
|
|
171
176
|
onValidate = _ref2.onValidate,
|
|
172
177
|
_ref2$validate = _ref2.validate,
|
|
173
|
-
|
|
178
|
+
validateOnProp = _ref2$validate === void 0 ? 'submit' : _ref2$validate,
|
|
174
179
|
valueProp = _ref2.value,
|
|
175
180
|
rest = _objectWithoutPropertiesLoose(_ref2, _excluded);
|
|
176
181
|
var formRef = useForwardedRef(ref);
|
|
@@ -185,12 +190,15 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
185
190
|
var _useState2 = useState(defaultTouched),
|
|
186
191
|
touched = _useState2[0],
|
|
187
192
|
setTouched = _useState2[1];
|
|
188
|
-
var _useState3 = useState(
|
|
193
|
+
var _useState3 = useState(validateOnProp),
|
|
194
|
+
validateOn = _useState3[0],
|
|
195
|
+
setValidateOn = _useState3[1];
|
|
196
|
+
var _useState4 = useState({
|
|
189
197
|
errors: errorsProp,
|
|
190
198
|
infos: infosProp
|
|
191
199
|
}),
|
|
192
|
-
validationResults =
|
|
193
|
-
setValidationResults =
|
|
200
|
+
validationResults = _useState4[0],
|
|
201
|
+
setValidationResults = _useState4[1];
|
|
194
202
|
// maintain a copy of validationResults in a ref for useEffects
|
|
195
203
|
// which can't depend on validationResults directly without
|
|
196
204
|
// causing infinite renders.
|
|
@@ -198,16 +206,16 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
198
206
|
// Simulated onMount state. Consider Form to be mounted once it has
|
|
199
207
|
// accounted for values originating from controlled inputs (available
|
|
200
208
|
// at second rendering).
|
|
201
|
-
var
|
|
202
|
-
mounted =
|
|
203
|
-
setMounted =
|
|
209
|
+
var _useState5 = useState('unmounted'),
|
|
210
|
+
mounted = _useState5[0],
|
|
211
|
+
setMounted = _useState5[1];
|
|
204
212
|
useEffect(function () {
|
|
205
213
|
if (!mounted) setMounted('mounting');else if (mounted === 'mounting') setMounted('mounted');
|
|
206
214
|
}, [mounted]);
|
|
207
215
|
// `pendingValidation` is the name of the FormField awaiting validation.
|
|
208
|
-
var
|
|
209
|
-
pendingValidation =
|
|
210
|
-
setPendingValidation =
|
|
216
|
+
var _useState6 = useState(undefined),
|
|
217
|
+
pendingValidation = _useState6[0],
|
|
218
|
+
setPendingValidation = _useState6[1];
|
|
211
219
|
var validationRulesRef = useRef({});
|
|
212
220
|
var requiredFields = useRef([]);
|
|
213
221
|
var analyticsRef = useRef({
|
|
@@ -279,16 +287,20 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
279
287
|
var validationRules = Object.entries(validationRulesRef.current);
|
|
280
288
|
// Use simulated onMount state to account for values provided by
|
|
281
289
|
// controlled inputs.
|
|
282
|
-
if (mounted !== 'mounted' &&
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
290
|
+
if (mounted !== 'mounted' && (isInstantValidate(validateOn) || validationRules.some(function (_ref3) {
|
|
291
|
+
var v = _ref3[1];
|
|
292
|
+
return isInstantValidate(v.validateOn);
|
|
293
|
+
})) && Object.keys(value).length > 0 && Object.keys(touched).length === 0) {
|
|
294
|
+
applyValidationRules(validationRules.filter(function (_ref4) {
|
|
295
|
+
var n = _ref4[0],
|
|
296
|
+
v = _ref4[1];
|
|
297
|
+
return getFieldValue(n, value) && v.validateOn;
|
|
286
298
|
})
|
|
287
299
|
// Exlude empty arrays which may be initial values in
|
|
288
300
|
// an input such as DateInput.
|
|
289
|
-
.filter(function (
|
|
290
|
-
var n =
|
|
291
|
-
return !(Array.isArray(value
|
|
301
|
+
.filter(function (_ref5) {
|
|
302
|
+
var n = _ref5[0];
|
|
303
|
+
return !(Array.isArray(getFieldValue(n, value)) && getFieldValue(n, value).length === 0);
|
|
292
304
|
}));
|
|
293
305
|
}
|
|
294
306
|
}, [applyValidationRules, mounted, touched, validateOn, value]);
|
|
@@ -298,10 +310,14 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
298
310
|
useEffect(function () {
|
|
299
311
|
var validationRules = Object.entries(validationRulesRef.current);
|
|
300
312
|
var timer = setTimeout(function () {
|
|
301
|
-
if (pendingValidation &&
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
313
|
+
if (pendingValidation && (isInstantValidate(validateOn) || validationRules.some(function (_ref6) {
|
|
314
|
+
var v = _ref6[1];
|
|
315
|
+
return isInstantValidate(v.validateOn);
|
|
316
|
+
}))) {
|
|
317
|
+
applyValidationRules(validationRules.filter(function (_ref7) {
|
|
318
|
+
var n = _ref7[0],
|
|
319
|
+
v = _ref7[1];
|
|
320
|
+
return (touched[n] || pendingValidation.includes(n)) && v.validateOn;
|
|
305
321
|
}));
|
|
306
322
|
setPendingValidation(undefined);
|
|
307
323
|
}
|
|
@@ -323,8 +339,8 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
323
339
|
var _validationResultsRef2;
|
|
324
340
|
var validationRules = Object.entries(validationRulesRef.current);
|
|
325
341
|
if ((_validationResultsRef2 = validationResultsRef.current) != null && _validationResultsRef2.errors && Object.keys(validationResultsRef.current.errors).length > 0) {
|
|
326
|
-
applyValidationRules(validationRules.filter(function (
|
|
327
|
-
var n =
|
|
342
|
+
applyValidationRules(validationRules.filter(function (_ref8) {
|
|
343
|
+
var n = _ref8[0];
|
|
328
344
|
return touched[n] && validationResultsRef.current.errors[n];
|
|
329
345
|
}));
|
|
330
346
|
}
|
|
@@ -384,14 +400,14 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
384
400
|
// they can have access to it.
|
|
385
401
|
//
|
|
386
402
|
var formContextValue = useMemo(function () {
|
|
387
|
-
var useFormInput = function useFormInput(
|
|
388
|
-
var name =
|
|
389
|
-
componentValue =
|
|
390
|
-
initialValue =
|
|
391
|
-
validateArg =
|
|
392
|
-
var
|
|
393
|
-
inputValue =
|
|
394
|
-
setInputValue =
|
|
403
|
+
var useFormInput = function useFormInput(_ref9) {
|
|
404
|
+
var name = _ref9.name,
|
|
405
|
+
componentValue = _ref9.value,
|
|
406
|
+
initialValue = _ref9.initialValue,
|
|
407
|
+
validateArg = _ref9.validate;
|
|
408
|
+
var _useState7 = useState(initialValue),
|
|
409
|
+
inputValue = _useState7[0],
|
|
410
|
+
setInputValue = _useState7[1];
|
|
395
411
|
var formValue = name ? getFieldValue(name, value) : undefined;
|
|
396
412
|
// for dynamic forms, we need to track when an input has been added to
|
|
397
413
|
// the form value. if the input is unmounted, we will delete its
|
|
@@ -483,15 +499,26 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
483
499
|
if (initialValue !== undefined) setInputValue(nextComponentValue);
|
|
484
500
|
}];
|
|
485
501
|
};
|
|
486
|
-
var useFormField = function useFormField(
|
|
487
|
-
var errorArg =
|
|
488
|
-
infoArg =
|
|
489
|
-
name =
|
|
490
|
-
required =
|
|
491
|
-
disabled =
|
|
492
|
-
validateArg =
|
|
502
|
+
var useFormField = function useFormField(_ref10) {
|
|
503
|
+
var errorArg = _ref10.error,
|
|
504
|
+
infoArg = _ref10.info,
|
|
505
|
+
name = _ref10.name,
|
|
506
|
+
required = _ref10.required,
|
|
507
|
+
disabled = _ref10.disabled,
|
|
508
|
+
validateArg = _ref10.validate,
|
|
509
|
+
validateOnArg = _ref10.validateOn;
|
|
493
510
|
var error = disabled ? undefined : errorArg || validationResults.errors[name];
|
|
494
511
|
var info = infoArg || validationResults.infos[name];
|
|
512
|
+
useEffect(function () {
|
|
513
|
+
setValidateOn(function (prevValues) {
|
|
514
|
+
var _extends2;
|
|
515
|
+
if (typeof prevValues === 'string') {
|
|
516
|
+
var _ref11;
|
|
517
|
+
return _ref11 = {}, _ref11[name] = validateOnArg || validateOnProp, _ref11;
|
|
518
|
+
}
|
|
519
|
+
return _extends({}, prevValues, (_extends2 = {}, _extends2[name] = validateOnArg || validateOnProp, _extends2));
|
|
520
|
+
});
|
|
521
|
+
}, [validateOnArg, name]);
|
|
495
522
|
|
|
496
523
|
// Create validation rules for field
|
|
497
524
|
useEffect(function () {
|
|
@@ -504,8 +531,21 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
504
531
|
validationRulesRef.current[name] = {};
|
|
505
532
|
}
|
|
506
533
|
validationRulesRef.current[name].field = validateName(validateArg, required);
|
|
534
|
+
|
|
535
|
+
// priority is given to validateOn prop on formField, if it is
|
|
536
|
+
// undefined, then we will use the validate prop value of Form.
|
|
537
|
+
// The reason we don't want to add validateOn = "submit" here is
|
|
538
|
+
// because we don't want to trigger validation of "submit" field
|
|
539
|
+
// when the user is typing in the instant (blur, change)
|
|
540
|
+
// validation fields.
|
|
541
|
+
if (validateOnArg && validateOnArg !== 'submit') {
|
|
542
|
+
validationRulesRef.current[name].validateOn = validateOnArg;
|
|
543
|
+
} else if (!validateOnArg && validateOnProp !== 'submit') {
|
|
544
|
+
validationRulesRef.current[name].validateOn = validateOnProp;
|
|
545
|
+
}
|
|
507
546
|
return function () {
|
|
508
547
|
delete validationRulesRef.current[name].field;
|
|
548
|
+
delete validationRulesRef.current[name].validateOn;
|
|
509
549
|
var requiredFieldIndex = requiredFields.current.indexOf(name);
|
|
510
550
|
if (requiredFieldIndex !== -1) {
|
|
511
551
|
requiredFields.current.splice(requiredFieldIndex, 1);
|
|
@@ -513,15 +553,15 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
513
553
|
};
|
|
514
554
|
}
|
|
515
555
|
return undefined;
|
|
516
|
-
}, [error, name, required, validateArg, disabled]);
|
|
556
|
+
}, [error, name, required, validateArg, disabled, validateOnArg]);
|
|
517
557
|
return {
|
|
518
558
|
error: error,
|
|
519
559
|
info: info,
|
|
520
560
|
inForm: true,
|
|
521
|
-
onBlur: validateOn === 'blur' ? function () {
|
|
561
|
+
onBlur: validateOnArg === 'blur' || validateOn[name] === 'blur' ? function () {
|
|
522
562
|
return setPendingValidation(pendingValidation ? [].concat(pendingValidation, [name]) : [name]);
|
|
523
563
|
} : undefined,
|
|
524
|
-
onChange: validateOn === 'change' ? function () {
|
|
564
|
+
onChange: validateOnArg === 'change' || validateOn[name] === 'change' ? function () {
|
|
525
565
|
return setPendingValidation(pendingValidation ? [].concat(pendingValidation, [name]) : [name]);
|
|
526
566
|
} : undefined
|
|
527
567
|
};
|
|
@@ -531,7 +571,7 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
531
571
|
useFormInput: useFormInput,
|
|
532
572
|
kind: kind
|
|
533
573
|
};
|
|
534
|
-
}, [onChange, kind, pendingValidation, touched, validateOn, validationResults.errors, validationResults.infos, value, valueProp]);
|
|
574
|
+
}, [onChange, kind, pendingValidation, touched, validateOn, validationResults.errors, validationResults.infos, value, valueProp, validateOnProp]);
|
|
535
575
|
return /*#__PURE__*/React.createElement("form", _extends({
|
|
536
576
|
ref: formRef
|
|
537
577
|
}, rest, {
|
|
@@ -569,7 +609,18 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
569
609
|
// otherwise.
|
|
570
610
|
event.preventDefault();
|
|
571
611
|
setPendingValidation(undefined);
|
|
572
|
-
|
|
612
|
+
// adding validateOn: "submit" prop to the undefined validateOn fields
|
|
613
|
+
// as we want to trigger "submit" validation once form is submitted
|
|
614
|
+
var newValidationRulesRef = Object.keys(validationRulesRef.current).reduce(function (acc, key) {
|
|
615
|
+
acc[key] = validationRulesRef.current[key];
|
|
616
|
+
if (!acc[key].validateOn) {
|
|
617
|
+
acc[key] = _extends({}, validationRulesRef.current[key], {
|
|
618
|
+
validateOn: 'submit'
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
return acc;
|
|
622
|
+
}, {});
|
|
623
|
+
var _validateForm2 = validateForm(Object.entries(newValidationRulesRef), value, format, messages, true),
|
|
573
624
|
nextErrors = _validateForm2[0],
|
|
574
625
|
nextInfos = _validateForm2[1];
|
|
575
626
|
setValidationResults(function () {
|