@pingux/astro 2.25.0-alpha.1 → 2.25.0-alpha.2

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.
@@ -32,6 +32,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
32
32
  /* eslint-disable testing-library/no-node-access */
33
33
  import React from 'react';
34
34
  import { useAsyncList } from 'react-stately';
35
+ import { useCollator } from '@react-aria/i18n';
35
36
  import { act, fireEvent, render, screen, within } from '@testing-library/react';
36
37
  import { act as actHooks, renderHook } from '@testing-library/react-hooks';
37
38
  import { DataTableBody, DataTableCell, DataTableColumn, DataTableHeader, DataTableRow } from '../../index';
@@ -307,7 +308,7 @@ describe('Async DataTable', function () {
307
308
  act(function () {
308
309
  jest.runAllTimers();
309
310
  });
310
- expect(onLoadMore).toHaveBeenCalledTimes(2);
311
+ expect(onLoadMore).toHaveBeenCalledTimes(6);
311
312
  });
312
313
  test('renders a spinner at the bottom when loading more', function () {
313
314
  var testId = 'loadingMoreTable';
@@ -811,10 +812,16 @@ describe('Sortable DataTable with useAsyncList', function () {
811
812
  })));
812
813
  };
813
814
  test('click on column header should sort column A => Z', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
814
- var _renderHook5, result, sortableTable, headers;
815
+ var utils, collator, _renderHook5, result, sortableTable, headers;
815
816
  return _regeneratorRuntime().wrap(function _callee24$(_context28) {
816
817
  while (1) switch (_context28.prev = _context28.next) {
817
818
  case 0:
819
+ utils = renderHook(function () {
820
+ return useCollator({
821
+ numeric: true
822
+ });
823
+ });
824
+ collator = utils.result.current;
818
825
  _renderHook5 = renderHook(function () {
819
826
  return useAsyncList({
820
827
  load: function load() {
@@ -844,7 +851,7 @@ describe('Sortable DataTable with useAsyncList', function () {
844
851
  var first = a[sortDescriptor.column];
845
852
  var second = b[sortDescriptor.column];
846
853
  // eslint-disable-next-line radix
847
- var cmp = (_parseInt(first) || first) < (_parseInt(second) || second) ? -1 : 1;
854
+ var cmp = collator.compare(first, second);
848
855
  if (sortDescriptor.direction === 'descending') {
849
856
  cmp *= -1;
850
857
  }
@@ -864,7 +871,7 @@ describe('Sortable DataTable with useAsyncList', function () {
864
871
  }
865
872
  });
866
873
  }), result = _renderHook5.result;
867
- _context28.next = 3;
874
+ _context28.next = 5;
868
875
  return actHooks( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
869
876
  return _regeneratorRuntime().wrap(function _callee19$(_context23) {
870
877
  while (1) switch (_context23.prev = _context23.next) {
@@ -876,11 +883,11 @@ describe('Sortable DataTable with useAsyncList', function () {
876
883
  }
877
884
  }, _callee19);
878
885
  })));
879
- case 3:
886
+ case 5:
880
887
  sortableDataTable({
881
888
  result: result
882
889
  });
883
- _context28.next = 6;
890
+ _context28.next = 8;
884
891
  return actHooks( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
885
892
  return _regeneratorRuntime().wrap(function _callee20$(_context24) {
886
893
  while (1) switch (_context24.prev = _context24.next) {
@@ -892,7 +899,7 @@ describe('Sortable DataTable with useAsyncList', function () {
892
899
  }
893
900
  }, _callee20);
894
901
  })));
895
- case 6:
902
+ case 8:
896
903
  sortableTable = screen.getByTestId(testId);
897
904
  expect(sortableTable).toBeInTheDocument();
898
905
  expect(sortableTable).toBeVisible();
@@ -916,7 +923,7 @@ describe('Sortable DataTable with useAsyncList', function () {
916
923
  expect(result.current.items[1].continent).toBe('North America');
917
924
  expect(result.current.items[2].continent).toBe('Asia');
918
925
  expect(result.current.items[3].continent).toBe('Europe');
919
- _context28.next = 31;
926
+ _context28.next = 33;
920
927
  return actHooks( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
921
928
  return _regeneratorRuntime().wrap(function _callee21$(_context25) {
922
929
  while (1) switch (_context25.prev = _context25.next) {
@@ -928,12 +935,12 @@ describe('Sortable DataTable with useAsyncList', function () {
928
935
  }
929
936
  }, _callee21);
930
937
  })));
931
- case 31:
938
+ case 33:
932
939
  expect(result.current.items[0].country).toBe('Canada');
933
940
  expect(result.current.items[1].country).toBe('China');
934
941
  expect(result.current.items[2].country).toBe('France');
935
942
  expect(result.current.items[3].country).toBe('USA');
936
- _context28.next = 37;
943
+ _context28.next = 39;
937
944
  return actHooks( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
938
945
  return _regeneratorRuntime().wrap(function _callee22$(_context26) {
939
946
  while (1) switch (_context26.prev = _context26.next) {
@@ -945,12 +952,12 @@ describe('Sortable DataTable with useAsyncList', function () {
945
952
  }
946
953
  }, _callee22);
947
954
  })));
948
- case 37:
955
+ case 39:
949
956
  expect(result.current.items[0].population).toBe(37000000);
950
957
  expect(result.current.items[1].population).toBe(67000000);
951
958
  expect(result.current.items[2].population).toBe(320000000);
952
959
  expect(result.current.items[3].population).toBe(1398000000);
953
- _context28.next = 43;
960
+ _context28.next = 45;
954
961
  return actHooks( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
955
962
  return _regeneratorRuntime().wrap(function _callee23$(_context27) {
956
963
  while (1) switch (_context27.prev = _context27.next) {
@@ -962,12 +969,12 @@ describe('Sortable DataTable with useAsyncList', function () {
962
969
  }
963
970
  }, _callee23);
964
971
  })));
965
- case 43:
972
+ case 45:
966
973
  expect(result.current.items[0].continent).toBe('Asia');
967
974
  expect(result.current.items[1].continent).toBe('Europe');
968
975
  expect(result.current.items[2].continent).toBe('North America');
969
976
  expect(result.current.items[3].continent).toBe('North America');
970
- case 47:
977
+ case 49:
971
978
  case "end":
972
979
  return _context28.stop();
973
980
  }
@@ -9,6 +9,7 @@ var DataTableMenu = /*#__PURE__*/forwardRef(function (props, ref) {
9
9
  }, ___EmotionJSX(OverlayProvider, null, ___EmotionJSX(PopoverMenu, null, ___EmotionJSX(IconButton, {
10
10
  "aria-label": "row menu"
11
11
  }, ___EmotionJSX(Icon, {
12
+ size: 25,
12
13
  icon: DotsVerticalIcon,
13
14
  title: {
14
15
  name: 'Dots Vertical Icon'
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
3
- var _excluded = ["layout", "collection", "focusedKey", "renderView", "renderWrapper", "domRef", "bodyRef", "setTableWidth", "getColumnWidth", "onVisibleRectChange"];
3
+ var _excluded = ["layout", "collection", "renderView", "renderWrapper", "domRef", "bodyRef", "setTableWidth", "getColumnWidth", "onVisibleRectChange"];
4
4
  import React, { forwardRef, useCallback, useRef } from 'react';
5
5
  import { chain, mergeProps, useLayoutEffect } from '@react-aria/utils';
6
6
  import { ScrollView, setScrollLeft, useVirtualizer } from '@react-aria/virtualizer';
@@ -17,7 +17,6 @@ var DataTableVirtualizer = /*#__PURE__*/forwardRef(function (_ref, ref) {
17
17
  var _layout$getLayoutInfo;
18
18
  var layout = _ref.layout,
19
19
  collection = _ref.collection,
20
- focusedKey = _ref.focusedKey,
21
20
  renderView = _ref.renderView,
22
21
  renderWrapper = _ref.renderWrapper,
23
22
  domRef = _ref.domRef,
@@ -31,6 +30,7 @@ var DataTableVirtualizer = /*#__PURE__*/forwardRef(function (_ref, ref) {
31
30
  var loadingState = collection.body.props.loadingState;
32
31
  var isLoading = loadingState === 'loading' || loadingState === 'loadingMore';
33
32
  var onLoadMore = collection.body.props.onLoadMore;
33
+ /* istanbul ignore next */
34
34
  var state = useVirtualizerState({
35
35
  layout: layout,
36
36
  collection: collection,
@@ -44,7 +44,6 @@ var DataTableVirtualizer = /*#__PURE__*/forwardRef(function (_ref, ref) {
44
44
  transitionDuration: isLoading ? 160 : 220
45
45
  });
46
46
  var _useVirtualizer = useVirtualizer({
47
- focusedKey: focusedKey,
48
47
  scrollToItem: function scrollToItem(key) {
49
48
  var item = collection.getItem(key);
50
49
  state.virtualizer.scrollToItem(key, {
@@ -59,7 +58,7 @@ var DataTableVirtualizer = /*#__PURE__*/forwardRef(function (_ref, ref) {
59
58
  }, state, domRef),
60
59
  virtualizerProps = _useVirtualizer.virtualizerProps;
61
60
 
62
- // If column widths change, need to relay out.
61
+ // If column widths change, need to relay out
63
62
  useLayoutEffect(function () {
64
63
  state.virtualizer.relayoutNow({
65
64
  sizeChanged: true
@@ -73,7 +72,6 @@ var DataTableVirtualizer = /*#__PURE__*/forwardRef(function (_ref, ref) {
73
72
  headerRef.current.scrollLeft = bodyRef.current.scrollLeft;
74
73
  }, [bodyRef]);
75
74
  var onVisibleRectChange = useCallback(function (rect) {
76
- setTableWidth(rect.width);
77
75
  state.setVisibleRect(rect);
78
76
  if (!isLoading && onLoadMore) {
79
77
  var scrollOffset = state.virtualizer.contentSize.height - rect.height * 2;
@@ -81,9 +79,8 @@ var DataTableVirtualizer = /*#__PURE__*/forwardRef(function (_ref, ref) {
81
79
  onLoadMore();
82
80
  }
83
81
  }
84
- },
85
- // eslint-disable-next-line react-hooks/exhaustive-deps
86
- [onLoadMore, isLoading, state.setVisibleRect, state.virtualizer]);
82
+ // eslint-disable-next-line react-hooks/exhaustive-deps
83
+ }, [onLoadMore, isLoading, state.setVisibleRect, state.virtualizer]);
87
84
  useLayoutEffect(function () {
88
85
  if (!isLoading && onLoadMore && !state.isAnimating) {
89
86
  if (state.contentSize.height <= state.virtualizer.visibleRect.height) {
@@ -120,7 +117,8 @@ var DataTableVirtualizer = /*#__PURE__*/forwardRef(function (_ref, ref) {
120
117
  onVisibleRectChange: chain(onVisibleRectChange, onVisibleRectChangeProp),
121
118
  onScrollStart: state.startScrolling,
122
119
  onScrollEnd: state.endScrolling,
123
- onScroll: onScroll
120
+ onScroll: onScroll,
121
+ tabIndex: 0
124
122
  }, state.visibleViews[1]));
125
123
  });
126
124
  DataTableVirtualizer.propTypes = {
@@ -140,7 +138,6 @@ DataTableVirtualizer.propTypes = {
140
138
  getItem: PropTypes.func
141
139
  }),
142
140
  domRef: PropTypes.shape({}),
143
- focusedKey: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
144
141
  getColumnWidth: PropTypes.func,
145
142
  layout: PropTypes.shape({
146
143
  getLayoutInfo: PropTypes.func
@@ -2,4 +2,4 @@ export { default } from './DataTable';
2
2
  export { default as DataTableBadge } from './DataTableBadge';
3
3
  export { default as DataTableMenu } from './DataTableMenu';
4
4
  export { default as DataTableMultiLine } from './DataTableMultiLine';
5
- export { default as DataTableVirtualize } from './DataTableVirtualizer';
5
+ export { default as DataTableVirtualizer } from './DataTableVirtualizer';
@@ -182,6 +182,12 @@ export var text = {
182
182
  sectionTitle: sectionTitle,
183
183
  subtitle: subtitle,
184
184
  tabLabel: tabLabel,
185
+ tableHeader: _objectSpread(_objectSpread({}, wordWrap), {}, {
186
+ fontSize: 'sm',
187
+ fontWeight: 3,
188
+ color: 'text.primary',
189
+ fontFamily: 'standard'
190
+ }),
185
191
  tableData: _objectSpread(_objectSpread({}, wordWrap), {}, {
186
192
  fontSize: 'sm',
187
193
  fontWeight: 1,
@@ -0,0 +1,403 @@
1
+ import _typeof from "@babel/runtime-corejs3/helpers/esm/typeof";
2
+ import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
3
+ import _asyncToGenerator from "@babel/runtime-corejs3/helpers/esm/asyncToGenerator";
4
+ import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
5
+ 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 exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = _Object$defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof _Symbol ? _Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return _Object$defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = _Object$create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = _Object$getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = _Object$create(IteratorPrototype); function defineIteratorMethods(prototype) { var _context6; _forEachInstanceProperty(_context6 = ["next", "throw", "return"]).call(_context6, function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], _forEachInstanceProperty(tryLocsList).call(tryLocsList, pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return _Object$setPrototypeOf ? _Object$setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = _Object$create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = _Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return _reverseInstanceProperty(keys).call(keys), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { var _context7; if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, _forEachInstanceProperty(_context7 = this.tryEntries).call(_context7, resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+_sliceInstanceProperty(name).call(name, 1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
6
+ import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
7
+ import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
8
+ import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
9
+ import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
10
+ import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
11
+ import _Symbol from "@babel/runtime-corejs3/core-js-stable/symbol";
12
+ import _Object$create from "@babel/runtime-corejs3/core-js-stable/object/create";
13
+ import _Object$getPrototypeOf from "@babel/runtime-corejs3/core-js-stable/object/get-prototype-of";
14
+ import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
15
+ import _Object$setPrototypeOf from "@babel/runtime-corejs3/core-js-stable/object/set-prototype-of";
16
+ import _Promise from "@babel/runtime-corejs3/core-js-stable/promise";
17
+ import _reverseInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/reverse";
18
+ import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/slice";
19
+ import React, { useMemo, useState } from 'react';
20
+ import { useAsyncList } from 'react-stately';
21
+ import ArrowCollapseRightIcon from '@pingux/mdi-react/ArrowCollapseRightIcon';
22
+ import EyeOutlineIcon from '@pingux/mdi-react/EyeOutlineIcon';
23
+ import TrayArrowDownIcon from '@pingux/mdi-react/TrayArrowDownIcon';
24
+ import { Box, Button, CheckboxField, DataTable, DataTableBody, DataTableCell, DataTableColumn, DataTableHeader, DataTableRow, Icon, Image, Item, RadioField, RadioGroupField, SearchField, SelectField, Separator, Text } from '../index';
25
+ import { placeholder } from '../utils/devUtils/constants/images';
26
+ import { jsx as ___EmotionJSX } from "@emotion/react";
27
+ export default {
28
+ title: 'Recipes/Data Visualization with Filtering'
29
+ };
30
+ var columns = [{
31
+ name: 'Country',
32
+ key: 'country'
33
+ }, {
34
+ name: 'Population',
35
+ key: 'population'
36
+ }, {
37
+ name: 'Continent',
38
+ key: 'continent'
39
+ }];
40
+ var numberRanges = [{
41
+ label: '0-100',
42
+ numberLow: 0,
43
+ numberHigh: 100000000
44
+ }, {
45
+ label: '100+',
46
+ numberLow: 100000001,
47
+ numberHigh: 1000000000000
48
+ }];
49
+ var rows = [{
50
+ id: 1,
51
+ country: 'USA',
52
+ population: 320000000,
53
+ continent: 'North America'
54
+ }, {
55
+ id: 2,
56
+ country: 'Canada',
57
+ population: 37000000,
58
+ continent: 'North America'
59
+ }, {
60
+ id: 3,
61
+ country: 'China',
62
+ population: 1398000000,
63
+ continent: 'Asia'
64
+ }, {
65
+ id: 4,
66
+ country: 'France',
67
+ population: 67000000,
68
+ continent: 'Europe'
69
+ }, {
70
+ id: 5,
71
+ country: 'Mexico',
72
+ population: 126000000,
73
+ continent: 'South America'
74
+ }, {
75
+ id: 6,
76
+ country: 'Ethiopia',
77
+ population: 120000000,
78
+ continent: 'Africa'
79
+ }, {
80
+ id: 7,
81
+ country: 'Austria',
82
+ population: 25000000,
83
+ continent: 'Oceania'
84
+ }];
85
+ var ControlledCheckBoxGroup = function ControlledCheckBoxGroup(props) {
86
+ var value = props.value,
87
+ object = props.object,
88
+ onChangeCallback = props.onChangeCallback,
89
+ state = props.state;
90
+ var onSelect = function onSelect() {
91
+ if (_includesInstanceProperty(state).call(state, object)) {
92
+ var _context;
93
+ var newarr = _filterInstanceProperty(state).call(state, function (pop) {
94
+ return pop !== object;
95
+ });
96
+ onChangeCallback(_concatInstanceProperty(_context = []).call(_context, newarr));
97
+ } else {
98
+ var _context2;
99
+ onChangeCallback(_concatInstanceProperty(_context2 = []).call(_context2, state, [object]));
100
+ }
101
+ };
102
+ return ___EmotionJSX(CheckboxField, {
103
+ isSelected: _includesInstanceProperty(state).call(state, object),
104
+ onChange: function onChange() {
105
+ return onSelect();
106
+ },
107
+ label: value,
108
+ key: value,
109
+ paddingBottom: "5px"
110
+ });
111
+ };
112
+ var MemoizedCheckbox = /*#__PURE__*/React.memo(ControlledCheckBoxGroup);
113
+ var ControlledSelectField = function ControlledSelectField(props) {
114
+ var setSelectedContinent = props.setSelectedContinent,
115
+ selectedContinent = props.selectedContinent;
116
+ var handleSelectionChange = function handleSelectionChange(key) {
117
+ return setSelectedContinent(key);
118
+ };
119
+ return ___EmotionJSX(SelectField, {
120
+ selectedKey: selectedContinent,
121
+ onSelectionChange: handleSelectionChange,
122
+ label: "Filter by Continent",
123
+ mb: "lg",
124
+ key: "selectfield"
125
+ }, ___EmotionJSX(Item, {
126
+ key: "North America"
127
+ }, "North America"), ___EmotionJSX(Item, {
128
+ key: "South America"
129
+ }, "South America"), ___EmotionJSX(Item, {
130
+ key: "Africa"
131
+ }, "Africa"), ___EmotionJSX(Item, {
132
+ key: "Oceania"
133
+ }, "Oceania"), ___EmotionJSX(Item, {
134
+ key: "Europe"
135
+ }, "Europe"), ___EmotionJSX(Item, {
136
+ key: "Asia"
137
+ }, "Asia"), ___EmotionJSX(Item, {
138
+ key: "All Continents"
139
+ }, "All Continents"));
140
+ };
141
+ var ControlledRadioGroup = function ControlledRadioGroup(props) {
142
+ var state = props.state,
143
+ callback = props.callback;
144
+ return ___EmotionJSX(RadioGroupField, {
145
+ label: "Filter by Continent",
146
+ value: state,
147
+ onChange: function onChange(newValue) {
148
+ return callback(newValue);
149
+ },
150
+ key: "radioParent"
151
+ }, ___EmotionJSX(RadioField, {
152
+ value: "North America",
153
+ label: "North America",
154
+ key: "North America",
155
+ pb: "5px"
156
+ }), ___EmotionJSX(RadioField, {
157
+ value: "South America",
158
+ label: "South America",
159
+ key: "South America",
160
+ pb: "5px"
161
+ }), ___EmotionJSX(RadioField, {
162
+ value: "Africa",
163
+ label: "Africa",
164
+ key: "Africa",
165
+ pb: "5px"
166
+ }), ___EmotionJSX(RadioField, {
167
+ value: "Oceania",
168
+ label: "Oceania",
169
+ key: "Oceania",
170
+ pb: "5px"
171
+ }), ___EmotionJSX(RadioField, {
172
+ value: "Europe",
173
+ label: "Europe",
174
+ key: "Europe",
175
+ pb: "5px"
176
+ }), ___EmotionJSX(RadioField, {
177
+ value: "Asia",
178
+ label: "Asia",
179
+ key: "Asia",
180
+ pb: "5px"
181
+ }), ___EmotionJSX(RadioField, {
182
+ value: "All Continents",
183
+ label: "All Continents",
184
+ key: "All Continents",
185
+ pb: "5px"
186
+ }));
187
+ };
188
+ var SideBar = function SideBar(props) {
189
+ var selectedPopulationRanges = props.selectedPopulationRanges,
190
+ setSelectedPopulationRanges = props.setSelectedPopulationRanges,
191
+ selectedContinent = props.selectedContinent,
192
+ setSelectedContinent = props.setSelectedContinent;
193
+ return ___EmotionJSX(Box, {
194
+ sx: {
195
+ minWidth: '194px',
196
+ overflowY: 'hidden',
197
+ paddingLeft: '2px'
198
+ },
199
+ isRow: true,
200
+ key: "sidebarParent"
201
+ }, ___EmotionJSX(Box, {
202
+ sx: {
203
+ width: '174px'
204
+ },
205
+ key: "filterParent"
206
+ }, ___EmotionJSX(ControlledSelectField, {
207
+ key: "controlled selectfield",
208
+ setSelectedContinent: setSelectedContinent,
209
+ selectedContinent: selectedContinent
210
+ }), ___EmotionJSX(ControlledRadioGroup, {
211
+ key: "radioGroup",
212
+ state: selectedContinent,
213
+ callback: setSelectedContinent
214
+ }), ___EmotionJSX(Text, {
215
+ mt: "lg",
216
+ key: "populationRange",
217
+ variant: "label"
218
+ }, "Population Range"), _mapInstanceProperty(numberRanges).call(numberRanges, function (num) {
219
+ return ___EmotionJSX(MemoizedCheckbox, {
220
+ value: num.label,
221
+ object: num,
222
+ key: num.label,
223
+ onChangeCallback: setSelectedPopulationRanges,
224
+ state: selectedPopulationRanges
225
+ });
226
+ })), ___EmotionJSX(Separator, {
227
+ key: "separator",
228
+ orientation: "vertical",
229
+ sx: {
230
+ '&.is-vertical': {
231
+ mx: 'md',
232
+ my: 0
233
+ }
234
+ }
235
+ }));
236
+ };
237
+ export var Default = function Default(args) {
238
+ var _useState = useState('All Continents'),
239
+ _useState2 = _slicedToArray(_useState, 2),
240
+ selectedContinent = _useState2[0],
241
+ setSelectedContinent = _useState2[1];
242
+ var _useState3 = useState([]),
243
+ _useState4 = _slicedToArray(_useState3, 2),
244
+ selectedPopulationRanges = _useState4[0],
245
+ setSelectedPopulationRanges = _useState4[1];
246
+ var _useState5 = useState(''),
247
+ _useState6 = _slicedToArray(_useState5, 2),
248
+ filterText = _useState6[0],
249
+ setFilterText = _useState6[1];
250
+ var list = useAsyncList({
251
+ load: function load() {
252
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
253
+ return _regeneratorRuntime().wrap(function _callee$(_context3) {
254
+ while (1) switch (_context3.prev = _context3.next) {
255
+ case 0:
256
+ return _context3.abrupt("return", {
257
+ items: rows
258
+ });
259
+ case 1:
260
+ case "end":
261
+ return _context3.stop();
262
+ }
263
+ }, _callee);
264
+ }))();
265
+ }
266
+ });
267
+ var filteredItems = useMemo(function () {
268
+ var _context4;
269
+ return _filterInstanceProperty(_context4 = list.items).call(_context4, function (item) {
270
+ var _context5;
271
+ if (!_includesInstanceProperty(_context5 = item.country).call(_context5, filterText)) {
272
+ return false;
273
+ }
274
+ if (selectedContinent !== 'All Continents' && selectedContinent !== item.continent) {
275
+ return false;
276
+ }
277
+ var min = Math.min.apply(Math, _mapInstanceProperty(selectedPopulationRanges).call(selectedPopulationRanges, function (range) {
278
+ return range.numberLow;
279
+ }));
280
+ var max = Math.max.apply(Math, _mapInstanceProperty(selectedPopulationRanges).call(selectedPopulationRanges, function (range) {
281
+ return range.numberHigh;
282
+ }));
283
+ if (selectedPopulationRanges.length !== 0) {
284
+ if (item.population > min && item.population < max) {
285
+ return true;
286
+ }
287
+ return false;
288
+ }
289
+ return true;
290
+ });
291
+ }, [list.items, filterText, selectedContinent, selectedPopulationRanges]);
292
+ var onChange = function onChange(value) {
293
+ setFilterText(value);
294
+ };
295
+ var CustomButton = function CustomButton(_ref) {
296
+ var icon = _ref.icon,
297
+ label = _ref.label,
298
+ iconTitle = _ref.iconTitle;
299
+ return ___EmotionJSX(Button, {
300
+ variant: "exampleText",
301
+ ml: "25px",
302
+ pr: "0px",
303
+ pl: "0px"
304
+ }, ___EmotionJSX(Box, {
305
+ isRow: true,
306
+ alignItems: "center"
307
+ }, ___EmotionJSX(Icon, {
308
+ icon: icon,
309
+ mr: "sm",
310
+ color: "active",
311
+ size: 25,
312
+ title: {
313
+ name: iconTitle
314
+ }
315
+ }), ___EmotionJSX(Text, {
316
+ sx: {
317
+ fontSize: 'md',
318
+ fontWeight: 0,
319
+ color: 'active'
320
+ }
321
+ }, label)));
322
+ };
323
+ var CustomDataTable = function CustomDataTable() {
324
+ return ___EmotionJSX(DataTable, _extends({}, args, {
325
+ "aria-label": "Static table",
326
+ height: "100%"
327
+ }), ___EmotionJSX(DataTableHeader, {
328
+ columns: columns
329
+ }, function (column) {
330
+ return ___EmotionJSX(DataTableColumn, {
331
+ align: "center"
332
+ }, column.name);
333
+ }), ___EmotionJSX(DataTableBody, {
334
+ items: filteredItems
335
+ }, function (item) {
336
+ return ___EmotionJSX(DataTableRow, null, function (columnKey) {
337
+ return ___EmotionJSX(DataTableCell, null, item[columnKey]);
338
+ });
339
+ }));
340
+ };
341
+ return ___EmotionJSX(Box, {
342
+ isRow: true
343
+ }, ___EmotionJSX(SideBar, {
344
+ key: "sidebar",
345
+ setSelectedPopulationRanges: setSelectedPopulationRanges,
346
+ selectedPopulationRanges: selectedPopulationRanges,
347
+ selectedContinent: selectedContinent,
348
+ setSelectedContinent: setSelectedContinent
349
+ }), ___EmotionJSX(Box, {
350
+ sx: {
351
+ display: 'block',
352
+ margin: 'md',
353
+ minHeight: '317px',
354
+ minWidth: '916px',
355
+ width: '916px'
356
+ }
357
+ }, ___EmotionJSX(Box, null, ___EmotionJSX(Image, {
358
+ alt: "placeholder graph",
359
+ src: placeholder
360
+ })), ___EmotionJSX(Box, {
361
+ maxWidth: "916px"
362
+ }, ___EmotionJSX(Box, {
363
+ isRow: true,
364
+ sx: {
365
+ pt: 'lg',
366
+ pb: 'lg'
367
+ }
368
+ }, ___EmotionJSX(SearchField, {
369
+ onChange: onChange,
370
+ value: filterText,
371
+ "aria-label": "filter results",
372
+ containerProps: {
373
+ sx: {
374
+ width: '400px'
375
+ }
376
+ },
377
+ iconProps: {
378
+ size: 20
379
+ }
380
+ }), ___EmotionJSX(Box, {
381
+ isRow: true,
382
+ sx: {
383
+ ml: 'auto',
384
+ mr: '0px',
385
+ alignItems: 'center',
386
+ justifyContent: 'center'
387
+ }
388
+ }, ___EmotionJSX(CustomButton, {
389
+ label: "Download Report",
390
+ icon: TrayArrowDownIcon,
391
+ iconTitle: "Tray Arrow Down Icon"
392
+ }), ___EmotionJSX(CustomButton, {
393
+ label: "Modify Columns",
394
+ icon: EyeOutlineIcon,
395
+ iconTitle: "Eye Outline Icon"
396
+ }), ___EmotionJSX(CustomButton, {
397
+ label: "Run Report",
398
+ icon: ArrowCollapseRightIcon,
399
+ iconTitle: "Arrow Collapse Right Icon"
400
+ }))), ___EmotionJSX(Box, null, ___EmotionJSX(CustomDataTable, {
401
+ key: "customDataTable"
402
+ })))));
403
+ };