physics-animator 0.15.3 → 0.16.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 +2 -2
- package/dist/cjs/react/useSpringState.js +7 -3
- package/dist/cjs/react/useSpringValue.js +9 -0
- package/dist/esm/react/useSpringState.js +7 -3
- package/dist/esm/react/useSpringValue.js +9 -0
- package/dist/types/react/useSpringState.d.ts +7 -5
- package/dist/types/react/useSpringValue.d.ts +9 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,9 +24,9 @@ useSpringValue(
|
|
|
24
24
|
Or via state
|
|
25
25
|
|
|
26
26
|
```tsx
|
|
27
|
-
const
|
|
27
|
+
const opacitySpring = useSpringState({ initial: 0, duration_s: 0.8, target: opacity })
|
|
28
28
|
|
|
29
|
-
return <div style={{ opacity }} />
|
|
29
|
+
return <div style={{ opacity: opacitySpring }} />
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
It works with arrays and objects
|
|
@@ -7,15 +7,19 @@ const useSpringValue_js_1 = require("./useSpringValue.js");
|
|
|
7
7
|
* A value that animates to a target value using a spring animation.
|
|
8
8
|
* This **will** cause a re-render when the value changes.
|
|
9
9
|
*
|
|
10
|
+
* Usage example:
|
|
11
|
+
* ```tsx
|
|
12
|
+
* const opacity = useSpringState({ initial: 0, target: 1, duration_s: 0.8 });
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
10
15
|
* See {@link useSpringValue} for a version that does not cause re-renders.
|
|
11
16
|
*/
|
|
12
17
|
function useSpringState(options) {
|
|
13
18
|
const [state, setState] = (0, react_1.useState)(options.initial);
|
|
14
|
-
const [target, setTarget] = (0, react_1.useState)(options.initial);
|
|
15
19
|
(0, useSpringValue_js_1.useSpringValue)({
|
|
16
20
|
...options,
|
|
17
21
|
initial: options.initial,
|
|
18
|
-
target
|
|
22
|
+
target: options.target,
|
|
19
23
|
}, setState);
|
|
20
|
-
return
|
|
24
|
+
return state;
|
|
21
25
|
}
|
|
@@ -8,6 +8,15 @@ const react_1 = require("react");
|
|
|
8
8
|
* A value that animates to a target value using a spring animation.
|
|
9
9
|
* This will **not** cause a re-render when the value changes.
|
|
10
10
|
*
|
|
11
|
+
* Usage example:
|
|
12
|
+
* ```tsx
|
|
13
|
+
* useSpringValue(
|
|
14
|
+
* { initial: 0, target: 1, duration_s: 0.8 },
|
|
15
|
+
* // onChange
|
|
16
|
+
* value => el.style.opacity = value
|
|
17
|
+
* );
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
11
20
|
* See {@link useSpringState} for a version that does cause re-renders.
|
|
12
21
|
*/
|
|
13
22
|
function useSpringValue(options, onChange) {
|
|
@@ -4,15 +4,19 @@ import { useSpringValue } from "./useSpringValue.js";
|
|
|
4
4
|
* A value that animates to a target value using a spring animation.
|
|
5
5
|
* This **will** cause a re-render when the value changes.
|
|
6
6
|
*
|
|
7
|
+
* Usage example:
|
|
8
|
+
* ```tsx
|
|
9
|
+
* const opacity = useSpringState({ initial: 0, target: 1, duration_s: 0.8 });
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
7
12
|
* See {@link useSpringValue} for a version that does not cause re-renders.
|
|
8
13
|
*/
|
|
9
14
|
export function useSpringState(options) {
|
|
10
15
|
const [state, setState] = useState(options.initial);
|
|
11
|
-
const [target, setTarget] = useState(options.initial);
|
|
12
16
|
useSpringValue({
|
|
13
17
|
...options,
|
|
14
18
|
initial: options.initial,
|
|
15
|
-
target
|
|
19
|
+
target: options.target,
|
|
16
20
|
}, setState);
|
|
17
|
-
return
|
|
21
|
+
return state;
|
|
18
22
|
}
|
|
@@ -5,6 +5,15 @@ import { useEffect } from "react";
|
|
|
5
5
|
* A value that animates to a target value using a spring animation.
|
|
6
6
|
* This will **not** cause a re-render when the value changes.
|
|
7
7
|
*
|
|
8
|
+
* Usage example:
|
|
9
|
+
* ```tsx
|
|
10
|
+
* useSpringValue(
|
|
11
|
+
* { initial: 0, target: 1, duration_s: 0.8 },
|
|
12
|
+
* // onChange
|
|
13
|
+
* value => el.style.opacity = value
|
|
14
|
+
* );
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
8
17
|
* See {@link useSpringState} for a version that does cause re-renders.
|
|
9
18
|
*/
|
|
10
19
|
export function useSpringValue(options, onChange) {
|
|
@@ -5,6 +5,11 @@ type WidenNumber<T> = T extends number ? number : T;
|
|
|
5
5
|
* A value that animates to a target value using a spring animation.
|
|
6
6
|
* This **will** cause a re-render when the value changes.
|
|
7
7
|
*
|
|
8
|
+
* Usage example:
|
|
9
|
+
* ```tsx
|
|
10
|
+
* const opacity = useSpringState({ initial: 0, target: 1, duration_s: 0.8 });
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
8
13
|
* See {@link useSpringValue} for a version that does not cause re-renders.
|
|
9
14
|
*/
|
|
10
15
|
export declare function useSpringState<T extends number | number[] | {
|
|
@@ -12,9 +17,6 @@ export declare function useSpringState<T extends number | number[] | {
|
|
|
12
17
|
}>(options: {
|
|
13
18
|
animator?: Animator;
|
|
14
19
|
initial: T;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
readonly target: WidenNumber<T>;
|
|
18
|
-
readonly setTarget: import("react").Dispatch<import("react").SetStateAction<WidenNumber<T>>>;
|
|
19
|
-
};
|
|
20
|
+
target: T;
|
|
21
|
+
} & SpringParameters): WidenNumber<T>;
|
|
20
22
|
export {};
|
|
@@ -4,6 +4,15 @@ import { SpringParameters } from "../animators/SpringAnimator.js";
|
|
|
4
4
|
* A value that animates to a target value using a spring animation.
|
|
5
5
|
* This will **not** cause a re-render when the value changes.
|
|
6
6
|
*
|
|
7
|
+
* Usage example:
|
|
8
|
+
* ```tsx
|
|
9
|
+
* useSpringValue(
|
|
10
|
+
* { initial: 0, target: 1, duration_s: 0.8 },
|
|
11
|
+
* // onChange
|
|
12
|
+
* value => el.style.opacity = value
|
|
13
|
+
* );
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
7
16
|
* See {@link useSpringState} for a version that does cause re-renders.
|
|
8
17
|
*/
|
|
9
18
|
export declare function useSpringValue<T extends number | number[] | {
|
package/package.json
CHANGED