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
|
@@ -56,8 +56,8 @@ var Row = /*#__PURE__*/memo(function (_ref) {
|
|
|
56
56
|
if (isSelected) {
|
|
57
57
|
onSelect(selected.filter(function (s) {
|
|
58
58
|
return s !== primaryValue;
|
|
59
|
-
}));
|
|
60
|
-
} else onSelect([].concat(selected, [primaryValue]));
|
|
59
|
+
}), datum);
|
|
60
|
+
} else onSelect([].concat(selected, [primaryValue]), datum);
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
} : undefined,
|
|
@@ -69,6 +69,7 @@ var Row = /*#__PURE__*/memo(function (_ref) {
|
|
|
69
69
|
} : undefined
|
|
70
70
|
}, (selected || onSelect) && /*#__PURE__*/React.createElement(Cell, {
|
|
71
71
|
background: (pinnedOffset == null ? void 0 : pinnedOffset._grommetDataTableSelect) && cellProps.pinned.background || cellProps.background,
|
|
72
|
+
border: cellProps.pinned.border || cellProps.border,
|
|
72
73
|
pinnedOffset: pinnedOffset == null ? void 0 : pinnedOffset._grommetDataTableSelect,
|
|
73
74
|
"aria-disabled": isDisabled || !onSelect || undefined,
|
|
74
75
|
column: {
|
|
@@ -85,8 +86,8 @@ var Row = /*#__PURE__*/memo(function (_ref) {
|
|
|
85
86
|
if (isSelected) {
|
|
86
87
|
onSelect(selected.filter(function (s) {
|
|
87
88
|
return s !== primaryValue;
|
|
88
|
-
}));
|
|
89
|
-
} else onSelect([].concat(selected, [primaryValue]));
|
|
89
|
+
}), datum);
|
|
90
|
+
} else onSelect([].concat(selected, [primaryValue]), datum);
|
|
90
91
|
},
|
|
91
92
|
pad: cellProps.pad
|
|
92
93
|
});
|
|
@@ -160,16 +161,17 @@ var Body = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
160
161
|
// Determine if using a keyboard to cover focus behavior
|
|
161
162
|
var usingKeyboard = useKeyboard();
|
|
162
163
|
var onFocusActive = (_ref3 = active != null ? active : lastActive) != null ? _ref3 : usingKeyboard ? 0 : undefined;
|
|
164
|
+
var activePrimaryValue = active >= 0 ? datumValue(data[active], primaryProperty) : undefined;
|
|
163
165
|
var selectRow = function selectRow() {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}));
|
|
170
|
-
}
|
|
166
|
+
if (activePrimaryValue !== undefined) {
|
|
167
|
+
if (selected && selected.includes(activePrimaryValue)) {
|
|
168
|
+
onSelect(selected.filter(function (s) {
|
|
169
|
+
return s !== activePrimaryValue;
|
|
170
|
+
}));
|
|
171
|
+
} else onSelect([].concat(selected, [activePrimaryValue]));
|
|
172
|
+
}
|
|
171
173
|
};
|
|
172
|
-
var clickableRow = onClickRow && active >= 0 && (!disabled || !disabled.includes(
|
|
174
|
+
var clickableRow = onClickRow && active >= 0 && (!disabled || activePrimaryValue !== undefined && !disabled.includes(activePrimaryValue));
|
|
173
175
|
return /*#__PURE__*/React.createElement(Keyboard, {
|
|
174
176
|
onEnter: clickableRow ? function (event) {
|
|
175
177
|
if (clickableRow) {
|
|
@@ -225,7 +227,7 @@ var Body = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
225
227
|
var isRowExpanded = rowExpand && rowExpand.includes(index);
|
|
226
228
|
var cellProps = normalizeRowCellProps(rowProps, cellPropsProp, primaryValue, index);
|
|
227
229
|
return /*#__PURE__*/React.createElement(Row, {
|
|
228
|
-
key: index,
|
|
230
|
+
key: primaryValue != null ? primaryValue : index,
|
|
229
231
|
setActive: setActive,
|
|
230
232
|
rowRef: rowRef,
|
|
231
233
|
cellProps: cellProps,
|
|
@@ -51,7 +51,7 @@ var DataTable = function DataTable(_ref) {
|
|
|
51
51
|
dataProp = _ref.data,
|
|
52
52
|
disabled = _ref.disabled,
|
|
53
53
|
fill = _ref.fill,
|
|
54
|
-
|
|
54
|
+
groupByProp = _ref.groupBy,
|
|
55
55
|
onClickRow = _ref.onClickRow,
|
|
56
56
|
onMore = _ref.onMore,
|
|
57
57
|
onSearch = _ref.onSearch,
|
|
@@ -132,6 +132,9 @@ var DataTable = function DataTable(_ref) {
|
|
|
132
132
|
if (sortProp) setSort(sortProp);else if (view != null && view.sort) setSort(view.sort);
|
|
133
133
|
}, [sortProp, view]);
|
|
134
134
|
|
|
135
|
+
// what we are grouping on
|
|
136
|
+
var groupBy = (view == null ? void 0 : view.groupBy) || groupByProp;
|
|
137
|
+
|
|
135
138
|
// the data filtered and sorted, if needed
|
|
136
139
|
// Note: onUpdate mode expects the data to be passed
|
|
137
140
|
// in completely filtered and sorted already.
|
|
@@ -139,6 +139,7 @@ export var GroupedBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
139
139
|
verticalAlign: verticalAlign
|
|
140
140
|
}), (selected || onSelect) && /*#__PURE__*/React.createElement(TableCell, {
|
|
141
141
|
background: cellProps.background,
|
|
142
|
+
border: cellProps.pinned.border || cellProps.border,
|
|
142
143
|
plain: "noPad",
|
|
143
144
|
size: "auto",
|
|
144
145
|
verticalAlign: verticalAlign,
|
|
@@ -17,7 +17,7 @@ export var set = function set(obj, path, value) {
|
|
|
17
17
|
|
|
18
18
|
// get the value for the property in the datum object
|
|
19
19
|
export var datumValue = function datumValue(datum, property) {
|
|
20
|
-
if (!property) return undefined;
|
|
20
|
+
if (!property || !datum) return undefined;
|
|
21
21
|
var parts = property.split('.');
|
|
22
22
|
if (parts.length === 1) return datum[property];
|
|
23
23
|
if (!datum[parts[0]]) return undefined;
|
|
@@ -26,15 +26,17 @@ export var datumValue = function datumValue(datum, property) {
|
|
|
26
26
|
|
|
27
27
|
// get the primary property name
|
|
28
28
|
export var normalizePrimaryProperty = function normalizePrimaryProperty(columns, primaryKey) {
|
|
29
|
-
var result;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
var result = primaryKey;
|
|
30
|
+
if (result === undefined) {
|
|
31
|
+
columns.forEach(function (column) {
|
|
32
|
+
// remember the first key property
|
|
33
|
+
if (column.primary && !result) {
|
|
34
|
+
result = column.property;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (result === undefined && columns.length > 0) {
|
|
39
|
+
result = columns[0].property;
|
|
38
40
|
}
|
|
39
41
|
return result;
|
|
40
42
|
};
|
|
@@ -187,6 +187,10 @@ export var DataTableColumns = function DataTableColumns(_ref5) {
|
|
|
187
187
|
var _useState3 = useState(),
|
|
188
188
|
showContent = _useState3[0],
|
|
189
189
|
setShowContent = _useState3[1];
|
|
190
|
+
var tip = format({
|
|
191
|
+
id: 'dataTableColumns.tip',
|
|
192
|
+
messages: messages == null ? void 0 : messages.dataTableColumns
|
|
193
|
+
});
|
|
190
194
|
var content = /*#__PURE__*/React.createElement(Content, {
|
|
191
195
|
drop: drop,
|
|
192
196
|
options: options
|
|
@@ -204,6 +208,7 @@ export var DataTableColumns = function DataTableColumns(_ref5) {
|
|
|
204
208
|
}),
|
|
205
209
|
kind: "toolbar",
|
|
206
210
|
icon: /*#__PURE__*/React.createElement(Splits, null),
|
|
211
|
+
tip: tip,
|
|
207
212
|
dropProps: dropProps,
|
|
208
213
|
dropContent: content,
|
|
209
214
|
open: showContent,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Box, Data, DataTable, Notification, Toolbar } from 'grommet';
|
|
2
|
+
import { Box, Data, DataSearch, DataSummary, DataTable, Notification, Toolbar } from 'grommet';
|
|
3
3
|
import { DataTableColumns } from '../DataTableColumns';
|
|
4
4
|
import { columns, DATA } from '../../DataTable/stories/data';
|
|
5
5
|
|
|
@@ -28,11 +28,12 @@ export var Simple = function Simple() {
|
|
|
28
28
|
}), /*#__PURE__*/React.createElement(Data, {
|
|
29
29
|
data: DATA,
|
|
30
30
|
updateOn: "change"
|
|
31
|
-
}, /*#__PURE__*/React.createElement(Toolbar, null, /*#__PURE__*/React.createElement(DataTableColumns, {
|
|
31
|
+
}, /*#__PURE__*/React.createElement(Toolbar, null, /*#__PURE__*/React.createElement(DataSearch, null), /*#__PURE__*/React.createElement(DataTableColumns, {
|
|
32
32
|
drop: true,
|
|
33
33
|
options: options
|
|
34
|
-
})), /*#__PURE__*/React.createElement(DataTable, {
|
|
35
|
-
columns: columns
|
|
34
|
+
})), /*#__PURE__*/React.createElement(DataSummary, null), /*#__PURE__*/React.createElement(DataTable, {
|
|
35
|
+
columns: columns,
|
|
36
|
+
primaryKey: "name"
|
|
36
37
|
})))
|
|
37
38
|
// </Grommet>
|
|
38
39
|
);
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
var _excluded = ["id", "options"];
|
|
2
|
+
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); }
|
|
3
|
+
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; }
|
|
4
|
+
import React, { useContext, useEffect } from 'react';
|
|
5
|
+
import { DataForm } from '../Data/DataForm';
|
|
6
|
+
import { DataContext } from '../../contexts/DataContext';
|
|
7
|
+
import { FormContext } from '../Form/FormContext';
|
|
8
|
+
import { FormField } from '../FormField';
|
|
9
|
+
import { Select } from '../Select';
|
|
10
|
+
import { MessageContext } from '../../contexts/MessageContext';
|
|
11
|
+
import { DataTableGroupByPropTypes } from './propTypes';
|
|
12
|
+
export var DataTableGroupBy = function DataTableGroupBy(_ref) {
|
|
13
|
+
var idProp = _ref.id,
|
|
14
|
+
options = _ref.options,
|
|
15
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
16
|
+
var _useContext = useContext(DataContext),
|
|
17
|
+
dataId = _useContext.id,
|
|
18
|
+
messages = _useContext.messages,
|
|
19
|
+
view = _useContext.view,
|
|
20
|
+
addToolbarKey = _useContext.addToolbarKey;
|
|
21
|
+
var _useContext2 = useContext(FormContext),
|
|
22
|
+
noForm = _useContext2.noForm;
|
|
23
|
+
var _useContext3 = useContext(MessageContext),
|
|
24
|
+
format = _useContext3.format;
|
|
25
|
+
var id = idProp || dataId + "--groupby";
|
|
26
|
+
useEffect(function () {
|
|
27
|
+
if (noForm) addToolbarKey('_groupBy');
|
|
28
|
+
}, [addToolbarKey, noForm]);
|
|
29
|
+
if (!options) return null;
|
|
30
|
+
var content = /*#__PURE__*/React.createElement(Select, _extends({
|
|
31
|
+
id: id,
|
|
32
|
+
name: "_groupBy",
|
|
33
|
+
showSelectedInline: true,
|
|
34
|
+
placeholder: noForm ? 'Group by' : undefined,
|
|
35
|
+
options: options,
|
|
36
|
+
labelKey: "label",
|
|
37
|
+
clear: view != null && view.groupBy ? {
|
|
38
|
+
position: 'top',
|
|
39
|
+
label: format({
|
|
40
|
+
id: 'dataTableGroupBy.clear',
|
|
41
|
+
messages: messages == null ? void 0 : messages.dataTableGroupBy
|
|
42
|
+
})
|
|
43
|
+
} : undefined,
|
|
44
|
+
value: view == null ? void 0 : view.groupBy
|
|
45
|
+
}, rest));
|
|
46
|
+
if (noForm)
|
|
47
|
+
// likely in Toolbar
|
|
48
|
+
content = /*#__PURE__*/React.createElement(DataForm, {
|
|
49
|
+
footer: false,
|
|
50
|
+
updateOn: "change"
|
|
51
|
+
}, content);else content = /*#__PURE__*/React.createElement(FormField, {
|
|
52
|
+
htmlFor: id,
|
|
53
|
+
label: format({
|
|
54
|
+
id: 'dataTableGroupBy.label',
|
|
55
|
+
messages: messages == null ? void 0 : messages.dataTableGroupBy
|
|
56
|
+
})
|
|
57
|
+
}, content);
|
|
58
|
+
return content;
|
|
59
|
+
};
|
|
60
|
+
DataTableGroupBy.propTypes = DataTableGroupByPropTypes;
|
|
@@ -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 @@
|
|
|
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
|
+
};
|
|
@@ -174,7 +174,7 @@ var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
|
|
|
174
174
|
if (range && Array.isArray(nextValue)) {
|
|
175
175
|
normalizedValue = nextValue[0];
|
|
176
176
|
} // clicking an edge date removes it
|
|
177
|
-
else if (range) normalizedValue = [nextValue, nextValue];else normalizedValue = nextValue;
|
|
177
|
+
else if (range && nextValue) normalizedValue = [nextValue, nextValue];else normalizedValue = nextValue;
|
|
178
178
|
if (schema) setTextValue(valueToText(normalizedValue, schema));
|
|
179
179
|
setValue(normalizedValue);
|
|
180
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);
|