grommet 2.22.0 → 2.23.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/Box/propTypes.js +1 -1
- package/components/Button/index.d.ts +15 -16
- package/components/CheckBox/CheckBox.js +1 -1
- package/components/CheckBox/StyledCheckBox.js +6 -2
- package/components/CheckBox/index.d.ts +2 -1
- package/components/DataChart/DataChart.js +26 -15
- package/components/DataChart/XAxis.js +18 -6
- package/components/DataChart/index.d.ts +1 -1
- package/components/DataChart/propTypes.js +3 -1
- package/components/DataChart/stories/Offset.js +6 -1
- package/components/DataTable/Body.js +76 -24
- package/components/DataTable/Cell.js +10 -4
- package/components/DataTable/DataTable.js +14 -5
- package/components/DataTable/Footer.js +6 -3
- package/components/DataTable/GroupedBody.js +22 -6
- package/components/DataTable/Header.js +85 -40
- package/components/DataTable/StyledDataTable.js +2 -2
- package/components/DataTable/index.d.ts +14 -2
- package/components/DataTable/propTypes.js +9 -2
- package/components/DataTable/stories/Units.js +41 -2
- package/components/DataTable/stories/VerticalAlign.js +51 -0
- package/components/DataTable/stories/typescript/Clickable.tsx +1 -0
- package/components/DataTable/stories/typescript/OnSelect.tsx +5 -10
- package/components/Drop/DropContainer.js +5 -2
- package/components/Drop/index.d.ts +2 -0
- package/components/Footer/index.d.ts +2 -2
- package/components/FormField/index.d.ts +4 -1
- package/components/Header/Header.js +62 -7
- package/components/Header/index.d.ts +8 -2
- package/components/Header/propTypes.js +19 -0
- package/components/Header/stories/Sticky.js +134 -0
- package/components/InfiniteScroll/index.d.ts +1 -0
- package/components/Keyboard/index.d.ts +1 -0
- package/components/List/List.js +5 -2
- package/components/List/index.d.ts +1 -0
- package/components/List/stories/Basic.js +1 -0
- package/components/Main/index.d.ts +2 -2
- package/components/Menu/Menu.js +4 -3
- package/components/Menu/index.d.ts +2 -1
- package/components/Menu/stories/Simple.js +1 -0
- package/components/Menu/stories/typescript/Children.tsx +1 -1
- package/components/NameValueList/index.d.ts +4 -1
- package/components/Nav/index.d.ts +2 -2
- package/components/Page/index.d.ts +2 -2
- package/components/PageContent/index.d.ts +2 -2
- package/components/RadioButton/index.d.ts +2 -1
- package/components/RangeSelector/stories/Thin.js +1 -9
- package/components/Select/SelectContainer.js +17 -10
- package/components/Select/stories/Clear.js +27 -2
- package/components/Spinner/index.d.ts +2 -1
- package/components/TableCell/TableCell.js +8 -4
- package/components/Tip/index.d.ts +1 -0
- package/components/Video/StyledVideo.js +1 -1
- package/components/Video/Video.js +72 -20
- package/components/Video/index.d.ts +14 -8
- package/components/Video/propTypes.js +7 -5
- package/components/Video/stories/typescript/ControlsBelow.tsx +6 -4
- package/components/Video/stories/typescript/Simple.tsx +1 -1
- package/components/Video/stories/typescript/TheaterMode.tsx +1 -2
- package/contexts/ThemeContext/index.d.ts +4 -1
- package/es6/components/Box/propTypes.js +1 -1
- package/es6/components/Button/index.d.ts +15 -16
- package/es6/components/CheckBox/CheckBox.js +1 -1
- package/es6/components/CheckBox/StyledCheckBox.js +6 -2
- package/es6/components/CheckBox/index.d.ts +2 -1
- package/es6/components/DataChart/DataChart.js +26 -15
- package/es6/components/DataChart/XAxis.js +18 -6
- package/es6/components/DataChart/index.d.ts +1 -1
- package/es6/components/DataChart/propTypes.js +3 -1
- package/es6/components/DataChart/stories/Offset.js +6 -1
- package/es6/components/DataTable/Body.js +76 -24
- package/es6/components/DataTable/Cell.js +11 -4
- package/es6/components/DataTable/DataTable.js +14 -5
- package/es6/components/DataTable/Footer.js +6 -3
- package/es6/components/DataTable/GroupedBody.js +22 -6
- package/es6/components/DataTable/Header.js +85 -40
- package/es6/components/DataTable/StyledDataTable.js +2 -2
- package/es6/components/DataTable/index.d.ts +14 -2
- package/es6/components/DataTable/propTypes.js +9 -2
- package/es6/components/DataTable/stories/Units.js +41 -2
- package/es6/components/DataTable/stories/VerticalAlign.js +38 -0
- package/es6/components/DataTable/stories/typescript/Clickable.tsx +1 -0
- package/es6/components/DataTable/stories/typescript/OnSelect.tsx +5 -10
- package/es6/components/Drop/DropContainer.js +5 -2
- package/es6/components/Drop/index.d.ts +2 -0
- package/es6/components/Footer/index.d.ts +2 -2
- package/es6/components/FormField/index.d.ts +4 -1
- package/es6/components/Header/Header.js +57 -6
- package/es6/components/Header/index.d.ts +8 -2
- package/es6/components/Header/propTypes.js +10 -0
- package/es6/components/Header/stories/Sticky.js +121 -0
- package/es6/components/InfiniteScroll/index.d.ts +1 -0
- package/es6/components/Keyboard/index.d.ts +1 -0
- package/es6/components/List/List.js +5 -2
- package/es6/components/List/index.d.ts +1 -0
- package/es6/components/List/stories/Basic.js +1 -0
- package/es6/components/Main/index.d.ts +2 -2
- package/es6/components/Menu/Menu.js +4 -3
- package/es6/components/Menu/index.d.ts +2 -1
- package/es6/components/Menu/stories/Simple.js +1 -0
- package/es6/components/Menu/stories/typescript/Children.tsx +1 -1
- package/es6/components/NameValueList/index.d.ts +4 -1
- package/es6/components/Nav/index.d.ts +2 -2
- package/es6/components/Page/index.d.ts +2 -2
- package/es6/components/PageContent/index.d.ts +2 -2
- package/es6/components/RadioButton/index.d.ts +2 -1
- package/es6/components/RangeSelector/stories/Thin.js +1 -7
- package/es6/components/Select/SelectContainer.js +17 -10
- package/es6/components/Select/stories/Clear.js +27 -2
- package/es6/components/Spinner/index.d.ts +2 -1
- package/es6/components/TableCell/TableCell.js +7 -4
- package/es6/components/Tip/index.d.ts +1 -0
- package/es6/components/Video/StyledVideo.js +2 -2
- package/es6/components/Video/Video.js +71 -20
- package/es6/components/Video/index.d.ts +14 -8
- package/es6/components/Video/propTypes.js +7 -5
- package/es6/components/Video/stories/typescript/ControlsBelow.tsx +6 -4
- package/es6/components/Video/stories/typescript/Simple.tsx +1 -1
- package/es6/components/Video/stories/typescript/TheaterMode.tsx +1 -2
- package/es6/contexts/ThemeContext/index.d.ts +4 -1
- package/es6/themes/base.d.ts +21 -14
- package/es6/themes/base.js +10 -3
- package/grommet.min.js +1 -1
- package/grommet.min.js.map +1 -1
- package/package.json +40 -40
- package/themes/base.d.ts +21 -14
- package/themes/base.js +10 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
var _excluded = ["background", "border", "color", "font", "gap", "pad", "units"],
|
|
2
|
-
_excluded2 = ["cellProps", "columns", "data", "fill", "filtering", "filters", "groupBy", "groups", "groupState", "onFilter", "onFiltering", "onResize", "onSelect", "onSort", "onToggle", "onWidths", "pin", "pinnedOffset", "primaryProperty", "selected", "rowDetails", "sort", "widths"];
|
|
2
|
+
_excluded2 = ["cellProps", "columns", "data", "disabled", "fill", "filtering", "filters", "groupBy", "groups", "groupState", "onFilter", "onFiltering", "onResize", "onSelect", "onSort", "onToggle", "onWidths", "pin", "pinnedOffset", "primaryProperty", "selected", "rowDetails", "sort", "widths", "verticalAlign"];
|
|
3
3
|
|
|
4
4
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
5
5
|
|
|
@@ -12,7 +12,7 @@ import { defaultProps } from '../../default-props';
|
|
|
12
12
|
import { Box } from '../Box';
|
|
13
13
|
import { Button } from '../Button';
|
|
14
14
|
import { CheckBox } from '../CheckBox';
|
|
15
|
-
import { TableCell } from '../TableCell';
|
|
15
|
+
import { TableCell, verticalAlignToJustify } from '../TableCell/TableCell';
|
|
16
16
|
import { Text } from '../Text';
|
|
17
17
|
import { Resizer } from './Resizer';
|
|
18
18
|
import { Searcher } from './Searcher';
|
|
@@ -51,7 +51,8 @@ var separateThemeProps = function separateThemeProps(theme) {
|
|
|
51
51
|
|
|
52
52
|
var buttonStyle = function buttonStyle(_ref) {
|
|
53
53
|
var pad = _ref.pad,
|
|
54
|
-
theme = _ref.theme
|
|
54
|
+
theme = _ref.theme,
|
|
55
|
+
verticalAlign = _ref.verticalAlign;
|
|
55
56
|
var styles = [];
|
|
56
57
|
|
|
57
58
|
var _separateThemeProps = separateThemeProps(theme),
|
|
@@ -80,6 +81,14 @@ var buttonStyle = function buttonStyle(_ref) {
|
|
|
80
81
|
styles.push(css(["svg{stroke:", ";fill:", ";}"], normalizeColor(iconProps.color, theme), normalizeColor(iconProps.color, theme)));
|
|
81
82
|
}
|
|
82
83
|
|
|
84
|
+
var align = 'center';
|
|
85
|
+
if (verticalAlign === 'bottom') align = 'end';
|
|
86
|
+
if (verticalAlign === 'top') align = 'start';
|
|
87
|
+
|
|
88
|
+
if (verticalAlign) {
|
|
89
|
+
styles.push(css(["display:inline-flex;align-items:", ";"], align));
|
|
90
|
+
}
|
|
91
|
+
|
|
83
92
|
return styles;
|
|
84
93
|
};
|
|
85
94
|
|
|
@@ -100,6 +109,7 @@ var Header = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
100
109
|
var cellProps = _ref2.cellProps,
|
|
101
110
|
columns = _ref2.columns,
|
|
102
111
|
data = _ref2.data,
|
|
112
|
+
disabled = _ref2.disabled,
|
|
103
113
|
fill = _ref2.fill,
|
|
104
114
|
filtering = _ref2.filtering,
|
|
105
115
|
filters = _ref2.filters,
|
|
@@ -120,6 +130,7 @@ var Header = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
120
130
|
rowDetails = _ref2.rowDetails,
|
|
121
131
|
sort = _ref2.sort,
|
|
122
132
|
widths = _ref2.widths,
|
|
133
|
+
verticalAlign = _ref2.verticalAlign,
|
|
123
134
|
rest = _objectWithoutPropertiesLoose(_ref2, _excluded2);
|
|
124
135
|
|
|
125
136
|
var theme = useContext(ThemeContext) || defaultProps.theme;
|
|
@@ -148,6 +159,49 @@ var Header = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
148
159
|
return cur && groupBy.select[cur] === 'all' ? total + 1 : total;
|
|
149
160
|
}, 0) : 0;
|
|
150
161
|
var totalSelected = ((selected == null ? void 0 : selected.length) || 0) + totalSelectedGroups;
|
|
162
|
+
var onChangeSelection = useCallback(function () {
|
|
163
|
+
var nextSelected;
|
|
164
|
+
var nextGroupSelected = {}; // Since some rows might be disabled but already selected, we need to
|
|
165
|
+
// note which rows are enabled when determining how aggregate selection
|
|
166
|
+
// works.
|
|
167
|
+
|
|
168
|
+
var primaryValues = data.map(function (datum) {
|
|
169
|
+
return datumValue(datum, primaryProperty);
|
|
170
|
+
}) || []; // enabled includes what can be changed
|
|
171
|
+
|
|
172
|
+
var enabled = disabled && primaryValues.filter(function (v) {
|
|
173
|
+
return !disabled.includes(v);
|
|
174
|
+
}) || primaryValues; // enabledSelected includes what can be changed and is currently selected
|
|
175
|
+
|
|
176
|
+
var enabledSelected = selected && enabled.filter(function (v) {
|
|
177
|
+
return selected.includes(v);
|
|
178
|
+
}) || primaryValues;
|
|
179
|
+
var allSelected = groupBy != null && groupBy.select ? groupBy.select[''] === 'all' : enabledSelected.length === enabled.length;
|
|
180
|
+
|
|
181
|
+
if (allSelected) {
|
|
182
|
+
// if any are disabled and selected, leave those, otherwise clear
|
|
183
|
+
nextSelected = disabled ? primaryValues.filter(function (v) {
|
|
184
|
+
return disabled.includes(v) && selected.includes(v);
|
|
185
|
+
}) : [];
|
|
186
|
+
nextGroupSelected[''] = 'none';
|
|
187
|
+
} else {
|
|
188
|
+
var _groupBy$expandable;
|
|
189
|
+
|
|
190
|
+
// if some or none are selected, select all enabled plus all disabled
|
|
191
|
+
// that are already selected
|
|
192
|
+
nextSelected = disabled ? primaryValues.filter(function (v) {
|
|
193
|
+
return !disabled.includes(v) || selected.includes(v);
|
|
194
|
+
}) : primaryValues;
|
|
195
|
+
nextGroupSelected[''] = 'all';
|
|
196
|
+
groupBy == null ? void 0 : (_groupBy$expandable = groupBy.expandable) == null ? void 0 : _groupBy$expandable.forEach(function (key) {
|
|
197
|
+
nextGroupSelected[key] = 'all';
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (groupBy != null && groupBy.onSelect) {
|
|
202
|
+
groupBy.onSelect(nextSelected, undefined, nextGroupSelected);
|
|
203
|
+
} else onSelect(nextSelected);
|
|
204
|
+
}, [data, disabled, groupBy, onSelect, primaryProperty, selected]);
|
|
151
205
|
return /*#__PURE__*/React.createElement(StyledDataTableHeader, _extends({
|
|
152
206
|
ref: ref,
|
|
153
207
|
fillProp: fill
|
|
@@ -168,36 +222,13 @@ var Header = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
168
222
|
context: "header",
|
|
169
223
|
scope: "col",
|
|
170
224
|
pin: selectPin,
|
|
171
|
-
pinnedOffset: pinnedOffset == null ? void 0 : pinnedOffset._grommetDataTableSelect
|
|
225
|
+
pinnedOffset: pinnedOffset == null ? void 0 : pinnedOffset._grommetDataTableSelect,
|
|
226
|
+
verticalAlign: verticalAlign
|
|
172
227
|
}, onSelect && /*#__PURE__*/React.createElement(CheckBox, {
|
|
173
228
|
a11yTitle: totalSelected === data.length ? 'unselect all' : 'select all',
|
|
174
229
|
checked: groupBy != null && groupBy.select ? groupBy.select[''] === 'all' : totalSelected > 0 && data.length > 0 && totalSelected === data.length,
|
|
175
230
|
indeterminate: groupBy != null && groupBy.select ? groupBy.select[''] === 'some' : totalSelected > 0 && totalSelected < data.length,
|
|
176
|
-
onChange:
|
|
177
|
-
var nextSelected;
|
|
178
|
-
var nextGroupSelected = {};
|
|
179
|
-
var allSelected = groupBy != null && groupBy.select ? groupBy.select[''] === 'all' : totalSelected === data.length; // if all are selected, clear selection
|
|
180
|
-
|
|
181
|
-
if (allSelected) {
|
|
182
|
-
nextSelected = [];
|
|
183
|
-
nextGroupSelected[''] = 'none';
|
|
184
|
-
} else {
|
|
185
|
-
var _groupBy$expandable;
|
|
186
|
-
|
|
187
|
-
// if some or none are selected, select all data
|
|
188
|
-
nextSelected = data.map(function (datum) {
|
|
189
|
-
return datumValue(datum, primaryProperty);
|
|
190
|
-
});
|
|
191
|
-
nextGroupSelected[''] = 'all';
|
|
192
|
-
groupBy == null ? void 0 : (_groupBy$expandable = groupBy.expandable) == null ? void 0 : _groupBy$expandable.forEach(function (key) {
|
|
193
|
-
nextGroupSelected[key] = 'all';
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
if (groupBy != null && groupBy.onSelect) {
|
|
198
|
-
groupBy.onSelect(nextSelected, undefined, nextGroupSelected);
|
|
199
|
-
} else onSelect(nextSelected);
|
|
200
|
-
},
|
|
231
|
+
onChange: onChangeSelection,
|
|
201
232
|
pad: cellProps.pad
|
|
202
233
|
})), rowDetails && /*#__PURE__*/React.createElement(TableCell, {
|
|
203
234
|
size: "xxsmall",
|
|
@@ -210,7 +241,7 @@ var Header = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
210
241
|
columnPin = _ref3.pin,
|
|
211
242
|
search = _ref3.search,
|
|
212
243
|
sortable = _ref3.sortable,
|
|
213
|
-
|
|
244
|
+
columnVerticalAlign = _ref3.verticalAlign,
|
|
214
245
|
size = _ref3.size,
|
|
215
246
|
units = _ref3.units;
|
|
216
247
|
var content;
|
|
@@ -227,6 +258,21 @@ var Header = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
227
258
|
}
|
|
228
259
|
} else content = header;
|
|
229
260
|
|
|
261
|
+
if (unitsContent) {
|
|
262
|
+
content = /*#__PURE__*/React.createElement(Box, {
|
|
263
|
+
justify: align,
|
|
264
|
+
direction: "row"
|
|
265
|
+
}, content, unitsContent);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
if (verticalAlign || columnVerticalAlign) {
|
|
269
|
+
var vertical = verticalAlign || columnVerticalAlign;
|
|
270
|
+
content = /*#__PURE__*/React.createElement(Box, {
|
|
271
|
+
height: "100%",
|
|
272
|
+
justify: verticalAlignToJustify[vertical]
|
|
273
|
+
}, content);
|
|
274
|
+
}
|
|
275
|
+
|
|
230
276
|
if (onSort && sortable !== false) {
|
|
231
277
|
var Icon;
|
|
232
278
|
|
|
@@ -245,25 +291,24 @@ var Header = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
245
291
|
onClick: onSort(property),
|
|
246
292
|
sort: sort,
|
|
247
293
|
pad: cellProps.pad,
|
|
248
|
-
sortable: true
|
|
294
|
+
sortable: true,
|
|
295
|
+
verticalAlign: verticalAlign || columnVerticalAlign
|
|
249
296
|
}, /*#__PURE__*/React.createElement(Box, {
|
|
250
297
|
direction: "row",
|
|
251
298
|
align: "center",
|
|
252
299
|
gap: "xsmall",
|
|
253
300
|
justify: align
|
|
254
301
|
}, content, Icon && /*#__PURE__*/React.createElement(Icon, null)));
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
if (unitsContent) {
|
|
258
|
-
content = /*#__PURE__*/React.createElement(Box, {
|
|
259
|
-
align: "baseline",
|
|
260
|
-
direction: "row"
|
|
261
|
-
}, content, unitsContent);
|
|
262
302
|
} // content should fill any available space in cell
|
|
303
|
+
// If `onResize` or `search` is true we need to explicitly set
|
|
304
|
+
// fill because later if either of these props is true content
|
|
305
|
+
// will be wrapped with an additional Box, preventing this Box
|
|
306
|
+
// from automatically filling the vertical space.
|
|
263
307
|
|
|
264
308
|
|
|
265
309
|
content = /*#__PURE__*/React.createElement(Box, {
|
|
266
|
-
flex: "grow"
|
|
310
|
+
flex: "grow",
|
|
311
|
+
fill: onResize || search ? 'vertical' : false
|
|
267
312
|
}, content);
|
|
268
313
|
|
|
269
314
|
if (search || onResize) {
|
|
@@ -301,7 +346,7 @@ var Header = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
301
346
|
key: property,
|
|
302
347
|
align: align,
|
|
303
348
|
context: "header",
|
|
304
|
-
verticalAlign: verticalAlign,
|
|
349
|
+
verticalAlign: verticalAlign || columnVerticalAlign,
|
|
305
350
|
background: cellProps.background,
|
|
306
351
|
border: cellProps.border,
|
|
307
352
|
onWidth: updateWidths // if sortable, pad will be included in the button styling
|
|
@@ -12,7 +12,7 @@ import { TableFooter } from '../TableFooter'; // border-collapse: separate is ne
|
|
|
12
12
|
var StyledDataTable = styled(Table).withConfig({
|
|
13
13
|
displayName: "StyledDataTable",
|
|
14
14
|
componentId: "sc-xrlyjm-0"
|
|
15
|
-
})(["position:relative;border-spacing:0;border-collapse:separate;height:
|
|
15
|
+
})(["position:relative;border-spacing:0;border-collapse:separate;height:100%;", " ", " ", ";"], genericStyles, function (props) {
|
|
16
16
|
return props.fillProp && fillStyle(props.fillProp);
|
|
17
17
|
}, function (props) {
|
|
18
18
|
return props.theme.dataTable && props.theme.dataTable.body && props.theme.dataTable.body.extend;
|
|
@@ -64,7 +64,7 @@ var StyledDataTableHeader = styled(TableHeader).withConfig({
|
|
|
64
64
|
displayName: "StyledDataTable__StyledDataTableHeader",
|
|
65
65
|
componentId: "sc-xrlyjm-4"
|
|
66
66
|
})(["", ""], function (props) {
|
|
67
|
-
return props.size && "\n display: table;\n width: calc(100% - " + props.scrollOffset + "px);\n table-layout: fixed;\n ";
|
|
67
|
+
return props.size && "\n height: fit-content;\n display: table;\n width: calc(100% - " + props.scrollOffset + "px);\n table-layout: fixed;\n ";
|
|
68
68
|
});
|
|
69
69
|
StyledDataTableHeader.defaultProps = {};
|
|
70
70
|
Object.setPrototypeOf(StyledDataTableHeader.defaultProps, defaultProps);
|
|
@@ -36,6 +36,8 @@ export type MouseClick<TRowType> = React.MouseEvent<HTMLTableRowElement> & {
|
|
|
36
36
|
|
|
37
37
|
export type KeyPress<TRowType> = React.KeyboardEvent & { datum: TRowType };
|
|
38
38
|
|
|
39
|
+
type VerticalAlignType = 'middle' | 'top' | 'bottom';
|
|
40
|
+
|
|
39
41
|
export interface ColumnConfig<TRowType> {
|
|
40
42
|
align?: 'center' | 'start' | 'end';
|
|
41
43
|
aggregate?: 'avg' | 'max' | 'min' | 'sum';
|
|
@@ -51,7 +53,7 @@ export interface ColumnConfig<TRowType> {
|
|
|
51
53
|
sortable?: boolean;
|
|
52
54
|
size?: ColumnSizeType | string;
|
|
53
55
|
units?: string;
|
|
54
|
-
verticalAlign?:
|
|
56
|
+
verticalAlign?: VerticalAlignType;
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
export interface DataTableProps<TRowType = any> {
|
|
@@ -85,6 +87,7 @@ export interface DataTableProps<TRowType = any> {
|
|
|
85
87
|
|
|
86
88
|
// Data
|
|
87
89
|
data?: TRowType[];
|
|
90
|
+
disabled?: (string | number)[];
|
|
88
91
|
groupBy?:
|
|
89
92
|
| string
|
|
90
93
|
| {
|
|
@@ -102,7 +105,9 @@ export interface DataTableProps<TRowType = any> {
|
|
|
102
105
|
step?: number;
|
|
103
106
|
|
|
104
107
|
// Events
|
|
105
|
-
onClickRow?:
|
|
108
|
+
onClickRow?:
|
|
109
|
+
| 'select'
|
|
110
|
+
| ((event: MouseClick<TRowType> | KeyPress<TRowType>) => void);
|
|
106
111
|
onMore?: () => void;
|
|
107
112
|
onSearch?: (search: string) => void;
|
|
108
113
|
onSelect?: (select: (string | number)[], datum: TRowType) => void;
|
|
@@ -113,6 +118,13 @@ export interface DataTableProps<TRowType = any> {
|
|
|
113
118
|
show: number;
|
|
114
119
|
count: number;
|
|
115
120
|
}) => void;
|
|
121
|
+
verticalAlign?:
|
|
122
|
+
| VerticalAlignType
|
|
123
|
+
| {
|
|
124
|
+
header?: VerticalAlignType;
|
|
125
|
+
body?: VerticalAlignType;
|
|
126
|
+
footer?: VerticalAlignType;
|
|
127
|
+
};
|
|
116
128
|
}
|
|
117
129
|
|
|
118
130
|
export interface DataTableExtendedProps<TRowType = any>
|
|
@@ -5,6 +5,7 @@ import { genericProps } from '../../utils/general-prop-types';
|
|
|
5
5
|
var sizes = ['xxsmall', 'xsmall', 'small', 'medium', 'large', 'xlarge'];
|
|
6
6
|
var sides = ['horizontal', 'vertical', 'top', 'bottom', 'left', 'right'];
|
|
7
7
|
var parts = ['header', 'body', 'footer'];
|
|
8
|
+
var verticalAlign = ['bottom', 'middle', 'top'];
|
|
8
9
|
var padShapeSides = {};
|
|
9
10
|
sides.forEach(function (side) {
|
|
10
11
|
padShapeSides[side] = PropTypes.oneOfType([PropTypes.oneOf(sizes), PropTypes.string]);
|
|
@@ -62,6 +63,7 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
62
63
|
verticalAlign: PropTypes.oneOf(['middle', 'top', 'bottom'])
|
|
63
64
|
})),
|
|
64
65
|
data: PropTypes.arrayOf(PropTypes.shape({})),
|
|
66
|
+
disabled: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])),
|
|
65
67
|
fill: PropTypes.oneOfType([PropTypes.oneOf(['horizontal', 'vertical']), PropTypes.bool]),
|
|
66
68
|
groupBy: PropTypes.oneOfType([PropTypes.string, PropTypes.shape({
|
|
67
69
|
property: PropTypes.string,
|
|
@@ -71,7 +73,7 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
71
73
|
onExpand: PropTypes.func,
|
|
72
74
|
onSelect: PropTypes.func
|
|
73
75
|
})]),
|
|
74
|
-
onClickRow: PropTypes.func,
|
|
76
|
+
onClickRow: PropTypes.oneOfType([PropTypes.func, PropTypes.oneOf(['select'])]),
|
|
75
77
|
rowDetails: PropTypes.func,
|
|
76
78
|
onMore: PropTypes.func,
|
|
77
79
|
onSearch: PropTypes.func,
|
|
@@ -97,7 +99,12 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
97
99
|
property: PropTypes.string.isRequired
|
|
98
100
|
}),
|
|
99
101
|
sortable: PropTypes.bool,
|
|
100
|
-
step: PropTypes.number
|
|
102
|
+
step: PropTypes.number,
|
|
103
|
+
verticalAlign: PropTypes.oneOfType([PropTypes.oneOf(verticalAlign), PropTypes.shape({
|
|
104
|
+
header: PropTypes.oneOf(verticalAlign),
|
|
105
|
+
body: PropTypes.oneOf(verticalAlign),
|
|
106
|
+
footer: PropTypes.oneOf(verticalAlign)
|
|
107
|
+
})])
|
|
101
108
|
});
|
|
102
109
|
}
|
|
103
110
|
|
|
@@ -30,20 +30,59 @@ var columns = [{
|
|
|
30
30
|
align: 'end',
|
|
31
31
|
units: '%'
|
|
32
32
|
}];
|
|
33
|
+
var SORTABLE_DATA = [{
|
|
34
|
+
last: 'Lullaby',
|
|
35
|
+
first: 'Julius',
|
|
36
|
+
count: '7',
|
|
37
|
+
percentUsed: '79.3',
|
|
38
|
+
consumption: '651'
|
|
39
|
+
}, {
|
|
40
|
+
last: 'Rhodes',
|
|
41
|
+
first: 'Fender',
|
|
42
|
+
count: '5',
|
|
43
|
+
percentUsed: '22.5',
|
|
44
|
+
consumption: '37'
|
|
45
|
+
}];
|
|
46
|
+
var sortableColumns = [{
|
|
47
|
+
property: 'last',
|
|
48
|
+
header: 'Last'
|
|
49
|
+
}, {
|
|
50
|
+
property: 'first',
|
|
51
|
+
header: 'First'
|
|
52
|
+
}, {
|
|
53
|
+
property: 'count',
|
|
54
|
+
header: 'Count',
|
|
55
|
+
align: 'end'
|
|
56
|
+
}, {
|
|
57
|
+
property: 'percentUsed',
|
|
58
|
+
header: 'Percent Used',
|
|
59
|
+
align: 'end',
|
|
60
|
+
units: '%'
|
|
61
|
+
}, {
|
|
62
|
+
property: 'consumption',
|
|
63
|
+
header: 'Consumption',
|
|
64
|
+
align: 'end',
|
|
65
|
+
units: 'TiB'
|
|
66
|
+
}];
|
|
33
67
|
export var UnitsDataTable = function UnitsDataTable() {
|
|
34
68
|
return (
|
|
35
69
|
/*#__PURE__*/
|
|
36
70
|
// Uncomment <Grommet> lines when using outside of storybook
|
|
37
71
|
// <Grommet theme={grommet}>
|
|
38
72
|
React.createElement(Box, {
|
|
39
|
-
align: "center"
|
|
40
|
-
pad: "large"
|
|
73
|
+
align: "center"
|
|
41
74
|
}, /*#__PURE__*/React.createElement(Heading, {
|
|
42
75
|
level: "3"
|
|
43
76
|
}, "Table with units in the heading"), /*#__PURE__*/React.createElement(DataTable, {
|
|
44
77
|
columns: columns,
|
|
45
78
|
data: DATA,
|
|
46
79
|
primaryKey: false
|
|
80
|
+
}), /*#__PURE__*/React.createElement(Heading, {
|
|
81
|
+
level: "3"
|
|
82
|
+
}, "Sortable with units in the heading"), /*#__PURE__*/React.createElement(DataTable, {
|
|
83
|
+
sortable: true,
|
|
84
|
+
columns: sortableColumns,
|
|
85
|
+
data: SORTABLE_DATA
|
|
47
86
|
})) // </Grommet>
|
|
48
87
|
|
|
49
88
|
);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Box, DataTable } from 'grommet'; // Source code for the data can be found here
|
|
3
|
+
// https://github.com/grommet/grommet/blob/master/src/js/components/DataTable/stories/data.js
|
|
4
|
+
|
|
5
|
+
import { columns, DATA } from './data';
|
|
6
|
+
export var VerticalAlign = function VerticalAlign() {
|
|
7
|
+
return (
|
|
8
|
+
/*#__PURE__*/
|
|
9
|
+
// Uncomment <Grommet> lines when using outside of storybook
|
|
10
|
+
// <Grommet theme={grommet}>
|
|
11
|
+
React.createElement(Box, {
|
|
12
|
+
align: "center",
|
|
13
|
+
pad: "large"
|
|
14
|
+
}, /*#__PURE__*/React.createElement(DataTable, {
|
|
15
|
+
columns: [{
|
|
16
|
+
property: 'large',
|
|
17
|
+
header: 'This header name is long and wraps',
|
|
18
|
+
render: function render() {
|
|
19
|
+
return 'This content is long and wraps a lot too.';
|
|
20
|
+
},
|
|
21
|
+
size: 'small',
|
|
22
|
+
footer: 'This footer content is long and wraps.'
|
|
23
|
+
}].concat(columns),
|
|
24
|
+
data: DATA,
|
|
25
|
+
step: 10,
|
|
26
|
+
verticalAlign: {
|
|
27
|
+
header: 'bottom',
|
|
28
|
+
body: 'top',
|
|
29
|
+
footer: 'top'
|
|
30
|
+
}
|
|
31
|
+
})) // </Grommet>
|
|
32
|
+
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
VerticalAlign.storyName = 'Vertical Align';
|
|
36
|
+
export default {
|
|
37
|
+
title: 'Visualizations/DataTable/Vertical Align'
|
|
38
|
+
};
|
|
@@ -25,16 +25,9 @@ const columns: ColumnConfig<RowType>[] = [
|
|
|
25
25
|
header: 'Location',
|
|
26
26
|
render: (datum) =>
|
|
27
27
|
datum.location ? (
|
|
28
|
-
<
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
hoverIndicator
|
|
32
|
-
fill
|
|
33
|
-
>
|
|
34
|
-
<Text truncate weight="bold">
|
|
35
|
-
{datum.location}
|
|
36
|
-
</Text>
|
|
37
|
-
</Box>
|
|
28
|
+
<Text truncate weight="bold">
|
|
29
|
+
{datum.location}
|
|
30
|
+
</Text>
|
|
38
31
|
) : undefined,
|
|
39
32
|
plain: true,
|
|
40
33
|
},
|
|
@@ -166,7 +159,9 @@ export const OnSelectDataTable = () => {
|
|
|
166
159
|
columns={columns}
|
|
167
160
|
data={DATA}
|
|
168
161
|
step={10}
|
|
162
|
+
disabled={['Matt']}
|
|
169
163
|
select={select}
|
|
164
|
+
onClickRow="select"
|
|
170
165
|
onSelect={setSelect}
|
|
171
166
|
/>
|
|
172
167
|
</Box>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _excluded = ["align", "background", "onAlign", "children", "dropTarget", "elevation", "onClickOutside", "onEsc", "onKeyDown", "overflow", "plain", "responsive", "restrictFocus", "stretch", "trapFocus"];
|
|
1
|
+
var _excluded = ["a11yTitle", "aria-label", "align", "background", "onAlign", "children", "dropTarget", "elevation", "onClickOutside", "onEsc", "onKeyDown", "overflow", "plain", "responsive", "restrictFocus", "stretch", "trapFocus"];
|
|
2
2
|
|
|
3
3
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
4
4
|
|
|
@@ -28,7 +28,9 @@ var defaultAlign = {
|
|
|
28
28
|
};
|
|
29
29
|
var defaultPortalContext = [];
|
|
30
30
|
var DropContainer = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
31
|
-
var
|
|
31
|
+
var a11yTitle = _ref.a11yTitle,
|
|
32
|
+
ariaLabel = _ref['aria-label'],
|
|
33
|
+
_ref$align = _ref.align,
|
|
32
34
|
align = _ref$align === void 0 ? defaultAlign : _ref$align,
|
|
33
35
|
background = _ref.background,
|
|
34
36
|
onAlign = _ref.onAlign,
|
|
@@ -300,6 +302,7 @@ var DropContainer = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
300
302
|
}
|
|
301
303
|
}, [ref, restrictFocus]);
|
|
302
304
|
var content = /*#__PURE__*/React.createElement(StyledDrop, _extends({
|
|
305
|
+
"aria-label": a11yTitle || ariaLabel,
|
|
303
306
|
ref: ref || dropRef,
|
|
304
307
|
as: Box,
|
|
305
308
|
background: background,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import {
|
|
3
|
+
A11yTitleType,
|
|
3
4
|
BackgroundType,
|
|
4
5
|
ElevationType,
|
|
5
6
|
KeyboardType,
|
|
@@ -8,6 +9,7 @@ import {
|
|
|
8
9
|
} from '../../utils';
|
|
9
10
|
|
|
10
11
|
export interface DropProps {
|
|
12
|
+
a11yTitle?: A11yTitleType;
|
|
11
13
|
align?: {
|
|
12
14
|
top?: 'top' | 'bottom';
|
|
13
15
|
bottom?: 'top' | 'bottom';
|
|
@@ -35,7 +35,10 @@ export interface FormFieldProps {
|
|
|
35
35
|
)[];
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
type inputProps = Omit<
|
|
38
|
+
type inputProps = Omit<
|
|
39
|
+
JSX.IntrinsicElements['input'],
|
|
40
|
+
'placeholder' | 'required'
|
|
41
|
+
>;
|
|
39
42
|
|
|
40
43
|
export interface FormFieldExtendedProps extends FormFieldProps, inputProps {}
|
|
41
44
|
|
|
@@ -1,20 +1,71 @@
|
|
|
1
|
+
var _excluded = ["sticky"];
|
|
2
|
+
|
|
1
3
|
function _extends() { _extends = Object.assign || 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); }
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
6
|
+
|
|
7
|
+
import React, { useContext, useEffect } from 'react';
|
|
8
|
+
import { ThemeContext } from 'styled-components';
|
|
9
|
+
import { findScrollParent, useForwardedRef } from '../../utils';
|
|
4
10
|
import { Box } from '../Box';
|
|
5
11
|
var Header = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
6
|
-
var
|
|
12
|
+
var _theme$header2, _theme$header2$sticky;
|
|
13
|
+
|
|
14
|
+
var sticky = _ref.sticky,
|
|
15
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
16
|
+
|
|
17
|
+
var theme = useContext(ThemeContext);
|
|
18
|
+
var headerRef = useForwardedRef(ref);
|
|
19
|
+
useEffect(function () {
|
|
20
|
+
var scrollTop = 0;
|
|
21
|
+
|
|
22
|
+
var updateScrollDir = function updateScrollDir() {
|
|
23
|
+
// target is its scroll parent
|
|
24
|
+
var target = findScrollParent(headerRef.current);
|
|
25
|
+
var header = headerRef.current;
|
|
26
|
+
|
|
27
|
+
if (target && sticky === 'scrollup') {
|
|
28
|
+
var nextScrollTop = target === document ? window.pageYOffset : target.scrollTop;
|
|
29
|
+
|
|
30
|
+
if (scrollTop - nextScrollTop <= 0) {
|
|
31
|
+
header.style.top = "-" + header.getBoundingClientRect().height + "px";
|
|
32
|
+
header.style.zIndex = '';
|
|
33
|
+
} else if (scrollTop - nextScrollTop > 0) {
|
|
34
|
+
var _theme$header, _theme$header$sticky;
|
|
35
|
+
|
|
36
|
+
// ensure that header moves with the target
|
|
37
|
+
header.style.position = 'sticky';
|
|
38
|
+
header.style.top = '0px';
|
|
39
|
+
header.style.zIndex = "" + ((_theme$header = theme.header) == null ? void 0 : (_theme$header$sticky = _theme$header.sticky) == null ? void 0 : _theme$header$sticky.zIndex);
|
|
40
|
+
header.style.transition = 'top 0.6s';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
scrollTop = nextScrollTop;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
if (sticky === 'scrollup') {
|
|
48
|
+
updateScrollDir();
|
|
49
|
+
window.addEventListener('resize', updateScrollDir);
|
|
50
|
+
window.addEventListener('scroll', updateScrollDir, true);
|
|
51
|
+
}
|
|
7
52
|
|
|
53
|
+
return function () {
|
|
54
|
+
if (sticky === 'scrollup') {
|
|
55
|
+
window.removeEventListener('resize', updateScrollDir);
|
|
56
|
+
window.removeEventListener('scroll', updateScrollDir, true);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}, [headerRef, sticky, (_theme$header2 = theme.header) == null ? void 0 : (_theme$header2$sticky = _theme$header2.sticky) == null ? void 0 : _theme$header2$sticky.zIndex]);
|
|
8
60
|
return /*#__PURE__*/React.createElement(Box, _extends({
|
|
9
61
|
align: "center",
|
|
10
62
|
as: "header",
|
|
11
63
|
direction: "row",
|
|
12
64
|
flex: false,
|
|
13
65
|
justify: "between",
|
|
14
|
-
gap: "medium"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}));
|
|
66
|
+
gap: "medium",
|
|
67
|
+
ref: headerRef
|
|
68
|
+
}, rest));
|
|
18
69
|
});
|
|
19
70
|
Header.displayName = 'Header';
|
|
20
71
|
export { Header };
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { BoxExtendedProps } from '../Box';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
export interface HeaderProps {
|
|
5
|
+
sticky?: 'scrollup';
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface HeaderExtendedProps extends BoxExtendedProps, HeaderProps {}
|
|
9
|
+
|
|
10
|
+
declare const Header: React.FC<HeaderExtendedProps>;
|
|
5
11
|
|
|
6
12
|
export { Header };
|