@uxf/core-react 11.36.0 → 11.42.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.
package/README.md CHANGED
@@ -1,7 +1,10 @@
1
1
  # UXF Core-React
2
2
 
3
3
  ## Hooks
4
+ ---
5
+ ### useBodyScrollLock
4
6
 
7
+ Lock scrolling on body element. Useful for modals, popovers, etc.
5
8
  ```tsx
6
9
  import { useBodyScrollLock } from "@uxf/core-react/hooks/use-body-scroll-lock";
7
10
  import { useState } from "react";
@@ -19,17 +22,25 @@ useBodyScrollLock<HTMLDivElement>(innerRef, isOpen, {
19
22
 
20
23
  <div ref={innerRef}>Element which activates scroll lock on its parent elements.</div>
21
24
  ```
25
+ ---
26
+ ### isMounted
27
+ Check if component is mounted.
22
28
  ```tsx
23
29
  import { useIsMounted } from "@uxf/core-react/hooks/use-is-mounted";
24
30
 
25
31
  const isMounted = useIsMounted();
26
32
  ```
33
+ ---
34
+ ### useIsomorphicLayoutEffect
35
+ Returns `useEffect` on client and `useLayoutEffect` on server.
27
36
  ```tsx
28
37
  import { useIsomorphicLayoutEffect } from "@uxf/core-react/hooks/use-isomorphic-layout-effect";
29
38
 
30
39
  useIsomorphicLayoutEffect(() => {/* code */}, [/* deps */]);
31
40
  ```
32
-
41
+ ---
42
+ ### useKey
43
+ Trigger callback on given key.
33
44
  ```tsx
34
45
  import { useKey } from "@uxf/core-react/hooks/use-key";
35
46
  import { useRef } from "react";
@@ -45,6 +56,9 @@ useKey<HTMLDivElement>("Enter", () => console.log("callback"), {
45
56
 
46
57
  <div ref={targetRef} tabIndex={0}>Element with callback triggerable by enter key.</div>
47
58
  ```
59
+ ---
60
+ ### useMinWindowWidth
61
+ Returns boolean if window width is equal or greater than given value.
48
62
  ```tsx
49
63
  import { useMinWindowWidth } from "@uxf/core-react/hooks/use-min-window-width";
50
64
 
@@ -54,18 +68,25 @@ const isDesktopWithDebounce = useMinWindowWidth(1200, 200); // will be updated e
54
68
  const example = isDesktop ? "desktop" : "tablet";
55
69
  const debouncedExample = isDesktopWithDebounce ? "debouncedDesktop" : "debouncedTablet";
56
70
  ```
57
-
71
+ ---
72
+ ### usePagination
73
+ Returns array of pagination items.
58
74
  ```ts
59
75
  import { usePagination } from "@uxf/core-react/hooks/use-pagination";
60
76
 
61
77
  const paginationItems = usePagination({ page: 1, count: 10 })
62
78
  ```
63
-
79
+ ---
80
+ ### useRafState
81
+ Updates state only in the callback of `requestAnimationFrame`.
64
82
  ```tsx
65
83
  import { useRafState } from "@uxf/core-react/hooks/use-raf-state";
66
84
 
67
85
  const [state, setState] = useRafState<boolean>(false);
68
86
  ```
87
+ ---
88
+ ### useOnMount
89
+ Calls the callback on component mount.
69
90
  ```tsx
70
91
  import { useOnUnmount } from "@uxf/core-react/hooks/use-on-unmount";
71
92
 
@@ -73,11 +94,17 @@ const exampleCallback = () => {};
73
94
 
74
95
  useOnUnmount(exampleCallback());
75
96
  ```
97
+ ---
98
+ ### useOnUpdate
99
+ Calls the callback only on component update, except initial mount.
76
100
  ```tsx
77
101
  import { useOnUpdate } from "@uxf/core-react/hooks/use-on-update";
78
102
 
79
103
  useOnUpdate(() => {/* code */}, [/* deps */]);
80
104
  ```
105
+ ---
106
+ ### useWindowScroll
107
+ Returns x and y scroll coordinates of window on scroll.
81
108
  ```tsx
82
109
  import { useWindowScroll } from "@uxf/core-react/hooks/use-window-scroll";
83
110
 
@@ -85,6 +112,9 @@ const windowScroll = useWindowScroll();
85
112
 
86
113
  const example = windowScroll && windowScroll.y > 100 ? "scroled" : "on top";
87
114
  ```
115
+ ---
116
+ ### useWindowSize
117
+ Returns window width and height.
88
118
  ```tsx
89
119
  import { useWindowSize } from "@uxf/core-react/hooks/use-window-size";
90
120
 
@@ -92,6 +122,9 @@ const windowSize = useWindowSize();
92
122
 
93
123
  const example = windowSize && windowSize.width > 1200 ? "desktop" : "tablet";
94
124
  ```
125
+ ---
126
+ ### useFocusTrap
127
+ Locks focus inside given element.
95
128
  ```tsx
96
129
  import { useFocusTrap } from "@uxf/core-react/hooks/use-focus-trap";
97
130
  import { useState } from "react";
@@ -102,6 +135,9 @@ const focusTrapRef = useFocusTrap(active);
102
135
 
103
136
  <div ref={focusTrapRef}>Element which trap focus inside if `active` is truthy.</div>
104
137
  ```
138
+ ---
139
+ ### useFocusReturn
140
+ Returns focus to last active element.
105
141
  ```tsx
106
142
  import { useFocusReturn } from "@uxf/core-react/hooks/use-focus-return";
107
143
  import { useState } from "react";
@@ -111,6 +147,9 @@ const [active, setActive] = useState<boolean>();
111
147
  // Returns focus to last active element, e.g. in Modal or Popover
112
148
  useFocusReturn(active);
113
149
  ```
