-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite on hooks. Add TypeScript declarations 🎉
- Loading branch information
Vladislav
committed
Dec 16, 2022
1 parent
ffcc2aa
commit 4282858
Showing
11 changed files
with
2,145 additions
and
2,935 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,32 @@ | ||
module.exports = { | ||
parser: 'babel-eslint', | ||
extends: 'airbnb', | ||
plugins: ['react'], | ||
env: { | ||
browser: true, | ||
es2021: true, | ||
}, | ||
extends: ['plugin:react/recommended', 'standard-with-typescript'], | ||
overrides: [], | ||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
project: ['./tsconfig.json'], | ||
sourceType: 'module', | ||
}, | ||
plugins: ['react'], | ||
rules: { | ||
'import/no-extraneous-dependencies': 0, | ||
'react/jsx-filename-extension': ['error', { extensions: ['.js', '.jsx'] }], | ||
'react/require-default-props': 0, | ||
'comma-dangle': 0, | ||
'no-irregular-whitespace': ['error', { skipComments: true }], | ||
semi: 0, | ||
'@typescript-eslint/comma-dangle': ['error', 'always-multiline'], | ||
'@typescript-eslint/member-delimiter-style': ['error', { | ||
multiline: { | ||
delimiter: 'semi', | ||
requireLast: true, | ||
}, | ||
singleline: { | ||
delimiter: 'semi', | ||
requireLast: true, | ||
}, | ||
multilineDetection: 'brackets', | ||
}], | ||
'@typescript-eslint/semi': ['error', 'always'], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
node_modules/ | ||
npm-debug.log | ||
dist | ||
.yarn/ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
nodeLinker: node-modules | ||
|
||
plugins: | ||
- path: .yarn/plugins/@yarnpkg/plugin-outdated.cjs | ||
spec: "https://mskelton.dev/yarn-outdated/v3" | ||
|
||
yarnPath: .yarn/releases/yarn-3.3.0.cjs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
declare module 'odometer' { | ||
import { type ReactOdometerProps } from './src'; | ||
class Odometer { | ||
constructor (options: ReactOdometerProps); | ||
public update (value: number): number; | ||
} | ||
export default Odometer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { createElement, useEffect, useRef, type FC } from 'react'; | ||
import Odometer from 'odometer'; | ||
|
||
export interface ReactOdometerProps { | ||
/** | ||
* Count is a simpler animation method which just increments the value, use it when you're looking for something more | ||
* subtle. | ||
*/ | ||
animation?: 'count'; | ||
/** | ||
* Change how long the javascript expects the CSS animation to take. | ||
* @default 2000 | ||
*/ | ||
duration?: number; | ||
/** | ||
* Change how digit groups are formatted, and how many digits are shown after the decimal point. | ||
* (,ddd) - 12,345,678 | ||
* (,ddd).dd - 12,345,678.09 | ||
* (.ddd),dd - 12.345.678,09 | ||
* ( ddd),dd - 12 345 678,09 | ||
* d - 12345678 | ||
*/ | ||
format?: string; | ||
/** | ||
* Change the selector used to automatically find things to be animated | ||
*/ | ||
selector?: string; | ||
/** | ||
* Specify the theme (if you have more than one theme css file on the page). | ||
* Will add CSS class .odometer-theme-{prop value} to wrapper `div`. | ||
*/ | ||
theme?: string; | ||
/** | ||
* Current value. Change it to run animation. | ||
*/ | ||
value: number; | ||
} | ||
|
||
const ReactOdometer: FC<ReactOdometerProps> = ({ value, ...options }) => { | ||
const node = useRef(); | ||
const odometer = useRef( | ||
new Odometer({ | ||
el: node.current, | ||
auto: false, | ||
value, | ||
...options, | ||
}), | ||
); | ||
|
||
useEffect(() => { | ||
odometer.current.update(value); | ||
}, [value]); | ||
|
||
return createElement('div', { | ||
ref: node, | ||
}); | ||
}; | ||
|
||
export default ReactOdometer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "esnext", | ||
"module": "commonjs", | ||
"declaration": true, | ||
"outDir": "./dist", | ||
"strict": true, | ||
"skipLibCheck": true | ||
}, | ||
"include": ["src", "odometer.d.ts"], | ||
"exclude": ["node_modules"], | ||
} |
Oops, something went wrong.