@pingux/astro 2.71.0-alpha.0 → 2.71.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.
- package/lib/cjs/components/ListBox/ListBox.js +4 -2
- package/lib/cjs/components/ListBox/ListBox.styles.js +20 -0
- package/lib/cjs/components/ListBox/Option.js +47 -8
- package/lib/cjs/components/MultivaluesField/CondensedMultivaluesField.js +508 -0
- package/lib/cjs/components/MultivaluesField/DefaultMultivaluesField.js +616 -0
- package/lib/cjs/components/MultivaluesField/MultivaluesField.js +18 -481
- package/lib/cjs/components/MultivaluesField/MultivaluesField.stories.js +114 -2
- package/lib/cjs/components/MultivaluesField/MultivaluesField.test.js +251 -2
- package/lib/cjs/components/SelectFieldBase/SelectFieldBase.js +3 -1
- package/lib/cjs/recipes/DateTimeRangePicker.stories.js +182 -0
- package/lib/cjs/types/listBox.d.ts +6 -0
- package/lib/cjs/utils/designUtils/figmaLinks.d.ts +3 -0
- package/lib/cjs/utils/designUtils/figmaLinks.js +3 -0
- package/lib/components/ListBox/ListBox.js +4 -2
- package/lib/components/ListBox/ListBox.styles.js +20 -0
- package/lib/components/ListBox/Option.js +47 -8
- package/lib/components/MultivaluesField/CondensedMultivaluesField.js +495 -0
- package/lib/components/MultivaluesField/DefaultMultivaluesField.js +603 -0
- package/lib/components/MultivaluesField/MultivaluesField.js +18 -480
- package/lib/components/MultivaluesField/MultivaluesField.stories.js +111 -1
- package/lib/components/MultivaluesField/MultivaluesField.test.js +250 -2
- package/lib/components/SelectFieldBase/SelectFieldBase.js +3 -1
- package/lib/recipes/DateTimeRangePicker.stories.js +167 -0
- package/lib/utils/designUtils/figmaLinks.js +3 -0
- package/package.json +1 -1
@@ -2,7 +2,6 @@ import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object
|
|
2
2
|
import _Symbol from "@babel/runtime-corejs3/core-js-stable/symbol";
|
3
3
|
import _Object$create from "@babel/runtime-corejs3/core-js-stable/object/create";
|
4
4
|
import _Object$getPrototypeOf from "@babel/runtime-corejs3/core-js-stable/object/get-prototype-of";
|
5
|
-
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
6
5
|
import _Object$setPrototypeOf from "@babel/runtime-corejs3/core-js-stable/object/set-prototype-of";
|
7
6
|
import _Promise from "@babel/runtime-corejs3/core-js-stable/promise";
|
8
7
|
import _reverseInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/reverse";
|
@@ -10,10 +9,12 @@ import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instan
|
|
10
9
|
import _typeof from "@babel/runtime-corejs3/helpers/esm/typeof";
|
11
10
|
import _asyncToGenerator from "@babel/runtime-corejs3/helpers/esm/asyncToGenerator";
|
12
11
|
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
12
|
+
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
13
|
+
import _Array$isArray from "@babel/runtime-corejs3/core-js-stable/array/is-array";
|
13
14
|
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 _context3; _forEachInstanceProperty(_context3 = ["next", "throw", "return"]).call(_context3, 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 _context4; 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(_context4 = this.tryEntries).call(_context4, 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; }
|
14
15
|
import React from 'react';
|
15
16
|
import userEvent from '@testing-library/user-event';
|
16
|
-
import { Item, MultivaluesField, OverlayProvider } from '../../index';
|
17
|
+
import { Item, MultivaluesField, OverlayProvider, Section } from '../../index';
|
17
18
|
import statuses from '../../utils/devUtils/constants/statuses';
|
18
19
|
import { fireEvent, getDefaultNormalizer, render, screen, within } from '../../utils/testUtils/testWrapper';
|
19
20
|
import { universalComponentTests } from '../../utils/testUtils/universalComponentTest';
|
@@ -31,10 +32,33 @@ var items = [{
|
|
31
32
|
name: 'Snake',
|
32
33
|
key: 'Snake'
|
33
34
|
}];
|
35
|
+
var withSection = [{
|
36
|
+
name: 'Animals',
|
37
|
+
key: 'Animals',
|
38
|
+
children: [{
|
39
|
+
name: 'Option A1'
|
40
|
+
}, {
|
41
|
+
name: 'Option A2'
|
42
|
+
}]
|
43
|
+
}, {
|
44
|
+
name: 'People',
|
45
|
+
key: 'People',
|
46
|
+
children: [{
|
47
|
+
name: 'Option B1'
|
48
|
+
}, {
|
49
|
+
name: 'Option B2'
|
50
|
+
}, {
|
51
|
+
name: 'Option B3'
|
52
|
+
}]
|
53
|
+
}];
|
34
54
|
var defaultProps = {
|
35
55
|
items: items,
|
36
56
|
label: 'Field Label'
|
37
57
|
};
|
58
|
+
var defaultSectionProps = {
|
59
|
+
items: withSection,
|
60
|
+
label: 'Field Label'
|
61
|
+
};
|
38
62
|
var getComponent = function getComponent() {
|
39
63
|
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
40
64
|
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
@@ -61,6 +85,25 @@ var getComponentInForm = function getComponentInForm(onFormSubmit) {
|
|
61
85
|
}, item.name);
|
62
86
|
}))));
|
63
87
|
};
|
88
|
+
var getSectionsComponent = function getSectionsComponent() {
|
89
|
+
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
90
|
+
var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
91
|
+
_ref3$renderFn = _ref3.renderFn,
|
92
|
+
renderFn = _ref3$renderFn === void 0 ? render : _ref3$renderFn;
|
93
|
+
return renderFn(___EmotionJSX(OverlayProvider, null, ___EmotionJSX(MultivaluesField, _extends({}, defaultSectionProps, props, {
|
94
|
+
mode: "condensed"
|
95
|
+
}), function (section) {
|
96
|
+
return ___EmotionJSX(Section, {
|
97
|
+
key: section.key,
|
98
|
+
items: section.children,
|
99
|
+
title: section.name
|
100
|
+
}, function (item) {
|
101
|
+
return ___EmotionJSX(Item, {
|
102
|
+
key: item.name
|
103
|
+
}, item.name);
|
104
|
+
});
|
105
|
+
})));
|
106
|
+
};
|
64
107
|
beforeAll(function () {
|
65
108
|
jest.spyOn(window.HTMLElement.prototype, 'clientWidth', 'get').mockImplementation(function () {
|
66
109
|
return 1000;
|
@@ -730,6 +773,211 @@ test('in non-restrictive mode the partial string values should be accepted', fun
|
|
730
773
|
expect(input).not.toHaveValue('');
|
731
774
|
expect(input).toHaveValue(value);
|
732
775
|
});
|
776
|
+
test('in condensed mode selects and deselects ', function () {
|
777
|
+
getComponent({
|
778
|
+
mode: 'condensed'
|
779
|
+
});
|
780
|
+
userEvent.tab();
|
781
|
+
var listbox = screen.getByRole('listbox');
|
782
|
+
var options = within(listbox).getAllByRole('option');
|
783
|
+
var firstOption = options[0];
|
784
|
+
var buttons = screen.getAllByRole('button');
|
785
|
+
var button = buttons[1];
|
786
|
+
expect(button).toHaveTextContent('Select All');
|
787
|
+
button.click();
|
788
|
+
expect(button).toHaveTextContent('Deselect All');
|
789
|
+
expect(screen.getByText('All Selected')).toBeInTheDocument();
|
790
|
+
firstOption.click();
|
791
|
+
expect(button).toHaveTextContent('Select All');
|
792
|
+
expect(screen.getByText('2 Selected')).toBeInTheDocument();
|
793
|
+
button.click();
|
794
|
+
expect(button).toHaveTextContent('Deselect All');
|
795
|
+
button.click();
|
796
|
+
expect(button).toHaveTextContent('Select All');
|
797
|
+
});
|
798
|
+
test('in condensed mode "onSelectionChange" is called', function () {
|
799
|
+
var onSelectionChange = jest.fn();
|
800
|
+
getComponent({
|
801
|
+
mode: 'condensed',
|
802
|
+
onSelectionChange: onSelectionChange
|
803
|
+
});
|
804
|
+
var input = screen.getByRole('combobox');
|
805
|
+
var value = 'Aardvark';
|
806
|
+
userEvent.type(input, value);
|
807
|
+
var option = within(screen.getByRole('listbox')).getByRole('option');
|
808
|
+
userEvent.click(option);
|
809
|
+
expect(screen.getByText('1 Selected')).toBeInTheDocument();
|
810
|
+
expect(onSelectionChange).toBeCalledTimes(1);
|
811
|
+
expect(onSelectionChange.mock.calls[0][0].has(value)).toBeTruthy();
|
812
|
+
});
|
813
|
+
test('opening and closing listbox fires "onOpenChange" in condensed mode', function () {
|
814
|
+
var onOpenChange = jest.fn();
|
815
|
+
getComponent({
|
816
|
+
mode: 'condensed',
|
817
|
+
onOpenChange: onOpenChange
|
818
|
+
});
|
819
|
+
var input = screen.getByRole('combobox');
|
820
|
+
userEvent.tab();
|
821
|
+
expect(input).toHaveFocus();
|
822
|
+
expect(screen.queryByRole('listbox')).toBeInTheDocument();
|
823
|
+
expect(onOpenChange).toHaveBeenCalledWith(true);
|
824
|
+
input.blur();
|
825
|
+
expect(screen.queryByRole('listbox')).not.toBeInTheDocument();
|
826
|
+
expect(onOpenChange).toHaveBeenCalledWith(false);
|
827
|
+
});
|
828
|
+
test('selected keys in condensed mode ', function () {
|
829
|
+
getComponent({
|
830
|
+
mode: 'condensed',
|
831
|
+
selectedKeys: [items[1].key, items[2].key]
|
832
|
+
});
|
833
|
+
var listbox = screen.queryByRole('listbox');
|
834
|
+
expect(listbox).not.toBeInTheDocument();
|
835
|
+
expect(screen.getByText('2 Selected')).toBeInTheDocument();
|
836
|
+
});
|
837
|
+
test('default selected keys in condensed mode ', function () {
|
838
|
+
getComponent({
|
839
|
+
mode: 'condensed',
|
840
|
+
defaultSelectedKeys: [items[1].key, items[2].key]
|
841
|
+
});
|
842
|
+
var listbox = screen.queryByRole('listbox');
|
843
|
+
expect(listbox).not.toBeInTheDocument();
|
844
|
+
expect(screen.getByText('2 Selected')).toBeInTheDocument();
|
845
|
+
});
|
846
|
+
test('onInputChange is called in condensed mode ', function () {
|
847
|
+
var onInputChange = jest.fn();
|
848
|
+
getComponent({
|
849
|
+
mode: 'condensed',
|
850
|
+
onInputChange: onInputChange
|
851
|
+
});
|
852
|
+
var input = screen.getByRole('combobox');
|
853
|
+
var value = 'Aardvark';
|
854
|
+
userEvent.type(input, value);
|
855
|
+
var listbox = screen.getByRole('listbox');
|
856
|
+
expect(listbox).toBeInTheDocument();
|
857
|
+
var options = within(listbox).getAllByRole('option');
|
858
|
+
expect(options.length).toBe(1);
|
859
|
+
expect(onInputChange).toBeCalledTimes(value.length);
|
860
|
+
expect(onInputChange).toHaveBeenCalledWith(value);
|
861
|
+
});
|
862
|
+
test('opens listbox on focus and fires "onFocus', function () {
|
863
|
+
var onFocus = jest.fn();
|
864
|
+
getComponent({
|
865
|
+
mode: 'condensed',
|
866
|
+
onFocus: onFocus
|
867
|
+
});
|
868
|
+
var input = screen.getByRole('combobox');
|
869
|
+
userEvent.tab();
|
870
|
+
expect(input).toHaveFocus();
|
871
|
+
expect(screen.getByRole('listbox')).toBeInTheDocument();
|
872
|
+
var options = screen.getAllByRole('option');
|
873
|
+
expect(options.length).toBe(items.length);
|
874
|
+
expect(options[0]).toHaveTextContent(items[0].name);
|
875
|
+
expect(onFocus).toBeCalled();
|
876
|
+
});
|
877
|
+
test('closes listbox on blur and fires "onBlur"', function () {
|
878
|
+
var onBlur = jest.fn();
|
879
|
+
getComponent({
|
880
|
+
mode: 'condensed',
|
881
|
+
onBlur: onBlur
|
882
|
+
});
|
883
|
+
var input = screen.getByRole('combobox');
|
884
|
+
userEvent.tab();
|
885
|
+
expect(input).toHaveFocus();
|
886
|
+
expect(screen.queryByRole('listbox')).toBeInTheDocument();
|
887
|
+
input.blur();
|
888
|
+
expect(screen.queryByRole('listbox')).not.toBeInTheDocument();
|
889
|
+
expect(onBlur).toBeCalled();
|
890
|
+
});
|
891
|
+
test('list and button are keyboard accessible', function () {
|
892
|
+
getComponent({
|
893
|
+
mode: 'condensed'
|
894
|
+
});
|
895
|
+
userEvent.tab();
|
896
|
+
var listbox = screen.getByRole('listbox');
|
897
|
+
var options = within(listbox).getAllByRole('option');
|
898
|
+
var firstOption = options[0];
|
899
|
+
var secondOption = options[1];
|
900
|
+
var buttons = screen.getAllByRole('button');
|
901
|
+
var button = buttons[1];
|
902
|
+
userEvent.tab();
|
903
|
+
expect(button).toHaveFocus();
|
904
|
+
userEvent.tab();
|
905
|
+
expect(firstOption).toHaveFocus();
|
906
|
+
userEvent.type(firstOption, '{arrowdown}', {
|
907
|
+
skipClick: true
|
908
|
+
});
|
909
|
+
expect(secondOption).toHaveFocus();
|
910
|
+
userEvent.type(secondOption, '{esc}', {
|
911
|
+
skipClick: true
|
912
|
+
});
|
913
|
+
expect(screen.queryByRole('listbox')).not.toBeInTheDocument();
|
914
|
+
});
|
915
|
+
test('popover closes on input blur', function () {
|
916
|
+
getComponent({
|
917
|
+
mode: 'condensed'
|
918
|
+
});
|
919
|
+
expect(screen.queryByRole('listbox')).not.toBeInTheDocument();
|
920
|
+
expect(screen.queryByRole('option')).not.toBeInTheDocument();
|
921
|
+
var input = screen.getByRole('combobox');
|
922
|
+
userEvent.click(input);
|
923
|
+
var listbox = screen.getByRole('listbox');
|
924
|
+
var options = within(listbox).getAllByRole('option');
|
925
|
+
var checkboxes = within(listbox).getAllByRole('img');
|
926
|
+
expect(checkboxes.length).toBe(3);
|
927
|
+
var secondOption = options[1];
|
928
|
+
secondOption.click();
|
929
|
+
var value = 'Aardvark';
|
930
|
+
userEvent.type(input, value);
|
931
|
+
userEvent.click(document.body);
|
932
|
+
expect(input).toHaveValue('');
|
933
|
+
expect(listbox).not.toBeInTheDocument();
|
934
|
+
});
|
935
|
+
test('trigger button handles popover open and close in condensed', function () {
|
936
|
+
getComponent({
|
937
|
+
mode: 'condensed'
|
938
|
+
});
|
939
|
+
expect(screen.queryByRole('listbox')).not.toBeInTheDocument();
|
940
|
+
var input = screen.getByRole('combobox');
|
941
|
+
userEvent.click(screen.getAllByRole('button')[0]);
|
942
|
+
expect(screen.queryByRole('listbox')).toBeInTheDocument();
|
943
|
+
expect(input).toHaveFocus();
|
944
|
+
userEvent.tab();
|
945
|
+
fireEvent.click(screen.getAllByRole('button')[0]);
|
946
|
+
expect(screen.queryByRole('listbox')).not.toBeInTheDocument();
|
947
|
+
});
|
948
|
+
test('should render items with sections passed in props', function () {
|
949
|
+
getSectionsComponent();
|
950
|
+
expect(screen.queryByRole('listbox')).not.toBeInTheDocument();
|
951
|
+
expect(screen.queryByRole('option')).not.toBeInTheDocument();
|
952
|
+
var input = screen.getByRole('combobox');
|
953
|
+
userEvent.click(input);
|
954
|
+
expect(screen.getAllByRole('group')).toHaveLength(2);
|
955
|
+
expect(screen.queryByRole('listbox')).toBeInTheDocument();
|
956
|
+
expect(screen.queryAllByRole('option')).toHaveLength(5);
|
957
|
+
});
|
958
|
+
test('should render the separators', function () {
|
959
|
+
getSectionsComponent();
|
960
|
+
var input = screen.getByRole('combobox');
|
961
|
+
userEvent.click(input);
|
962
|
+
expect(screen.queryAllByRole('separator')).toHaveLength(3);
|
963
|
+
var groups = screen.getAllByRole('group');
|
964
|
+
expect(groups).toHaveLength(2);
|
965
|
+
expect(screen.queryByRole('listbox')).toBeInTheDocument();
|
966
|
+
expect(screen.queryAllByRole('option')).toHaveLength(5);
|
967
|
+
_forEachInstanceProperty(groups).call(groups, function (group, index) {
|
968
|
+
expect(function () {
|
969
|
+
return within(group).getByText(withSection[index].name);
|
970
|
+
});
|
971
|
+
var itemOpt = withSection[index].options;
|
972
|
+
if (_Array$isArray(itemOpt)) {
|
973
|
+
_forEachInstanceProperty(itemOpt).call(itemOpt, function (opt) {
|
974
|
+
return expect(function () {
|
975
|
+
return within(group).getByText(opt.name);
|
976
|
+
});
|
977
|
+
});
|
978
|
+
}
|
979
|
+
});
|
980
|
+
});
|
733
981
|
|
734
982
|
// Needs to be added to each components test file
|
735
983
|
universalComponentTests({
|
@@ -73,7 +73,7 @@ var SelectFieldBase = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
73
73
|
variant: "forms.select"
|
74
74
|
}, triggerProps, ariaProps, {
|
75
75
|
"aria-describedby": helperText && helperTextId
|
76
|
-
}), ___EmotionJSX(Box, _extends({
|
76
|
+
}), slots === null || slots === void 0 ? void 0 : slots.leftOfData, ___EmotionJSX(Box, _extends({
|
77
77
|
as: "span",
|
78
78
|
variant: "forms.select.currentValue"
|
79
79
|
}, valueProps), state.selectedItem ? state.selectedItem.rendered : ___EmotionJSX(Text, {
|
@@ -148,6 +148,8 @@ SelectFieldBase.propTypes = _objectSpread(_objectSpread({
|
|
148
148
|
}),
|
149
149
|
/** Provides a way to insert markup in specified places. */
|
150
150
|
slots: PropTypes.shape({
|
151
|
+
/** The given node will be inserted before the text in field container. */
|
152
|
+
leftOfData: PropTypes.node,
|
151
153
|
/** The given node will be inserted into the field container. */
|
152
154
|
inContainer: PropTypes.node
|
153
155
|
}),
|
@@ -0,0 +1,167 @@
|
|
1
|
+
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
2
|
+
import _padStartInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/pad-start";
|
3
|
+
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
4
|
+
import React, { useState } from 'react';
|
5
|
+
import { Time } from '@internationalized/date';
|
6
|
+
import CalendarIcon from '@pingux/mdi-react/CalendarIcon';
|
7
|
+
import { withDesign } from 'storybook-addon-designs';
|
8
|
+
import { useModalState } from '../hooks';
|
9
|
+
import { Box, Button, ButtonBar, Icon, Item, Modal, OverlayProvider, RangeCalendar, SelectField, Separator, Text, TimeField } from '../index';
|
10
|
+
import { FIGMA_LINKS } from '../utils/designUtils/figmaLinks';
|
11
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
12
|
+
export default {
|
13
|
+
title: 'Recipes/DateTimeRangePicker',
|
14
|
+
decorators: [withDesign]
|
15
|
+
};
|
16
|
+
var dropdownItems = [{
|
17
|
+
key: 'Today',
|
18
|
+
name: 'Today'
|
19
|
+
}, {
|
20
|
+
key: 'From Yesterday',
|
21
|
+
name: 'From Yesterday'
|
22
|
+
}, {
|
23
|
+
key: 'Last 7 Days',
|
24
|
+
name: 'Last 7 Days'
|
25
|
+
}, {
|
26
|
+
key: 'Last 30 Days',
|
27
|
+
name: 'Last 30 Days'
|
28
|
+
}, {
|
29
|
+
key: 'This Month',
|
30
|
+
name: 'This Month'
|
31
|
+
}, {
|
32
|
+
key: 'Last Month',
|
33
|
+
name: 'Last Month'
|
34
|
+
}, {
|
35
|
+
key: 'Custom Range',
|
36
|
+
name: 'Custom Range'
|
37
|
+
}];
|
38
|
+
function convertDateTimeValueToString(timeValue, DateValue) {
|
39
|
+
var _context, _context2, _context3, _context4;
|
40
|
+
// eslint-disable-next-line prefer-const
|
41
|
+
var hour = timeValue.hour,
|
42
|
+
minute = timeValue.minute;
|
43
|
+
var ampm = hour >= 12 ? 'PM' : 'AM';
|
44
|
+
hour %= 12;
|
45
|
+
hour = hour || 12;
|
46
|
+
var hourString = String(hour);
|
47
|
+
var minuteString = _padStartInstanceProperty(_context = String(minute)).call(_context, 2, '0');
|
48
|
+
return _concatInstanceProperty(_context2 = _concatInstanceProperty(_context3 = _concatInstanceProperty(_context4 = "".concat(DateValue.toString(), " ")).call(_context4, hourString, ":")).call(_context3, minuteString, " ")).call(_context2, ampm);
|
49
|
+
}
|
50
|
+
export var Default = function Default() {
|
51
|
+
var modalState = useModalState();
|
52
|
+
var _useState = useState({
|
53
|
+
start: '2030-01-12',
|
54
|
+
end: '2030-01-15'
|
55
|
+
}),
|
56
|
+
_useState2 = _slicedToArray(_useState, 2),
|
57
|
+
range = _useState2[0],
|
58
|
+
setRange = _useState2[1];
|
59
|
+
var _useState3 = useState(new Time(1)),
|
60
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
61
|
+
startTime = _useState4[0],
|
62
|
+
setStartTime = _useState4[1];
|
63
|
+
var _useState5 = useState(new Time(12, 59)),
|
64
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
65
|
+
endTime = _useState6[0],
|
66
|
+
setEndTime = _useState6[1];
|
67
|
+
var _useState7 = useState('Today'),
|
68
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
69
|
+
selectedKey = _useState8[0],
|
70
|
+
setSelectedKey = _useState8[1];
|
71
|
+
var handleSelectionChange = function handleSelectionChange(key) {
|
72
|
+
if (key === 'Custom Range') {
|
73
|
+
modalState.open();
|
74
|
+
}
|
75
|
+
setSelectedKey(key);
|
76
|
+
};
|
77
|
+
return ___EmotionJSX(Box, {
|
78
|
+
gap: "lg"
|
79
|
+
}, ___EmotionJSX(Text, null, "Click on the \u2018Custom Range\u2019 option to view the modal"), ___EmotionJSX(OverlayProvider, null, ___EmotionJSX(SelectField, {
|
80
|
+
width: "200px",
|
81
|
+
items: dropdownItems,
|
82
|
+
selectedKey: selectedKey,
|
83
|
+
onSelectionChange: handleSelectionChange,
|
84
|
+
label: "Date Range",
|
85
|
+
slots: {
|
86
|
+
leftOfData: ___EmotionJSX(Icon, {
|
87
|
+
icon: CalendarIcon,
|
88
|
+
color: "accent.40",
|
89
|
+
mr: "xs",
|
90
|
+
title: {
|
91
|
+
name: 'Calendar Icon'
|
92
|
+
}
|
93
|
+
})
|
94
|
+
}
|
95
|
+
}, function (item) {
|
96
|
+
return ___EmotionJSX(Item, {
|
97
|
+
key: item.key
|
98
|
+
}, item.name);
|
99
|
+
}), modalState.isOpen && ___EmotionJSX(Modal, {
|
100
|
+
isOpen: modalState.isOpen,
|
101
|
+
onClose: modalState.close,
|
102
|
+
hasCloseButton: true,
|
103
|
+
title: "Custom Date and Time Range",
|
104
|
+
contentProps: {
|
105
|
+
maxWidth: '636px',
|
106
|
+
width: '100%'
|
107
|
+
}
|
108
|
+
}, ___EmotionJSX(Box, {
|
109
|
+
gap: "lg",
|
110
|
+
mt: "lg"
|
111
|
+
}, ___EmotionJSX(Box, {
|
112
|
+
minHeight: "358px"
|
113
|
+
}, ___EmotionJSX(Text, {
|
114
|
+
as: "h2",
|
115
|
+
variant: "H2",
|
116
|
+
mb: "xs"
|
117
|
+
}, "Date Range"), ___EmotionJSX(RangeCalendar, {
|
118
|
+
value: range,
|
119
|
+
onChange: setRange
|
120
|
+
})), ___EmotionJSX(Separator, {
|
121
|
+
margin: 0
|
122
|
+
}), ___EmotionJSX(Box, null, ___EmotionJSX(Text, {
|
123
|
+
as: "h2",
|
124
|
+
variant: "H2"
|
125
|
+
}, "Time Range"), ___EmotionJSX(Box, {
|
126
|
+
isRow: true,
|
127
|
+
gap: "lg",
|
128
|
+
alignItems: "center",
|
129
|
+
mt: "xs"
|
130
|
+
}, ___EmotionJSX(TimeField, {
|
131
|
+
label: "Start Time",
|
132
|
+
value: startTime,
|
133
|
+
onChange: setStartTime
|
134
|
+
}), ___EmotionJSX(Box, {
|
135
|
+
height: "59.95px"
|
136
|
+
}, ___EmotionJSX(Box, {
|
137
|
+
height: "19.95px"
|
138
|
+
}), ___EmotionJSX(Box, {
|
139
|
+
height: "40px",
|
140
|
+
justifyContent: "center"
|
141
|
+
}, ___EmotionJSX(Text, {
|
142
|
+
as: "h2",
|
143
|
+
variant: "H2"
|
144
|
+
}, "-"))), ___EmotionJSX(TimeField, {
|
145
|
+
label: "End Time",
|
146
|
+
value: endTime,
|
147
|
+
onChange: setEndTime
|
148
|
+
}))), ___EmotionJSX(Separator, {
|
149
|
+
margin: 0
|
150
|
+
}), ___EmotionJSX(Text, null, convertDateTimeValueToString(startTime, range.start), ' ', "-", ' ', convertDateTimeValueToString(endTime, range.end)), ___EmotionJSX(ButtonBar, {
|
151
|
+
sx: {
|
152
|
+
padding: 0
|
153
|
+
}
|
154
|
+
}, ___EmotionJSX(Button, {
|
155
|
+
variant: "primary",
|
156
|
+
"data-id": "apply-button"
|
157
|
+
}, "Apply"), ___EmotionJSX(Button, {
|
158
|
+
variant: "link",
|
159
|
+
"data-id": "cancel-button"
|
160
|
+
}, "Cancel"))))));
|
161
|
+
};
|
162
|
+
Default.parameters = {
|
163
|
+
design: {
|
164
|
+
type: 'figma',
|
165
|
+
url: FIGMA_LINKS.dateTimeRangePicker["default"]
|
166
|
+
}
|
167
|
+
};
|
@@ -79,6 +79,9 @@ export var FIGMA_LINKS = {
|
|
79
79
|
countryPicker: {
|
80
80
|
"default": 'https://www.figma.com/file/Oa6VYtJcUJzEJuuRp0p4ls/Astro?type=design&node-id=4568-7532&mode=design&t=eSfQYHRFNPf37J4C-0'
|
81
81
|
},
|
82
|
+
dateTimeRangePicker: {
|
83
|
+
"default": 'https://www.figma.com/design/bpbEw54gTTcdIiZs4PKK1p/Astro-Specs?node-id=49152-4497&t=n7OkhpTOBBWW4rme-0'
|
84
|
+
},
|
82
85
|
helpHint: {
|
83
86
|
"default": 'https://www.figma.com/file/Oa6VYtJcUJzEJuuRp0p4ls/Astro?type=design&node-id=0%3A4534&t=We3h7LaaFJQnxdSy-1',
|
84
87
|
withLink: 'https://www.figma.com/file/bpbEw54gTTcdIiZs4PKK1p/Astro-Specs?type=design&node-id=28958%3A40081&mode=design&t=WmSYPx1hR8kxFiXf-1'
|