grommet 2.36.1 → 2.37.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.
Files changed (67) hide show
  1. package/components/Data/stories/OnSelect.js +264 -0
  2. package/components/DataSearch/DataSearch.js +5 -0
  3. package/components/DataTable/DataTable.js +9 -16
  4. package/components/DataTable/Header.js +22 -15
  5. package/components/DataTable/index.d.ts +5 -1
  6. package/components/DataTableColumns/DataTableColumns.js +16 -2
  7. package/components/DataTableColumns/index.d.ts +9 -1
  8. package/components/DataTableColumns/propTypes.js +1 -0
  9. package/components/DataTableColumns/stories/Pinned.js +46 -0
  10. package/components/FormField/FormField.js +1 -1
  11. package/components/List/List.js +43 -19
  12. package/components/List/index.d.ts +20 -6
  13. package/components/List/propTypes.js +6 -1
  14. package/components/Pagination/Pagination.js +3 -0
  15. package/components/Skeleton/StyledSkeleton.js +5 -2
  16. package/components/ToggleGroup/README.md +2 -0
  17. package/components/ToggleGroup/StyledToggleGroup.js +36 -0
  18. package/components/ToggleGroup/ToggleGroup.js +165 -0
  19. package/components/ToggleGroup/index.d.ts +26 -0
  20. package/components/ToggleGroup/index.js +6 -0
  21. package/components/ToggleGroup/propTypes.js +21 -0
  22. package/components/ToggleGroup/stories/Controlled.js +31 -0
  23. package/components/ToggleGroup/stories/multiple.tsx +28 -0
  24. package/components/ToggleGroup/stories/simple.js +37 -0
  25. package/components/index.d.ts +1 -0
  26. package/components/index.js +6 -0
  27. package/es6/components/Data/stories/OnSelect.js +258 -0
  28. package/es6/components/DataSearch/DataSearch.js +5 -0
  29. package/es6/components/DataTable/DataTable.js +9 -16
  30. package/es6/components/DataTable/Header.js +22 -15
  31. package/es6/components/DataTable/index.d.ts +5 -1
  32. package/es6/components/DataTableColumns/DataTableColumns.js +16 -2
  33. package/es6/components/DataTableColumns/index.d.ts +9 -1
  34. package/es6/components/DataTableColumns/propTypes.js +1 -0
  35. package/es6/components/DataTableColumns/stories/Pinned.js +42 -0
  36. package/es6/components/FormField/FormField.js +1 -1
  37. package/es6/components/List/List.js +44 -20
  38. package/es6/components/List/index.d.ts +20 -6
  39. package/es6/components/List/propTypes.js +7 -2
  40. package/es6/components/Pagination/Pagination.js +3 -0
  41. package/es6/components/Skeleton/StyledSkeleton.js +5 -2
  42. package/es6/components/ToggleGroup/README.md +2 -0
  43. package/es6/components/ToggleGroup/StyledToggleGroup.js +31 -0
  44. package/es6/components/ToggleGroup/ToggleGroup.js +160 -0
  45. package/es6/components/ToggleGroup/index.d.ts +26 -0
  46. package/es6/components/ToggleGroup/index.js +1 -0
  47. package/es6/components/ToggleGroup/propTypes.js +16 -0
  48. package/es6/components/ToggleGroup/stories/Controlled.js +25 -0
  49. package/es6/components/ToggleGroup/stories/multiple.tsx +28 -0
  50. package/es6/components/ToggleGroup/stories/simple.js +34 -0
  51. package/es6/components/index.d.ts +1 -0
  52. package/es6/components/index.js +1 -0
  53. package/es6/index.d.ts +1 -0
  54. package/es6/themes/base.d.ts +20 -1
  55. package/es6/themes/base.js +19 -0
  56. package/es6/utils/DOM.js +3 -1
  57. package/es6/utils/styles.js +1 -1
  58. package/es6/utils/useControlled.js +25 -0
  59. package/grommet.min.js +1 -1
  60. package/grommet.min.js.map +1 -1
  61. package/index.d.ts +1 -0
  62. package/package.json +18 -18
  63. package/themes/base.d.ts +20 -1
  64. package/themes/base.js +19 -0
  65. package/utils/DOM.js +3 -1
  66. package/utils/styles.js +1 -1
  67. package/utils/useControlled.js +28 -0
