@uxf/core-react 11.71.0 → 11.74.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.
Files changed (84) hide show
  1. package/README.md +70 -0
  2. package/package.json +2 -2
  3. package/clickable/_use-simulated-button.d.ts +0 -17
  4. package/clickable/_use-simulated-button.js +0 -61
  5. package/clickable/add-busy-and-disabled-classnames.d.ts +0 -9
  6. package/clickable/add-busy-and-disabled-classnames.js +0 -17
  7. package/clickable/types.d.ts +0 -3
  8. package/clickable/types.js +0 -2
  9. package/clickable/use-anchor-props.d.ts +0 -9
  10. package/clickable/use-anchor-props.js +0 -67
  11. package/clickable/use-button-props.d.ts +0 -7
  12. package/clickable/use-button-props.js +0 -60
  13. package/clickable/use-clickable-props.d.ts +0 -9
  14. package/clickable/use-clickable-props.js +0 -45
  15. package/components/hide.d.ts +0 -7
  16. package/components/hide.js +0 -13
  17. package/components/show.d.ts +0 -7
  18. package/components/show.js +0 -13
  19. package/components/viewport-height-polyfill.d.ts +0 -2
  20. package/components/viewport-height-polyfill.js +0 -49
  21. package/hooks/use-body-scroll-lock.d.ts +0 -6
  22. package/hooks/use-body-scroll-lock.js +0 -34
  23. package/hooks/use-debounce.d.ts +0 -1
  24. package/hooks/use-debounce.js +0 -15
  25. package/hooks/use-focus-return.d.ts +0 -1
  26. package/hooks/use-focus-return.js +0 -34
  27. package/hooks/use-focus-trap.d.ts +0 -2
  28. package/hooks/use-focus-trap.js +0 -145
  29. package/hooks/use-increment.d.ts +0 -2
  30. package/hooks/use-increment.js +0 -11
  31. package/hooks/use-increment.test.d.ts +0 -1
  32. package/hooks/use-increment.test.js +0 -61
  33. package/hooks/use-input-focus.d.ts +0 -7
  34. package/hooks/use-input-focus.js +0 -26
  35. package/hooks/use-is-mounted.d.ts +0 -1
  36. package/hooks/use-is-mounted.js +0 -9
  37. package/hooks/use-isomorphic-layout-effect.d.ts +0 -2
  38. package/hooks/use-isomorphic-layout-effect.js +0 -6
  39. package/hooks/use-key.d.ts +0 -10
  40. package/hooks/use-key.js +0 -27
  41. package/hooks/use-latest.d.ts +0 -1
  42. package/hooks/use-latest.js +0 -9
  43. package/hooks/use-media-query.d.ts +0 -1
  44. package/hooks/use-media-query.js +0 -18
  45. package/hooks/use-min-window-width.d.ts +0 -1
  46. package/hooks/use-min-window-width.js +0 -28
  47. package/hooks/use-mouse-drag-to-scroll.d.ts +0 -2
  48. package/hooks/use-mouse-drag-to-scroll.js +0 -38
  49. package/hooks/use-on-mount.d.ts +0 -2
  50. package/hooks/use-on-mount.js +0 -9
  51. package/hooks/use-on-unmount.d.ts +0 -2
  52. package/hooks/use-on-unmount.js +0 -14
  53. package/hooks/use-on-update.d.ts +0 -2
  54. package/hooks/use-on-update.js +0 -14
  55. package/hooks/use-pagination.d.ts +0 -2
  56. package/hooks/use-pagination.js +0 -20
  57. package/hooks/use-pagination.test.d.ts +0 -1
  58. package/hooks/use-pagination.test.js +0 -58
  59. package/hooks/use-previous.d.ts +0 -1
  60. package/hooks/use-previous.js +0 -11
  61. package/hooks/use-raf-state.d.ts +0 -2
  62. package/hooks/use-raf-state.js +0 -17
  63. package/hooks/use-toggle.d.ts +0 -2
  64. package/hooks/use-toggle.js +0 -11
  65. package/hooks/use-toggle.test.d.ts +0 -1
  66. package/hooks/use-toggle.test.js +0 -46
  67. package/hooks/use-window-scroll.d.ts +0 -4
  68. package/hooks/use-window-scroll.js +0 -21
  69. package/hooks/use-window-scroll.test.d.ts +0 -1
  70. package/hooks/use-window-scroll.test.js +0 -47
  71. package/hooks/use-window-size.d.ts +0 -4
  72. package/hooks/use-window-size.js +0 -18
  73. package/hooks/use-window-size.test.d.ts +0 -1
  74. package/hooks/use-window-size.test.js +0 -36
  75. package/string/nl2br.d.ts +0 -2
  76. package/string/nl2br.js +0 -37
  77. package/swipeable/types.d.ts +0 -152
  78. package/swipeable/types.js +0 -7
  79. package/swipeable/use-swipeable.d.ts +0 -3
  80. package/swipeable/use-swipeable.js +0 -314
  81. package/utils/compose-refs.d.ts +0 -2
  82. package/utils/compose-refs.js +0 -15
  83. package/utils/compose-refs.test.d.ts +0 -1
  84. package/utils/compose-refs.test.js +0 -41
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const react_1 = require("@testing-library/react");
4
- const use_toggle_1 = require("./use-toggle");
5
- describe("useToggle Hook", () => {
6
- it("should initialize with the default value", () => {
7
- const { result } = (0, react_1.renderHook)(() => (0, use_toggle_1.useToggle)(false));
8
- const [isOn] = result.current;
9
- expect(isOn).toBe(false);
10
- });
11
- it("should toggle the value when toggleHandler is called", () => {
12
- const { result } = (0, react_1.renderHook)(() => (0, use_toggle_1.useToggle)(false));
13
- const [isOn, toggleHandler] = result.current;
14
- expect(isOn).toBe(false);
15
- (0, react_1.act)(() => {
16
- toggleHandler();
17
- });
18
- const [isOnNew] = result.current;
19
- expect(isOnNew).toBe(true);
20
- (0, react_1.act)(() => {
21
- toggleHandler();
22
- });
23
- const [isOnFinal] = result.current;
24
- expect(isOnFinal).toBe(false);
25
- });
26
- it("should set the value to true when setTrueHandler is called", () => {
27
- const { result } = (0, react_1.renderHook)(() => (0, use_toggle_1.useToggle)(false));
28
- const [isOn, , setTrueHandler] = result.current;
29
- expect(isOn).toBe(false);
30
- (0, react_1.act)(() => {
31
- setTrueHandler();
32
- });
33
- const [isOnNew] = result.current;
34
- expect(isOnNew).toBe(true);
35
- });
36
- it("should set the value to false when setFalseHandler is called", () => {
37
- const { result } = (0, react_1.renderHook)(() => (0, use_toggle_1.useToggle)(true));
38
- const [isOn, , , setFalseHandler] = result.current;
39
- expect(isOn).toBe(true);
40
- (0, react_1.act)(() => {
41
- setFalseHandler();
42
- });
43
- const [isOnNew] = result.current;
44
- expect(isOnNew).toBe(false);
45
- });
46
- });
@@ -1,4 +0,0 @@
1
- export declare function useWindowScroll(): {
2
- x: number;
3
- y: number;
4
- } | undefined;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useWindowScroll = useWindowScroll;
4
- const react_1 = require("react");
5
- const use_raf_state_1 = require("./use-raf-state");
6
- function useWindowScroll() {
7
- const [state, setState] = (0, use_raf_state_1.useRafState)();
8
- (0, react_1.useEffect)(() => {
9
- const handler = () => setState({
10
- x: window.scrollX,
11
- y: window.scrollY,
12
- });
13
- handler();
14
- window.addEventListener("scroll", handler, {
15
- capture: false,
16
- passive: true,
17
- });
18
- return () => window.removeEventListener("scroll", handler);
19
- }, [setState]);
20
- return state;
21
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,47 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const react_1 = require("@testing-library/react");
4
- const use_window_scroll_1 = require("./use-window-scroll");
5
- beforeAll(() => {
6
- window.scrollX = 0;
7
- window.scrollY = 0;
8
- window.addEventListener = jest.fn((event, callback) => {
9
- if (event === "scroll") {
10
- window.scrollHandler = callback;
11
- }
12
- });
13
- window.removeEventListener = jest.fn();
14
- });
15
- jest.mock("./use-raf-state", () => ({
16
- useRafState: jest.fn().mockImplementation(() => {
17
- const state = { x: window.scrollX, y: window.scrollY };
18
- const setState = jest.fn((newState) => {
19
- state.x = newState.x;
20
- state.y = newState.y;
21
- });
22
- return [state, setState];
23
- }),
24
- }));
25
- afterAll(() => {
26
- jest.clearAllMocks();
27
- });
28
- describe("useWindowScroll", () => {
29
- it("should return the initial scroll position", () => {
30
- const { result } = (0, react_1.renderHook)(() => (0, use_window_scroll_1.useWindowScroll)());
31
- expect(result.current).toEqual({ x: 0, y: 0 });
32
- });
33
- it("should update scroll position on window scroll", () => {
34
- const { result } = (0, react_1.renderHook)(() => (0, use_window_scroll_1.useWindowScroll)());
35
- (0, react_1.act)(() => {
36
- window.scrollX = 100;
37
- window.scrollY = 200;
38
- window.scrollHandler();
39
- });
40
- expect(result.current).toEqual({ x: 100, y: 200 });
41
- });
42
- it("should clean up the event listener on unmount", () => {
43
- const { unmount } = (0, react_1.renderHook)(() => (0, use_window_scroll_1.useWindowScroll)());
44
- unmount();
45
- expect(window.removeEventListener).toHaveBeenCalledWith("scroll", expect.any(Function));
46
- });
47
- });
@@ -1,4 +0,0 @@
1
- export declare function useWindowSize(): {
2
- width: number;
3
- height: number;
4
- } | undefined;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useWindowSize = useWindowSize;
4
- const react_1 = require("react");
5
- const use_raf_state_1 = require("./use-raf-state");
6
- function useWindowSize() {
7
- const [state, setState] = (0, use_raf_state_1.useRafState)();
8
- (0, react_1.useEffect)(() => {
9
- const handler = () => setState({
10
- width: window.innerWidth,
11
- height: window.innerHeight,
12
- });
13
- handler();
14
- window.addEventListener("resize", handler);
15
- return () => window.removeEventListener("resize", handler);
16
- }, [setState]);
17
- return state;
18
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const react_1 = require("@testing-library/react");
4
- const use_window_size_1 = require("./use-window-size");
5
- beforeAll(() => {
6
- window.innerWidth = 1024;
7
- window.innerHeight = 768;
8
- window.resizeHandler = null;
9
- window.addEventListener = jest.fn((event, callback) => {
10
- if (event === "resize") {
11
- window.resizeHandler = callback;
12
- }
13
- });
14
- window.removeEventListener = jest.fn();
15
- });
16
- jest.mock("./use-raf-state", () => ({
17
- useRafState: jest.fn().mockImplementation(() => {
18
- const state = { width: window.innerWidth, height: window.innerHeight };
19
- const setState = jest.fn();
20
- return [state, setState];
21
- }),
22
- }));
23
- afterAll(() => {
24
- jest.clearAllMocks();
25
- });
26
- describe("useWindowSize", () => {
27
- it("should return the initial window size", () => {
28
- const { result } = (0, react_1.renderHook)(() => (0, use_window_size_1.useWindowSize)());
29
- expect(result.current).toEqual({ width: 1024, height: 768 });
30
- });
31
- it("should clean up the event listener on unmount", () => {
32
- const { unmount } = (0, react_1.renderHook)(() => (0, use_window_size_1.useWindowSize)());
33
- unmount();
34
- expect(window.removeEventListener).toHaveBeenCalledWith("resize", expect.any(Function));
35
- });
36
- });
package/string/nl2br.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import React from "react";
2
- export declare function nl2br(str: string): (string | React.JSX.Element)[];
package/string/nl2br.js DELETED
@@ -1,37 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.nl2br = nl2br;
27
- const react_1 = __importStar(require("react"));
28
- function nl2br(str) {
29
- return str.split("\n").map(function (item, i) {
30
- if (i === 0) {
31
- return item;
32
- }
33
- return (react_1.default.createElement(react_1.Fragment, { key: i },
34
- react_1.default.createElement("br", null),
35
- item));
36
- });
37
- }
@@ -1,152 +0,0 @@
1
- import { MouseEvent as ReactMouseEvent } from "react";
2
- export declare const LEFT = "Left";
3
- export declare const RIGHT = "Right";
4
- export declare const UP = "Up";
5
- export declare const DOWN = "Down";
6
- export type HandledEvents = ReactMouseEvent | TouchEvent | MouseEvent;
7
- export type Vector2 = [number, number];
8
- export type SwipeDirections = typeof LEFT | typeof RIGHT | typeof UP | typeof DOWN;
9
- export interface SwipeEventData {
10
- /**
11
- * Absolute displacement of swipe in x. Math.abs(deltaX);
12
- */
13
- absX: number;
14
- /**
15
- * Absolute displacement of swipe in y. Math.abs(deltaY);
16
- */
17
- absY: number;
18
- /**
19
- * Displacement of swipe in x. (current.x - initial.x)
20
- */
21
- deltaX: number;
22
- /**
23
- * Displacement of swipe in y. (current.y - initial.y)
24
- */
25
- deltaY: number;
26
- /**
27
- * Direction of swipe - Left | Right | Up | Down
28
- */
29
- dir: SwipeDirections;
30
- /**
31
- * Source event.
32
- */
33
- event: HandledEvents;
34
- /**
35
- * True for the first event of a tracked swipe.
36
- */
37
- first: boolean;
38
- /**
39
- * Location where swipe started - [x, y].
40
- */
41
- initial: Vector2;
42
- /**
43
- * "Absolute velocity" (speed) - √(absX^2 + absY^2) / time
44
- */
45
- velocity: number;
46
- /**
47
- * Velocity per axis - [ deltaX/time, deltaY/time ]
48
- */
49
- vxvy: Vector2;
50
- }
51
- export type SwipeCallback = (eventData: SwipeEventData) => void;
52
- export type TapCallback = ({ event }: {
53
- event: HandledEvents;
54
- }) => void;
55
- export type SwipeableDirectionCallbacks = {
56
- /**
57
- * Called after a DOWN swipe
58
- */
59
- onSwipedDown: SwipeCallback;
60
- /**
61
- * Called after a LEFT swipe
62
- */
63
- onSwipedLeft: SwipeCallback;
64
- /**
65
- * Called after a RIGHT swipe
66
- */
67
- onSwipedRight: SwipeCallback;
68
- /**
69
- * Called after a UP swipe
70
- */
71
- onSwipedUp: SwipeCallback;
72
- };
73
- export type SwipeableCallbacks = SwipeableDirectionCallbacks & {
74
- /**
75
- * Called at start of a tracked swipe.
76
- */
77
- onSwipeStart: SwipeCallback;
78
- /**
79
- * Called after any swipe.
80
- */
81
- onSwiped: SwipeCallback;
82
- /**
83
- * Called for each move event during a tracked swipe.
84
- */
85
- onSwiping: SwipeCallback;
86
- /**
87
- * Called after a tap. A touch under the min distance, `delta`.
88
- */
89
- onTap: TapCallback;
90
- /**
91
- * Called for `touchstart` and `mousedown`.
92
- */
93
- onTouchStartOrOnMouseDown: TapCallback;
94
- /**
95
- * Called for `touchend` and `mouseup`.
96
- */
97
- onTouchEndOrOnMouseUp: TapCallback;
98
- };
99
- export type ConfigurationOptionDelta = number | {
100
- [key in Lowercase<SwipeDirections>]?: number;
101
- };
102
- export interface ConfigurationOptions {
103
- /**
104
- * Min distance(px) before a swipe starts. **Default**: `10`
105
- */
106
- delta: ConfigurationOptionDelta;
107
- /**
108
- * Prevents scroll during swipe in most cases. **Default**: `false`
109
- */
110
- preventScrollOnSwipe: boolean;
111
- /**
112
- * Set a rotation angle. **Default**: `0`
113
- */
114
- rotationAngle: number;
115
- /**
116
- * Track mouse input. **Default**: `false`
117
- */
118
- trackMouse: boolean;
119
- /**
120
- * Track touch input. **Default**: `true`
121
- */
122
- trackTouch: boolean;
123
- /**
124
- * Allowable duration of a swipe (ms). **Default**: `Infinity`
125
- */
126
- swipeDuration: number;
127
- /**
128
- * Options for touch event listeners
129
- */
130
- touchEventOptions: {
131
- passive: boolean;
132
- };
133
- }
134
- export type SwipeableProps = Partial<SwipeableCallbacks & ConfigurationOptions>;
135
- export type SwipeablePropsWithDefaultOptions = Partial<SwipeableCallbacks> & ConfigurationOptions;
136
- export interface SwipeableHandlers {
137
- ref(element: HTMLElement | null): void;
138
- onMouseDown?(event: React.MouseEvent): void;
139
- }
140
- export type SwipeableState = {
141
- cleanUpTouch?: () => void;
142
- el?: HTMLElement;
143
- eventData?: SwipeEventData;
144
- first: boolean;
145
- initial: Vector2;
146
- start: number;
147
- swiping: boolean;
148
- xy: Vector2;
149
- };
150
- export type StateSetter = (state: SwipeableState, props: SwipeablePropsWithDefaultOptions) => SwipeableState;
151
- export type Setter = (stateSetter: StateSetter) => void;
152
- export type AttachTouch = (el: HTMLElement, props: SwipeablePropsWithDefaultOptions) => () => void;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DOWN = exports.UP = exports.RIGHT = exports.LEFT = void 0;
4
- exports.LEFT = "Left";
5
- exports.RIGHT = "Right";
6
- exports.UP = "Up";
7
- exports.DOWN = "Down";
@@ -1,3 +0,0 @@
1
- import { DOWN, LEFT, RIGHT, SwipeableDirectionCallbacks, SwipeableHandlers, SwipeableProps, SwipeCallback, SwipeDirections, SwipeEventData, TapCallback, UP, Vector2 } from "./types";
2
- export { DOWN, LEFT, RIGHT, UP, type SwipeableDirectionCallbacks, type SwipeableHandlers, type SwipeableProps, type SwipeCallback, type SwipeDirections, type SwipeEventData, type TapCallback, type Vector2, };
3
- export declare function useSwipeable(options: SwipeableProps): SwipeableHandlers;