@pingux/astro 1.5.0 → 1.6.0-alpha.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.
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+
3
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
4
+
5
+ _Object$defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+
9
+ exports.usCities = exports["default"] = void 0;
10
+ var _default = {
11
+ '(GMT-11:00) Pago Pago': 'Pacific/Pago_Pago',
12
+ '(GMT-10:00) Hawaii Time': 'Pacific/Honolulu',
13
+ '(GMT-08:00) Pacific Time': 'America/Los_Angeles',
14
+ '(GMT-08:00) Pacific Time - Tijuana': 'America/Tijuana',
15
+ '(GMT-07:00) Mountain Time': 'America/Denver',
16
+ '(GMT-07:00) Mountain Time - Arizona': 'America/Phoenix',
17
+ '(GMT-07:00) Mountain Time - Chihuahua, Mazatlan': 'America/Mazatlan',
18
+ '(GMT-06:00) Central Time': 'America/Chicago',
19
+ '(GMT-06:00) Central Time - Mexico City': 'America/Mexico_City',
20
+ '(GMT-06:00) Central Time - Regina': 'America/Regina',
21
+ '(GMT-06:00) Guatemala': 'America/Guatemala',
22
+ '(GMT-05:00) Bogota': 'America/Bogota',
23
+ '(GMT-05:00) Eastern Time': 'America/New_York',
24
+ '(GMT-05:00) Lima': 'America/Lima',
25
+ '(GMT-04:30) Caracas': 'America/Caracas',
26
+ '(GMT-04:00) Atlantic Time - Halifax': 'America/Halifax',
27
+ '(GMT-04:00) Guyana': 'America/Guyana',
28
+ '(GMT-04:00) La Paz': 'America/La_Paz',
29
+ '(GMT-03:00) Buenos Aires': 'America/Argentina/Buenos_Aires',
30
+ '(GMT-03:00) Godthab': 'America/Godthab',
31
+ '(GMT-03:00) Montevideo': 'America/Montevideo',
32
+ '(GMT-03:30) Newfoundland Time - St. Johns': 'America/St_Johns',
33
+ '(GMT-03:00) Santiago': 'America/Santiago',
34
+ '(GMT-02:00) Sao Paulo': 'America/Sao_Paulo',
35
+ '(GMT-02:00) South Georgia': 'Atlantic/South_Georgia',
36
+ '(GMT-01:00) Azores': 'Atlantic/Azores',
37
+ '(GMT-01:00) Cape Verde': 'Atlantic/Cape_Verde',
38
+ '(GMT+00:00) Casablanca': 'Africa/Casablanca',
39
+ '(GMT+00:00) Dublin': 'Europe/Dublin',
40
+ '(GMT+00:00) Lisbon': 'Europe/Lisbon',
41
+ '(GMT+00:00) London': 'Europe/London',
42
+ '(GMT+00:00) Monrovia': 'Africa/Monrovia',
43
+ '(GMT+01:00) Algiers': 'Africa/Algiers',
44
+ '(GMT+01:00) Amsterdam': 'Europe/Amsterdam',
45
+ '(GMT+01:00) Berlin': 'Europe/Berlin',
46
+ '(GMT+01:00) Brussels': 'Europe/Brussels',
47
+ '(GMT+01:00) Budapest': 'Europe/Budapest',
48
+ '(GMT+01:00) Central European Time - Belgrade': 'Europe/Belgrade',
49
+ '(GMT+01:00) Central European Time - Prague': 'Europe/Prague',
50
+ '(GMT+01:00) Copenhagen': 'Europe/Copenhagen',
51
+ '(GMT+01:00) Madrid': 'Europe/Madrid',
52
+ '(GMT+01:00) Paris': 'Europe/Paris',
53
+ '(GMT+01:00) Rome': 'Europe/Rome',
54
+ '(GMT+01:00) Stockholm': 'Europe/Stockholm',
55
+ '(GMT+01:00) Vienna': 'Europe/Vienna',
56
+ '(GMT+01:00) Warsaw': 'Europe/Warsaw',
57
+ '(GMT+02:00) Athens': 'Europe/Athens',
58
+ '(GMT+02:00) Bucharest': 'Europe/Bucharest',
59
+ '(GMT+02:00) Cairo': 'Africa/Cairo',
60
+ '(GMT+02:00) Jerusalem': 'Asia/Jerusalem',
61
+ '(GMT+02:00) Johannesburg': 'Africa/Johannesburg',
62
+ '(GMT+02:00) Helsinki': 'Europe/Helsinki',
63
+ '(GMT+02:00) Kiev': 'Europe/Kiev',
64
+ '(GMT+02:00) Moscow-01 - Kaliningrad': 'Europe/Kaliningrad',
65
+ '(GMT+02:00) Riga': 'Europe/Riga',
66
+ '(GMT+02:00) Sofia': 'Europe/Sofia',
67
+ '(GMT+02:00) Tallinn': 'Europe/Tallinn',
68
+ '(GMT+02:00) Vilnius': 'Europe/Vilnius',
69
+ '(GMT+03:00) Istanbul': 'Europe/Istanbul',
70
+ '(GMT+03:00) Baghdad': 'Asia/Baghdad',
71
+ '(GMT+03:00) Nairobi': 'Africa/Nairobi',
72
+ '(GMT+03:00) Minsk': 'Europe/Minsk',
73
+ '(GMT+03:00) Riyadh': 'Asia/Riyadh',
74
+ '(GMT+03:00) Moscow+00 - Moscow': 'Europe/Moscow',
75
+ '(GMT+03:30) Tehran': 'Asia/Tehran',
76
+ '(GMT+04:00) Baku': 'Asia/Baku',
77
+ '(GMT+04:00) Moscow+01 - Samara': 'Europe/Samara',
78
+ '(GMT+04:00) Tbilisi': 'Asia/Tbilisi',
79
+ '(GMT+04:00) Yerevan': 'Asia/Yerevan',
80
+ '(GMT+04:30) Kabul': 'Asia/Kabul',
81
+ '(GMT+05:00) Karachi': 'Asia/Karachi',
82
+ '(GMT+05:00) Moscow+02 - Yekaterinburg': 'Asia/Yekaterinburg',
83
+ '(GMT+05:00) Tashkent': 'Asia/Tashkent',
84
+ '(GMT+05:30) Colombo': 'Asia/Colombo',
85
+ '(GMT+06:00) Almaty': 'Asia/Almaty',
86
+ '(GMT+06:00) Dhaka': 'Asia/Dhaka',
87
+ '(GMT+06:30) Rangoon': 'Asia/Rangoon',
88
+ '(GMT+07:00) Bangkok': 'Asia/Bangkok',
89
+ '(GMT+07:00) Jakarta': 'Asia/Jakarta',
90
+ '(GMT+07:00) Moscow+04 - Krasnoyarsk': 'Asia/Krasnoyarsk',
91
+ '(GMT+08:00) China Time - Beijing': 'Asia/Shanghai',
92
+ '(GMT+08:00) Hong Kong': 'Asia/Hong_Kong',
93
+ '(GMT+08:00) Kuala Lumpur': 'Asia/Kuala_Lumpur',
94
+ '(GMT+08:00) Moscow+05 - Irkutsk': 'Asia/Irkutsk',
95
+ '(GMT+08:00) Singapore': 'Asia/Singapore',
96
+ '(GMT+08:00) Taipei': 'Asia/Taipei',
97
+ '(GMT+08:00) Ulaanbaatar': 'Asia/Ulaanbaatar',
98
+ '(GMT+08:00) Western Time - Perth': 'Australia/Perth',
99
+ '(GMT+09:00) Moscow+06 - Yakutsk': 'Asia/Yakutsk',
100
+ '(GMT+09:00) Seoul': 'Asia/Seoul',
101
+ '(GMT+09:00) Tokyo': 'Asia/Tokyo',
102
+ '(GMT+09:30) Central Time - Darwin': 'Australia/Darwin',
103
+ '(GMT+10:00) Eastern Time - Brisbane': 'Australia/Brisbane',
104
+ '(GMT+10:00) Guam': 'Pacific/Guam',
105
+ '(GMT+10:00) Moscow+07 - Magadan': 'Asia/Magadan',
106
+ '(GMT+10:00) Moscow+07 - Yuzhno-Sakhalinsk': 'Asia/Vladivostok',
107
+ '(GMT+10:00) Port Moresby': 'Pacific/Port_Moresby',
108
+ '(GMT+10:30) Central Time - Adelaide': 'Australia/Adelaide',
109
+ '(GMT+11:00) Eastern Time - Hobart': 'Australia/Hobart',
110
+ '(GMT+11:00) Eastern Time - Melbourne, Sydney': 'Australia/Sydney',
111
+ '(GMT+11:00) Guadalcanal': 'Pacific/Guadalcanal',
112
+ '(GMT+11:00) Noumea': 'Pacific/Noumea',
113
+ '(GMT+12:00) Majuro': 'Pacific/Majuro',
114
+ '(GMT+12:00) Moscow+09 - Petropavlovsk-Kamchatskiy': 'Asia/Kamchatka',
115
+ '(GMT+13:00) Auckland': 'Pacific/Auckland',
116
+ '(GMT+13:00) Fakaofo': 'Pacific/Fakaofo',
117
+ '(GMT+13:00) Fiji': 'Pacific/Fiji',
118
+ '(GMT+13:00) Tongatapu': 'Pacific/Tongatapu',
119
+ '(GMT+14:00) Apia': 'Pacific/Apia'
120
+ };
121
+ exports["default"] = _default;
122
+ var usCities = ['Los Angeles', 'Denver', 'Phoenix', 'Chicago', 'New York'];
123
+ exports.usCities = usCities;
package/lib/cjs/index.js CHANGED
@@ -91,6 +91,7 @@ var _exportNames = {
91
91
  TextField: true,
92
92
  TextArea: true,
93
93
  TextAreaField: true,
94
+ TimeZonePicker: true,
94
95
  TooltipTrigger: true,
95
96
  Item: true,
96
97
  Section: true,
@@ -618,6 +619,13 @@ _Object$defineProperty(exports, "TextAreaField", {
618
619
  }
619
620
  });
