@uxf/core 11.51.0 → 11.52.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.
Files changed (99) hide show
  1. package/README.md +15 -249
  2. package/index.d.ts +2 -2
  3. package/index.js +2 -2
  4. package/package.json +1 -8
  5. package/utils/adjust-textarea-height.d.ts +1 -0
  6. package/utils/adjust-textarea-height.js +13 -0
  7. package/utils/adjust-textarea-height.test.js +83 -0
  8. package/utils/build-array.test.js +10 -0
  9. package/utils/camel-case-to-dash.test.js +8 -0
  10. package/utils/image.d.ts +0 -22
  11. package/utils/image.js +0 -41
  12. package/utils/{isBrowser.test.js → is-browser.test.js} +3 -3
  13. package/utils/{isServer.js → is-server.js} +2 -2
  14. package/utils/is-server.test.js +12 -0
  15. package/utils/trim-trailing-zeros.test.js +6 -6
  16. package/{Validators/FormValidator.js → validators/form-validator.js} +3 -3
  17. package/validators/form-validator.test.js +45 -0
  18. package/validators/validator.test.js +17 -0
  19. package/Validators/FormValidator.test.js +0 -45
  20. package/Validators/Validator.test.js +0 -17
  21. package/components/hide.d.ts +0 -10
  22. package/components/hide.js +0 -16
  23. package/components/show.d.ts +0 -10
  24. package/components/show.js +0 -16
  25. package/hooks/_useSimulatedButton.d.ts +0 -19
  26. package/hooks/_useSimulatedButton.js +0 -54
  27. package/hooks/useAnchorProps.d.ts +0 -14
  28. package/hooks/useAnchorProps.js +0 -68
  29. package/hooks/useBodyScrollLock.d.ts +0 -12
  30. package/hooks/useBodyScrollLock.js +0 -37
  31. package/hooks/useButtonProps.d.ts +0 -12
  32. package/hooks/useButtonProps.js +0 -61
  33. package/hooks/useClickableProps.d.ts +0 -14
  34. package/hooks/useClickableProps.js +0 -46
  35. package/hooks/useFocusReturn.d.ts +0 -4
  36. package/hooks/useFocusReturn.js +0 -37
  37. package/hooks/useFocusTrap.d.ts +0 -5
  38. package/hooks/useFocusTrap.js +0 -148
  39. package/hooks/useInputFocus.d.ts +0 -10
  40. package/hooks/useInputFocus.js +0 -29
  41. package/hooks/useIsMounted.d.ts +0 -4
  42. package/hooks/useIsMounted.js +0 -12
  43. package/hooks/useIsomorphicLayoutEffect.d.ts +0 -5
  44. package/hooks/useIsomorphicLayoutEffect.js +0 -9
  45. package/hooks/useKey.d.ts +0 -19
  46. package/hooks/useKey.js +0 -30
  47. package/hooks/useLatest.d.ts +0 -4
  48. package/hooks/useLatest.js +0 -12
  49. package/hooks/useMinWindowWidth.d.ts +0 -4
  50. package/hooks/useMinWindowWidth.js +0 -31
  51. package/hooks/useMouseDragToScroll.d.ts +0 -5
  52. package/hooks/useMouseDragToScroll.js +0 -41
  53. package/hooks/useOnMount.d.ts +0 -5
  54. package/hooks/useOnMount.js +0 -12
  55. package/hooks/useOnUnmount.d.ts +0 -5
  56. package/hooks/useOnUnmount.js +0 -17
  57. package/hooks/useOnUpdate.d.ts +0 -5
  58. package/hooks/useOnUpdate.js +0 -17
  59. package/hooks/usePagination.d.ts +0 -5
  60. package/hooks/usePagination.js +0 -23
  61. package/hooks/usePrevious.d.ts +0 -4
  62. package/hooks/usePrevious.js +0 -14
  63. package/hooks/useRafState.d.ts +0 -5
  64. package/hooks/useRafState.js +0 -20
  65. package/hooks/useTabs.d.ts +0 -16
  66. package/hooks/useTabs.js +0 -43
  67. package/hooks/useWindowScroll.d.ts +0 -7
  68. package/hooks/useWindowScroll.js +0 -24
  69. package/hooks/useWindowSize.d.ts +0 -7
  70. package/hooks/useWindowSize.js +0 -21
  71. package/next/index.d.ts +0 -2
  72. package/next/index.js +0 -7
  73. package/next/query-param.test.js +0 -35
  74. package/utils/buildArray.test.js +0 -10
  75. package/utils/camelCaseToDash.test.js +0 -8
  76. package/utils/composeRefs.d.ts +0 -5
  77. package/utils/composeRefs.js +0 -18
  78. package/utils/isServer.test.js +0 -12
  79. /package/{Validators/FormValidator.test.d.ts → utils/adjust-textarea-height.test.d.ts} +0 -0
  80. /package/utils/{bodyScrollLock.d.ts → body-scroll-lock.d.ts} +0 -0
  81. /package/utils/{bodyScrollLock.js → body-scroll-lock.js} +0 -0
  82. /package/utils/{buildArray.d.ts → build-array.d.ts} +0 -0
  83. /package/utils/{buildArray.js → build-array.js} +0 -0
  84. /package/{Validators/Validator.test.d.ts → utils/build-array.test.d.ts} +0 -0
  85. /package/utils/{camelCaseToDash.d.ts → camel-case-to-dash.d.ts} +0 -0
  86. /package/utils/{camelCaseToDash.js → camel-case-to-dash.js} +0 -0
  87. /package/{next/query-param.test.d.ts → utils/camel-case-to-dash.test.d.ts} +0 -0
  88. /package/utils/{isBrowser.d.ts → is-browser.d.ts} +0 -0
  89. /package/utils/{isBrowser.js → is-browser.js} +0 -0
  90. /package/utils/{buildArray.test.d.ts → is-browser.test.d.ts} +0 -0
  91. /package/utils/{isServer.d.ts → is-server.d.ts} +0 -0
  92. /package/utils/{camelCaseToDash.test.d.ts → is-server.test.d.ts} +0 -0
  93. /package/utils/{trimTrailingZeros.d.ts → trim-trailing-zeros.d.ts} +0 -0
  94. /package/utils/{trimTrailingZeros.js → trim-trailing-zeros.js} +0 -0
  95. /package/{Validators/FormValidator.d.ts → validators/form-validator.d.ts} +0 -0
  96. /package/{utils/isBrowser.test.d.ts → validators/form-validator.test.d.ts} +0 -0
  97. /package/{Validators/Validator.d.ts → validators/validator.d.ts} +0 -0
  98. /package/{Validators/Validator.js → validators/validator.js} +0 -0
  99. /package/{utils/isServer.test.d.ts → validators/validator.test.d.ts} +0 -0
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const FormValidator_1 = require("./FormValidator");
4
- test("required", () => {
5
- expect(FormValidator_1.FormValidator.required("error")("not empty")).toBeUndefined();
6
- expect(FormValidator_1.FormValidator.required("error")(0)).toBeUndefined();
7
- expect(FormValidator_1.FormValidator.required("error")(false)).toBeUndefined();
8
- expect(FormValidator_1.FormValidator.required("error")("")).toBe("error");
9
- expect(FormValidator_1.FormValidator.required("error")(null)).toBe("error");
10
- expect(FormValidator_1.FormValidator.required("error")(undefined)).toBe("error");
11
- });
12
- test("isEmail", () => {
13
- expect(FormValidator_1.FormValidator.isEmail("error")("")).toBeUndefined();
14
- expect(FormValidator_1.FormValidator.isEmail("error")("dev@uxf.cz")).toBeUndefined();
15
- expect(FormValidator_1.FormValidator.isEmail("error")("dev@uxfcz")).toBe("error");
16
- });
17
- test("isPhone", () => {
18
- expect(FormValidator_1.FormValidator.isPhone("error")("")).toBeUndefined();
19
- expect(FormValidator_1.FormValidator.isPhone("error")("777888999")).toBeUndefined();
20
- expect(FormValidator_1.FormValidator.isPhone("error")("dev@uxfcz")).toBe("error");
21
- });
22
- test("isLessThan", () => {
23
- expect(FormValidator_1.FormValidator.isLessThan(10, "error")("")).toBeUndefined();
24
- expect(FormValidator_1.FormValidator.isLessThan(10, "error")("9.9")).toBeUndefined();
25
- expect(FormValidator_1.FormValidator.isLessThan(10, "error")("10")).toBe("error");
26
- expect(FormValidator_1.FormValidator.isLessThan(10, "error")("100")).toBe("error");
27
- });
28
- test("isLessOrEqualThan", () => {
29
- expect(FormValidator_1.FormValidator.isLessOrEqualThan(10, "error")("")).toBeUndefined();
30
- expect(FormValidator_1.FormValidator.isLessOrEqualThan(10, "error")("9.9")).toBeUndefined();
31
- expect(FormValidator_1.FormValidator.isLessOrEqualThan(10, "error")("10")).toBeUndefined();
32
- expect(FormValidator_1.FormValidator.isLessOrEqualThan(10, "error")("10.001")).toBe("error");
33
- });
34
- test("isGreaterThan", () => {
35
- expect(FormValidator_1.FormValidator.isGreaterThan(10, "error")("")).toBeUndefined();
36
- expect(FormValidator_1.FormValidator.isGreaterThan(10, "error")("9")).toBe("error");
37
- expect(FormValidator_1.FormValidator.isGreaterThan(10, "error")("10")).toBe("error");
38
- expect(FormValidator_1.FormValidator.isGreaterThan(10, "error")("10.001")).toBeUndefined();
39
- });
40
- test("isGreaterOrEqualThan", () => {
41
- expect(FormValidator_1.FormValidator.isGreaterOrEqualThan(10, "error")("")).toBeUndefined();
42
- expect(FormValidator_1.FormValidator.isGreaterOrEqualThan(10, "error")("9")).toBe("error");
43
- expect(FormValidator_1.FormValidator.isGreaterOrEqualThan(10, "error")("10")).toBeUndefined();
44
- expect(FormValidator_1.FormValidator.isGreaterOrEqualThan(10, "error")("10.001")).toBeUndefined();
45
- });
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const Validator_1 = require("./Validator");
4
- test("isEmail", () => {
5
- expect(Validator_1.Validator.isEmail("dev@uxf.cz")).toBe(true);
6
- expect(Validator_1.Validator.isEmail("dev@uxf.c")).toBe(false);
7
- expect(Validator_1.Validator.isEmail("dev@uxf@c")).toBe(false);
8
- });
9
- test("isPhone", () => {
10
- expect(Validator_1.Validator.isPhone("+420777000111")).toBe(true);
11
- expect(Validator_1.Validator.isPhone("00420777000111")).toBe(true);
12
- expect(Validator_1.Validator.isPhone("777000111")).toBe(true);
13
- expect(Validator_1.Validator.isPhone("77700011")).toBe(false);
14
- expect(Validator_1.Validator.isPhone("+1777000111")).toBe(true);
15
- expect(Validator_1.Validator.isPhone("+22777000111")).toBe(true);
16
- expect(Validator_1.Validator.isPhone("+001777000111")).toBe(true);
17
- });
@@ -1,10 +0,0 @@
1
- import React, { ReactNode } from "react";
2
- interface HideProps {
3
- when: boolean;
4
- children?: ReactNode;
5
- }
6
- /**
7
- * @deprecated Use import from @uxf/core-react instead.
8
- */
9
- export declare function Hide(props: HideProps): React.JSX.Element | null;
10
- export {};
@@ -1,16 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Hide = Hide;
7
- const react_1 = __importDefault(require("react"));
8
- /**
9
- * @deprecated Use import from @uxf/core-react instead.
10
- */
11
- function Hide(props) {
12
- if (props.when) {
13
- return null;
14
- }
15
- return react_1.default.createElement(react_1.default.Fragment, null, props.children);
16
- }
@@ -1,10 +0,0 @@
1
- import React, { ReactNode } from "react";
2
- interface ShowProps {
3
- when: boolean;
4
- children?: ReactNode;
5
- }
6
- /**
7
- * @deprecated Use import from @uxf/core-react instead.
8
- */
9
- export declare function Show(props: ShowProps): React.JSX.Element | null;
10
- export {};
@@ -1,16 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Show = Show;
7
- const react_1 = __importDefault(require("react"));
8
- /**
9
- * @deprecated Use import from @uxf/core-react instead.
10
- */
11
- function Show(props) {
12
- if (!props.when) {
13
- return null;
14
- }
15
- return react_1.default.createElement(react_1.default.Fragment, null, props.children);
16
- }
@@ -1,19 +0,0 @@
1
- import { KeyboardEventHandler, MouseEventHandler } from "react";
2
- interface Props<T extends HTMLElement> {
3
- analyticsCallback?: () => void;
4
- isClickable: boolean;
5
- isHyperlink: boolean;
6
- onClick?: MouseEventHandler<T>;
7
- onKeyDown?: KeyboardEventHandler<T>;
8
- onKeyUp?: KeyboardEventHandler<T>;
9
- submit?: boolean;
10
- }
11
- /**
12
- * @deprecated Use import from @uxf/core-react instead.
13
- */
14
- export declare function _useSimulatedButton<T extends HTMLElement>({ analyticsCallback, isClickable, isHyperlink, onClick, onKeyDown, onKeyUp, submit, }: Props<T>): {
15
- onClick: MouseEventHandler<T>;
16
- onKeyDown: KeyboardEventHandler<T>;
17
- onKeyUp: KeyboardEventHandler<T>;
18
- };
19
- export {};
@@ -1,54 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._useSimulatedButton = _useSimulatedButton;
4
- const react_1 = require("react");
5
- /**
6
- * @deprecated Use import from @uxf/core-react instead.
7
- */
8
- function _useSimulatedButton({ analyticsCallback, isClickable, isHyperlink, onClick, onKeyDown, onKeyUp, submit, }) {
9
- // eslint-disable-next-line react-hooks/rules-of-hooks
10
- const _onClick = (0, react_1.useCallback)((e) => {
11
- var _a;
12
- if ((isClickable || isHyperlink) && analyticsCallback) {
13
- analyticsCallback();
14
- }
15
- if (isClickable) {
16
- if (submit) {
17
- const closestForm = (_a = document.activeElement) === null || _a === void 0 ? void 0 : _a.closest("form");
18
- if (closestForm) {
19
- closestForm.dispatchEvent(new Event("submit", { bubbles: true, cancelable: true }));
20
- }
21
- }
22
- if (onClick) {
23
- onClick(e);
24
- }
25
- }
26
- else {
27
- e.preventDefault();
28
- }
29
- }, [analyticsCallback, isClickable, isHyperlink, onClick, submit]);
30
- // eslint-disable-next-line react-hooks/rules-of-hooks
31
- const _onKeyUp = (0, react_1.useCallback)((e) => {
32
- if (isClickable && (e.key === "Enter" || e.key === " ")) {
33
- e.target.dispatchEvent(new MouseEvent("click", {
34
- bubbles: true,
35
- buttons: 1,
36
- cancelable: true,
37
- view: window,
38
- }));
39
- if (onKeyUp) {
40
- onKeyUp(e);
41
- }
42
- }
43
- }, [isClickable, onKeyUp]);
44
- // eslint-disable-next-line react-hooks/rules-of-hooks
45
- const _onKeyDown = (0, react_1.useCallback)((e) => {
46
- if (isClickable && e.key === " ") {
47
- e.preventDefault();
48
- if (onKeyDown) {
49
- onKeyDown(e);
50
- }
51
- }
52
- }, [isClickable, onKeyDown]);
53
- return { onClick: _onClick, onKeyDown: _onKeyDown, onKeyUp: _onKeyUp };
54
- }
@@ -1,14 +0,0 @@
1
- import { AnchorHTMLAttributes } from "react";
2
- /**
3
- * @deprecated Use import from @uxf/core-react instead.
4
- */
5
- export interface UseAnchorProps {
6
- analyticsCallback?: () => void;
7
- disabled?: boolean;
8
- loading?: boolean;
9
- type?: "submit";
10
- }
11
- /**
12
- * @deprecated Use import from @uxf/core-react instead.
13
- */
14
- export declare function useAnchorProps<T extends AnchorHTMLAttributes<HTMLAnchorElement>>({ ["aria-busy"]: ariaBusy, ["aria-disabled"]: ariaDisabled, analyticsCallback, className, disabled, download, href, hrefLang, loading, media, onClick, onKeyDown, onKeyUp, ping, referrerPolicy, rel, role, tabIndex, target, type, ...restProps }: UseAnchorProps & T): T;
@@ -1,68 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useAnchorProps = useAnchorProps;
4
- const classes_1 = require("../constants/classes");
5
- const cx_1 = require("../utils/cx");
6
- const is_not_nil_1 = require("../utils/is-not-nil");
7
- const _useSimulatedButton_1 = require("./_useSimulatedButton");
8
- /**
9
- * @deprecated Use import from @uxf/core-react instead.
10
- */
11
- function useAnchorProps({ ["aria-busy"]: ariaBusy, ["aria-disabled"]: ariaDisabled, analyticsCallback, className, disabled, download, href, hrefLang, loading, media, onClick, onKeyDown, onKeyUp, ping, referrerPolicy, rel, role, tabIndex, target, type, ...restProps }) {
12
- const isBusy = loading ? loading : Boolean(ariaBusy);
13
- const isDisabled = disabled ? disabled : Boolean(ariaDisabled);
14
- const isBusyOrDisabled = isBusy || isDisabled;
15
- const submit = type === "submit";
16
- const isButton = submit || (0, is_not_nil_1.isNotNil)(onClick);
17
- const tabIndexInteractive = isBusyOrDisabled ? -1 : tabIndex;
18
- const _className = [isBusy && classes_1.CLASSES.IS_LOADING, disabled && classes_1.CLASSES.IS_DISABLED, className];
19
- const simulatedButton = (0, _useSimulatedButton_1._useSimulatedButton)({
20
- analyticsCallback,
21
- isClickable: !isBusyOrDisabled || isButton,
22
- isHyperlink: !isBusyOrDisabled || Boolean(href),
23
- onClick,
24
- onKeyDown,
25
- onKeyUp,
26
- submit,
27
- });
28
- if (href) {
29
- return {
30
- "aria-busy": isBusy,
31
- "aria-disabled": isDisabled,
32
- className: (0, cx_1.cx)(classes_1.CLASSES.IS_HOVERABLE, ..._className),
33
- download,
34
- href,
35
- hrefLang,
36
- media,
37
- onClick: simulatedButton.onClick,
38
- onKeyDown: simulatedButton.onKeyDown,
39
- onKeyUp: simulatedButton.onKeyUp,
40
- ping,
41
- referrerPolicy,
42
- rel: target === "_blank" ? (rel ? `noopener noreferrer ${rel}` : "noopener noreferrer") : rel,
43
- role: role || (isButton ? "button" : undefined),
44
- tabIndex: tabIndexInteractive,
45
- target,
46
- ...restProps,
47
- };
48
- }
49
- if (isButton) {
50
- return {
51
- "aria-busy": isBusy,
52
- "aria-disabled": isDisabled,
53
- className: (0, cx_1.cx)(classes_1.CLASSES.IS_HOVERABLE, ..._className),
54
- onClick: simulatedButton.onClick,
55
- onKeyDown: simulatedButton.onKeyDown,
56
- onKeyUp: simulatedButton.onKeyUp,
57
- role: role || "button",
58
- tabIndex: tabIndexInteractive !== null && tabIndexInteractive !== void 0 ? tabIndexInteractive : 0,
59
- ...restProps,
60
- };
61
- }
62
- return {
63
- className: (0, cx_1.cx)(..._className),
64
- role: role || "none",
65
- tabIndex,
66
- ...restProps,
67
- };
68
- }
@@ -1,12 +0,0 @@
1
- import { RefObject } from "react";
2
- import { BodyScrollOptions } from "../utils/bodyScrollLock";
3
- /**
4
- * @deprecated Use import from @uxf/core-react instead.
5
- */
6
- export interface UseBodyScrollLockOptions extends BodyScrollOptions {
7
- clearAllOnClose?: boolean;
8
- }
9
- /**
10
- * @deprecated Use import from @uxf/core-react instead.
11
- */
12
- export declare function useBodyScrollLock<T extends HTMLElement>(containerRef: RefObject<T>, isOpen: boolean, { allowTouchMove, clearAllOnClose, reserveScrollBarGap }?: Partial<UseBodyScrollLockOptions>): void;
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useBodyScrollLock = useBodyScrollLock;
4
- const react_1 = require("react");
5
- const bodyScrollLock_1 = require("../utils/bodyScrollLock");
6
- /**
7
- * @deprecated Use import from @uxf/core-react instead.
8
- */
9
- function useBodyScrollLock(containerRef, isOpen, { allowTouchMove, clearAllOnClose, reserveScrollBarGap } = {}) {
10
- (0, react_1.useEffect)(() => {
11
- const node = containerRef.current;
12
- if (isOpen && node) {
13
- (0, bodyScrollLock_1.disableBodyScroll)(node, {
14
- allowTouchMove: allowTouchMove ||
15
- ((element) => {
16
- var _a;
17
- while (element !== document.body) {
18
- if (element.getAttribute("data-body-scroll-lock-ignore") !== null) {
19
- return true;
20
- }
21
- element = (_a = element.parentElement) !== null && _a !== void 0 ? _a : element;
22
- }
23
- return false;
24
- }),
25
- reserveScrollBarGap,
26
- });
27
- }
28
- return () => {
29
- if (node) {
30
- (0, bodyScrollLock_1.enableBodyScroll)(node);
31
- }
32
- if (clearAllOnClose) {
33
- (0, bodyScrollLock_1.clearAllBodyScrollLocks)();
34
- }
35
- };
36
- }, [allowTouchMove, clearAllOnClose, containerRef, isOpen, reserveScrollBarGap]);
37
- }
@@ -1,12 +0,0 @@
1
- import { ButtonHTMLAttributes } from "react";
2
- /**
3
- * @deprecated Use import from @uxf/core-react instead.
4
- */
5
- export interface UseButtonProps {
6
- analyticsCallback?: () => void;
7
- loading?: boolean;
8
- }
9
- /**
10
- * @deprecated Use import from @uxf/core-react instead.
11
- */
12
- export declare function useButtonProps<T extends ButtonHTMLAttributes<HTMLButtonElement>>({ ["aria-busy"]: ariaBusy, ["aria-disabled"]: ariaDisabled, autoFocus, analyticsCallback, className, disabled, formAction, formEncType, formMethod, formNoValidate, formTarget, loading, name, onClick, role, tabIndex, type, value, ...restProps }: UseButtonProps & T): T;
@@ -1,61 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useButtonProps = useButtonProps;
4
- const react_1 = require("react");
5
- const classes_1 = require("../constants/classes");
6
- const cx_1 = require("../utils/cx");
7
- /**
8
- * @deprecated Use import from @uxf/core-react instead.
9
- */
10
- function useButtonProps({ ["aria-busy"]: ariaBusy, ["aria-disabled"]: ariaDisabled, autoFocus, analyticsCallback, className, disabled, formAction, formEncType, formMethod, formNoValidate, formTarget, loading, name, onClick, role, tabIndex, type, value, ...restProps }) {
11
- const isBusy = loading ? loading : Boolean(ariaBusy);
12
- const isDisabled = disabled ? disabled : Boolean(ariaDisabled);
13
- const isBusyOrDisabled = isBusy || isDisabled;
14
- const _className = [isBusy && classes_1.CLASSES.IS_LOADING, isDisabled && classes_1.CLASSES.IS_DISABLED, className];
15
- const _onClick = (0, react_1.useCallback)((e) => {
16
- if (isBusyOrDisabled) {
17
- e.preventDefault();
18
- }
19
- else {
20
- if (analyticsCallback) {
21
- analyticsCallback();
22
- }
23
- if (onClick) {
24
- onClick(e);
25
- }
26
- }
27
- }, [analyticsCallback, isBusyOrDisabled, onClick]);
28
- if (onClick || type === "reset" || type === "submit") {
29
- let submitProps = {};
30
- if (type === "submit") {
31
- submitProps = {
32
- formAction,
33
- formEncType,
34
- formMethod,
35
- formNoValidate,
36
- formTarget,
37
- name,
38
- value,
39
- };
40
- }
41
- return {
42
- "aria-busy": isBusy,
43
- "aria-disabled": ariaDisabled,
44
- autoFocus,
45
- className: (0, cx_1.cx)(classes_1.CLASSES.IS_HOVERABLE, ..._className),
46
- disabled,
47
- onClick: _onClick,
48
- role,
49
- tabIndex: isBusyOrDisabled ? -1 : tabIndex,
50
- type,
51
- ...submitProps,
52
- ...restProps,
53
- };
54
- }
55
- return {
56
- className: (0, cx_1.cx)(..._className),
57
- role,
58
- tabIndex: tabIndex !== null && tabIndex !== void 0 ? tabIndex : -1,
59
- ...restProps,
60
- };
61
- }
@@ -1,14 +0,0 @@
1
- import { HTMLAttributes } from "react";
2
- /**
3
- * @deprecated Use import from @uxf/core-react instead.
4
- */
5
- export interface UseClickableProps {
6
- analyticsCallback?: () => void;
7
- disabled?: boolean;
8
- loading?: boolean;
9
- type?: "submit";
10
- }
11
- /**
12
- * @deprecated Use import from @uxf/core-react instead.
13
- */
14
- export declare function useClickableProps<T extends HTMLAttributes<HTMLElement>>({ ["aria-busy"]: ariaBusy, ["aria-disabled"]: ariaDisabled, analyticsCallback, className, disabled, loading, onClick, onKeyDown, onKeyUp, role, tabIndex, type, ...restProps }: UseClickableProps & T): T;
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useClickableProps = useClickableProps;
4
- const classes_1 = require("../constants/classes");
5
- const cx_1 = require("../utils/cx");
6
- const is_not_nil_1 = require("../utils/is-not-nil");
7
- const _useSimulatedButton_1 = require("./_useSimulatedButton");
8
- /**
9
- * @deprecated Use import from @uxf/core-react instead.
10
- */
11
- function useClickableProps({ ["aria-busy"]: ariaBusy, ["aria-disabled"]: ariaDisabled, analyticsCallback, className, disabled, loading, onClick, onKeyDown, onKeyUp, role, tabIndex, type, ...restProps }) {
12
- const isBusy = loading ? loading : Boolean(ariaBusy);
13
- const isDisabled = disabled ? disabled : Boolean(ariaDisabled);
14
- const isBusyOrDisabled = isBusy || isDisabled;
15
- const submit = type === "submit";
16
- const isButton = submit || (0, is_not_nil_1.isNotNil)(onClick);
17
- const _className = [isBusy && classes_1.CLASSES.IS_LOADING, isDisabled && classes_1.CLASSES.IS_DISABLED, className];
18
- const simulatedButton = (0, _useSimulatedButton_1._useSimulatedButton)({
19
- analyticsCallback,
20
- isClickable: !isBusyOrDisabled || isButton,
21
- isHyperlink: false,
22
- onClick,
23
- onKeyDown,
24
- onKeyUp,
25
- submit,
26
- });
27
- if (isButton) {
28
- return {
29
- "aria-busy": isBusy,
30
- "aria-disabled": isDisabled,
31
- className: (0, cx_1.cx)(classes_1.CLASSES.IS_HOVERABLE, ..._className),
32
- onClick: simulatedButton.onClick,
33
- onKeyDown: simulatedButton.onKeyDown,
34
- onKeyUp: simulatedButton.onKeyUp,
35
- role: role || "button",
36
- tabIndex: isBusyOrDisabled ? -1 : (tabIndex !== null && tabIndex !== void 0 ? tabIndex : 0),
37
- ...restProps,
38
- };
39
- }
40
- return {
41
- className: (0, cx_1.cx)(..._className),
42
- role,
43
- tabIndex,
44
- ...restProps,
45
- };
46
- }
@@ -1,4 +0,0 @@
1
- /**
2
- * @deprecated Use import from @uxf/core-react instead.
3
- */
4
- export declare function useFocusReturn(opened: boolean, transitionDuration?: number, shouldReturnFocus?: boolean): () => void;
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useFocusReturn = useFocusReturn;
4
- const react_1 = require("react");
5
- const useOnUpdate_1 = require("./useOnUpdate");
6
- /**
7
- * @deprecated Use import from @uxf/core-react instead.
8
- */
9
- function useFocusReturn(opened, transitionDuration = 0, shouldReturnFocus = true) {
10
- const lastActiveElement = (0, react_1.useRef)();
11
- const returnFocus = () => {
12
- const node = lastActiveElement.current;
13
- if (node && "focus" in node && typeof node.focus === "function") {
14
- node.focus();
15
- }
16
- };
17
- (0, useOnUpdate_1.useOnUpdate)(() => {
18
- let timeout = -1;
19
- const clearFocusTimeout = (e) => {
20
- if (e.key === "Tab") {
21
- clearTimeout(timeout);
22
- }
23
- };
24
- document.addEventListener("keydown", clearFocusTimeout);
25
- if (opened) {
26
- lastActiveElement.current = document.activeElement;
27
- }
28
- else if (shouldReturnFocus) {
29
- timeout = window.setTimeout(returnFocus, transitionDuration + 10);
30
- }
31
- return () => {
32
- clearTimeout(timeout);
33
- document.removeEventListener("keydown", clearFocusTimeout);
34
- };
35
- }, [opened, shouldReturnFocus, transitionDuration]);
36
- return returnFocus;
37
- }
@@ -1,5 +0,0 @@
1
- import { RefCallback } from "react";
2
- /**
3
- * @deprecated Use import from @uxf/core-react instead.
4
- */
5
- export declare function useFocusTrap<T extends HTMLElement>(active?: boolean): RefCallback<T>;
@@ -1,148 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useFocusTrap = useFocusTrap;
4
- const react_1 = require("react");
5
- const useOnUnmount_1 = require("./useOnUnmount");
6
- const TABBABLE_NODES = /input|select|textarea|button|object/;
7
- const FOCUS_SELECTOR = "a, input, select, textarea, button, object, [tabindex]";
8
- function hidden(element) {
9
- return element.style.display === "none";
10
- }
11
- function visible(element) {
12
- let parentElement = element;
13
- while (parentElement) {
14
- if (parentElement === document.body) {
15
- break;
16
- }
17
- if (hidden(parentElement)) {
18
- return false;
19
- }
20
- parentElement = parentElement.parentElement;
21
- }
22
- return true;
23
- }
24
- function getElementTabIndex(element) {
25
- const tabIndex = element.getAttribute("tabindex");
26
- if (tabIndex === null) {
27
- return NaN;
28
- }
29
- return parseInt(tabIndex, 10);
30
- }
31
- function focusable(element) {
32
- const nodeName = element.nodeName.toLowerCase();
33
- const isTabIndexNotNaN = !Number.isNaN(getElementTabIndex(element));
34
- const res = (TABBABLE_NODES.test(nodeName) && !element.disabled) ||
35
- (element instanceof HTMLAnchorElement ? Boolean(element.href) || isTabIndexNotNaN : isTabIndexNotNaN);
36
- return res && visible(element);
37
- }
38
- function tabbable(element) {
39
- const tabIndex = getElementTabIndex(element);
40
- const isTabIndexNaN = Number.isNaN(tabIndex);
41
- return (isTabIndexNaN || tabIndex >= 0) && focusable(element);
42
- }
43
- function findTabbableDescendants(element) {
44
- return Array.from(element.querySelectorAll(FOCUS_SELECTOR)).filter(tabbable);
45
- }
46
- function scopeTab(node, event) {
47
- const _tabbable = findTabbableDescendants(node);
48
- if (!_tabbable.length) {
49
- event.preventDefault();
50
- return;
51
- }
52
- const finalTabbable = _tabbable[event.shiftKey ? 0 : _tabbable.length - 1];
53
- const leavingFinalTabbable = finalTabbable === document.activeElement || node === document.activeElement;
54
- if (!leavingFinalTabbable) {
55
- return;
56
- }
57
- event.preventDefault();
58
- const target = _tabbable[event.shiftKey ? _tabbable.length - 1 : 0];
59
- if (target) {
60
- target.focus();
61
- }
62
- }
63
- function createAriaHider(containerNode, selector = "body > :not(script)") {
64
- const rootNodes = Array.from(document.querySelectorAll(selector)).map((node) => {
65
- if (node.contains(containerNode)) {
66
- return;
67
- }
68
- const ariaHidden = node.getAttribute("aria-hidden");
69
- if (ariaHidden === null || ariaHidden === "false") {
70
- node.setAttribute("aria-hidden", "true");
71
- }
72
- return { node, ariaHidden };
73
- });
74
- return () => {
75
- rootNodes.forEach((item) => {
76
- if (!item) {
77
- return;
78
- }
79
- if (item.ariaHidden === null) {
80
- item.node.removeAttribute("aria-hidden");
81
- }
82
- else {
83
- item.node.setAttribute("aria-hidden", item.ariaHidden);
84
- }
85
- });
86
- };
87
- }
88
- /**
89
- * @deprecated Use import from @uxf/core-react instead.
90
- */
91
- function useFocusTrap(active = true) {
92
- const ref = (0, react_1.useRef)();
93
- const restoreAria = (0, react_1.useRef)();
94
- const timer = (0, react_1.useRef)();
95
- const setRef = (0, react_1.useCallback)((node) => {
96
- if (!active) {
97
- ref.current = null;
98
- return;
99
- }
100
- if (restoreAria.current) {
101
- restoreAria.current();
102
- }
103
- if (node) {
104
- const processNode = (_node) => {
105
- restoreAria.current = createAriaHider(_node);
106
- let focusElement = node.querySelector("[data-autofocus]");
107
- if (!focusElement) {
108
- const children = Array.from(node.querySelectorAll(FOCUS_SELECTOR));
109
- focusElement = children.find(tabbable) || children.find(focusable) || null;
110
- if (!focusElement && focusable(node)) {
111
- focusElement = node;
112
- }
113
- }
114
- if (focusElement) {
115
- focusElement.focus();
116
- }
117
- };
118
- // Delay processing the HTML node by a frame. This ensures focus is assigned correctly.
119
- timer.current = window.setTimeout(() => {
120
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
121
- if (node.ownerDocument) {
122
- processNode(node);
123
- }
124
- });
125
- ref.current = node;
126
- }
127
- else {
128
- ref.current = null;
129
- }
130
- }, [active]);
131
- (0, react_1.useEffect)(() => {
132
- if (!active) {
133
- return;
134
- }
135
- const handler = (e) => {
136
- const node = ref.current;
137
- if (e.key === "Tab" && node) {
138
- scopeTab(node, e);
139
- }
140
- };
141
- document.addEventListener("keydown", handler);
142
- return () => {
143
- document.removeEventListener("keydown", handler);
144
- };
145
- }, [active]);
146
- (0, useOnUnmount_1.useOnUnmount)(() => clearTimeout(timer.current));
147
- return setRef;
148
- }