├── .eslintignore
├── example
├── src
│ ├── index.css
│ ├── index.js
│ ├── App.css
│ ├── App.js
│ ├── logo.svg
│ └── registerServiceWorker.js
├── public
│ ├── favicon.ico
│ ├── manifest.json
│ └── index.html
├── README.md
├── .gitignore
└── package.json
├── react-flip-numbers.gif
├── .github
├── FUNDING.yml
└── ISSUE_TEMPLATE
│ ├── feature_request.md
│ └── bug_report.md
├── src
├── index.js
├── index.d.ts
├── flipNumbers.js
└── flipNumber.js
├── .flowconfig
├── .npmignore
├── .babelrc
├── CONTRIBUTING.md
├── rollup.config.js
├── test
├── flipNumbers.test.js
├── __snapshots__
│ ├── flipNumbers.test.js.snap
│ └── flipNumber.test.js.snap
└── flipNumber.test.js
├── .eslintrc
├── LICENSE
├── .gitignore
├── README.md
└── package.json
/.eslintignore:
--------------------------------------------------------------------------------
1 | /**/*.d.ts
--------------------------------------------------------------------------------
/example/src/index.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | padding: 0;
4 | font-family: sans-serif;
5 | }
6 |
--------------------------------------------------------------------------------
/react-flip-numbers.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beekai-oss/react-flip-numbers/HEAD/react-flip-numbers.gif
--------------------------------------------------------------------------------
/example/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beekai-oss/react-flip-numbers/HEAD/example/public/favicon.ico
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | patreon: bluebill1049
4 | github: [bluebill1049]
5 |
--------------------------------------------------------------------------------
/example/README.md:
--------------------------------------------------------------------------------
1 | # React flip numbers
2 |
3 | ## Install and start
4 |
5 | $ yarn && yarn start
6 | or
7 | $ npm install && npm start
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import FlipNumbers from './flipNumbers';
2 | import FlipNumber from './flipNumber';
3 |
4 | export default FlipNumbers;
5 |
6 | export { FlipNumber };
7 |
--------------------------------------------------------------------------------
/.flowconfig:
--------------------------------------------------------------------------------
1 | [ignore]
2 | .*/example
3 | .*/node_modules/eslint-plugin-jsx-a11y/*
4 |
5 | [include]
6 |
7 | [libs]
8 |
9 | [options]
10 | suppress_comment=\\(.\\|\n\\)*\\$FlowIgnoreLine
11 |
12 | [lints]
13 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | example/
2 | .circleci/
3 | src/
4 | test/
5 | .babelrc
6 | .flowconfig
7 | .npmignore
8 | yarn-error.log
9 | yarn.lock
10 | .idea/
11 | CONTRIBUTING.md
12 | .eslintrc
13 | rollup.config.js
14 | .coveralls.yml
15 | react-flip-numbers.gif
16 |
--------------------------------------------------------------------------------
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["@babel/preset-flow", "@babel/preset-env", "@babel/preset-react"],
3 | "plugins": [
4 | "@babel/plugin-transform-flow-strip-types",
5 | "@babel/plugin-proposal-class-properties",
6 | "@babel/plugin-proposal-optional-chaining"
7 | ]
8 | }
9 |
--------------------------------------------------------------------------------
/example/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import './index.css';
4 | import App from './App';
5 | import registerServiceWorker from './registerServiceWorker';
6 |
7 | ReactDOM.render(, document.getElementById('root'));
8 | registerServiceWorker();
9 |
--------------------------------------------------------------------------------
/example/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 |
6 | # testing
7 | /coverage
8 |
9 | # production
10 | /build
11 |
12 | # misc
13 | .DS_Store
14 | .env.local
15 | .env.development.local
16 | .env.test.local
17 | .env.production.local
18 |
19 | npm-debug.log*
20 | yarn-debug.log*
21 | yarn-error.log*
22 |
--------------------------------------------------------------------------------
/example/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | }
10 | ],
11 | "start_url": "./index.html",
12 | "display": "standalone",
13 | "theme_color": "#000000",
14 | "background_color": "#ffffff"
15 | }
16 |
--------------------------------------------------------------------------------
/example/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "react": "^16.8.0",
7 | "react-dom": "^16.8.0",
8 | "react-flip-numbers": "3.0.1-beta.3",
9 | "react-scripts": "1.1.4"
10 | },
11 | "scripts": {
12 | "start": "react-scripts start",
13 | "build": "react-scripts build",
14 | "test": "react-scripts test --env=jsdom",
15 | "eject": "react-scripts eject"
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/example/src/App.css:
--------------------------------------------------------------------------------
1 | .App {
2 | text-align: center;
3 | }
4 |
5 | .App-logo {
6 | animation: App-logo-spin infinite 20s linear;
7 | height: 80px;
8 | }
9 |
10 | .App-header {
11 | background-color: #222;
12 | height: 150px;
13 | padding: 20px;
14 | color: white;
15 | }
16 |
17 | .App-title {
18 | font-size: 1.5em;
19 | }
20 |
21 | .App-intro {
22 | font-size: large;
23 | }
24 |
25 | @keyframes App-logo-spin {
26 | from { transform: rotate(0deg); }
27 | to { transform: rotate(360deg); }
28 | }
29 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to React Simple Animate
2 |
3 | ## Pull Requests
4 |
5 | Welcome your pull requests for documentation and code. 🙏
6 |
7 | 1. Fork the repo and create your branch from `master`.
8 | 2. If you've added code that should be tested.
9 | 3. If you've changed APIs, update the documentation.
10 | 4. Ensure the test suite passes.
11 | 5. Make sure your code lints.
12 | 6. Make sure your code pass flow type check.
13 |
14 | ## Coding Style
15 |
16 | * 2 spaces for indentation rather than tabs
17 | * See .eslintrc for the gory details.
18 | * Run prettier if you can :)
19 |
--------------------------------------------------------------------------------
/rollup.config.js:
--------------------------------------------------------------------------------
1 | import flow from 'rollup-plugin-flow';
2 | import babel from 'rollup-plugin-babel';
3 | import copy from 'rollup-plugin-copy';
4 |
5 | const plugins = [
6 | flow({
7 | pretty: true,
8 | }),
9 | babel({
10 | exclude: 'node_modules/**',
11 | }),
12 | copy({
13 | targets: [
14 | { src: 'src/index.d.ts', dest: 'lib/' },
15 | ],
16 | }),
17 | ];
18 |
19 | export default {
20 | input: 'src/index.js',
21 | plugins,
22 | external: ['react', 'react-simple-animate'],
23 | output: {
24 | file: 'lib/index.js',
25 | format: 'cjs',
26 | },
27 | };
28 |
--------------------------------------------------------------------------------
/src/index.d.ts:
--------------------------------------------------------------------------------
1 | declare module 'react-flip-numbers' {
2 | import type React from 'react';
3 |
4 | export interface FlipNumbersProps {
5 | background?: string;
6 | color: string;
7 | delay?: number;
8 | duration?: number;
9 | height: number;
10 | nonNumberClassName?: string;
11 | nonNumberStyle?: React.CSSProperties;
12 | numberClassName?: string;
13 | numbers: string;
14 | numberStyle?: React.CSSProperties;
15 | perspective?: number;
16 | play: boolean;
17 | width: number;
18 | }
19 |
20 | export default class FlipNumbers extends React.Component {}
21 | }
22 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Is your feature request related to a problem? Please describe.**
11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12 |
13 | **Describe the solution you'd like**
14 | A clear and concise description of what you want to happen.
15 |
16 | **Describe alternatives you've considered**
17 | A clear and concise description of any alternative solutions or features you've considered.
18 |
19 | **Additional context**
20 | Add any other context or screenshots about the feature request here.
21 |
--------------------------------------------------------------------------------
/test/flipNumbers.test.js:
--------------------------------------------------------------------------------
1 | import renderer from 'react-test-renderer';
2 | import FlipNumbers from '../src/flipNumbers';
3 | import React from 'react';
4 |
5 | jest.mock('../src/flipNumber', () => 'FlipNumber');
6 |
7 | describe('FlipNumbers', () => {
8 | const props = {
9 | numbers: '00:00',
10 | nonNumberStyle: ':',
11 | height: 20,
12 | width: 20,
13 | color: 'black',
14 | background: 'white',
15 | perspective: '1000px',
16 | durationSeconds: 0.3,
17 | delaySeconds: 0.3,
18 | startAnimation: false,
19 | };
20 |
21 | it('should render correctly', () => {
22 | const tree = renderer.create();
23 | expect(tree).toMatchSnapshot();
24 | });
25 | });
26 |
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": ["airbnb", "plugin:flowtype/recommended"],
3 | "rules": {
4 | "flowtype/define-flow-type": 2,
5 | "react/prop-types": 0,
6 | "react/no-unused-prop-types": 0,
7 | "react/jsx-filename-extension": 0,
8 | "global-require": 0,
9 | "max-len": 0,
10 | "no-underscore-dangle": 0,
11 | "import/first": 0,
12 | "indent": 0,
13 | "import/no-named-as-default": 0,
14 | "no-plusplus": 0,
15 | "arrow-parens": 0,
16 | "no-console": 0,
17 | "implicit-arrow-linebreak": 0,
18 | "prefer-destructuring": 0,
19 | "operator-linebreak": 0,
20 | "object-curly-newline": 0,
21 | "function-paren-newline": 0,
22 | "react/destructuring-assignment": 0,
23 | "react/require-default-props": 0
24 | },
25 | "env": {
26 | "browser": true,
27 | "node": true,
28 | "jest": true
29 | },
30 | "parser": "babel-eslint",
31 | "plugins": ["flowtype"]
32 | }
33 |
--------------------------------------------------------------------------------
/example/src/App.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from "react";
2 | import FlipNumbers from "react-flip-numbers";
3 |
4 | class App extends Component {
5 | state = {
6 | timeRemaining: 10000,
7 | };
8 |
9 | componentDidMount() {
10 | this.timer = setInterval(() => {
11 | this.setState({
12 | timeRemaining: this.state.timeRemaining - 1,
13 | });
14 | }, 1000);
15 | }
16 |
17 | componentWillUnmount() {
18 | clearInterval(this.timer);
19 | }
20 |
21 | render() {
22 | return (
23 |
35 | );
36 | }
37 | }
38 |
39 | export default App;
40 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Describe the bug**
11 | A clear and concise description of what the bug is.
12 |
13 | **To Reproduce**
14 | Steps to reproduce the behavior:
15 | 1. Go to '...'
16 | 2. Click on '....'
17 | 3. Scroll down to '....'
18 | 4. See error
19 |
20 | **Expected behavior**
21 | A clear and concise description of what you expected to happen.
22 |
23 | **Screenshots**
24 | If applicable, add screenshots to help explain your problem.
25 |
26 | **Desktop (please complete the following information):**
27 | - OS: [e.g. iOS]
28 | - Browser [e.g. chrome, safari]
29 | - Version [e.g. 22]
30 |
31 | **Smartphone (please complete the following information):**
32 | - Device: [e.g. iPhone6]
33 | - OS: [e.g. iOS8.1]
34 | - Browser [e.g. stock browser, safari]
35 | - Version [e.g. 22]
36 |
37 | **Additional context**
38 | Add any other context about the problem here.
39 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Bill Luo
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 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Runtime data
9 | pids
10 | *.pid
11 | *.seed
12 | *.pid.lock
13 |
14 | # Directory for instrumented libs generated by jscoverage/JSCover
15 | lib-cov
16 |
17 | # Coverage directory used by tools like istanbul
18 | coverage
19 |
20 | # nyc test coverage
21 | .nyc_output
22 |
23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24 | .grunt
25 |
26 | # Bower dependency directory (https://bower.io/)
27 | bower_components
28 |
29 | # node-waf configuration
30 | .lock-wscript
31 |
32 | # Compiled binary addons (http://nodejs.org/api/addons.html)
33 | build/Release
34 |
35 | # Dependency directories
36 | node_modules/
37 | example/node_modules/
38 | example/build/
39 | jspm_packages/
40 |
41 | # Typescript v1 declaration files
42 | typings/
43 |
44 | # Optional npm cache directory
45 | .npm
46 |
47 | # Optional eslint cache
48 | .eslintcache
49 |
50 | # Optional REPL history
51 | .node_repl_history
52 |
53 | # Output of 'npm pack'
54 | *.tgz
55 |
56 | # Yarn Integrity file
57 | .yarn-integrity
58 |
59 | # dotenv environment variables file
60 | .env
61 |
62 | .DS_Store
63 |
64 | /lib
65 | .idea/
66 | .coveralls.yml
67 |
--------------------------------------------------------------------------------
/test/__snapshots__/flipNumbers.test.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`FlipNumbers should render correctly 1`] = `
4 |
14 |
28 |
42 |
46 | :
47 |
48 |
62 |
76 |
77 | `;
78 |
--------------------------------------------------------------------------------
/example/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
11 |
12 |
13 |
22 | React App
23 |
24 |
25 |
28 |
29 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/test/flipNumber.test.js:
--------------------------------------------------------------------------------
1 | import renderer from 'react-test-renderer';
2 | import { shallow, configure } from 'enzyme';
3 | import FlipNumber from '../src/flipNumber';
4 | import React from 'react';
5 | import Adapter from 'enzyme-adapter-react-16';
6 |
7 | configure({ adapter: new Adapter() });
8 |
9 | jest.mock('react-simple-animate', () => ({ Animate: 'Animate' }));
10 |
11 | const numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
12 |
13 | describe('FlipNumber', () => {
14 | const props = {
15 | height: 20,
16 | color: 'white',
17 | background: 'black',
18 | numbers,
19 | width: 20,
20 | perspective: '1000px',
21 | durationSeconds: 0.3,
22 | activeNumber: 0,
23 | delaySeconds: 0,
24 | startAnimation: true,
25 | };
26 |
27 | it('should render correctly', () => {
28 | const tree = renderer.create();
29 | expect(tree).toMatchSnapshot();
30 | });
31 |
32 | it('should only update component when active number changed or degree is 0', () => {
33 | const tree = shallow();
34 |
35 | const nextProps = {
36 | ...props,
37 | activeNumber: 0,
38 | };
39 |
40 | expect(tree.instance().shouldComponentUpdate(nextProps)).toBeTruthy();
41 |
42 | tree.setState({
43 | degree: 1,
44 | isStatic: false,
45 | });
46 |
47 | const nextState = {
48 | degree: 1,
49 | rotateCounter: 0,
50 | rotateDegreePerNumber: 0,
51 | isStatic: false,
52 | };
53 |
54 | expect(tree.instance().shouldComponentUpdate(nextProps, nextState)).toBeFalsy();
55 |
56 | expect(
57 | tree.instance().shouldComponentUpdate({
58 | activeNumber: 1,
59 | })
60 | ).toBeTruthy();
61 | });
62 |
63 | it('should return the correct position for matching number', () => {
64 | const tree = renderer.create(
65 |
71 | );
72 | expect(tree).toMatchSnapshot();
73 | });
74 | });
75 |
--------------------------------------------------------------------------------
/example/src/logo.svg:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # React Flip Numbers
2 |
3 | [](https://coveralls.io/github/bluebill1049/react-flip-numbers?branch=master)
4 | [](https://www.npmjs.com/package/react-flip-numbers)
5 | [](https://www.npmjs.com/package/react-flip-numbers)
6 | [](https://www.npmjs.com/package/react-flip-numbers)
7 | [](https://badgen.net/bundlephobia/minzip/react-flip-numbers)
8 |
9 | > **Make number animation looks sexy** :clap:
10 |
11 | - Flip your numbers in 3D space
12 | - Super easy to use
13 |
14 | ## Install
15 |
16 | npm install react-flip-numbers -S
17 |
18 |
19 |
20 |
21 |
22 | ## Quickstart
23 |
24 | ```jsx
25 | import react from 'react';
26 | import FlipNumbers from 'react-flip-numbers';
27 |
28 | export default () => {
29 | return ;
30 | };
31 | ```
32 |
33 | ## API
34 |
35 | | Prop | Type | Required | Description |
36 | | :--------------- | :------ | :------: | :--------------------------------------- |
37 | | `numbers` | string | ✓ | |
38 | | `play` | boolean | ✓ | Start the animation | |
39 | | `height` | number | ✓ | Individual number height |
40 | | `width` | number | ✓ | Individual number width |
41 | | `color` | string | ✓ | Number color |
42 | | `background` | string | | Background color |
43 | | `perspective` | number | | CSS 3D transition perspective |
44 | | `nonNumberStyle` | string | | CSS inline style for not number eg , : . |
45 | | `numberStyle` | string | | CSS inline style for number |
46 | | `duration` | number | | |
47 | | `delay` | number | | |
48 |
49 |
50 | ## By the makers of BEEKAI
51 |
52 | We also make [BEEKAI](https://www.beekai.com/). Build the next-generation forms with modern technology and best in class user experience and accessibility.
53 |
--------------------------------------------------------------------------------
/test/__snapshots__/flipNumber.test.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`FlipNumber should render correctly 1`] = `
4 |
17 |
37 |
59 | 0
60 |
61 |
62 | `;
63 |
64 | exports[`FlipNumber should return the correct position for matching number 1`] = `
65 |
78 |
98 |
120 | 2
121 |
122 |
123 | `;
124 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-flip-numbers",
3 | "version": "3.0.9",
4 | "description": "react flip your numbers",
5 | "main": "lib/index.js",
6 | "typings": "lib/index.d.ts",
7 | "keywords": [
8 | "react",
9 | "number",
10 | "animate"
11 | ],
12 | "scripts": {
13 | "clean": "rimraf lib/",
14 | "release": "npm version",
15 | "postrelease": "yarn publish && git push --follow-tags",
16 | "test": "jest",
17 | "testw": "yarn test -- --watchAll",
18 | "coverage": "jest --coverage --coverageReporters=text-lcov | coveralls",
19 | "build": "rollup -c",
20 | "lint": "eslint ./src",
21 | "prepublish": "yarn test && yarn flow && yarn lint && yarn run clean && yarn build",
22 | "flow": "flow"
23 | },
24 | "repository": "https://github.com/bluebill1049/react-flip-numbers.git",
25 | "author": "beier luo",
26 | "license": "Mit",
27 | "bugs": {
28 | "url": "https://github.com/bluebill1049/react-flip-numbers/issues"
29 | },
30 | "devDependencies": {
31 | "@babel/cli": "^7.0.0",
32 | "@babel/core": "^7.3.3",
33 | "@babel/plugin-proposal-class-properties": "^7.3.3",
34 | "@babel/plugin-proposal-decorators": "^7.3.0",
35 | "@babel/plugin-proposal-do-expressions": "^7.0.0",
36 | "@babel/plugin-proposal-export-default-from": "^7.0.0",
37 | "@babel/plugin-proposal-export-namespace-from": "^7.0.0",
38 | "@babel/plugin-proposal-function-bind": "^7.0.0",
39 | "@babel/plugin-proposal-function-sent": "^7.0.0",
40 | "@babel/plugin-proposal-json-strings": "^7.0.0",
41 | "@babel/plugin-proposal-logical-assignment-operators": "^7.0.0",
42 | "@babel/plugin-proposal-nullish-coalescing-operator": "^7.0.0",
43 | "@babel/plugin-proposal-numeric-separator": "^7.0.0",
44 | "@babel/plugin-proposal-optional-chaining": "^7.0.0",
45 | "@babel/plugin-proposal-pipeline-operator": "^7.3.2",
46 | "@babel/plugin-proposal-throw-expressions": "^7.0.0",
47 | "@babel/plugin-syntax-dynamic-import": "^7.0.0",
48 | "@babel/plugin-syntax-import-meta": "^7.0.0",
49 | "@babel/plugin-transform-flow-strip-types": "^7.0.0",
50 | "@babel/preset-env": "^7.3.1",
51 | "@babel/preset-flow": "^7.0.0",
52 | "@babel/preset-react": "^7.0.0",
53 | "@types/react": "^18.0.21",
54 | "@types/react-dom": "^18.0.6",
55 | "babel-core": "^7.0.0-bridge.0",
56 | "babel-eslint": "^10.0.1",
57 | "babel-jest": "^24.1.0",
58 | "coveralls": "^3.0.3",
59 | "enzyme": "^3.9.0",
60 | "enzyme-adapter-react-16": "^1.9.1",
61 | "eslint": "^5.14.1",
62 | "eslint-config-airbnb": "^17.1.0",
63 | "eslint-plugin-babel": "^5.3.0",
64 | "eslint-plugin-flowtype": "^3.4.2",
65 | "eslint-plugin-import": "^2.16.0",
66 | "eslint-plugin-jsx-a11y": "^6.2.1",
67 | "eslint-plugin-react": "^7.12.4",
68 | "flow-bin": "^0.93.0",
69 | "flow-typed": "^2.5.1",
70 | "jest": "^24.1.0",
71 | "react": "16.8.3",
72 | "react-dom": "16.8.3",
73 | "react-test-renderer": "^16.8.3",
74 | "rimraf": "^2.6.3",
75 | "rollup": "^1.2.2",
76 | "rollup-plugin-babel": "^4.3.2",
77 | "rollup-plugin-commonjs": "^9.2.0",
78 | "rollup-plugin-copy": "^3.4.0",
79 | "rollup-plugin-flow": "^1.1.1"
80 | },
81 | "peerDependencies": {
82 | "react": "^16.8.0 || ^17 || ^18 || ^19",
83 | "react-dom": "^16.8.0 || ^17 || ^18 || ^19",
84 | "react-simple-animate": "^3.0.1"
85 | },
86 | "dependencies": {
87 | "react-simple-animate": "^3.0.1"
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/src/flipNumbers.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | import React from 'react';
3 | import FlipNumber from './flipNumber';
4 |
5 | type Props = {
6 | numbers: string | Array,
7 | nonNumberStyle?: Object,
8 | numberClassName?: string,
9 | nonNumberClassName?: string,
10 | height: number,
11 | width: number,
12 | color: string,
13 | background?: string,
14 | perspective?: number,
15 | duration?: number,
16 | delay?: number,
17 | animate?: boolean,
18 | play?: boolean,
19 | numberStyle?: { [string]: string | number },
20 | };
21 |
22 | export default class FlipNumbers extends React.Component {
23 | static defaultProps = {
24 | perspective: 500,
25 | duration: 0.3,
26 | animate: true,
27 | play: false,
28 | delay: 0,
29 | nonNumberStyle: {},
30 | numberStyle: {},
31 | };
32 |
33 | shouldComponentUpdate(nextProps: Props) {
34 | return (
35 | nextProps.nonNumberClassName !== this.props.nonNumberClassName ||
36 | nextProps.numberClassName !== this.props.numberClassName ||
37 | nextProps.numbers !== this.props.numbers ||
38 | nextProps.height !== this.props.height ||
39 | nextProps.width !== this.props.width ||
40 | nextProps.duration !== this.props.duration ||
41 | nextProps.delay !== this.props.delay ||
42 | nextProps.play !== this.props.play
43 | );
44 | }
45 |
46 | render() {
47 | const {
48 | numbers,
49 | nonNumberStyle,
50 | numberStyle,
51 | numberClassName,
52 | nonNumberClassName,
53 | height,
54 | width,
55 | color,
56 | background,
57 | perspective,
58 | duration,
59 | animate,
60 | play,
61 | delay,
62 | } = this.props;
63 | let numberCounter = 0;
64 |
65 | return (
66 |
74 | {Array.from(numbers).map((n, key) => {
75 | const nonNumber = (
76 |
77 | {n}
78 |
79 | );
80 |
81 | if (animate) {
82 | numberCounter += 1;
83 | return !Number.isNaN(parseInt(n, 10)) ? (
84 |
102 | ) : (
103 | nonNumber
104 | );
105 | }
106 |
107 | return !Number.isNaN(parseInt(n, 10)) ? (
108 |
115 | {n}
116 |
117 | ) : (
118 | nonNumber
119 | );
120 | })}
121 |
122 | );
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/example/src/registerServiceWorker.js:
--------------------------------------------------------------------------------
1 | // In production, we register a service worker to serve assets from local cache.
2 |
3 | // This lets the app load faster on subsequent visits in production, and gives
4 | // it offline capabilities. However, it also means that developers (and users)
5 | // will only see deployed updates on the "N+1" visit to a page, since previously
6 | // cached resources are updated in the background.
7 |
8 | // To learn more about the benefits of this model, read https://goo.gl/KwvDNy.
9 | // This link also includes instructions on opting out of this behavior.
10 |
11 | const isLocalhost = Boolean(
12 | window.location.hostname === 'localhost' ||
13 | // [::1] is the IPv6 localhost address.
14 | window.location.hostname === '[::1]' ||
15 | // 127.0.0.1/8 is considered localhost for IPv4.
16 | window.location.hostname.match(
17 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
18 | )
19 | );
20 |
21 | export default function register() {
22 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
23 | // The URL constructor is available in all browsers that support SW.
24 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location);
25 | if (publicUrl.origin !== window.location.origin) {
26 | // Our service worker won't work if PUBLIC_URL is on a different origin
27 | // from what our page is served on. This might happen if a CDN is used to
28 | // serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374
29 | return;
30 | }
31 |
32 | window.addEventListener('load', () => {
33 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
34 |
35 | if (isLocalhost) {
36 | // This is running on localhost. Lets check if a service worker still exists or not.
37 | checkValidServiceWorker(swUrl);
38 |
39 | // Add some additional logging to localhost, pointing developers to the
40 | // service worker/PWA documentation.
41 | navigator.serviceWorker.ready.then(() => {
42 | console.log(
43 | 'This web app is being served cache-first by a service ' +
44 | 'worker. To learn more, visit https://goo.gl/SC7cgQ'
45 | );
46 | });
47 | } else {
48 | // Is not local host. Just register service worker
49 | registerValidSW(swUrl);
50 | }
51 | });
52 | }
53 | }
54 |
55 | function registerValidSW(swUrl) {
56 | navigator.serviceWorker
57 | .register(swUrl)
58 | .then(registration => {
59 | registration.onupdatefound = () => {
60 | const installingWorker = registration.installing;
61 | installingWorker.onstatechange = () => {
62 | if (installingWorker.state === 'installed') {
63 | if (navigator.serviceWorker.controller) {
64 | // At this point, the old content will have been purged and
65 | // the fresh content will have been added to the cache.
66 | // It's the perfect time to display a "New content is
67 | // available; please refresh." message in your web app.
68 | console.log('New content is available; please refresh.');
69 | } else {
70 | // At this point, everything has been precached.
71 | // It's the perfect time to display a
72 | // "Content is cached for offline use." message.
73 | console.log('Content is cached for offline use.');
74 | }
75 | }
76 | };
77 | };
78 | })
79 | .catch(error => {
80 | console.error('Error during service worker registration:', error);
81 | });
82 | }
83 |
84 | function checkValidServiceWorker(swUrl) {
85 | // Check if the service worker can be found. If it can't reload the page.
86 | fetch(swUrl)
87 | .then(response => {
88 | // Ensure service worker exists, and that we really are getting a JS file.
89 | if (
90 | response.status === 404 ||
91 | response.headers.get('content-type').indexOf('javascript') === -1
92 | ) {
93 | // No service worker found. Probably a different app. Reload the page.
94 | navigator.serviceWorker.ready.then(registration => {
95 | registration.unregister().then(() => {
96 | window.location.reload();
97 | });
98 | });
99 | } else {
100 | // Service worker found. Proceed as normal.
101 | registerValidSW(swUrl);
102 | }
103 | })
104 | .catch(() => {
105 | console.log(
106 | 'No internet connection found. App is running in offline mode.'
107 | );
108 | });
109 | }
110 |
111 | export function unregister() {
112 | if ('serviceWorker' in navigator) {
113 | navigator.serviceWorker.ready.then(registration => {
114 | registration.unregister();
115 | });
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/src/flipNumber.js:
--------------------------------------------------------------------------------
1 | // @flow
2 | import { Animate } from 'react-simple-animate';
3 | import React from 'react';
4 |
5 | const commonAnimateStyle = {
6 | position: 'absolute',
7 | height: '100%',
8 | transformStyle: 'preserve-3d',
9 | };
10 | const easeType = 'cubic-bezier(0.19, 1, 0.22, 1)';
11 | const revolutionDegrees = 360;
12 | const resetRouteCounter = 1000;
13 | const numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
14 | const rotateDegreePerNumber = 36;
15 |
16 | type Props = {
17 | position: number,
18 | length: number,
19 | height: number,
20 | color: string,
21 | background?: string,
22 | width: number,
23 | perspective: number,
24 | duration: number,
25 | activeNumber: number,
26 | delay: number,
27 | play: boolean,
28 | numberStyle: Object,
29 | className?: string,
30 | };
31 |
32 | type State = {
33 | degree: number,
34 | rotateCounter: number,
35 | };
36 |
37 | const calculateDegrees = (rotateCounter, activeNumber) => {
38 | const animateDegree = numbers.findIndex(v => v === activeNumber) * rotateDegreePerNumber;
39 | const amountDegree = rotateCounter * revolutionDegrees;
40 |
41 | return {
42 | ...(activeNumber === 0
43 | ? {
44 | rotateCounter: rotateCounter > resetRouteCounter ? 0 : rotateCounter + 1,
45 | }
46 | : null),
47 | degree: amountDegree - animateDegree,
48 | };
49 | };
50 |
51 | export default class FlipNumber extends React.Component {
52 | static getDerivedStateFromProps({ activeNumber }: Props, { rotateCounter }: State) {
53 | return calculateDegrees(rotateCounter, activeNumber);
54 | }
55 |
56 | state = {
57 | degree: 0,
58 | rotateCounter: 0, // eslint-disable-line react/no-unused-state
59 | };
60 |
61 | updateNumberTimeout: TimeoutID;
62 |
63 | componentDidMount() {
64 | this.updateNumberTimeout = setTimeout(() => this.updateNumber(), 50 * this.props.position);
65 | }
66 |
67 | shouldComponentUpdate(nextProps: Props) {
68 | return (
69 | nextProps.className !== this.props.className ||
70 | nextProps.activeNumber !== this.props.activeNumber ||
71 | nextProps.height !== this.props.height ||
72 | nextProps.width !== this.props.width ||
73 | this.state.degree === 0 ||
74 | nextProps.play !== this.props.play
75 | );
76 | }
77 |
78 | componentWillUnmount() {
79 | clearTimeout(this.updateNumberTimeout);
80 | }
81 |
82 | updateNumber = () => {
83 | this.setState(({ rotateCounter }) => calculateDegrees(rotateCounter, this.props.activeNumber));
84 | };
85 |
86 | render() {
87 | const {
88 | activeNumber,
89 | height,
90 | color,
91 | background,
92 | width,
93 | perspective,
94 | duration,
95 | play,
96 | delay,
97 | length,
98 | position,
99 | numberStyle = {},
100 | className,
101 | } = this.props;
102 | const { degree } = this.state;
103 | const viewPortSize = {
104 | width: `${width}px`,
105 | height: `${height + 3}px`,
106 | };
107 | const halfElementHeight = height / 2;
108 | const translateZ = halfElementHeight + height;
109 |
110 | return (
111 |
123 | (
135 |
136 | {numbers.map((n, i) => (
137 |
158 | {n}
159 |
160 | ))}
161 |
162 | )}
163 | />
164 |
165 | 4 ? 0.25 : 0}px`, // hacky fix for weird misalignment in Chrome.
173 | position: 'absolute',
174 | display: 'flex',
175 | justifyContent: 'center',
176 | alignItems: 'center',
177 | textAlign: 'center',
178 | WebkitFontSmoothing: 'antialiased',
179 | color,
180 | background,
181 | transform: `rotateX(0deg) translateZ(${translateZ}px)`,
182 | visibility: 'hidden',
183 | ...numberStyle,
184 | }}
185 | >
186 | {activeNumber}
187 |
188 |
189 | );
190 | }
191 | }
192 |
--------------------------------------------------------------------------------