react-simplikit 0.0.49 → 0.0.50
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/dist/components/ImpressionArea/index.d.cts +1 -1
- package/dist/hooks/useCounter/index.cjs +12 -14
- package/dist/hooks/usePrevious/index.d.cts +3 -3
- package/dist/index.cjs +12 -14
- package/esm/components/ImpressionArea/index.d.ts +1 -1
- package/esm/hooks/useCounter/index.js +12 -14
- package/esm/hooks/usePrevious/index.d.ts +3 -3
- package/esm/index.js +12 -14
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ElementType, ReactNode, Ref } from 'react';
|
|
2
2
|
import { UseImpressionRefOptions } from '../../hooks/useImpressionRef/index.cjs';
|
|
3
3
|
|
|
4
|
-
type Element<T extends ElementType,
|
|
4
|
+
type Element<T extends ElementType, IntrinsicElementsOf = T extends keyof React.JSX.IntrinsicElements ? React.JSX.IntrinsicElements[T] : HTMLElement> = IntrinsicElementsOf extends React.ClassAttributes<infer E extends HTMLElement> ? E : HTMLElement;
|
|
5
5
|
type Props<Tag extends ElementType> = React.ComponentPropsWithoutRef<Tag> & UseImpressionRefOptions & {
|
|
6
6
|
as?: Tag;
|
|
7
7
|
children?: ReactNode;
|
|
@@ -27,27 +27,25 @@ module.exports = __toCommonJS(useCounter_exports);
|
|
|
27
27
|
|
|
28
28
|
// src/hooks/useCounter/useCounter.ts
|
|
29
29
|
var import_react = require("react");
|
|
30
|
+
var validateValue = (value, { min, max }) => {
|
|
31
|
+
if (min !== void 0 && value < min) {
|
|
32
|
+
return min;
|
|
33
|
+
}
|
|
34
|
+
if (max !== void 0 && value > max) {
|
|
35
|
+
return max;
|
|
36
|
+
}
|
|
37
|
+
return value;
|
|
38
|
+
};
|
|
30
39
|
function useCounter(initialValue = 0, { min, max, step = 1 } = {}) {
|
|
31
|
-
const
|
|
32
|
-
let validatedValue = value;
|
|
33
|
-
if (min !== void 0 && validatedValue < min) {
|
|
34
|
-
validatedValue = min;
|
|
35
|
-
}
|
|
36
|
-
if (max !== void 0 && validatedValue > max) {
|
|
37
|
-
validatedValue = max;
|
|
38
|
-
}
|
|
39
|
-
return validatedValue;
|
|
40
|
-
};
|
|
41
|
-
const [count, setCountState] = (0, import_react.useState)(() => validateValue(initialValue));
|
|
42
|
-
const validateValueMemoized = (0, import_react.useCallback)(validateValue, [min, max]);
|
|
40
|
+
const [count, setCountState] = (0, import_react.useState)(() => validateValue(initialValue, { min, max }));
|
|
43
41
|
const setCount = (0, import_react.useCallback)(
|
|
44
42
|
(value) => {
|
|
45
43
|
setCountState((prev) => {
|
|
46
44
|
const nextValue = typeof value === "function" ? value(prev) : value;
|
|
47
|
-
return
|
|
45
|
+
return validateValue(nextValue, { min, max });
|
|
48
46
|
});
|
|
49
47
|
},
|
|
50
|
-
[
|
|
48
|
+
[min, max]
|
|
51
49
|
);
|
|
52
50
|
const increment = (0, import_react.useCallback)(() => {
|
|
53
51
|
setCount((prev) => prev + step);
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @description
|
|
3
3
|
* `usePrevious` is a React hook that returns the previous value of the input state.
|
|
4
|
-
* It preserves the previous value unchanged when re-
|
|
4
|
+
* It preserves the previous value unchanged when re-renders occur without state changes.
|
|
5
5
|
* If the state is an object or requires custom change detection, a `compare` function can be provided.
|
|
6
6
|
* By default, state changes are detected using `prev === next`.
|
|
7
7
|
*
|
|
8
8
|
* @template T - The type of the state.
|
|
9
9
|
* @param {T} state - The state whose previous value is to be tracked.
|
|
10
|
-
* @param {(prev: T
|
|
10
|
+
* @param {(prev: T, next: T) => boolean} [compare] - An optional comparison function to determine if the state has changed.
|
|
11
11
|
*
|
|
12
|
-
* @returns {T
|
|
12
|
+
* @returns {T} The previous value of the state.
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* const [count, setCount] = useState(0);
|
package/dist/index.cjs
CHANGED
|
@@ -440,27 +440,25 @@ function isSetStateAction(next) {
|
|
|
440
440
|
|
|
441
441
|
// src/hooks/useCounter/useCounter.ts
|
|
442
442
|
var import_react14 = require("react");
|
|
443
|
+
var validateValue = (value, { min, max }) => {
|
|
444
|
+
if (min !== void 0 && value < min) {
|
|
445
|
+
return min;
|
|
446
|
+
}
|
|
447
|
+
if (max !== void 0 && value > max) {
|
|
448
|
+
return max;
|
|
449
|
+
}
|
|
450
|
+
return value;
|
|
451
|
+
};
|
|
443
452
|
function useCounter(initialValue = 0, { min, max, step = 1 } = {}) {
|
|
444
|
-
const
|
|
445
|
-
let validatedValue = value;
|
|
446
|
-
if (min !== void 0 && validatedValue < min) {
|
|
447
|
-
validatedValue = min;
|
|
448
|
-
}
|
|
449
|
-
if (max !== void 0 && validatedValue > max) {
|
|
450
|
-
validatedValue = max;
|
|
451
|
-
}
|
|
452
|
-
return validatedValue;
|
|
453
|
-
};
|
|
454
|
-
const [count, setCountState] = (0, import_react14.useState)(() => validateValue(initialValue));
|
|
455
|
-
const validateValueMemoized = (0, import_react14.useCallback)(validateValue, [min, max]);
|
|
453
|
+
const [count, setCountState] = (0, import_react14.useState)(() => validateValue(initialValue, { min, max }));
|
|
456
454
|
const setCount = (0, import_react14.useCallback)(
|
|
457
455
|
(value) => {
|
|
458
456
|
setCountState((prev) => {
|
|
459
457
|
const nextValue = typeof value === "function" ? value(prev) : value;
|
|
460
|
-
return
|
|
458
|
+
return validateValue(nextValue, { min, max });
|
|
461
459
|
});
|
|
462
460
|
},
|
|
463
|
-
[
|
|
461
|
+
[min, max]
|
|
464
462
|
);
|
|
465
463
|
const increment = (0, import_react14.useCallback)(() => {
|
|
466
464
|
setCount((prev) => prev + step);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ElementType, ReactNode, Ref } from 'react';
|
|
2
2
|
import { UseImpressionRefOptions } from '../../hooks/useImpressionRef/index.js';
|
|
3
3
|
|
|
4
|
-
type Element<T extends ElementType,
|
|
4
|
+
type Element<T extends ElementType, IntrinsicElementsOf = T extends keyof React.JSX.IntrinsicElements ? React.JSX.IntrinsicElements[T] : HTMLElement> = IntrinsicElementsOf extends React.ClassAttributes<infer E extends HTMLElement> ? E : HTMLElement;
|
|
5
5
|
type Props<Tag extends ElementType> = React.ComponentPropsWithoutRef<Tag> & UseImpressionRefOptions & {
|
|
6
6
|
as?: Tag;
|
|
7
7
|
children?: ReactNode;
|
|
@@ -2,27 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
// src/hooks/useCounter/useCounter.ts
|
|
4
4
|
import { useCallback, useState } from "react";
|
|
5
|
+
var validateValue = (value, { min, max }) => {
|
|
6
|
+
if (min !== void 0 && value < min) {
|
|
7
|
+
return min;
|
|
8
|
+
}
|
|
9
|
+
if (max !== void 0 && value > max) {
|
|
10
|
+
return max;
|
|
11
|
+
}
|
|
12
|
+
return value;
|
|
13
|
+
};
|
|
5
14
|
function useCounter(initialValue = 0, { min, max, step = 1 } = {}) {
|
|
6
|
-
const
|
|
7
|
-
let validatedValue = value;
|
|
8
|
-
if (min !== void 0 && validatedValue < min) {
|
|
9
|
-
validatedValue = min;
|
|
10
|
-
}
|
|
11
|
-
if (max !== void 0 && validatedValue > max) {
|
|
12
|
-
validatedValue = max;
|
|
13
|
-
}
|
|
14
|
-
return validatedValue;
|
|
15
|
-
};
|
|
16
|
-
const [count, setCountState] = useState(() => validateValue(initialValue));
|
|
17
|
-
const validateValueMemoized = useCallback(validateValue, [min, max]);
|
|
15
|
+
const [count, setCountState] = useState(() => validateValue(initialValue, { min, max }));
|
|
18
16
|
const setCount = useCallback(
|
|
19
17
|
(value) => {
|
|
20
18
|
setCountState((prev) => {
|
|
21
19
|
const nextValue = typeof value === "function" ? value(prev) : value;
|
|
22
|
-
return
|
|
20
|
+
return validateValue(nextValue, { min, max });
|
|
23
21
|
});
|
|
24
22
|
},
|
|
25
|
-
[
|
|
23
|
+
[min, max]
|
|
26
24
|
);
|
|
27
25
|
const increment = useCallback(() => {
|
|
28
26
|
setCount((prev) => prev + step);
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @description
|
|
3
3
|
* `usePrevious` is a React hook that returns the previous value of the input state.
|
|
4
|
-
* It preserves the previous value unchanged when re-
|
|
4
|
+
* It preserves the previous value unchanged when re-renders occur without state changes.
|
|
5
5
|
* If the state is an object or requires custom change detection, a `compare` function can be provided.
|
|
6
6
|
* By default, state changes are detected using `prev === next`.
|
|
7
7
|
*
|
|
8
8
|
* @template T - The type of the state.
|
|
9
9
|
* @param {T} state - The state whose previous value is to be tracked.
|
|
10
|
-
* @param {(prev: T
|
|
10
|
+
* @param {(prev: T, next: T) => boolean} [compare] - An optional comparison function to determine if the state has changed.
|
|
11
11
|
*
|
|
12
|
-
* @returns {T
|
|
12
|
+
* @returns {T} The previous value of the state.
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* const [count, setCount] = useState(0);
|
package/esm/index.js
CHANGED
|
@@ -378,27 +378,25 @@ function isSetStateAction(next) {
|
|
|
378
378
|
|
|
379
379
|
// src/hooks/useCounter/useCounter.ts
|
|
380
380
|
import { useCallback as useCallback8, useState as useState3 } from "react";
|
|
381
|
+
var validateValue = (value, { min, max }) => {
|
|
382
|
+
if (min !== void 0 && value < min) {
|
|
383
|
+
return min;
|
|
384
|
+
}
|
|
385
|
+
if (max !== void 0 && value > max) {
|
|
386
|
+
return max;
|
|
387
|
+
}
|
|
388
|
+
return value;
|
|
389
|
+
};
|
|
381
390
|
function useCounter(initialValue = 0, { min, max, step = 1 } = {}) {
|
|
382
|
-
const
|
|
383
|
-
let validatedValue = value;
|
|
384
|
-
if (min !== void 0 && validatedValue < min) {
|
|
385
|
-
validatedValue = min;
|
|
386
|
-
}
|
|
387
|
-
if (max !== void 0 && validatedValue > max) {
|
|
388
|
-
validatedValue = max;
|
|
389
|
-
}
|
|
390
|
-
return validatedValue;
|
|
391
|
-
};
|
|
392
|
-
const [count, setCountState] = useState3(() => validateValue(initialValue));
|
|
393
|
-
const validateValueMemoized = useCallback8(validateValue, [min, max]);
|
|
391
|
+
const [count, setCountState] = useState3(() => validateValue(initialValue, { min, max }));
|
|
394
392
|
const setCount = useCallback8(
|
|
395
393
|
(value) => {
|
|
396
394
|
setCountState((prev) => {
|
|
397
395
|
const nextValue = typeof value === "function" ? value(prev) : value;
|
|
398
|
-
return
|
|
396
|
+
return validateValue(nextValue, { min, max });
|
|
399
397
|
});
|
|
400
398
|
},
|
|
401
|
-
[
|
|
399
|
+
[min, max]
|
|
402
400
|
);
|
|
403
401
|
const increment = useCallback8(() => {
|
|
404
402
|
setCount((prev) => prev + step);
|