├── .all-contributorsrc
├── .eslintignore
├── .eslintrc.js
├── .github
├── FUNDING.yml
├── ISSUE_TEMPLATE
│ ├── bug_report.md
│ ├── feature_request.md
│ └── question.md
├── PULL_REQUEST_TEMPLATE.md
├── dependabot.yml
└── workflows
│ ├── ci.yml
│ ├── codeql-analysis.yml
│ └── size.yml
├── .gitignore
├── .husky
├── pre-commit
└── pre-push
├── .nvmrc
├── .prettierignore
├── .vscode
└── settings.json
├── CHANGELOG.md
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── SECURITY.md
├── app
├── .eslintignore
├── .eslintrc.js
├── .gitignore
├── .stylelintrc.js
├── README.md
├── package.json
├── public
│ ├── favicon.ico
│ ├── index.html
│ ├── logo192.png
│ ├── logo512.png
│ ├── manifest.json
│ ├── og_image.png
│ └── robots.txt
├── src
│ ├── Animations
│ │ ├── index.tsx
│ │ └── styles.module.scss
│ ├── App
│ │ ├── index.tsx
│ │ └── styles.scss
│ ├── GitHubCorner
│ │ ├── index.tsx
│ │ └── styles.module.scss
│ ├── Main
│ │ ├── index.tsx
│ │ └── styles.module.scss
│ ├── index.tsx
│ ├── mixins
│ │ ├── common.scss
│ │ └── mq.scss
│ ├── react-app-env.d.ts
│ └── types
│ │ └── index.d.ts
├── tsconfig.json
└── yarn.lock
├── babel.config.json
├── jest.config.js
├── package.json
├── rollup.config.js
├── src
├── __tests__
│ ├── useLatest.ts
│ └── useWebAnimations.ts
├── animations
│ ├── backInDown.ts
│ ├── backInLeft.ts
│ ├── backInRight.ts
│ ├── backInUp.ts
│ ├── backOutDown.ts
│ ├── backOutLeft.ts
│ ├── backOutRight.ts
│ ├── backOutUp.ts
│ ├── bounce.ts
│ ├── bounceIn.ts
│ ├── bounceInDown.ts
│ ├── bounceInLeft.ts
│ ├── bounceInRight.ts
│ ├── bounceInUp.ts
│ ├── bounceOut.ts
│ ├── bounceOutDown.ts
│ ├── bounceOutLeft.ts
│ ├── bounceOutRight.ts
│ ├── bounceOutUp.ts
│ ├── fadeIn.ts
│ ├── fadeInBottomLeft.ts
│ ├── fadeInBottomRight.ts
│ ├── fadeInDown.ts
│ ├── fadeInDownBig.ts
│ ├── fadeInLeft.ts
│ ├── fadeInLeftBig.ts
│ ├── fadeInRight.ts
│ ├── fadeInRightBig.ts
│ ├── fadeInTopLeft.ts
│ ├── fadeInTopRight.ts
│ ├── fadeInUp.ts
│ ├── fadeInUpBig.ts
│ ├── fadeOut.ts
│ ├── fadeOutBottomLeft.ts
│ ├── fadeOutBottomRight.ts
│ ├── fadeOutDown.ts
│ ├── fadeOutDownBig.ts
│ ├── fadeOutLeft.ts
│ ├── fadeOutLeftBig.ts
│ ├── fadeOutRight.ts
│ ├── fadeOutRightBig.ts
│ ├── fadeOutTopLeft.ts
│ ├── fadeOutTopRight.ts
│ ├── fadeOutUp.ts
│ ├── fadeOutUpBig.ts
│ ├── flash.ts
│ ├── flip.ts
│ ├── flipInX.ts
│ ├── flipInY.ts
│ ├── flipOutX.ts
│ ├── flipOutY.ts
│ ├── headShake.ts
│ ├── heartBeat.ts
│ ├── hinge.ts
│ ├── index.ts
│ ├── jackInTheBox.ts
│ ├── jello.ts
│ ├── lightSpeedInLeft.ts
│ ├── lightSpeedInRight.ts
│ ├── lightSpeedOutLeft.ts
│ ├── lightSpeedOutRight.ts
│ ├── pulse.ts
│ ├── rollIn.ts
│ ├── rollOut.ts
│ ├── rotateIn.ts
│ ├── rotateInDownLeft.ts
│ ├── rotateInDownRight.ts
│ ├── rotateInUpLeft.ts
│ ├── rotateInUpRight.ts
│ ├── rotateOut.ts
│ ├── rotateOutDownLeft.ts
│ ├── rotateOutDownRight.ts
│ ├── rotateOutUpLeft.ts
│ ├── rotateOutUpRight.ts
│ ├── rubberBand.ts
│ ├── shakeX.ts
│ ├── shakeY.ts
│ ├── slideInDown.ts
│ ├── slideInLeft.ts
│ ├── slideInRight.ts
│ ├── slideInUp.ts
│ ├── slideOutDown.ts
│ ├── slideOutLeft.ts
│ ├── slideOutRight.ts
│ ├── slideOutUp.ts
│ ├── swing.ts
│ ├── tada.ts
│ ├── wobble.ts
│ ├── zoomIn.ts
│ ├── zoomInDown.ts
│ ├── zoomInLeft.ts
│ ├── zoomInRight.ts
│ ├── zoomInUp.ts
│ ├── zoomOut.ts
│ ├── zoomOutDown.ts
│ ├── zoomOutLeft.ts
│ ├── zoomOutRight.ts
│ └── zoomOutUp.ts
├── index.ts
├── use-web-animations.d.ts
├── useLatest.ts
└── useWebAnimations.ts
├── tsconfig.json
└── yarn.lock
/.all-contributorsrc:
--------------------------------------------------------------------------------
1 | {
2 | "files": [
3 | "README.md"
4 | ],
5 | "imageSize": 100,
6 | "commit": false,
7 | "contributors": [
8 | {
9 | "login": "wellyshen",
10 | "name": "Welly",
11 | "avatar_url": "https://avatars1.githubusercontent.com/u/21308003?v=4",
12 | "profile": "https://wellyshen.com",
13 | "contributions": [
14 | "code",
15 | "doc",
16 | "maintenance"
17 | ]
18 | }
19 | ],
20 | "contributorsPerLine": 7,
21 | "projectName": "use-web-animations",
22 | "projectOwner": "wellyshen",
23 | "repoType": "github",
24 | "repoHost": "https://github.com",
25 | "skipCi": true
26 | }
27 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | app
2 | dist
--------------------------------------------------------------------------------
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | extends: ["welly"],
3 | rules: {
4 | "no-console": [
5 | "warn",
6 | {
7 | allow: ["warn", "error"],
8 | },
9 | ],
10 | "react/react-in-jsx-scope": "off",
11 | },
12 | };
13 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4 | patreon: # Replace with a single Patreon username
5 | open_collective: use-web-animations
6 | ko_fi: # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | otechie: # Replace with a single Otechie username
12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
13 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: "\U0001F41B Bug Report"
3 | about: Create a report to help us improve
4 | title: ""
5 | labels: ""
6 | assignees: ""
7 | ---
8 |
9 | # Bug Report
10 |
11 | ## Describe the Bug
12 |
13 | A clear and concise description of what the bug is.
14 |
15 | ## How to Reproduce
16 |
17 | Steps to reproduce the behavior, please provide code snippets or a repository:
18 |
19 | 1. Go to '....'
20 | 2. Click on '....'
21 | 3. See error
22 |
23 | ## CodeSandbox Link
24 |
25 | Show me the bug on [CodeSandbox](https://codesandbox.io).
26 |
27 | ## Expected Behavior
28 |
29 | Tell me what should happen.
30 |
31 | ## Screenshots
32 |
33 | Add screenshots to help explain your problem.
34 |
35 | ## Your Environment
36 |
37 | - Device: [e.g. MacBook Pro, iPhone12]
38 | - OS: [e.g. macOS, iOS, Windows]
39 | - Browser: [e.g. Chrome, Safari]
40 | - Version: [e.g. v1.0.0]
41 |
42 | ## Additional Information
43 |
44 | Any other information about the problem here.
45 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: "\U0001F4A1 Feature Request"
3 | about: Suggest an idea for this project
4 | title: ""
5 | labels: ""
6 | assignees: ""
7 | ---
8 |
9 | # Feature Request
10 |
11 | ## Describe the Feature
12 |
13 | A clear and concise description of what you want and what your use case is.
14 |
15 | ## Describe the Solution You'd Like
16 |
17 | A clear and concise description of what you want to happen.
18 |
19 | ## Describe Alternatives You've Considered
20 |
21 | A clear and concise description of any alternative solutions or features you've considered.
22 |
23 | ## Additional Information
24 |
25 | Any other information about the feature here.
26 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/question.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: "\U0001F914 Questions and Help"
3 | about: This issue tracker is not for questions. Please ask questions at https://stackoverflow.com/questions/tagged/react.
4 | title: ""
5 | labels: ""
6 | assignees: ""
7 | ---
8 |
9 | GitHub Issues are reserved for Bug reports and Feature requests. Support requests that are created as issues are likely to be closed. We want to make sure you are able to find the help you seek. Please take a look at the following resources.
10 |
11 | ## Coding Questions
12 |
13 | If you have a coding question related to React, it might be better suited for Stack Overflow. It's a great place to browse through frequent questions about using React, as well as ask for help with specific questions.
14 |
15 | https://stackoverflow.com/questions/tagged/react
16 |
17 | ## Support Forums
18 |
19 | There are many online forums which are a great place for discussion about best practices and application architecture.
20 |
21 | https://reactjs.org/community/support.html#popular-discussion-forums
22 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
12 |
13 | ## What
14 |
15 | What changes are being made? (e.g. feature, bug, docs, etc.)
16 |
17 | ## Why
18 |
19 | Why are these changes necessary?
20 |
21 | ## How
22 |
23 | How were these changes implemented?
24 |
25 | ## Checklist
26 |
27 | Have you done all of these things?
28 |
29 |
30 |
31 |
32 | - [ ] Documentation added
33 | - [ ] Tests
34 | - [ ] TypeScript definitions updated
35 | - [ ] Ready to be merged
36 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: npm
4 | directory: "/"
5 | schedule:
6 | interval: daily
7 | time: "21:00"
8 | open-pull-requests-limit: 10
9 | ignore:
10 | - dependency-name: husky
11 | versions:
12 | - 5.0.9
13 | - 5.1.1
14 | - 6.0.0
15 | - dependency-name: "@rollup/plugin-commonjs"
16 | versions:
17 | - 18.0.0
18 | - dependency-name: stylelint-config-standard
19 | versions:
20 | - 21.0.0
21 | - dependency-name: "@babel/runtime"
22 | versions:
23 | - 7.13.8
24 | - dependency-name: "@testing-library/react-hooks"
25 | versions:
26 | - 5.0.3
27 | - package-ecosystem: github-actions
28 | directory: "/"
29 | schedule:
30 | interval: daily
31 | time: "21:00"
32 | open-pull-requests-limit: 10
33 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on:
4 | push:
5 | branches:
6 | - master
7 | tags-ignore:
8 | - "**"
9 | pull_request:
10 | branches:
11 | - master
12 |
13 | jobs:
14 | build:
15 | runs-on: ubuntu-latest
16 |
17 | strategy:
18 | matrix:
19 | node: [16]
20 |
21 | steps:
22 | - uses: actions/checkout@v3
23 | - name: Use Node.js ${{ matrix.node-version }}
24 | uses: actions/setup-node@v3
25 | with:
26 | node-version: ${{ matrix.node-version }}
27 |
28 | - name: Get yarn cache directory path
29 | id: yarn-cache-dir-path
30 | run: echo "::set-output name=dir::$(yarn cache dir)"
31 | - uses: actions/cache@v3
32 | id: yarn-cache
33 | with:
34 | path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
35 | key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
36 | restore-keys: |
37 | ${{ runner.os }}-yarn-
38 | - name: Install dependencies
39 | run: yarn install --frozen-lockfile
40 | - name: Run lint
41 | run: yarn lint
42 | - name: Run test
43 | run: yarn test:cov
44 | - name: Run build package
45 | run: yarn build:prod
46 |
47 | - name: Coveralls GitHub Action
48 | uses: coverallsapp/github-action@master
49 | with:
50 | github-token: ${{ secrets.GITHUB_TOKEN }}
51 |
52 | deploy:
53 | runs-on: ubuntu-latest
54 | needs: build
55 | if: github.ref == 'refs/heads/master'
56 |
57 | steps:
58 | - uses: actions/checkout@v3
59 |
60 | - name: Get yarn cache directory path
61 | id: yarn-cache-dir-path
62 | run: echo "::set-output name=dir::$(yarn cache dir)"
63 | - uses: actions/cache@v3
64 | id: yarn-cache
65 | with:
66 | path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
67 | key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
68 | restore-keys: |
69 | ${{ runner.os }}-yarn-
70 | - name: Install dependencies
71 | run: yarn install --frozen-lockfile
72 | - name: Run build demo app
73 | run: yarn build:demo
74 |
75 | - name: Netlify GitHub Action
76 | uses: netlify/actions/cli@master
77 | with:
78 | args: deploy --prod --dir=app/build
79 | env:
80 | NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
81 | NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
82 |
--------------------------------------------------------------------------------
/.github/workflows/codeql-analysis.yml:
--------------------------------------------------------------------------------
1 | name: "CodeQL"
2 |
3 | on:
4 | push:
5 | branches: [master]
6 | pull_request:
7 | branches: [master]
8 | schedule:
9 | # ┌───────────── minute (0 - 59)
10 | # │ ┌───────────── hour (0 - 23)
11 | # │ │ ┌───────────── day of the month (1 - 31)
12 | # │ │ │ ┌───────────── month (1 - 12 or JAN-DEC)
13 | # │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
14 | # │ │ │ │ │
15 | # │ │ │ │ │
16 | # │ │ │ │ │
17 | # * * * * *
18 | - cron: "40 18 * * 1"
19 |
20 | jobs:
21 | CodeQL-Build:
22 | # CodeQL runs on ubuntu-latest, windows-latest, and macos-latest
23 | runs-on: ubuntu-latest
24 |
25 | permissions:
26 | # required for all workflows
27 | security-events: write
28 |
29 | # only required for workflows in private repositories
30 | actions: read
31 | contents: read
32 |
33 | steps:
34 | - name: Checkout repository
35 | uses: actions/checkout@v3
36 |
37 | # Initializes the CodeQL tools for scanning.
38 | - name: Initialize CodeQL
39 | uses: github/codeql-action/init@v2
40 | # Override language selection by uncommenting this and choosing your languages
41 | with:
42 | languages: javascript
43 |
44 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
45 | # If this step fails, then you should remove it and run the build manually (see below).
46 | - name: Autobuild
47 | uses: github/codeql-action/autobuild@v2
48 |
49 | # ℹ️ Command-line programs to run using the OS shell.
50 | # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
51 |
52 | # ✏️ If the Autobuild fails above, remove it and uncomment the following
53 | # three lines and modify them (or add more) to build your code if your
54 | # project uses a compiled language
55 |
56 | #- run: |
57 | # make bootstrap
58 | # make release
59 |
60 | - name: Perform CodeQL Analysis
61 | uses: github/codeql-action/analyze@v2
62 |
--------------------------------------------------------------------------------
/.github/workflows/size.yml:
--------------------------------------------------------------------------------
1 | name: Compressed Size
2 |
3 | on: [pull_request]
4 |
5 | jobs:
6 | build:
7 | runs-on: ubuntu-latest
8 |
9 | steps:
10 | - uses: actions/checkout@v3
11 | - uses: preactjs/compressed-size-action@v2
12 | with:
13 | repo-token: "${{ secrets.GITHUB_TOKEN }}"
14 | build-script: "build:prod"
15 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | *.log
3 |
4 | node_modules
5 | dist
6 | coverage
7 | .size-snapshot.json
--------------------------------------------------------------------------------
/.husky/pre-commit:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | . "$(dirname "$0")/_/husky.sh"
3 |
4 | yarn lint-staged
5 |
--------------------------------------------------------------------------------
/.husky/pre-push:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | . "$(dirname "$0")/_/husky.sh"
3 |
4 | yarn test
5 |
--------------------------------------------------------------------------------
/.nvmrc:
--------------------------------------------------------------------------------
1 | lts/*
2 |
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | *.log
2 | app
3 | dist
4 | coverage
5 | .size-snapshot.json
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "typescript.tsdk": "node_modules/typescript/lib"
3 | }
4 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | This project adheres to [Semantic Versioning](http://semver.org).
4 | Every release, along with the migration instructions, is documented on the Github [Releases](https://github.com/wellyshen/use-web-animations/releases) page.
5 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | We as members, contributors, and leaders pledge to make participation in our
6 | community a harassment-free experience for everyone, regardless of age, body
7 | size, visible or invisible disability, ethnicity, sex characteristics, gender
8 | identity and expression, level of experience, education, socio-economic status,
9 | nationality, personal appearance, race, religion, or sexual identity
10 | and orientation.
11 |
12 | We pledge to act and interact in ways that contribute to an open, welcoming,
13 | diverse, inclusive, and healthy community.
14 |
15 | ## Our Standards
16 |
17 | Examples of behavior that contributes to a positive environment for our
18 | community include:
19 |
20 | - Demonstrating empathy and kindness toward other people
21 | - Being respectful of differing opinions, viewpoints, and experiences
22 | - Giving and gracefully accepting constructive feedback
23 | - Accepting responsibility and apologizing to those affected by our mistakes,
24 | and learning from the experience
25 | - Focusing on what is best not just for us as individuals, but for the
26 | overall community
27 |
28 | Examples of unacceptable behavior include:
29 |
30 | - The use of sexualized language or imagery, and sexual attention or
31 | advances of any kind
32 | - Trolling, insulting or derogatory comments, and personal or political attacks
33 | - Public or private harassment
34 | - Publishing others' private information, such as a physical or email
35 | address, without their explicit permission
36 | - Other conduct which could reasonably be considered inappropriate in a
37 | professional setting
38 |
39 | ## Enforcement Responsibilities
40 |
41 | Community leaders are responsible for clarifying and enforcing our standards of
42 | acceptable behavior and will take appropriate and fair corrective action in
43 | response to any behavior that they deem inappropriate, threatening, offensive,
44 | or harmful.
45 |
46 | Community leaders have the right and responsibility to remove, edit, or reject
47 | comments, commits, code, wiki edits, issues, and other contributions that are
48 | not aligned to this Code of Conduct, and will communicate reasons for moderation
49 | decisions when appropriate.
50 |
51 | ## Scope
52 |
53 | This Code of Conduct applies within all community spaces, and also applies when
54 | an individual is officially representing the community in public spaces.
55 | Examples of representing our community include using an official e-mail address,
56 | posting via an official social media account, or acting as an appointed
57 | representative at an online or offline event.
58 |
59 | ## Enforcement
60 |
61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
62 | reported to the community leaders responsible for enforcement at
63 | hivoid19@gmail.com.
64 | All complaints will be reviewed and investigated promptly and fairly.
65 |
66 | All community leaders are obligated to respect the privacy and security of the
67 | reporter of any incident.
68 |
69 | ## Enforcement Guidelines
70 |
71 | Community leaders will follow these Community Impact Guidelines in determining
72 | the consequences for any action they deem in violation of this Code of Conduct:
73 |
74 | ### 1. Correction
75 |
76 | **Community Impact**: Use of inappropriate language or other behavior deemed
77 | unprofessional or unwelcome in the community.
78 |
79 | **Consequence**: A private, written warning from community leaders, providing
80 | clarity around the nature of the violation and an explanation of why the
81 | behavior was inappropriate. A public apology may be requested.
82 |
83 | ### 2. Warning
84 |
85 | **Community Impact**: A violation through a single incident or series
86 | of actions.
87 |
88 | **Consequence**: A warning with consequences for continued behavior. No
89 | interaction with the people involved, including unsolicited interaction with
90 | those enforcing the Code of Conduct, for a specified period of time. This
91 | includes avoiding interactions in community spaces as well as external channels
92 | like social media. Violating these terms may lead to a temporary or
93 | permanent ban.
94 |
95 | ### 3. Temporary Ban
96 |
97 | **Community Impact**: A serious violation of community standards, including
98 | sustained inappropriate behavior.
99 |
100 | **Consequence**: A temporary ban from any sort of interaction or public
101 | communication with the community for a specified period of time. No public or
102 | private interaction with the people involved, including unsolicited interaction
103 | with those enforcing the Code of Conduct, is allowed during this period.
104 | Violating these terms may lead to a permanent ban.
105 |
106 | ### 4. Permanent Ban
107 |
108 | **Community Impact**: Demonstrating a pattern of violation of community
109 | standards, including sustained inappropriate behavior, harassment of an
110 | individual, or aggression toward or disparagement of classes of individuals.
111 |
112 | **Consequence**: A permanent ban from any sort of public interaction within
113 | the community.
114 |
115 | ## Attribution
116 |
117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118 | version 2.0, available at
119 | [https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0].
120 |
121 | Community Impact Guidelines were inspired by
122 | [Mozilla's code of conduct enforcement ladder][mozilla coc].
123 |
124 | For answers to common questions about this code of conduct, see the FAQ at
125 | [https://www.contributor-covenant.org/faq][faq]. Translations are available
126 | at [https://www.contributor-covenant.org/translations][translations].
127 |
128 | [homepage]: https://www.contributor-covenant.org
129 | [v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html
130 | [mozilla coc]: https://github.com/mozilla/diversity
131 | [faq]: https://www.contributor-covenant.org/faq
132 | [translations]: https://www.contributor-covenant.org/translations
133 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to USE-WEB-ANIMATIONS
2 |
3 | When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.
4 |
5 | Please note we have a [code of conduct](CODE_OF_CONDUCT.md), please follow it in all your interactions with the project.
6 |
7 | > Working on your first Pull Request? You can learn how from [this free video series](https://egghead.io/courses/how-to-contribute-to-an-open-source-project-on-github).
8 |
9 | ## Pull Request Process
10 |
11 | 1. Fork the repository and create your branch from `master`.
12 | 2. Run `yarn` to install dependencies.
13 | 3. If you’ve fixed a bug or added code that should be tested.
14 | 4. Ensure the test suite passes by running `yarn test`.
15 | 5. Update the [README.md](README.md) with details of changes to the interface.
16 | 6. Update the [demo app](app/src) if needed.
17 | 7. Make sure your code lints by running `yarn lint`.
18 |
19 | ## Development Workflow
20 |
21 | You can test new features or debug an issue by the way that I'm using.
22 |
23 | 1. Run `yarn link-pkg` to link the package into the [app directory](app).
24 | 2. Run `yarn start` to create an `ESM` build and type definition file by `rollup` watch mode.
25 | 3. Access the [app directory](app).
26 | 4. In the **app directory**, run `yarn link-pkg` to link with the package then run `yarn start` to start development.
27 | 5. Try something cool via the [demo app](app/src).
28 |
29 | ## Scripts
30 |
31 | There're several useful scripts that you can use during the development:
32 |
33 | - `yarn link-pkg` links the package into the [app directory](app). You can develop or debug it via the [demo app](app/src).
34 | - `yarn start` creates a `dist` folder with an `ESM` build and type definition file by `rollup` watch mode.
35 | - `yarn lint:code` lints all `.js` and `.tsx?` files.
36 | - `yarn lint:type` runs the [TypeScript](https://www.typescriptlang.org) type-checks.
37 | - `yarn lint:format` formats all files except the file list of `.prettierignore`.
38 | - `yarn lint` lints `code`, `type`, and `format`.
39 | - `yarn test` runs the complete test suite.
40 | - `yarn test:watch` runs an interactive test watcher (helpful in development).
41 | - `yarn test:cov` runs the complete test suite with coverage report.
42 | - `yarn build:dev` creates a `dist` folder with an `ESM` build and type definition file for development.
43 | - `yarn build:prod` creates a `dist` folder with package builds (`CJS` & `ESM`) and type definition file. You can test the package locally via [yarn link](https://yarnpkg.com/lang/en/docs/cli/link).
44 | - `yarn clean:dist` deletes the `dist` build folder.
45 | - `yarn clean:size` deletes the `.size-snapshot.json` file.
46 | - `yarn clean:cov` deletes the `coverage` report folder.
47 | - `yarn clean` deletes build, test, and size relevant files.
48 |
49 | ## Style Guide
50 |
51 | We use [ESLint](https://eslint.org), [StyleLint](https://stylelint.io) and [Prettier](https://prettier.io) for code style and formatting. Run `yarn lint` after making any changes to the code. Then, our linter will catch most issues that may exist in your code.
52 |
53 | However, there are still some styles that the linter cannot pick up. If you are unsure about something, looking at [Airbnb’s Style Guide](https://github.com/airbnb/javascript) will guide you in the right direction.
54 |
55 | ## License
56 |
57 | By contributing to USE-WEB-ANIMATIONS, you agree that your contributions will be licensed under its MIT license.
58 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2020 Welly Shen
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # USE-WEB-ANIMATIONS
2 |
3 | Using [Web Animations API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API) (a.k.a WAAPI) in the React [hook](https://reactjs.org/docs/hooks-custom.html#using-a-custom-hook) way. Let's create highly-performant, flexible and manipulable web animations in the modern world. Hope you guys 👍🏻 it!
4 |
5 | ❤️ it? ⭐️ it on [GitHub](https://github.com/wellyshen/use-web-animations/stargazers) or [Tweet](https://twitter.com/intent/tweet?text=With%20@wellyshen/use-web-animations,%20I%20can%20build%20fancy%20and%20performant%20animations%20for%20my%20web%20app.%20Thanks,%20@Welly%20Shen%20🤩) about it.
6 |
7 | [](https://github.com/wellyshen/use-web-animations/actions?query=workflow%3ACI)
8 | [](https://coveralls.io/github/wellyshen/use-web-animations?branch=master)
9 | [](https://www.npmjs.com/package/@wellyshen/use-web-animations)
10 | [](https://www.npmtrends.com/@wellyshen/use-web-animations)
11 | [](https://www.npmtrends.com/@wellyshen/use-web-animations)
12 | [](https://bundlephobia.com/result?p=@wellyshen/use-web-animations)
13 | [](#contributors-)
14 | [](CONTRIBUTING.md)
15 | [](https://twitter.com/intent/tweet?text=With%20@wellyshen/use-web-animations,%20I%20can%20build%20fancy%20and%20performant%20animations%20for%20my%20web%20app.%20Thanks,%20@Welly%20Shen%20🤩)
16 |
17 | 
18 |
19 | ⚡️ Try yourself: https://use-web-animations.netlify.app
20 |
21 | 
22 |
23 | ⚡️ Try yourself: https://use-web-animations.netlify.app#animations
24 |
25 | ## Features
26 |
27 | - 🚀 Animate on the Web with [highly-performant](https://web.dev/animations-overview/#css-js) and manipulable way, using [Web Animations API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API).
28 | - 🎣 Easy to use, based on React [hook](https://reactjs.org/docs/hooks-custom.html#using-a-custom-hook).
29 | - 🎛 Super flexible [API](#api) design that can cover [all the cases](#usage) that you need.
30 | - 🎞 [Built-ins animations](#use-built-in-animations) for you, based on [Animate.css](https://animate.style).
31 | - 🔩 Supports custom `refs` for [some reasons](#use-your-own-ref).
32 | - 📜 Supports [TypeScript](https://www.typescriptlang.org) type definition.
33 | - 🗄️ Server-side rendering compatibility.
34 | - 🦔 Tiny size ([~ 4.4kB gzipped](https://bundlephobia.com/result?p=@wellyshen/use-web-animations)). No external dependencies, aside for the `react`.
35 |
36 | ## Requirement
37 |
38 | To use `use-web-animations`, you must use `react@16.8.0` or greater which includes hooks.
39 |
40 | ## Installation
41 |
42 | This package is distributed via [npm](https://www.npmjs.com/package/@wellyshen/use-web-animations).
43 |
44 | ```sh
45 | $ yarn add @wellyshen/use-web-animations
46 | # or
47 | $ npm install --save @wellyshen/use-web-animations
48 | ```
49 |
50 | ## Before We Start
51 |
52 | With the Web Animations API, we can move interactive animations from stylesheets to JavaScript, separating presentation from behavior. The API was designed based on the concept of the [CSS Animations](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Animations/Using_CSS_animations) but there're still some differences between them. I strongly recommend you to read the [documentation](https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API/Using_the_Web_Animations_API) before we dive into this hook.
53 |
54 | ## Usage
55 |
56 | The [API](#api) design of the hook not only inherits the DX of the [Web Animations API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API) but also provides useful features and sugar events to us. Here are some examples to show you how does it work.
57 |
58 | > ⚠️ [Most modern browsers support Web Animations API natively](https://caniuse.com/web-animation). You can also use [polyfill](#use-polyfill) for full browser support.
59 |
60 | ### Basic Usage
61 |
62 | Create an animation by the `keyframes` and `animationOptions` options (these are the [parameters](https://developer.mozilla.org/en-US/docs/Web/API/Element/animate#parameters) of the `Element.animate()`).
63 |
64 | > 💡 This hook supports the [pseudoElement](https://css-tricks.com/pseudo-elements-in-the-web-animations-api/) property via the `animationOptions` option.
65 |
66 | [](https://codesandbox.io/s/usewebanimations-basic-nf0kd?fontsize=14&hidenavigation=1&theme=dark)
67 |
68 | ```js
69 | import useWebAnimations from "@wellyshen/use-web-animations";
70 |
71 | const App = () => {
72 | const { ref, playState } = useWebAnimations({
73 | keyframes: {
74 | transform: "translateX(500px)", // Move by 500px
75 | background: ["red", "blue", "green"], // Go through three colors
76 | },
77 | animationOptions: {
78 | delay: 500, // Start with a 500ms delay
79 | duration: 1000, // Run for 1000ms
80 | iterations: 2, // Repeat once
81 | direction: "alternate", // Run the animation forwards and then backwards
82 | easing: "ease-in-out", // Use a fancy timing function
83 | },
84 | onReady: ({ playState, animate, animation }) => {
85 | // Triggered when the animation is ready to play
86 | },
87 | onUpdate: ({ playState, animate, animation }) => {
88 | // Triggered when the animation enters the running state or changes state
89 | },
90 | onFinish: ({ playState, animate, animation }) => {
91 | // Triggered when the animation enters the finished state
92 | },
93 | // More useful options...
94 | });
95 |
96 | return (
97 |
98 |
🍿 Animation is {playState}
99 |
100 |
101 | );
102 | };
103 | ```
104 |
105 | For browsers that don't yet support the `onReady` and `onFinish` events, we can use the `onUpdate` to monitor the animation's state instead.
106 |
107 | ```js
108 | let prevPending = true;
109 |
110 | const App = () => {
111 | const { ref } = useWebAnimations({
112 | // ...
113 | onUpdate: ({ playState, animation: { pending } }) => {
114 | if (prevPending && !pending) {
115 | console.log("Animation is ready to play");
116 | }
117 | prevPending = pending;
118 |
119 | if (playState === "finished") {
120 | console.log("Animation has finished playing");
121 | }
122 | },
123 | });
124 |
125 | // ...
126 | };
127 | ```
128 |
129 | ### Setting/Updating Animation
130 |
131 | The `keyframes` and `animationOptions` are cached when the hook is mounted. However, we can set/update the animation by the `animation` method.
132 |
133 | ```js
134 | const { animation } = useWebAnimations();
135 |
136 | const changeAnim = () =>
137 | animation({
138 | keyframes: { transform: ["translateX(0)", "translateX(100px)"] },
139 | animationOptions: 1000,
140 | id: "123",
141 | playbackRate: 1,
142 | autoPlay: true,
143 | });
144 | ```
145 |
146 | ### Playback Control
147 |
148 | The shortcoming with existing technologies was the lack of playback control. The Web Animations API provides several useful methods for controlling playback: play, pause, reverse, cancel, finish, seek, control speed via the [methods](https://developer.mozilla.org/en-US/docs/Web/API/Animation#Methods) of the **Animation** interface. This hook exposes the animation instance for us to interact with animations, we can access it by the `getAnimation()` return value.
149 |
150 | [](https://codesandbox.io/s/usewebanimations-controls-hst8v?fontsize=14&hidenavigation=1&theme=dark)
151 |
152 | ```js
153 | import useWebAnimations from "@wellyshen/use-web-animations";
154 |
155 | const App = () => {
156 | const { ref, playState, getAnimation } = useWebAnimations({
157 | playbackRate: 0.5, // Change playback rate, default is 1
158 | autoPlay: false, // Automatically starts the animation, default is true
159 | keyframes: { transform: "translateX(500px)" },
160 | animationOptions: { duration: 1000, fill: "forwards" },
161 | });
162 |
163 | const play = () => {
164 | getAnimation().play();
165 | };
166 |
167 | const pause = () => {
168 | getAnimation().pause();
169 | };
170 |
171 | const reverse = () => {
172 | getAnimation().reverse();
173 | };
174 |
175 | const cancel = () => {
176 | getAnimation().cancel();
177 | };
178 |
179 | const finish = () => {
180 | getAnimation().finish();
181 | };
182 |
183 | const seek = (e) => {
184 | const animation = getAnimation();
185 | const time = (animation.effect.getTiming().duration / 100) * e.target.value;
186 | animation.currentTime = time;
187 | };
188 |
189 | const updatePlaybackRate = (e) => {
190 | getAnimation().updatePlaybackRate(e.target.value);
191 | };
192 |
193 | return (
194 |
204 | );
205 | };
206 | ```
207 |
208 | ### Getting Animation's Information
209 |
210 | When using the Web Animations API, we can get the information of an animation via the [properties](https://developer.mozilla.org/en-US/docs/Web/API/Animation#Properties) of the **Animation** interface. However, we can get the information of an animation by the `getAnimation()` return value as well.
211 |
212 | ```js
213 | import useWebAnimations from "@wellyshen/use-web-animations";
214 |
215 | const App = () => {
216 | const { ref, getAnimation } = useWebAnimations({
217 | keyframes: { transform: "translateX(500px)" },
218 | animationOptions: { duration: 1000, fill: "forwards" },
219 | });
220 |
221 | const speedUp = () => {
222 | const animation = getAnimation();
223 | animation.updatePlaybackRate(animation.playbackRate * 0.25);
224 | };
225 |
226 | const jumpToHalf = () => {
227 | const animation = getAnimation();
228 | animation.currentTime = animation.effect.getTiming().duration / 2;
229 | };
230 |
231 | return (
232 |
233 |
234 |
235 |
236 |
237 | );
238 | };
239 | ```
240 |
241 | The animation instance isn't a part of [React state](https://reactjs.org/docs/hooks-state.html), which means we need to access it by the `getAnimation()` whenever we need. If you want to monitor an animation's information, here's the `onUpdate` event for you. The event is implemented by the [requestAnimationFrame](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame) internally and the event callback is triggered when the animation enters `running` state or changes state.
242 |
243 | ```js
244 | import { useState } from "react";
245 | import useWebAnimations from "@wellyshen/use-web-animations";
246 |
247 | const App = () => {
248 | const [showEl, setShowEl] = useState(false);
249 | const { ref } = useWebAnimations({
250 | keyframes: { transform: "translateX(500px)" },
251 | animationOptions: { duration: 1000, fill: "forwards" },
252 | onUpdate: ({ animation }) => {
253 | if (animation.currentTime > animation.effect.getTiming().duration / 2)
254 | setShowEl(true);
255 | },
256 | });
257 |
258 | return (
259 |
260 | {showEl && }
261 |
262 |
263 | );
264 | };
265 | ```
266 |
267 | ### Dynamic Interactions with Animation
268 |
269 | We can create and play an animation at the `animationOptions` we want by the `animate` method, which is implemented based on the [Element.animate()](https://developer.mozilla.org/en-US/docs/Web/API/Element/animate). It's useful for interactions and the [composite modes](https://css-tricks.com/additive-animation-web-animations-api).
270 |
271 | Let's create a mouse interaction effect:
272 |
273 | [](https://codesandbox.io/s/usewebanimations-interaction-4jrs9?fontsize=14&hidenavigation=1&theme=dark)
274 |
275 | ```js
276 | import { useEffect } from "react";
277 | import useWebAnimations from "@wellyshen/use-web-animations";
278 |
279 | const App = () => {
280 | const { ref, animate } = useWebAnimations();
281 |
282 | useEffect(() => {
283 | document.addEventListener("mousemove", (e) => {
284 | // The target will follow the mouse cursor
285 | animate({
286 | keyframes: { transform: `translate(${e.clientX}px, ${e.clientY}px)` },
287 | animationOptions: { duration: 500, fill: "forwards" },
288 | });
289 | });
290 | }, [animate]);
291 |
292 | return (
293 |
329 | );
330 | };
331 | ```
332 |
333 | > ⚠️ Composite modes isn't fully supported by all the browsers, please check the [browser compatibility](https://developer.mozilla.org/en-US/docs/Web/API/KeyframeEffect/composite#Browser_compatibility) carefully before using it.
334 |
335 | ## Use Built-in Animations
336 |
337 | Too lazy to think about animation? We provide a collection of ready-to-use animations for you, they are implemented based on [Animate.css](https://animate.style).
338 |
339 | 👉🏻 [Check out the demo](https://use-web-animations.netlify.app#animations).
340 |
341 | ```js
342 | import useWebAnimations, { bounce } from "@wellyshen/use-web-animations";
343 |
344 | const App = () => {
345 | // Add a pre-defined effect to the target
346 | const { ref } = useWebAnimations({ ...bounce });
347 |
348 | return (
349 |
350 |
351 |
352 | );
353 | };
354 | ```
355 |
356 | We can customize the built-in animation by overriding its properties:
357 |
358 | ```js
359 | const { keyframes, animationOptions } = bounce;
360 | const { ref } = useWebAnimations({
361 | keyframes,
362 | animationOptions: {
363 | ...animationOptions,
364 | delay: 1000, // Delay 1s
365 | duration: animationOptions.duration * 0.75, // Speed up the animation
366 | },
367 | });
368 | ```
369 |
370 |
371 | See all available animations
372 |
373 | #### Attention seekers
374 |
375 | - bounce
376 | - flash
377 | - pulse
378 | - rubberBand
379 | - shakeX
380 | - shakeY
381 | - headShake
382 | - swing
383 | - tada
384 | - wobble
385 | - jello
386 | - heartBeat
387 |
388 | #### Back entrances
389 |
390 | - backInDown
391 | - backInLeft
392 | - backInRight
393 | - backInUp
394 |
395 | #### Back exits
396 |
397 | - backOutDown
398 | - backOutLeft
399 | - backOutRight
400 | - backOutUp
401 |
402 | #### Bouncing entrances
403 |
404 | - bounceIn
405 | - bounceInDown
406 | - bounceInLeft
407 | - bounceInRight
408 | - bounceInUp
409 |
410 | #### Bouncing exits
411 |
412 | - bounceOut
413 | - bounceOutDown
414 | - bounceOutLeft
415 | - bounceOutRight
416 | - bounceOutUp
417 |
418 | #### Fading entrances
419 |
420 | - fadeIn
421 | - fadeInDown
422 | - fadeInDownBig
423 | - fadeInLeft
424 | - fadeInLeftBig
425 | - fadeInRight
426 | - fadeInRightBig
427 | - fadeInUp
428 | - fadeInUpBig
429 | - fadeInTopLeft
430 | - fadeInTopRight
431 | - fadeInBottomLeft
432 | - fadeInBottomRight
433 |
434 | #### Fading exits
435 |
436 | - fadeOut
437 | - fadeOutDown
438 | - fadeOutDownBig
439 | - fadeOutLeft
440 | - fadeOutLeftBig
441 | - fadeOutRight
442 | - fadeOutRightBig
443 | - fadeOutUp
444 | - fadeOutUpBig
445 | - fadeOutTopLeft
446 | - fadeOutTopRight
447 | - fadeOutBottomLeft
448 | - fadeOutBottomRight
449 |
450 | #### Flippers
451 |
452 | - flip
453 | - flipInX
454 | - flipInY
455 | - flipOutX
456 | - flipOutY
457 |
458 | #### Lightspeed
459 |
460 | - lightSpeedInRight
461 | - lightSpeedInLeft
462 | - lightSpeedOutRight
463 | - lightSpeedOutLeft
464 |
465 | #### Rotating entrances
466 |
467 | - rotateIn
468 | - rotateInDownLeft
469 | - rotateInDownRight
470 | - rotateInUpLeft
471 | - rotateInUpRight
472 |
473 | #### Rotating exits
474 |
475 | - rotateOut
476 | - rotateOutDownLeft
477 | - rotateOutDownRight
478 | - rotateOutUpLeft
479 | - rotateOutUpRight
480 |
481 | #### Specials
482 |
483 | - hinge
484 | - jackInTheBox
485 | - rollIn
486 | - rollOut
487 |
488 | #### Zooming entrances
489 |
490 | - zoomIn
491 | - zoomInDown
492 | - zoomInLeft
493 | - zoomInRight
494 | - zoomInUp
495 |
496 | #### Zooming exits
497 |
498 | - zoomOut
499 | - zoomOutDown
500 | - zoomOutLeft
501 | - zoomOutRight
502 | - zoomOutUp
503 |
504 | #### Sliding entrances
505 |
506 | - slideInDown
507 | - slideInLeft
508 | - slideInRight
509 | - slideInUp
510 |
511 | #### Sliding exits
512 |
513 | - slideOutDown
514 | - slideOutLeft
515 | - slideOutRight
516 | - slideOutUp
517 |
518 |
519 | ## Use Your Own `ref`
520 |
521 | In case of you had a ref already or you want to share a ref for other purposes. You can pass in the ref instead of using the one provided by this hook.
522 |
523 | ```js
524 | const ref = useRef();
525 | const { playState } = useWebAnimations({ ref });
526 | ```
527 |
528 | ## Working in TypeScript
529 |
530 | This hook supports [TypeScript](https://www.typescriptlang.org), you can tell the hook what type of element you are going to animate through the [generic type](https://www.typescriptlang.org/docs/handbook/generics.html):
531 |
532 | ```ts
533 | const App = () => {
534 | const { ref } = useWebAnimations();
535 |
536 | return ;
537 | };
538 | ```
539 |
540 | > 💡 For more available types, please [check it out](src/use-web-animations.d.ts).
541 |
542 | ## API
543 |
544 | ```js
545 | const returnObj = useWebAnimations(options?: object);
546 | ```
547 |
548 | ### Return Object
549 |
550 | It's returned with the following properties.
551 |
552 | | Key | Type | Default | Description |
553 | | -------------- | ------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
554 | | `ref` | object | | Used to set the target element for animating. |
555 | | `playState` | string \| undefined | | Describes the [playback state](https://developer.mozilla.org/en-US/docs/Web/API/Animation/playState#value) of an animation. |
556 | | `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. |
557 | | `animate` | function | | Imperatively [set/update the animation](#settingupdating-animation). Useful for [interactive animations and composite animations](#dynamic-interactions-with-animation). |
558 |
559 | ### Parameter
560 |
561 | The `options` provides the following configurations and event callbacks for you.
562 |
563 | | Key | Type | Default | Description |
564 | | ------------------ | ---------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
565 | | `ref` | object | | For [some reasons](#use-your-own-ref), you can pass in your own ref instead of using the built-in. |
566 | | `id` | string | `""` | Sets the ID of an animation, implemented based on the [Animation.id](https://developer.mozilla.org/en-US/docs/Web/API/Animation/id). |
567 | | `playbackRate` | number | `1` | Sets the playback rate of an animation, implemented based on the [Animation.playbackRate](https://developer.mozilla.org/en-US/docs/Web/API/Animation/playbackRate). |
568 | | `autoPlay` | boolean | `true` | Automatically starts the animation. |
569 | | `keyframes` | Array \| object | | An array of keyframe objects, or a keyframe object whose property are arrays of values to iterate over. See [basic usage](#basic-usage) for more details. |
570 | | `animationOptions` | number \| object | | An **integer** representing the animation's duration (in milliseconds), or an **object** containing one or more timing properties. See [basic usage](#basic-usage) for more details. |
571 | | `onReady` | function | | It's invoked when an animation is ready to play. You can access the [playState](#basic-usage), [animate](#dynamic-interactions-with-animation) and [animation](#getting-animations-information) from the event object. |
572 | | `onUpdate` | function | | It's invoked when an animation enters the `running` state or changes state. You can access the [playState](#basic-usage), [animate](#dynamic-interactions-with-animation) and [animation](#getting-animations-information) from the event object. |
573 | | `onFinish` | function | | It's invoked when an animation enters the `finished` state. You can access the [playState](#basic-usage), [animate](#dynamic-interactions-with-animation) and [animation](#getting-animations-information) from the event object. |
574 |
575 | ## Use Polyfill
576 |
577 | [Web Animations API has good support amongst browsers](https://caniuse.com/web-animation), but it's not universal. You'll need to polyfill browsers that don't support it. Polyfills is something you should do consciously at the application level. Therefore `use-web-animations` doesn't include it.
578 |
579 | Install [web-animations-js](https://github.com/web-animations/web-animations-js):
580 |
581 | ```sh
582 | $ yarn add web-animations-js
583 | # or
584 | $ npm install --save web-animations-js
585 | ```
586 |
587 | Then import it at your app's entry point:
588 |
589 | ```js
590 | import "web-animations-js/web-animations.min";
591 | ```
592 |
593 | You can read the [document](https://github.com/web-animations/web-animations-js/blob/dev/docs/support.md) for more information.
594 |
595 | ## Articles / Blog Posts
596 |
597 | > 💡 If you have written any blog post or article about `use-web-animations`, please open a PR to add it here.
598 |
599 | - Featured on [React Status #196](https://react.statuscode.com/issues/196).
600 | - Featured on [JavaScript Weekly #496](https://javascriptweekly.com/issues/496).
601 | - Featured on [React Newsletter #218](https://reactnewsletter.com/issues/218).
602 |
603 | ## Contributors ✨
604 |
605 | Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
606 |
607 |
608 |
609 |
610 |