Skip to content

Commit 343d8ce

Browse files
authored
Merge pull request #474 from wellyshen/play-state
refactor(types): enhance the types of `playState`
2 parents 8f01ae7 + 3f3e35f commit 343d8ce

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -552,12 +552,12 @@ const returnObj = useWebAnimations(options?: object);
552552

553553
It's returned with the following properties.
554554

555-
| Key | Type | Default | Description |
556-
| -------------- | -------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
557-
| `ref` | object | | Used to set the target element for animating. |
558-
| `playState` | string | | Describes the playback state of an animation. |
559-
| `getAnimation` | function | | Access the [animation instance](https://developer.mozilla.org/en-US/docs/Web/API/Animation) for [playback control](#playback-control), [animation's information](#getting-animations-information) and more. |
560-
| `animate` | function | | Imperatively [set/update the animation](#settingupdating-animation). Useful for [interactive animations and composite animations](#dynamic-interactions-with-animation). |
555+
| Key | Type | Default | Description |
556+
| -------------- | ------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
557+
| `ref` | object | | Used to set the target element for animating. |
558+
| `playState` | string \| undefined | | Describes the [playback state](https://developer.mozilla.org/en-US/docs/Web/API/Animation/playState#value) of an animation. |
559+
| `getAnimation` | function | | Access the [animation instance](https://developer.mozilla.org/en-US/docs/Web/API/Animation) for [playback control](#playback-control), [animation's information](#getting-animations-information) and more. |
560+
| `animate` | function | | Imperatively [set/update the animation](#settingupdating-animation). Useful for [interactive animations and composite animations](#dynamic-interactions-with-animation). |
561561

562562
### Parameter
563563

src/use-web-animations.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ declare module "@wellyshen/use-web-animations" {
33

44
export type Keyframes = Keyframe[] | PropertyIndexedKeyframes;
55

6-
export type PlayState = string | null;
6+
export type PlayState = AnimationPlayState | undefined;
77

88
type BaseOptions = Partial<{
99
id: string;

src/useWebAnimations.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const eventErr = (type: string): string =>
88
`💡 use-web-animations: the browser doesn't support ${type} event, please use "onUpdate" to monitor the animation's state instead. See https://github.com/wellyshen/use-web-animations#basic-usage`;
99

1010
type Keyframes = Keyframe[] | PropertyIndexedKeyframes;
11-
type PlayState = string | null;
11+
type PlayState = AnimationPlayState | undefined;
1212
type BaseOptions = Partial<{
1313
id: string;
1414
playbackRate: number;
@@ -52,7 +52,7 @@ const useWebAnimations = <T extends HTMLElement | null>({
5252
onUpdate,
5353
onFinish,
5454
}: Options<T> = {}): Return<T> => {
55-
const [playState, setPlayState] = useState<PlayState>(null);
55+
const [playState, setPlayState] = useState<PlayState>();
5656
const hasUnmountedRef = useRef(false);
5757
const animRef = useRef<Animation>();
5858
const prevPendingRef = useRef<boolean>();

0 commit comments

Comments
 (0)