150
+ ---
151
+ ### useAnchorProps
152
+ Returns props for anchor element.
114
153
  ```tsx
115
154
  import { useAnchorProps } from "@uxf/core-react/hooks/use-anchor-props";
116
155
  import { AnchorHTMLAttributes } from "react";
@@ -144,6 +183,9 @@ const anchorProps = useAnchorProps<Props>({
144
183
  <a {...anchorProps}>Click me</a>
145
184
 
146
185
  ```
186
+ ---
187
+ ### useButtonProps
188
+ Returns props for button element.
147
189
  ```tsx
148
190
  import { useButtonProps } from "@uxf/core-react/hooks/use-button-props";
149
191
  import { ButtonHTMLAttributes } from "react";
@@ -175,6 +217,9 @@ const buttonProps = useButtonProps<Props>({
175
217
 
176
218
  <button {...buttonProps}>Click me</button>
177
219
  ```
220
+ ---
221
+ ### useClickableProps
222
+ Returns props for clickable element.
178
223
  ```tsx
179
224
  import { useClickableProps } from "@uxf/core-react/hooks/use-clickable-props";
180
225
  import { HTMLAttributes } from "react";
@@ -206,6 +251,9 @@ const buttonProps = useClickableProps<Props>({
206
251
 
207
252
  <button {...buttonProps}>Click me</button>
208
253
  ```
254
+ ---
255
+ ### useMouseDragToScroll
256
+ Allow to scroll element by dragging mouse.
209
257
  ```tsx
210
258
  import { useMouseDragToScroll } from "@uxf/core-react/hooks/use-mouse-drag-to-scroll";
211
259
 
@@ -215,6 +263,9 @@ const style = useMouseDragToScroll(scrollRef);
215
263
 
216
264
  <div style={style}>Drag to scroll</div>
217
265
  ```
266
+ ---
267
+ ### useInputFocus
268
+ Manage focus states of input element.
218
269
  ```tsx
219
270
  import { useInputFocus } from "@uxf/core-react/hooks/use-input-focus";
220
271
 
@@ -227,6 +278,9 @@ const input = useInputFocus(focusRef, onBlur, onFocus);
227
278
  <button onClick={input.focus}>Focus input</button>
228
279
  <input onBlur={input.onBlur} onFocus={input.onFocus} ref={focusRef} />
229
280
  ```
281
+ ---
282
+ ### useLatest
283
+ Allways returns latest value of given variable.
230
284
  ```tsx
231
285
  import { useLatest } from "@uxf/core-react/hooks/use-latest";
232
286
 
@@ -236,6 +290,9 @@ useEffect(() => {
236
290
  latestState.current(); // use newest state of 'someUnstableWhatever' without affecting this effetct update
237
291
  }, [latestState])
238
292
  ```
293
+ ---
294
+ ### usePrevious
295
+ Returns previous value of given variable.
239
296
  ```tsx
240
297
  import { usePrevious } from "@uxf/core-react/hooks/use-previous";
241
298
 
@@ -245,6 +302,9 @@ useEffect(() => {
245
302
  previousState.current(); // use state of 'someUnstableWhatever' from previous render without affecting this effetct update
246
303
  }, [previousState])
247
304
  ```
305
+ ---
306
+ ### useToggle
307
+ Returns boolean state and methods to toggle it.
248
308
  ```tsx
249
309
  import { useToggle } from "@uxf/core-react/hooks/use-toggle";
250
310
 
@@ -252,7 +312,9 @@ const [isVisible, toggleIsVisible, setVisible, setInvisible] = useToggle(false);
252
312
 
253
313
  <button onClick={toggleIsVisible}>Toggle visibility</button>
254
314
  ```
255
-
315
+ ---
316
+ ### useIncrement
317
+ Returns number state and methods to increment, decrement and reset.
256
318
  ```tsx
257
319
  import { useIncrement } from "@uxf/core-react/hooks/use-increment";
258
320
 
@@ -260,3 +322,11 @@ const [count, increment, decrement, reset] = useIncrement(5, 1);
260
322
 
261
323
  <button onClick={increment}>Toggle visibility</button>
262
324
  ```
325
+ ---
326
+ ### useDebounce
327
+ Returns the latest value after given delay.
328
+ ```tsx
329
+ import { useDebounce } from "@uxf/core-react/hooks/use-debounce";
330
+
331
+ const debouncedValue = useDebounce<string>("some value", 300);
332
+ ```
@@ -0,0 +1 @@
1
+ export declare function useDebounce<T>(value: T, delay?: number): T;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useDebounce = useDebounce;
4
+ const react_1 = require("react");
5
+ const use_on_update_1 = require("./use-on-update");
6
+ function useDebounce(value, delay) {
7
+ const [debouncedValue, setDebouncedValue] = (0, react_1.useState)(value);
8
+ (0, use_on_update_1.useOnUpdate)(() => {
9
+ const timer = setTimeout(() => setDebouncedValue(value), delay !== null && delay !== void 0 ? delay : 500);
10
+ return () => {
11
+ clearTimeout(timer);
12
+ };
13
+ }, [value, delay]);
14
+ return debouncedValue;
15
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/core-react",
3
- "version": "11.36.0",
3
+ "version": "11.42.0",
4
4
  "description": "UXF Core",
5
5
  "author": "UX Fans s.r.o",
6
6
  "license": "MIT",
@@ -12,7 +12,7 @@
12
12
  "typecheck": "tsc --noEmit --skipLibCheck"
13
13
  },
14
14
  "dependencies": {
15
- "@uxf/core": "11.35.0"
15
+ "@uxf/core": "11.42.0"
16
16
  },
17
17
  "peerDependencies": {
18
18
  "react": ">=18.2.0"