@@ -0,0 +1,258 @@
1
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(typeof e + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
2
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
3
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
4
+ import React, { useEffect, useState } from 'react';
5
+ import { Box, DataTable, Data, Grid, Pagination, Text, Tip } from 'grommet';
6
+ import { StatusCritical } from "grommet-icons/es6/icons/StatusCritical";
7
+ var buildQuery = function buildQuery(view) {
8
+ var query = {};
9
+ var properties = (view == null ? void 0 : view.properties) || [];
10
+ Object.keys(properties).forEach(function (property) {
11
+ switch (property) {
12
+ case 'success':
13
+ if (properties.success.length === 1) {
14
+ query[property] = properties.success[0] === 'Successful';
15
+ }
16
+ break;
17
+ case 'rocket':
18
+ query.rocket = {
19
+ $in: properties.rocket
20
+ };
21
+ break;
22
+ default:
23
+ query[property] = properties[property];
24
+ }
25
+ });
26
+ if (view != null && view.search) query.$text = {
27
+ $search: view.search
28
+ };
29
+ return query;
30
+ };
31
+ var fetchLaunches = /*#__PURE__*/function () {
32
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(view) {
33
+ var _view$sort, _view$sort2, _sort;
34
+ var query, sort, body;
35
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
36
+ while (1) switch (_context.prev = _context.next) {
37
+ case 0:
38
+ query = buildQuery(view);
39
+ sort = (_sort = {}, _sort[(view == null || (_view$sort = view.sort) == null ? void 0 : _view$sort.property) || 'name'] = (view == null || (_view$sort2 = view.sort) == null ? void 0 : _view$sort2.direction) || 'asc', _sort);
40
+ body = {
41
+ options: {
42
+ populate: [{
43
+ path: 'rocket',
44
+ select: {
45
+ name: 1
46
+ }
47
+ }],
48
+ sort: sort,
49
+ select: ['name', 'success', 'failures'],
50
+ limit: (view == null ? void 0 : view.step) || 10,
51
+ page: (view == null ? void 0 : view.page) || 1
52
+ },
53
+ query: query
54
+ };
55
+ return _context.abrupt("return", fetch('https://api.spacexdata.com/v4/launches/query', {
56
+ method: 'POST',
57
+ headers: {
58
+ 'Content-Type': 'application/json'
59
+ },
60
+ body: JSON.stringify(body)
61
+ }).then(function (response) {
62
+ return response.json();
63
+ }));
64
+ case 4:
65
+ case "end":
66
+ return _context.stop();
67
+ }
68
+ }, _callee);
69
+ }));
70
+ return function fetchLaunches(_x) {
71
+ return _ref.apply(this, arguments);
72
+ };
73
+ }();
74
+ var fetchRockets = /*#__PURE__*/function () {
75
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
76
+ var body;
77
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
78
+ while (1) switch (_context2.prev = _context2.next) {
79
+ case 0:
80
+ body = {
81
+ options: {
82
+ sort: {
83
+ name: 'asc'
84
+ },
85
+ select: ['name', 'id']
86
+ }
87
+ };
88
+ return _context2.abrupt("return", fetch('https://api.spacexdata.com/v4/rockets/query', {
89
+ method: 'POST',
90
+ headers: {
91
+ 'Content-Type': 'application/json'
92
+ },
93
+ body: JSON.stringify(body)
94
+ }).then(function (response) {
95
+ return response.json();
96
+ }));
97
+ case 2:
98
+ case "end":
99
+ return _context2.stop();
100
+ }
101
+ }, _callee2);
102
+ }));
103
+ return function fetchRockets() {
104
+ return _ref2.apply(this, arguments);
105
+ };
106
+ }();
107
+ var columns = [{
108
+ property: 'name',
109
+ header: 'Name',
110
+ size: 'small',
111
+ primary: true
112
+ }, {
113
+ property: 'rocket.name',
114
+ header: 'Rocket',
115
+ size: 'xsmall',
116
+ sortable: false
117
+ }, {
118
+ property: 'success',
119
+ header: 'Success',
120
+ size: 'xsmall',
121
+ align: 'center',
122
+ sortable: false,
123
+ render: function render(datum) {
124
+ if (datum.success === false) {
125
+ var _datum$failures;
126
+ var content = /*#__PURE__*/React.createElement(Box, {
127
+ width: {
128
+ max: 'medium'
129
+ }
130
+ }, (_datum$failures = datum.failures) == null ? void 0 : _datum$failures.map(function (_ref3) {
131
+ var reason = _ref3.reason;
132
+ return /*#__PURE__*/React.createElement(Text, {
133
+ key: reason
134
+ }, reason);
135
+ }));
136
+ return /*#__PURE__*/React.createElement(Tip, {
137
+ content: content,
138
+ dropProps: {
139
+ pad: 'small',
140
+ background: 'background'
141
+ }
142
+ }, /*#__PURE__*/React.createElement(Box, {
143
+ direction: "row",
144
+ align: "center",
145
+ gap: "xsmall"
146
+ }, /*#__PURE__*/React.createElement(StatusCritical, {
147
+ color: "red"
148
+ }), /*#__PURE__*/React.createElement(Text, null, "Failed")));
149
+ }
150
+ return undefined;
151
+ }
152
+ }];
153
+ var defaultView = {
154
+ search: '',
155
+ sort: {
156
+ property: 'name',
157
+ direction: 'asc'
158
+ },
159
+ step: 10
160
+ };
161
+ export var OnSelect = function OnSelect() {
162
+ var _useState = useState(0),
163
+ total = _useState[0],
164
+ setTotal = _useState[1];
165
+ var _useState2 = useState({
166
+ data: []
167
+ }),
168
+ result = _useState2[0],
169
+ setResult = _useState2[1];
170
+ var _useState3 = useState([]),
171
+ rockets = _useState3[0],
172
+ setRockets = _useState3[1];
173
+ var _useState4 = useState(defaultView),
174
+ view = _useState4[0],
175
+ setView = _useState4[1];
176
+ var _useState5 = useState([]),
177
+ select = _useState5[0],
178
+ setSelect = _useState5[1];
179
+
180
+ // Fetch all rockets on first render for use in the filter
181
+ useEffect(function () {
182
+ fetchRockets().then(function (response) {
183
+ return setRockets(response.docs.map(function (_ref4) {
184
+ var name = _ref4.name,
185
+ id = _ref4.id;
186
+ return {
187
+ value: id,
188
+ label: name
189
+ };
190
+ }));
191
+ });
192
+ }, []);
193
+ useEffect(function () {
194
+ fetchLaunches(view).then(function (response) {
195
+ setResult({
196
+ data: response.docs,
197
+ filteredTotal: response.totalDocs,
198
+ page: response.page
199
+ });
200
+ // The REST API doesn't return the unfiltered total in responses.
201
+ // Since the first request likely has no filtering, we'll likely use
202
+ // response.totalDocs the first time and prevTotal thereafter.
203
+ setTotal(function (prevTotal) {
204
+ return Math.max(prevTotal, response.totalDocs);
205
+ });
206
+ });
207
+ }, [view]);
208
+ return (
209
+ /*#__PURE__*/
210
+ // Uncomment <Grommet> lines when using outside of storybook
211
+ // <Grommet theme={...}>
212
+ React.createElement(Grid, {
213
+ flex: false,
214
+ pad: "large",
215
+ columns: [['small', 'large']],
216
+ justifyContent: "center"
217
+ }, /*#__PURE__*/React.createElement(Data, {
218
+ properties: {
219
+ rocket: {
220
+ label: 'Rocket',
221
+ options: rockets
222
+ },
223
+ success: {
224
+ label: 'Success',
225
+ options: ['Successful', 'Failed']
226
+ }
227
+ },
228
+ data: result.data,
229
+ total: total,
230
+ filteredTotal: result.filteredTotal,
231
+ defaultView: defaultView,
232
+ view: view,
233
+ onView: setView,
234
+ toolbar: true
235
+ }, /*#__PURE__*/React.createElement(DataTable, {
236
+ columns: columns,
237
+ sortable: true,
238
+ select: select,
239
+ onSelect: setSelect
240
+ }), /*#__PURE__*/React.createElement(Pagination, {
241
+ summary: true,
242
+ stepOptions: true,
243
+ border: "top",
244
+ pad: {
245
+ vertical: 'xsmall',
246
+ left: 'small'
247
+ }
248
+ })))
249
+ // </Grommet>
250
+ );
251
+ };
252
+ OnSelect.storyName = 'OnSelect';
253
+ OnSelect.args = {
254
+ full: true
255
+ };
256
+ export default {
257
+ title: 'Data/Data/OnSelect'
258
+ };
@@ -76,6 +76,11 @@ export var DataSearch = function DataSearch(_ref) {
76
76
  delete nextView.view;
77
77
  delete nextView.name;
78
78
  }