620
621
 
622
+ _Object$defineProperty(exports, "TimeZonePicker", {
623
+ enumerable: true,
624
+ get: function get() {
625
+ return _TimeZonePicker["default"];
626
+ }
627
+ });
628
+
621
629
  _Object$defineProperty(exports, "TooltipTrigger", {
622
630
  enumerable: true,
623
631
  get: function get() {
@@ -1595,6 +1603,8 @@ _forEachInstanceProperty(_context65 = _Object$keys(_TextAreaField)).call(_contex
1595
1603
  });
1596
1604
  });
1597
1605
 
1606
+ var _TimeZonePicker = _interopRequireDefault(require("./components/TimeZonePicker"));
1607
+
1598
1608
  var _TooltipTrigger = _interopRequireWildcard(require("./components/TooltipTrigger"));
1599
1609
 
1600
1610
  _forEachInstanceProperty(_context66 = _Object$keys(_TooltipTrigger)).call(_context66, function (key) {
@@ -299,6 +299,14 @@ var fileInputFieldWrapper = {
299
299
  alignItems: 'center'
300
300
  }
301
301
  };
302
+ var floatLabelWrapper = {
303
+ backgroundColor: 'white',
304
+ position: 'relative',
305
+ height: '17px',
306
+ bottom: '-18px',
307
+ left: '3px',
308
+ zIndex: 2
309
+ };
302
310
  var _default = {
303
311
  base: base,
304
312
  card: card,
@@ -317,6 +325,7 @@ var _default = {
317
325
  radioContainer: radioContainer,
318
326
  scrollbox: scrollbox,
319
327
  topShadowScrollbox: topShadowScrollbox,
320
- bottomShadowScrollbox: bottomShadowScrollbox
328
+ bottomShadowScrollbox: bottomShadowScrollbox,
329
+ floatLabelWrapper: floatLabelWrapper
321
330
  };
322
331
  exports["default"] = _default;
@@ -195,6 +195,33 @@ var maskedValue = {
195
195
  fontWeight: 700
196
196
  }
197
197
  };
198
+ var timeZone = {
199
+ title: {
200
+ color: 'neutral.10',
201
+ fontSize: 'md',
202
+ whiteSpace: 'nowrap',
203
+ lineHeight: 1,
204
+ '.is-focused &': {
205
+ color: 'white'
206
+ }
207
+ },
208
+ subTitle: {
209
+ color: 'neutral.40',
210
+ fontSize: 'sm',
211
+ ml: 10,
212
+ '.is-focused &': {
213
+ color: 'white'
214
+ }
215
+ },
216
+ time: {
217
+ color: 'neutral.10',
218
+ fontSize: 'sm',
219
+ fontWeight: 1,
220
+ '.is-focused &': {
221
+ color: 'white'
222
+ }
223
+ }
224
+ };
198
225
  var text = {
199
226
  base: base,
200
227
  bodyStrong: _objectSpread(_objectSpread({}, wordWrap), {}, {
@@ -307,6 +334,7 @@ var text = {
307
334
  color: 'text.primary',
308
335
  fontFamily: 'standard'
309
336
  }),
310
- tooltipContent: tooltipContent
337
+ tooltipContent: tooltipContent,
338
+ timeZone: timeZone
311
339
  };
312
340
  exports.text = text;
@@ -73,7 +73,8 @@ var ComboBoxField = /*#__PURE__*/forwardRef(function (props, ref) {
73
73
  menuTrigger = props.menuTrigger,
74
74
  isNotFlippable = props.isNotFlippable,
75
75
  direction = props.direction,
76
- scrollBoxProps = props.scrollBoxProps;
76
+ scrollBoxProps = props.scrollBoxProps,
77
+ defaultFilter = props.defaultFilter;
77
78
  var comboBoxOptions = {
78
79
  children: children,
79
80
  isRequired: isRequired,
@@ -130,7 +131,7 @@ var ComboBoxField = /*#__PURE__*/forwardRef(function (props, ref) {
130
131
 
131
132
  var state = useComboBoxState(_objectSpread(_objectSpread({}, comboBoxOptions), {}, {
132
133
  onSelectionChange: hasCustomValue ? onSelectionChangeHandler : onSelectionChange,
133
- defaultFilter: contains
134
+ defaultFilter: typeof defaultFilter !== 'undefined' ? defaultFilter : contains
134
135
  }));
135
136
 
136
137
  var _useComboBox = useComboBox(_objectSpread(_objectSpread({}, comboBoxOptions), {}, {
@@ -183,7 +184,7 @@ var ComboBoxField = /*#__PURE__*/forwardRef(function (props, ref) {
183
184
  if (inputRef.current) {
184
185
  setMenuWidth(inputRef.current.offsetWidth);
185
186
  }
186
- }, [inputRef, setMenuWidth, state.isOpen]);
187
+ }, [inputRef, setMenuWidth]);
187
188
  useResizeObserver({
188
189
  ref: inputRef,
189
190
  onResize: onResize
@@ -354,6 +355,14 @@ ComboBoxField.propTypes = {
354
355
  * `(e: KeyboardEvent) => void`
355
356
  */
356
357
  onKeyUp: PropTypes.func,
358
+
359
+ /**
360
+ * Handler that determines the default filtering for items. If undefined, `contains` from
361
+ * [useFilter](https://react-spectrum.adobe.com/react-aria/useFilter.html) is used.
362
+ *
363
+ * `(option: string, inputValue: string) => boolean`
364
+ */
365
+ defaultFilter: PropTypes.func,
357
366
  // /** Props object that is spread directly into the ScrollBox element. */
358
367
 
359
368
  /** @ignore */
@@ -317,7 +317,7 @@ export var ControlledFiltering = function ControlledFiltering() {
317
317
  return _filterInstanceProperty(items).call(items, function (item) {
318
318
  return startsWith(item.name, filterValue);
319
319
  });
320
- }, [items, filterValue]);
320
+ }, [startsWith, filterValue]);
321
321
  return ___EmotionJSX(OverlayProvider, null, ___EmotionJSX(ComboBoxField, _extends({
322
322
  label: "Example label"
323
323
  }, actions, {
@@ -441,4 +441,20 @@ export var WithCustomHeight = function WithCustomHeight() {
441
441
  key: item.name
442
442
  }, item.name);
443
443
  }));
444
+ };
445
+ export var CustomDefaultFilter = function CustomDefaultFilter() {
446
+ var _useFilter2 = useFilter({
447
+ sensitivity: 'base'
448
+ }),
449
+ startsWith = _startsWithInstanceProperty(_useFilter2);
450
+
451
+ return ___EmotionJSX(OverlayProvider, null, ___EmotionJSX(ComboBoxField, _extends({
452
+ label: "Example label",
453
+ defaultItems: animals,
454
+ defaultFilter: startsWith
455
+ }, actions), function (item) {
456
+ return ___EmotionJSX(Item, {
457
+ key: item.name
458
+ }, item.name);
459
+ }));
444
460
  };
@@ -58,7 +58,7 @@ var ComboBoxWithCustomFilter = function ComboBoxWithCustomFilter() {
58
58
  return _filterInstanceProperty(items).call(items, function (item) {
59
59
  return startsWith(item.name, filterValue);
60
60
  });
61
- }, [items, filterValue]);
61
+ }, [startsWith, filterValue]);
62
62
  return ___EmotionJSX(ComboBoxField, _extends({}, defaultProps, {
63
63
  items: filteredItems,
64
64
  inputValue: filterValue,
@@ -356,6 +356,44 @@ test('should be able to use controlled filtering', /*#__PURE__*/_asyncToGenerato
356
356
  }
357
357
  }, _callee);
358
358
  })));
359
+ test('should be able to use custom default filtering', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
360
+ var options, defaultFilter, input;
361
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
362
+ while (1) {
363
+ switch (_context2.prev = _context2.next) {
364
+ case 0:
365
+ defaultFilter = function defaultFilter(option, inputValue) {
366
+ return _startsWithInstanceProperty(option).call(option, inputValue);
367
+ };
368
+
369
+ getComponent({
370
+ defaultFilter: defaultFilter
371
+ });
372
+ input = screen.queryByRole('combobox'); // Should list all without filterable input
373
+
374
+ userEvent.type(input, '{arrowdown}');
375
+ _context2.next = 6;
376
+ return screen.findAllByRole('option');
377
+
378
+ case 6:
379
+ options = _context2.sent;
380
+ expect(options).toHaveLength(items.length); // Should only list the second option
381
+
382
+ userEvent.type(input, 'K');
383
+ _context2.next = 11;
384
+ return screen.findAllByRole('option');
385
+
386
+ case 11:
387
+ options = _context2.sent;
388
+ expect(options[0]).toHaveTextContent(items[1].name);
389
+
390
+ case 13:
391
+ case "end":
392
+ return _context2.stop();
393
+ }
394
+ }
395
+ }, _callee2);
396
+ })));
359
397
  describe('loadingState', function () {
360
398
  it('combobox should not render a loader if menu is not open', function () {
361
399
  var _getComponent = getComponent({
@@ -674,26 +712,26 @@ test('onSelectionChange works properly with custom value', function () {
674
712
  userEvent.type(input, '{selectall}{backspace}{enter}');
675
713
  expect(onSelectionChange).toHaveBeenCalledWith('');
676
714
  });
677
- test('should have no accessibility violations', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
715
+ test('should have no accessibility violations', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
678
716
  var _getComponent6, container, results;
679
717
 
680
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
718
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
681
719
  while (1) {
682
- switch (_context2.prev = _context2.next) {
720
+ switch (_context3.prev = _context3.next) {
683
721
  case 0:
684
722
  jest.useRealTimers();
685
723
  _getComponent6 = getComponent(), container = _getComponent6.container;
686
- _context2.next = 4;
724
+ _context3.next = 4;
687
725
  return axe(container);
688
726
 
689
727
  case 4:
690
- results = _context2.sent;
728
+ results = _context3.sent;
691
729
  expect(results).toHaveNoViolations();
692
730
 
693
731
  case 6:
694
732
  case "end":
695
- return _context2.stop();
733
+ return _context3.stop();
696
734
  }
697
735
  }
698
- }, _callee2);
736
+ }, _callee3);
699
737
  })));
@@ -47,6 +47,7 @@ var TextAreaField = /*#__PURE__*/forwardRef(function (props, ref) {
47
47
 
48
48
  var textAreaRef = useRef();
49
49
  var labelRef = useRef();
50
+ var labelWrapperRef = useRef();
50
51
  var containerRef = useRef();
51
52
  var inputContainerRef = useRef();
52
53
  var slotContainer = useRef();
@@ -61,6 +62,7 @@ var TextAreaField = /*#__PURE__*/forwardRef(function (props, ref) {
61
62
  var resizeFloatLabel = function resizeFloatLabel() {
62
63
  /* istanbul ignore next */
63
64
  labelRef.current.style.width = textAreaRef.current.style.width;
65
+ labelWrapperRef.current.style.width = "".concat(textAreaRef.current.clientWidth - 2, "px");
64
66
  };
65
67
  /* istanbul ignore next */
66
68
 
@@ -101,19 +103,27 @@ var TextAreaField = /*#__PURE__*/forwardRef(function (props, ref) {
101
103
  thisRef.removeEventListener('mousemove', props.resizeCallback ? props.resizeCallback : resizeFloatLabel);
102
104
  };
103
105
  }, [props.isUnresizable, props.labelMode, props.resizeCallback]);
106
+
107
+ var labelNode = ___EmotionJSX(Label, _extends({
108
+ ref: labelRef
109
+ }, fieldLabelProps, {
110
+ sx: isLabelHigher && {
111
+ gridRow: '1/5'
112
+ }
113
+ }));
114
+
115
+ var wrappedLabel = ___EmotionJSX(Box, {
116
+ variant: "boxes.floatLabelWrapper",
117
+ ref: labelWrapperRef
118
+ }, labelNode);
119
+
104
120
  return ___EmotionJSX(Box, _extends({
105
121
  variant: "forms.input.wrapper"
106
122
  }, fieldContainerProps, {
107
123
  sx: _objectSpread(_objectSpread({}, columnStyleProps === null || columnStyleProps === void 0 ? void 0 : columnStyleProps.sx), fieldContainerProps === null || fieldContainerProps === void 0 ? void 0 : fieldContainerProps.sx),
108
124
  ref: containerRef,
109
125
  maxWidth: "100%"
110
- }), ___EmotionJSX(Label, _extends({
111
- ref: labelRef
112
- }, fieldLabelProps, {
113
- sx: isLabelHigher && {
114
- gridRow: '1/5'
115
- }
116
- })), ___EmotionJSX(Box, {
126
+ }), props.labelMode === 'float' ? wrappedLabel : labelNode, ___EmotionJSX(Box, {
117
127
  isRow: true,
118
128
  variant: "forms.input.container",
119
129
  className: fieldControlProps.className,
@@ -0,0 +1,230 @@
1
+ import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
2
+ import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
3
+ import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
4
+ import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
5
+ import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
6
+ import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
7
+ import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
8
+ import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
9
+ import _sortInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/sort";
10
+ import _parseFloat from "@babel/runtime-corejs3/core-js-stable/parse-float";
11
+ import _indexOfInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/index-of";
12
+ import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
13
+ import _Object$entries from "@babel/runtime-corejs3/core-js-stable/object/entries";
14
+ import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
15
+ import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
16
+ import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
17
+ import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
18
+ import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
19
+ import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
20
+
21
+ function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); if (enumerableOnly) symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
22
+
23
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context8; _forEachInstanceProperty(_context8 = ownKeys(Object(source), true)).call(_context8, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context9; _forEachInstanceProperty(_context9 = ownKeys(Object(source))).call(_context9, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
24
+
25
+ import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
26
+ import PropTypes from 'prop-types';
27
+ import defaultTimezones, { usCities } from './timezones.js';
28
+ import { Box, ComboBoxField, Item, Text } from '../../index';
29
+ import { jsx as ___EmotionJSX } from "@emotion/react";
30
+
31
+ var createSearchTags = function createSearchTags(_ref) {
32
+ var _context, _context2, _context3, _context4;
33
+
34
+ var gmt = _ref.gmt,
35
+ gmtLabel = _ref.gmtLabel,
36
+ timeZone = _ref.timeZone;
37
+ var additionalTags = '';
38
+ var americaTimeZone = _includesInstanceProperty(timeZone).call(timeZone, 'America') && timeZone.substring(8);
39
+
40
+ if (_includesInstanceProperty(usCities).call(usCities, americaTimeZone)) {
41
+ additionalTags = "US ".concat(americaTimeZone);
42
+ }
43
+
44
+ return _concatInstanceProperty(_context = _concatInstanceProperty(_context2 = _concatInstanceProperty(_context3 = _concatInstanceProperty(_context4 = "".concat(gmt, " ")).call(_context4, gmtLabel, " ")).call(_context3, timeZone, " ")).call(_context2, timeZone === null || timeZone === void 0 ? void 0 : timeZone.replace(/_/g, ' '), " ")).call(_context, additionalTags);
45
+ };
46
+
47
+ var getLocaleTime = function getLocaleTime(_ref2) {
48
+ var timeZone = _ref2.timeZone,
49
+ locales = _ref2.locales,
50
+ localeOptions = _ref2.localeOptions;
51
+ var date = new Date();
52
+ return date.toLocaleTimeString(locales, _objectSpread({
53
+ timeZone: timeZone
54
+ }, localeOptions));
55
+ };
56
+ /**
57
+ * Component allows users to choose a timezone from the list.
58
+ * You can checkout the default timezones list [here](https://github.com/yury-dymov/react-bootstrap-timezone-picker/blob/master/src/timezones.json).
59
+ *
60
+ * Utilizes ComboBoxField component. You can use the same props as with
61
+ * the ComboBoxField - they will be spread into it.
62
+ */
63
+
64
+
65
+ var TimeZonePicker = /*#__PURE__*/forwardRef(function (props, ref) {
66
+ var additionalTimeZones = props.additionalTimeZones,
67
+ emptySearchText = props.emptySearchText,
68
+ locales = props.locales,
69
+ localeOptions = props.localeOptions,
70
+ otherProps = _objectWithoutProperties(props, ["additionalTimeZones", "emptySearchText", "locales", "localeOptions"]);
71
+
72
+ var _useState = useState(''),
73
+ _useState2 = _slicedToArray(_useState, 2),
74
+ search = _useState2[0],
75
+ setSearch = _useState2[1];
76
+
77
+ var _useState3 = useState(false),
78
+ _useState4 = _slicedToArray(_useState3, 2),
79
+ timeUpdate = _useState4[0],
80
+ setTimeUpdate = _useState4[1];
81
+
82
+ var _useState5 = useState([]),
83
+ _useState6 = _slicedToArray(_useState5, 2),
84
+ timeZones = _useState6[0],
85
+ setTimeZones = _useState6[1];
86
+
87
+ var extendedTimeZonesList = additionalTimeZones ? _objectSpread(_objectSpread({}, defaultTimezones), additionalTimeZones) : defaultTimezones;
88
+ var timeZonePickerRef = useRef();
89
+ /* istanbul ignore next */
90
+
91
+ useImperativeHandle(ref, function () {
92
+ return timeZonePickerRef.current;
93
+ });
94
+ useEffect(function () {
95
+ if (timeUpdate) {
96
+ var createTimeZoneTimes = function createTimeZoneTimes() {
97
+ var _context5;
98
+
99
+ return _mapInstanceProperty(_context5 = _Object$entries(extendedTimeZonesList)).call(_context5, function (item) {
100
+ var _item$;
101
+
102
+ var gmt = item[0].substring(1, 10);
103
+ var gmtLabel = item[0].substring(12);
104
+ var timeZone = (_item$ = item[1]) === null || _item$ === void 0 ? void 0 : _item$.replace(/_/g, ' ');
105
+ var time = getLocaleTime({
106
+ timeZone: item[1],
107
+ locales: locales,
108
+ localeOptions: localeOptions
109
+ });
110
+ var searchTags = createSearchTags({
111
+ gmt: gmt,
112
+ gmtLabel: gmtLabel,
113
+ timeZone: timeZone
114
+ });
115
+ return {
116
+ gmt: gmt,
117
+ timeZone: timeZone,
118
+ time: time,
119
+ searchTags: searchTags
120
+ };
121
+ });
122
+ };
123
+
124
+ setTimeZones(createTimeZoneTimes());
125
+ setTimeUpdate(false);
126
+ }
127
+ }, [extendedTimeZonesList, locales, localeOptions, timeUpdate]);
128
+ var filterTimezones = useCallback(function (timeZonesList) {
129
+ return _filterInstanceProperty(timeZonesList).call(timeZonesList, function (_ref3) {
130
+ var _context6;
131
+
132
+ var searchTags = _ref3.searchTags;
133
+ return _indexOfInstanceProperty(_context6 = searchTags.toUpperCase()).call(_context6, search.toUpperCase()) > -1;
134
+ });
135
+ }, [search]);
136
+ var filteredTimezones = useMemo(function () {
137
+ return filterTimezones(timeZones);
138
+ }, [filterTimezones, timeZones]);
139
+
140
+ var sortByGMT = function sortByGMT(a, b) {
141
+ var aNum = _parseFloat(a.gmt.split('GMT')[1].split(':')[0]);
142
+
143
+ var bNum = _parseFloat(b.gmt.split('GMT')[1].split(')')[0]);
144
+
145
+ return aNum - bNum;
146
+ };
147
+
148
+ var items = useMemo(function () {
149
+ var _context7;
150
+
151
+ if (filteredTimezones.length === 0) {
152
+ return ___EmotionJSX(Item, {
153
+ key: emptySearchText
154
+ }, emptySearchText);
155
+ }
156
+
157
+ return _mapInstanceProperty(_context7 = _sortInstanceProperty(filteredTimezones).call(filteredTimezones, sortByGMT)).call(_context7, function (_ref4) {
158
+ var gmt = _ref4.gmt,
159
+ time = _ref4.time,
160
+ timeZone = _ref4.timeZone;
161
+ return ___EmotionJSX(Item, {
162
+ key: timeZone,
163
+ "data-id": timeZone,
164
+ textValue: timeZone
165
+ }, ___EmotionJSX(Box, {
166
+ flexDirection: "row",
167
+ justifyContent: "space-between",
168
+ width: "100%"
169
+ }, ___EmotionJSX(Box, {
170
+ flexDirection: "row"
171
+ }, ___EmotionJSX(Text, {
172
+ variant: "timeZone.title"
173
+ }, timeZone), ___EmotionJSX(Text, {
174
+ variant: "timeZone.subTitle"
175
+ }, gmt)), ___EmotionJSX(Box, null, ___EmotionJSX(Text, {
176
+ variant: "timeZone.time"
177
+ }, time))));
178
+ });
179
+ }, [emptySearchText, filteredTimezones]);
180
+ var comboBoxFieldProps = useMemo(function () {
181
+ return _objectSpread({
182
+ controlProps: {
183
+ sx: {
184
+ width: 400,
185
+ fontSize: 'md'
186
+ }
187
+ },
188
+ onInputChange: setSearch,
189
+ items: filteredTimezones,
190
+ ref: timeZonePickerRef,
191
+ onOpenChange: function onOpenChange(isOpen) {
192
+ return setTimeUpdate(isOpen);
193
+ },
194
+ disabledKeys: [{
195
+ emptySearchText: emptySearchText
196
+ }]
197
+ }, otherProps);
198
+ }, [emptySearchText, filteredTimezones, otherProps]);
199
+ return ___EmotionJSX(ComboBoxField, _extends({}, comboBoxFieldProps, {
200
+ disabledKeys: [emptySearchText]
201
+ }), items);
202
+ });
203
+ TimeZonePicker.propTypes = {
204
+ /**
205
+ * An object representing additional time zones to merge with the [default list](https://github.com/yury-dymov/react-bootstrap-timezone-picker/blob/master/src/timezones.json).
206
+ * The key may be customized, but the value should be a timezone string from the list in the [Time Zone Database](https://www.iana.org/time-zones).
207
+ *
208
+ * e.g. `{'(GMT+02:00) Africa/Juba': 'Africa/Juba'}`
209
+ */
210
+ additionalTimeZones: PropTypes.shape({}),
211
+
212
+ /** Text that will be shown if no search results are found. */
213
+ emptySearchText: PropTypes.string,
214
+
215
+ /** Locale(s) to use when generating the time format. See [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString#using_locales) for more info. */
216
+ locales: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
217
+
218
+ /** Custom options to use when generating the time format. See [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString#using_options) for more info. */
219
+ localeOptions: PropTypes.shape({})
220
+ };
221
+ TimeZonePicker.defaultProps = {
222
+ emptySearchText: 'No Search Result',
223
+ locales: [],
224
+ localeOptions: {
225
+ hour12: true,
226
+ hour: '2-digit',
227
+ minute: '2-digit'
228
+ }
229
+ };
230
+ export default TimeZonePicker;