@citygross/components 0.8.91 → 0.8.93

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.
@@ -12,17 +12,18 @@ export declare enum EButtonVariant {
12
12
  'ghost' = 4
13
13
  }
14
14
  export declare type TCgButton = {
15
- size?: ECgButtonSize;
16
- variant?: EButtonVariant;
17
- icon?: React.ReactNode;
18
- flexReverse?: boolean;
19
- loading?: boolean;
15
+ buttonRef?: React.Ref<HTMLButtonElement>;
20
16
  children?: React.ReactNode;
21
17
  disabled?: boolean;
22
- onClick?: () => void;
18
+ flexReverse?: boolean;
23
19
  fullWidth?: boolean;
24
- buttonRef?: React.Ref<HTMLButtonElement>;
20
+ icon?: React.ReactNode;
21
+ id?: string;
22
+ loading?: boolean;
23
+ onClick?: () => void;
25
24
  round?: boolean;
26
25
  shouldPreventDefault?: boolean;
26
+ size?: ECgButtonSize;
27
+ variant?: EButtonVariant;
27
28
  };
28
- export declare const CgButton: ({ size, variant, icon, flexReverse, disabled, onClick, children, loading, fullWidth, buttonRef, round, shouldPreventDefault }: TCgButton) => JSX.Element;
29
+ export declare const CgButton: ({ buttonRef, children, disabled, flexReverse, fullWidth, icon, id, loading, onClick, round, shouldPreventDefault, size, variant }: TCgButton) => JSX.Element;
@@ -25,16 +25,12 @@ exports.EButtonVariant = void 0;
25
25
  EButtonVariant[EButtonVariant["ghost"] = 4] = "ghost";
26
26
  })(exports.EButtonVariant || (exports.EButtonVariant = {}));
27
27
  var CgButton = function (_a) {
28
- var size = _a.size, variant = _a.variant, icon = _a.icon, flexReverse = _a.flexReverse, disabled = _a.disabled, onClick = _a.onClick, children = _a.children, loading = _a.loading, fullWidth = _a.fullWidth, buttonRef = _a.buttonRef, round = _a.round, _b = _a.shouldPreventDefault, shouldPreventDefault = _b === void 0 ? true : _b;
29
- return (React__default["default"].createElement(CgButton_styles.CgButtonContainer, { ref: buttonRef, round: round, size: size, variant: variant, isIconOnly: !children, flexReverse: flexReverse, disabled: disabled || loading, fullWidth: fullWidth, loading: loading, onKeyDown: function (event) {
30
- if (event.key === 'Enter' && !disabled) {
31
- onClick && onClick();
32
- }
33
- }, onClick: function (e) {
28
+ var buttonRef = _a.buttonRef, children = _a.children, disabled = _a.disabled, flexReverse = _a.flexReverse, fullWidth = _a.fullWidth, icon = _a.icon, _b = _a.id, id = _b === void 0 ? 'cg-button' : _b, loading = _a.loading, onClick = _a.onClick, round = _a.round, _c = _a.shouldPreventDefault, shouldPreventDefault = _c === void 0 ? true : _c, size = _a.size, variant = _a.variant;
29
+ return (React__default["default"].createElement(CgButton_styles.CgButtonContainer, { disabled: disabled || loading, flexReverse: flexReverse, fullWidth: fullWidth, isIconOnly: !children, id: id, loading: loading, onClick: function (e) {
34
30
  shouldPreventDefault && e.preventDefault();
35
31
  onClick && onClick();
36
- } },
37
- React__default["default"].createElement(CgButton_styles.CgButtonContent, { size: size, flexReverse: flexReverse, loading: loading },
32
+ }, ref: buttonRef, round: round, size: size, variant: variant },
33
+ React__default["default"].createElement(CgButton_styles.CgButtonContent, { flexReverse: flexReverse, loading: loading, size: size },
38
34
  icon,
39
35
  children),
40
36
  loading && (React__default["default"].createElement(CgButton_styles.CgButtonLoader, null,
@@ -1 +1 @@
1
- {"version":3,"file":"CgButton.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"CgButton.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -447,6 +447,45 @@ var makeCateringPortionsString = function (variant, cartItem, unit) {
447
447
  return qString;
448
448
  };
449
449
 
450
+ var focusTrap = function (_a) {
451
+ var _b;
452
+ var exitFunction = _a.exitFunction, ref = _a.ref;
453
+ var elements = 'button:not([disabled]), [href]:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
454
+ var focusableElements = (_b = ref.current) === null || _b === void 0 ? void 0 : _b.querySelectorAll(elements);
455
+ if (focusableElements &&
456
+ focusableElements.length > 0 &&
457
+ focusableElements[0] instanceof HTMLElement) {
458
+ focusableElements[0].focus();
459
+ }
460
+ var handleKeyDown = function (e) {
461
+ if (!ref.current)
462
+ return;
463
+ var focusable = Array.from(ref.current.querySelectorAll(elements));
464
+ if (focusable.length === 0)
465
+ return;
466
+ var firstElement = focusable[0];
467
+ var lastElement = focusable[focusable.length - 1];
468
+ if (e.key === 'Tab') {
469
+ if (e.shiftKey && document.activeElement === firstElement) {
470
+ e.preventDefault();
471
+ lastElement.focus();
472
+ }
473
+ else if (!e.shiftKey && document.activeElement === lastElement) {
474
+ e.preventDefault();
475
+ firstElement.focus();
476
+ }
477
+ }
478
+ else if (e.key === 'Escape')
479
+ exitFunction();
480
+ };
481
+ if (ref.current)
482
+ ref.current.addEventListener('keydown', handleKeyDown);
483
+ return function () {
484
+ if (ref.current)
485
+ ref.current.removeEventListener('keydown', handleKeyDown);
486
+ };
487
+ };
488
+
450
489
  var formatLeadingZero = function (day) { return day.replace(/^0+/, ''); };
451
490
 
452
491
  var formatPostalCode = function (postalCode, spaceIndex) {
@@ -18848,6 +18887,7 @@ index.__exports.capitalizeFirstLetter = capitalizeFirstLetter;
18848
18887
  index.__exports.capitalizedAllWords = capitalizedAllWords;
18849
18888
  index.__exports.comparisonTypes = comparisonTypes;
18850
18889
  index.__exports.emailRegex = emailRegex;
18890
+ index.__exports.focusTrap = focusTrap;
18851
18891
  index.__exports.formatDateToLocale = formatDateToLocale;
18852
18892
  index.__exports.formatLeadingZero = formatLeadingZero;
18853
18893
  index.__exports.formatPostalCode = formatPostalCode;