79
+
80
+ // If page is set, reset it to 1
81
+ if (nextView.page) {
82
+ nextView.page = 1;
83
+ }
79
84
  onView(nextView);
80
85
  };
81
86
  var onChange = function onChange(e) {
@@ -223,7 +223,7 @@ var DataTable = function DataTable(_ref) {
223
223
  pinnedProperties = ['_grommetDataTableSelect'].concat(pinnedProperties);
224
224
  }
225
225
  var nextPinnedOffset = {};
226
- if (columnWidths !== []) {
226
+ if (columnWidths.length !== 0) {
227
227
  pinnedProperties.forEach(function (property, index) {
228
228
  var columnIndex = property === '_grommetDataTableSelect' ? 0 : columns.findIndex(function (column) {
229
229
  return column.property === property;
@@ -420,6 +420,11 @@ var DataTable = function DataTable(_ref) {
420
420
  fill: "vertical"
421
421
  }, /*#__PURE__*/React.createElement(Text, null, placeholder));
422
422
  }
423
+ var handleSelect = function handleSelect(nextSelected, row) {
424
+ setSelected(nextSelected);
425
+ if (setSelectedDataContext) setSelectedDataContext(nextSelected.length);
426
+ if (row) onSelect(nextSelected, row);else onSelect(nextSelected);
427
+ };
423
428
  var bodyContent = groups ? /*#__PURE__*/React.createElement(GroupedBody, {
424
429
  ref: bodyRef,
425
430
  cellProps: {
@@ -451,11 +456,7 @@ var DataTable = function DataTable(_ref) {
451
456
  });
452
457
  }
453
458
  } : onMore,
454
- onSelect: onSelect ? function (nextSelected, row) {
455
- setSelected(nextSelected);
456
- if (setSelectedDataContext) setSelectedDataContext(nextSelected.length);
457
- if (onSelect) onSelect(nextSelected, row);
458
- } : undefined,
459
+ onSelect: onSelect ? handleSelect : undefined,
459
460
  onToggle: onToggleGroup,
460
461
  onUpdate: onUpdate,
461
462
  replace: replace,
@@ -485,11 +486,7 @@ var DataTable = function DataTable(_ref) {
485
486
  } : onMore,
486
487
  replace: replace,
487
488
  onClickRow: onClickRow,
488
- onSelect: onSelect ? function (nextSelected, row) {
489
- setSelected(nextSelected);
490
- if (setSelectedDataContext) setSelectedDataContext(nextSelected.length);
491
- if (onSelect) onSelect(nextSelected, row);
492
- } : undefined,
489
+ onSelect: onSelect ? handleSelect : undefined,
493
490
  pinnedCellProps: cellProps.pinned,
494
491
  pinnedOffset: pinnedOffset,
495
492
  primaryProperty: primaryProperty,
@@ -527,11 +524,7 @@ var DataTable = function DataTable(_ref) {
527
524
  onFiltering: onFiltering,
528
525
  onFilter: onFilter,
529
526
  onResize: resizeable ? onResize : undefined,
530
- onSelect: onSelect ? function (nextSelected) {
531
- setSelected(nextSelected);
532
- if (setSelectedDataContext) setSelectedDataContext(nextSelected.length);
533
- if (onSelect) onSelect(nextSelected);
534
- } : undefined,
527
+ onSelect: onSelect ? handleSelect : undefined,
535
528
  onSort: sortable || sortProp || onSortProp ? onSort : undefined,
536
529
  onToggle: onToggleGroups,
537
530
  onWidths: onHeaderWidths,
@@ -5,6 +5,7 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
5
5
  /* eslint-disable no-underscore-dangle */
6
6
  import React, { forwardRef, useCallback, useContext, useEffect, useState } from 'react';
7
7
  import styled, { css, ThemeContext } from 'styled-components';
8
+ import { DataContext } from '../../contexts/DataContext';
8
9
  import { defaultProps } from '../../default-props';
9
10
  import { Box } from '../Box';
10
11
  import { Button } from '../Button';
@@ -124,6 +125,8 @@ var Header = /*#__PURE__*/forwardRef(function (_ref2, ref) {
124
125
  var _separateThemeProps2 = separateThemeProps(theme),
125
126
  layoutProps = _separateThemeProps2[0],
126
127
  textProps = _separateThemeProps2[1];
128
+ var _useContext = useContext(DataContext),
129
+ contextTotal = _useContext.total;
127
130
  var _useState = useState([]),
128
131
  cellWidths = _useState[0],
129
132
  setCellWidths = _useState[1];
@@ -144,15 +147,14 @@ var Header = /*#__PURE__*/forwardRef(function (_ref2, ref) {
144
147
  }, 0) : 0;
145
148
  var totalSelected = ((selected == null ? void 0 : selected.length) || 0) + totalSelectedGroups;
146
149
  var onChangeSelection = useCallback(function () {
147
- var nextSelected;
150
+ var nextSelected = [].concat(selected);
148
151
  var nextGroupSelected = {};
149
152
 
150
- // Since some rows might be disabled but already selected, we need to
151
- // note which rows are enabled when determining how aggregate selection
152
- // works.
153
+ // get primary values for current data view
153
154
  var primaryValues = data.map(function (datum) {
154
155
  return datumValue(datum, primaryProperty);
155
156
  }) || [];
157
+
156
158
  // enabled includes what can be changed
157
159
  var enabled = disabled && primaryValues.filter(function (v) {
158
160
  return !disabled.includes(v);
@@ -162,19 +164,24 @@ var Header = /*#__PURE__*/forwardRef(function (_ref2, ref) {
162
164
  return selected.includes(v);
163
165
  }) || primaryValues;
164
166
  var allSelected = groupBy != null && groupBy.select ? groupBy.select[''] === 'all' : enabledSelected.length === enabled.length;
167
+
168
+ // if all enabled are already selected, remove them from selected,
169
+ // otherwise add them.
165
170
  if (allSelected) {
166
- // if any are disabled and selected, leave those, otherwise clear
167
- nextSelected = disabled ? primaryValues.filter(function (v) {
168
- return disabled.includes(v) && selected.includes(v);
169
- }) : [];
171
+ enabledSelected.forEach(function (p) {
172
+ var index = nextSelected.indexOf(p);
173
+ if (index >= 0) {
174
+ nextSelected.splice(index, 1);
175
+ }
176
+ });
170
177
  nextGroupSelected[''] = 'none';
171
178
  } else {
172
179
  var _groupBy$expandable;
173
- // if some or none are selected, select all enabled plus all disabled
174
- // that are already selected
175
- nextSelected = disabled ? primaryValues.filter(function (v) {
176
- return !disabled.includes(v) || selected.includes(v);
177
- }) : primaryValues;
180
+ enabled.forEach(function (p) {
181
+ if (!nextSelected.includes(p)) {
182
+ nextSelected.push(p);
183
+ }
184
+ });
178
185
  nextGroupSelected[''] = 'all';
179
186
  groupBy == null || (_groupBy$expandable = groupBy.expandable) == null || _groupBy$expandable.forEach(function (key) {
180
187
  nextGroupSelected[key] = 'all';
@@ -208,8 +215,8 @@ var Header = /*#__PURE__*/forwardRef(function (_ref2, ref) {
208
215
  verticalAlign: verticalAlign
209
216
  }, onSelect && allowSelectAll && /*#__PURE__*/React.createElement(CheckBox, {
210
217
  a11yTitle: totalSelected === data.length ? 'unselect all' : 'select all',
211
- checked: groupBy != null && groupBy.select ? groupBy.select[''] === 'all' : totalSelected > 0 && data.length > 0 && totalSelected === data.length,
212
- indeterminate: groupBy != null && groupBy.select ? groupBy.select[''] === 'some' : totalSelected > 0 && totalSelected < data.length,
218
+ checked: groupBy != null && groupBy.select ? groupBy.select[''] === 'all' : totalSelected > 0 && data.length > 0 && totalSelected === (contextTotal || data.length),
219
+ indeterminate: groupBy != null && groupBy.select ? groupBy.select[''] === 'some' : totalSelected > 0 && totalSelected < (contextTotal || data.length),
213
220
  onChange: onChangeSelection,
214
221
  pad: cellProps.pad
215
222
  })), rowDetails && /*#__PURE__*/React.createElement(TableCell, {
@@ -114,7 +114,11 @@ export interface DataTableProps<TRowType = any> {
114
114
  expandable?: Array<string>;
115
115
  select?: { [key: string]: 'all' | 'some' | 'none' };
116
116
  onExpand?: (expandedKeys: string[]) => void;
117
- onSelect?: (select: (string | number)[], datum: TRowType) => void;
117
+ onSelect?: (
118
+ select: (string | number)[],
119
+ datum: TRowType,
120
+ groupBySelected: any,
121
+ ) => void;
118
122
  };
119
123
  primaryKey?: string | boolean;
120
124
  select?: (string | number)[];
@@ -5,6 +5,7 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
5
5
  import React, { useCallback, useContext, useMemo, useState } from 'react';
6
6
  import { Search } from 'grommet-icons/icons/Search';
7
7
  import { Splits } from 'grommet-icons/icons/Splits';
8
+ import { Lock } from 'grommet-icons/icons/Lock';
8
9
  import { ThemeContext } from 'styled-components';
9
10
  import { Box } from '../Box';
10
11
  import { CheckBoxGroup } from '../CheckBoxGroup';
@@ -95,7 +96,19 @@ var Content = function Content(_ref) {
95
96
  var objectOptions = useMemo(function () {
96
97
  return options && options.length && typeof options[0] === 'object';
97
98
  }, [options]);
98
-
99
+ var pinned = useMemo(function () {
100
+ var items = objectOptions ? options.filter(function (option) {
101
+ return option.pinned && option.label;
102
+ }).map(function (option) {
103
+ return option.label;
104
+ }) : [];
105
+ return items != null && items.length ? {
106
+ background: 'none',
107
+ color: 'text-weak',
108
+ icon: /*#__PURE__*/React.createElement(Lock, null),
109
+ items: items
110
+ } : undefined;
111
+ }, [options, objectOptions]);
99
112
  // 'value' is an array of property names
100
113
  var _useFormInput = useFormInput({
101
114
  name: formColumnsKey,
@@ -173,7 +186,8 @@ var Content = function Content(_ref) {
173
186
  return setValue(optionsToValue(nextData));
174
187
  },
175
188
  pad: "none",
176
- primaryKey: objectOptions && 'label' || undefined
189
+ primaryKey: objectOptions && 'label' || undefined,
190
+ pinned: pinned
177
191
  })))));
178
192
  };
179
193
  export var DataTableColumns = function DataTableColumns(_ref5) {
@@ -2,7 +2,15 @@ import * as React from 'react';
2
2
 
3
3
  export interface DataTableColumnsProps {
4
4
  drop: boolean;
5
- options: (string | { property: string; label: string; disabled?: boolean })[];
5
+ options: (
6
+ | string
7
+ | {
8
+ property: string;
9
+ label: string;
10
+ disabled?: boolean;
11
+ pinned?: boolean;
12
+ }
13
+ )[];
6
14
  }
7
15
 
8
16
  declare const DataTableColumns: React.FC<DataTableColumnsProps>;
@@ -6,6 +6,7 @@ if (process.env.NODE_ENV !== 'production') {
6
6
  options: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.arrayOf(PropTypes.shape({
7
7
  disabled: PropTypes.bool,
8
8
  label: PropTypes.string,
9
+ pinned: PropTypes.bool,
9
10
  property: PropTypes.string
10
11
  }))]).isRequired
11
12
  };
@@ -0,0 +1,42 @@
1
+ import React from 'react';
2
+ import { Box, Data, DataSearch, DataSummary, DataTable, DataTableColumns, Toolbar } from 'grommet';
3
+ import { columns, DATA } from '../../DataTable/stories/data';
4
+
5
+ // simplify option label for name property
6
+ var options = columns.map(function (_ref, i) {
7
+ var header = _ref.header,
8
+ property = _ref.property;
9
+ return {
10
+ property: property,
11
+ label: property === 'name' ? 'Name' : header,
12
+ pinned: i === 0 || i === 1
13
+ };
14
+ });
15
+ export var Pinned = function Pinned() {
16
+ return (
17
+ /*#__PURE__*/
18
+ // Uncomment <Grommet> lines when using outside of storybook
19
+ // <Grommet theme={...}>
20
+ React.createElement(Box, {
21
+ align: "center",
22
+ justify: "start",
23
+ pad: "large",
24
+ gap: "medium"
25
+ }, /*#__PURE__*/React.createElement(Data, {
26
+ data: DATA
27
+ }, /*#__PURE__*/React.createElement(Toolbar, null, /*#__PURE__*/React.createElement(DataSearch, null), /*#__PURE__*/React.createElement(DataTableColumns, {
28
+ drop: true,
29
+ options: options
30
+ })), /*#__PURE__*/React.createElement(DataSummary, null), /*#__PURE__*/React.createElement(DataTable, {
31
+ columns: columns,
32
+ primaryKey: "name"
33
+ })))
34
+ // </Grommet>
35
+ );
36
+ };
37
+ Pinned.args = {
38
+ full: true
39
+ };
40
+ export default {
41
+ title: 'Data/DataTableColumns/Pinned'
42
+ };
@@ -171,7 +171,7 @@ var FormField = /*#__PURE__*/forwardRef(function (_ref3, ref) {
171
171
  if (children) {
172
172
  Children.map(children, function (child) {
173
173
  var _child$props, _child$props2;
174
- if ((((_child$props = child.props) == null ? void 0 : _child$props.readOnly) === true || ((_child$props2 = child.props) == null ? void 0 : _child$props2.readOnlyCopy) === true) && child.type && ('TextInput'.indexOf(child.type.displayName) !== -1 || 'DateInput'.indexOf(child.type.displayName) !== -1)) {
174
+ if (((child == null || (_child$props = child.props) == null ? void 0 : _child$props.readOnly) === true || (child == null || (_child$props2 = child.props) == null ? void 0 : _child$props2.readOnlyCopy) === true) && child.type && ('TextInput'.indexOf(child.type.displayName) !== -1 || 'DateInput'.indexOf(child.type.displayName) !== -1)) {
175
175
  readOnly = true;
176
176
  }
177
177
  });