grommet 2.31.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/Box/Box.js +14 -4
- package/components/Box/stories/Border.js +15 -1
- package/components/Button/BusyAnimation.js +51 -0
- package/components/Button/Button.js +64 -4
- package/components/Button/StyledButton.js +4 -2
- package/components/Button/StyledButtonKind.js +8 -4
- package/components/Button/index.d.ts +7 -0
- package/components/Button/propTypes.js +6 -0
- package/components/Button/stories/Busy.js +45 -0
- package/components/Calendar/stories/Dual.js +4 -6
- package/components/Data/DataForm.js +6 -2
- 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/DateInput/DateInput.js +1 -1
- 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 -2
- 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/NameValueList/NameValueList.js +1 -1
- package/components/SelectMultiple/SelectMultiple.js +13 -10
- package/components/SelectMultiple/SelectMultipleValue.js +1 -1
- 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/Box/Box.js +14 -4
- package/es6/components/Box/stories/Border.js +15 -1
- package/es6/components/Button/BusyAnimation.js +41 -0
- package/es6/components/Button/Button.js +64 -5
- package/es6/components/Button/StyledButton.js +4 -2
- package/es6/components/Button/StyledButtonKind.js +8 -4
- package/es6/components/Button/index.d.ts +7 -0
- package/es6/components/Button/propTypes.js +6 -0
- package/es6/components/Button/stories/Busy.js +37 -0
- package/es6/components/Calendar/stories/Dual.js +4 -6
- package/es6/components/Data/DataForm.js +4 -1
- 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/DateInput/DateInput.js +1 -1
- 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 -2
- 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/NameValueList/NameValueList.js +1 -1
- package/es6/components/SelectMultiple/SelectMultiple.js +13 -10
- package/es6/components/SelectMultiple/SelectMultipleValue.js +1 -1
- 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.js +1 -1
- 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 +37 -36
- package/themes/base.js +1 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { BoxProps } from '../Box/index';
|
|
3
|
+
|
|
4
|
+
export interface DataTableGroupByProps {
|
|
5
|
+
options: string[] | { label: string; property: string }[];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
type selectProps = Omit<
|
|
9
|
+
JSX.IntrinsicElements['select'],
|
|
10
|
+
'onClick' | 'property'
|
|
11
|
+
>;
|
|
12
|
+
|
|
13
|
+
export interface DataTableGroupByExtendedProps
|
|
14
|
+
extends BoxProps,
|
|
15
|
+
DataTableGroupByProps,
|
|
16
|
+
selectProps {}
|
|
17
|
+
|
|
18
|
+
declare const DataTableGroupBy: React.FC<DataTableGroupByExtendedProps>;
|
|
19
|
+
|
|
20
|
+
export { DataTableGroupBy };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.DataTableGroupByPropTypes = void 0;
|
|
5
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
6
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
7
|
+
var PropType = {};
|
|
8
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
9
|
+
PropType = {
|
|
10
|
+
options: _propTypes["default"].oneOfType([_propTypes["default"].arrayOf(_propTypes["default"].string), _propTypes["default"].arrayOf(_propTypes["default"].shape({
|
|
11
|
+
label: _propTypes["default"].string,
|
|
12
|
+
property: _propTypes["default"].string
|
|
13
|
+
}))])
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
var DataTableGroupByPropTypes = PropType;
|
|
17
|
+
exports.DataTableGroupByPropTypes = DataTableGroupByPropTypes;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports["default"] = exports.Simple = void 0;
|
|
5
|
+
var _react = _interopRequireDefault(require("react"));
|
|
6
|
+
var _grommet = require("grommet");
|
|
7
|
+
var _DataTableGroupBy = require("../DataTableGroupBy");
|
|
8
|
+
var _data = require("../../DataTable/stories/data");
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
10
|
+
// simplify option label for name property
|
|
11
|
+
var options = _data.columns.filter(function (_ref) {
|
|
12
|
+
var property = _ref.property;
|
|
13
|
+
return ['location', 'percent'].includes(property);
|
|
14
|
+
}).map(function (_ref2) {
|
|
15
|
+
var header = _ref2.header,
|
|
16
|
+
property = _ref2.property;
|
|
17
|
+
return {
|
|
18
|
+
property: property,
|
|
19
|
+
label: header
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
var Simple = function Simple() {
|
|
23
|
+
return (
|
|
24
|
+
/*#__PURE__*/
|
|
25
|
+
// Uncomment <Grommet> lines when using outside of storybook
|
|
26
|
+
// <Grommet theme={...}>
|
|
27
|
+
_react["default"].createElement(_grommet.Box, {
|
|
28
|
+
align: "center",
|
|
29
|
+
justify: "start",
|
|
30
|
+
pad: "large",
|
|
31
|
+
gap: "medium"
|
|
32
|
+
}, /*#__PURE__*/_react["default"].createElement(_grommet.Notification, {
|
|
33
|
+
status: "info",
|
|
34
|
+
message: "Data is in 'beta'. The API surface is subject to change."
|
|
35
|
+
}), /*#__PURE__*/_react["default"].createElement(_grommet.Data, {
|
|
36
|
+
data: _data.DATA
|
|
37
|
+
}, /*#__PURE__*/_react["default"].createElement(_grommet.Toolbar, null, /*#__PURE__*/_react["default"].createElement(_DataTableGroupBy.DataTableGroupBy, {
|
|
38
|
+
options: options
|
|
39
|
+
})), /*#__PURE__*/_react["default"].createElement(_grommet.DataTable, null)))
|
|
40
|
+
// </Grommet>
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
exports.Simple = Simple;
|
|
44
|
+
Simple.args = {
|
|
45
|
+
full: true
|
|
46
|
+
};
|
|
47
|
+
var _default = {
|
|
48
|
+
title: 'Data/DataTableGroupBy/Simple'
|
|
49
|
+
};
|
|
50
|
+
exports["default"] = _default;
|
|
@@ -180,7 +180,7 @@ var DateInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, refArg) {
|
|
|
180
180
|
if (range && Array.isArray(nextValue)) {
|
|
181
181
|
normalizedValue = nextValue[0];
|
|
182
182
|
} // clicking an edge date removes it
|
|
183
|
-
else if (range) normalizedValue = [nextValue, nextValue];else normalizedValue = nextValue;
|
|
183
|
+
else if (range && nextValue) normalizedValue = [nextValue, nextValue];else normalizedValue = nextValue;
|
|
184
184
|
if (schema) setTextValue((0, _utils2.valueToText)(normalizedValue, schema));
|
|
185
185
|
setValue(normalizedValue);
|
|
186
186
|
setReference(getReference(nextValue));
|
|
@@ -65,8 +65,8 @@ var DropContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
65
65
|
var onClickDocument = function onClickDocument(event) {
|
|
66
66
|
// determine which portal id the target is in, if any
|
|
67
67
|
var clickedPortalId = null;
|
|
68
|
-
var node =
|
|
69
|
-
while (clickedPortalId === null && node !== document) {
|
|
68
|
+
var node = event.composed && event.composedPath()[0] || event.target;
|
|
69
|
+
while (clickedPortalId === null && node && node !== document && !(node instanceof ShadowRoot)) {
|
|
70
70
|
var attr = node.getAttribute('data-g-portal-id');
|
|
71
71
|
if (attr !== null) clickedPortalId = parseInt(attr, 10);
|
|
72
72
|
node = node.parentNode;
|
|
@@ -44,8 +44,8 @@ var DropButton = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
44
44
|
var onDropClose = (0, _react.useCallback)(function (event) {
|
|
45
45
|
// if the user has clicked on our Button, don't do anything here,
|
|
46
46
|
// handle that in onClickInternal() below.
|
|
47
|
-
var node = event.target;
|
|
48
|
-
while (node !== document && node !== buttonRef.current) {
|
|
47
|
+
var node = event.composed && event.composedPath()[0] || event.target;
|
|
48
|
+
while (node && node !== document && !(node instanceof ShadowRoot) && node !== buttonRef.current) {
|
|
49
49
|
node = node.parentNode;
|
|
50
50
|
}
|
|
51
51
|
if (node !== buttonRef.current) {
|
|
@@ -28,11 +28,10 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
|
|
|
28
28
|
// If there are any files selected, we need to show the buttons to remove them.
|
|
29
29
|
// So, we offset the <input /> from the right by the appropriate width.
|
|
30
30
|
// We don't use Stack because of how we need to control the positioning.
|
|
31
|
-
|
|
32
31
|
var ContentsBox = (0, _styledComponents["default"])(_Box.Box).withConfig({
|
|
33
32
|
displayName: "FileInput__ContentsBox",
|
|
34
33
|
componentId: "sc-1jzq7im-0"
|
|
35
|
-
})(["cursor:pointer;position:relative;", " ", ";", ";", ";"], function (props) {
|
|
34
|
+
})(["cursor:pointer;position:relative;", " ", ";", ";", ";", ";", ";"], function (props) {
|
|
36
35
|
return props.disabled && (0, _utils.disabledStyle)();
|
|
37
36
|
}, function (props) {
|
|
38
37
|
return props.theme.fileInput && props.theme.fileInput.extend;
|
|
@@ -40,6 +39,10 @@ var ContentsBox = (0, _styledComponents["default"])(_Box.Box).withConfig({
|
|
|
40
39
|
return props.hover && props.theme.fileInput && props.theme.fileInput.hover && props.theme.fileInput.hover.extend;
|
|
41
40
|
}, function (props) {
|
|
42
41
|
return props.dragOver && props.theme.fileInput && props.theme.fileInput.dragOver && props.theme.fileInput.dragOver.extend;
|
|
42
|
+
}, function (props) {
|
|
43
|
+
return props.focus && (0, _utils.focusStyle)();
|
|
44
|
+
}, function (props) {
|
|
45
|
+
return !props.focus && (0, _utils.unfocusStyle)();
|
|
43
46
|
});
|
|
44
47
|
var Label = (0, _styledComponents["default"])(_Text.Text).withConfig({
|
|
45
48
|
displayName: "FileInput__Label",
|
|
@@ -85,6 +88,9 @@ var FileInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
85
88
|
var _React$useState2 = _react["default"].useState(),
|
|
86
89
|
dragOver = _React$useState2[0],
|
|
87
90
|
setDragOver = _React$useState2[1];
|
|
91
|
+
var _React$useState3 = _react["default"].useState(),
|
|
92
|
+
focus = _React$useState3[0],
|
|
93
|
+
setFocus = _React$useState3[1];
|
|
88
94
|
var _useState = (0, _react.useState)(false),
|
|
89
95
|
showRemoveConfirmation = _useState[0],
|
|
90
96
|
setShowRemoveConfirmation = _useState[1];
|
|
@@ -98,6 +104,7 @@ var FileInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
98
104
|
var removeRef = (0, _react.useRef)();
|
|
99
105
|
var ConfirmRemove = confirmRemove;
|
|
100
106
|
var RemoveIcon = theme.fileInput.icons.remove;
|
|
107
|
+
var usingKeyboard = (0, _utils.useKeyboard)();
|
|
101
108
|
var _formContext$useFormI = formContext.useFormInput({
|
|
102
109
|
name: name,
|
|
103
110
|
value: valueProp,
|
|
@@ -247,8 +254,54 @@ var FileInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
247
254
|
onMouseOut: disabled ? undefined : function () {
|
|
248
255
|
return setHover(false);
|
|
249
256
|
},
|
|
250
|
-
dragOver: dragOver
|
|
251
|
-
|
|
257
|
+
dragOver: dragOver,
|
|
258
|
+
focus: usingKeyboard && focus
|
|
259
|
+
}, /*#__PURE__*/_react["default"].createElement(_StyledFileInput.StyledFileInput, _extends({
|
|
260
|
+
ref: inputRef,
|
|
261
|
+
type: "file",
|
|
262
|
+
id: id,
|
|
263
|
+
name: name,
|
|
264
|
+
maxSize: maxSize,
|
|
265
|
+
multiple: multiple,
|
|
266
|
+
disabled: disabled,
|
|
267
|
+
plain: true,
|
|
268
|
+
rightOffset: rightOffset
|
|
269
|
+
}, rest, {
|
|
270
|
+
onDragOver: function onDragOver() {
|
|
271
|
+
return setDragOver(true);
|
|
272
|
+
},
|
|
273
|
+
onDragLeave: function onDragLeave() {
|
|
274
|
+
return setDragOver(false);
|
|
275
|
+
},
|
|
276
|
+
onChange: function onChange(event) {
|
|
277
|
+
event.persist();
|
|
278
|
+
var fileList = event.target.files;
|
|
279
|
+
var nextFiles = multiple ? [].concat(files) : [];
|
|
280
|
+
var _loop = function _loop(i) {
|
|
281
|
+
// avoid duplicates
|
|
282
|
+
var existing = nextFiles.filter(function (file) {
|
|
283
|
+
return file.name === fileList[i].name && file.size === fileList[i].size;
|
|
284
|
+
}).length > 0;
|
|
285
|
+
if (!existing) {
|
|
286
|
+
nextFiles.push(fileList[i]);
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
for (var i = 0; i < fileList.length; i += 1) {
|
|
290
|
+
_loop(i);
|
|
291
|
+
}
|
|
292
|
+
setFiles(nextFiles);
|
|
293
|
+
setDragOver(false);
|
|
294
|
+
if (_onChange) _onChange(event, {
|
|
295
|
+
files: nextFiles
|
|
296
|
+
});
|
|
297
|
+
},
|
|
298
|
+
onBlur: function onBlur() {
|
|
299
|
+
return setFocus(false);
|
|
300
|
+
},
|
|
301
|
+
onFocus: function onFocus() {
|
|
302
|
+
return setFocus(true);
|
|
303
|
+
}
|
|
304
|
+
})), (!files.length || files.length > 1) && /*#__PURE__*/_react["default"].createElement(_Box.Box, {
|
|
252
305
|
align: "center",
|
|
253
306
|
fill: "horizontal",
|
|
254
307
|
direction: "row",
|
|
@@ -261,7 +314,10 @@ var FileInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
261
314
|
onEnter: function onEnter(event) {
|
|
262
315
|
if (controlRef.current === event.target) inputRef.current.click();
|
|
263
316
|
}
|
|
264
|
-
}, theme.fileInput.button ? /*#__PURE__*/_react["default"].createElement(_Button.Button
|
|
317
|
+
}, theme.fileInput.button ? /*#__PURE__*/_react["default"].createElement(_Button.Button
|
|
318
|
+
// The focus here is redundant for keyboard users
|
|
319
|
+
, {
|
|
320
|
+
tabIndex: -1,
|
|
265
321
|
ref: controlRef,
|
|
266
322
|
kind: theme.fileInput.button,
|
|
267
323
|
label: format({
|
|
@@ -272,8 +328,10 @@ var FileInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
272
328
|
inputRef.current.click();
|
|
273
329
|
inputRef.current.focus();
|
|
274
330
|
}
|
|
275
|
-
}) : /*#__PURE__*/_react["default"].createElement(_Anchor.Anchor
|
|
276
|
-
|
|
331
|
+
}) : /*#__PURE__*/_react["default"].createElement(_Anchor.Anchor
|
|
332
|
+
// The focus here is redundant for keyboard users
|
|
333
|
+
, {
|
|
334
|
+
tabIndex: -1,
|
|
277
335
|
alignSelf: "center",
|
|
278
336
|
ref: controlRef,
|
|
279
337
|
margin: "small",
|
|
@@ -321,7 +379,10 @@ var FileInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
321
379
|
onEnter: function onEnter(event) {
|
|
322
380
|
if (controlRef.current === event.target) inputRef.current.click();
|
|
323
381
|
}
|
|
324
|
-
}, theme.fileInput.button ? /*#__PURE__*/_react["default"].createElement(_Button.Button
|
|
382
|
+
}, theme.fileInput.button ? /*#__PURE__*/_react["default"].createElement(_Button.Button
|
|
383
|
+
// The focus here is redundant for keyboard users
|
|
384
|
+
, {
|
|
385
|
+
tabIndex: -1,
|
|
325
386
|
ref: controlRef,
|
|
326
387
|
kind: theme.fileInput.button,
|
|
327
388
|
label: format({
|
|
@@ -332,8 +393,10 @@ var FileInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
332
393
|
inputRef.current.click();
|
|
333
394
|
inputRef.current.focus();
|
|
334
395
|
}
|
|
335
|
-
}) : /*#__PURE__*/_react["default"].createElement(_Anchor.Anchor
|
|
336
|
-
|
|
396
|
+
}) : /*#__PURE__*/_react["default"].createElement(_Anchor.Anchor
|
|
397
|
+
// The focus here is redundant for keyboard users
|
|
398
|
+
, {
|
|
399
|
+
tabIndex: -1,
|
|
337
400
|
alignSelf: "center",
|
|
338
401
|
ref: controlRef,
|
|
339
402
|
margin: "small",
|
|
@@ -387,7 +450,10 @@ var FileInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
387
450
|
onEnter: function onEnter(event) {
|
|
388
451
|
if (controlRef.current === event.target) inputRef.current.click();
|
|
389
452
|
}
|
|
390
|
-
}, theme.fileInput.button ? /*#__PURE__*/_react["default"].createElement(_Button.Button
|
|
453
|
+
}, theme.fileInput.button ? /*#__PURE__*/_react["default"].createElement(_Button.Button
|
|
454
|
+
// The focus here is redundant for keyboard users
|
|
455
|
+
, {
|
|
456
|
+
tabIndex: -1,
|
|
391
457
|
ref: controlRef,
|
|
392
458
|
kind: theme.fileInput.button,
|
|
393
459
|
label: format({
|
|
@@ -398,8 +464,10 @@ var FileInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
398
464
|
inputRef.current.click();
|
|
399
465
|
inputRef.current.focus();
|
|
400
466
|
}
|
|
401
|
-
}) : /*#__PURE__*/_react["default"].createElement(_Anchor.Anchor
|
|
402
|
-
|
|
467
|
+
}) : /*#__PURE__*/_react["default"].createElement(_Anchor.Anchor
|
|
468
|
+
// The focus here is redundant for keyboard users
|
|
469
|
+
, {
|
|
470
|
+
tabIndex: -1,
|
|
403
471
|
ref: controlRef,
|
|
404
472
|
margin: "small",
|
|
405
473
|
onClick: function onClick() {
|
|
@@ -411,46 +479,7 @@ var FileInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
411
479
|
messages: messages
|
|
412
480
|
})
|
|
413
481
|
}))));
|
|
414
|
-
}), /*#__PURE__*/_react["default"].createElement(
|
|
415
|
-
ref: inputRef,
|
|
416
|
-
type: "file",
|
|
417
|
-
id: id,
|
|
418
|
-
name: name,
|
|
419
|
-
maxSize: maxSize,
|
|
420
|
-
multiple: multiple,
|
|
421
|
-
disabled: disabled,
|
|
422
|
-
plain: true,
|
|
423
|
-
rightOffset: rightOffset
|
|
424
|
-
}, rest, {
|
|
425
|
-
onDragOver: function onDragOver() {
|
|
426
|
-
return setDragOver(true);
|
|
427
|
-
},
|
|
428
|
-
onDragLeave: function onDragLeave() {
|
|
429
|
-
return setDragOver(false);
|
|
430
|
-
},
|
|
431
|
-
onChange: function onChange(event) {
|
|
432
|
-
event.persist();
|
|
433
|
-
var fileList = event.target.files;
|
|
434
|
-
var nextFiles = multiple ? [].concat(files) : [];
|
|
435
|
-
var _loop = function _loop(i) {
|
|
436
|
-
// avoid duplicates
|
|
437
|
-
var existing = nextFiles.filter(function (file) {
|
|
438
|
-
return file.name === fileList[i].name && file.size === fileList[i].size;
|
|
439
|
-
}).length > 0;
|
|
440
|
-
if (!existing) {
|
|
441
|
-
nextFiles.push(fileList[i]);
|
|
442
|
-
}
|
|
443
|
-
};
|
|
444
|
-
for (var i = 0; i < fileList.length; i += 1) {
|
|
445
|
-
_loop(i);
|
|
446
|
-
}
|
|
447
|
-
setFiles(nextFiles);
|
|
448
|
-
setDragOver(false);
|
|
449
|
-
if (_onChange) _onChange(event, {
|
|
450
|
-
files: nextFiles
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
}))), showRemoveConfirmation && /*#__PURE__*/_react["default"].createElement(ConfirmRemove, {
|
|
482
|
+
})), showRemoveConfirmation && /*#__PURE__*/_react["default"].createElement(ConfirmRemove, {
|
|
454
483
|
onConfirm: function onConfirm() {
|
|
455
484
|
removeFile(pendingRemoval.index);
|
|
456
485
|
setPendingRemoval(defaultPendingRemoval);
|
package/components/Form/Form.js
CHANGED
|
@@ -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
|
-
|
|
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 =
|
|
199
|
-
setValidationResults =
|
|
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
|
|
208
|
-
mounted =
|
|
209
|
-
setMounted =
|
|
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
|
|
215
|
-
pendingValidation =
|
|
216
|
-
setPendingValidation =
|
|
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' &&
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
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 (
|
|
296
|
-
var n =
|
|
297
|
-
return !(Array.isArray(value
|
|
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 &&
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
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 (
|
|
333
|
-
var n =
|
|
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(
|
|
394
|
-
var name =
|
|
395
|
-
componentValue =
|
|
396
|
-
initialValue =
|
|
397
|
-
validateArg =
|
|
398
|
-
var
|
|
399
|
-
inputValue =
|
|
400
|
-
setInputValue =
|
|
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(
|
|
493
|
-
var errorArg =
|
|
494
|
-
infoArg =
|
|
495
|
-
name =
|
|
496
|
-
required =
|
|
497
|
-
disabled =
|
|
498
|
-
validateArg =
|
|
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
|
-
|
|
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 () {
|