Skip to content

Commit 06e0622

Browse files
committed
publish 0.0.1
0 parents  commit 06e0622

File tree

15 files changed

+3414
-0
lines changed

15 files changed

+3414
-0
lines changed

.github/workflows/npm-publish.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: npm publish
2+
3+
on:
4+
workflow_dispatch: # 允许手动触发工作流,默认是不开启的
5+
push: # 当有代码推送到仓库时触发
6+
branches:
7+
- main
8+
9+
jobs:
10+
build: # 工作流程中的一个作业
11+
runs-on: ubuntu-latest # 指定运行作业的虚拟环境
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
- name: Set up Node.js
16+
uses: actions/setup-node@v4
17+
with:
18+
node-version: 20
19+
registry-url: https://registry.npmjs.org/
20+
- name: enable pnpm
21+
run: corepack enable
22+
- name: install Dependencies
23+
run: |
24+
ls -al
25+
pnpm i
26+
pnpm build
27+
- name: Publish to NPM
28+
run: npm publish
29+
env:
30+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
registry=https://registry.npmjs.org/

.prettierrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"printWidth": 120,
3+
"tabWidth": 4,
4+
"useTabs": false,
5+
"singleQuote": true,
6+
"trailingComma": "all"
7+
}

README.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# React Number Animation
2+
3+
一个用于数字动画过渡的 React 组件库,提供了两种组件:`AnimatedNumber``Statistic`
4+
5+
## 安装
6+
7+
```bash
8+
npm install react-number-animation
9+
#
10+
yarn add react-number-animation
11+
```
12+
13+
## 使用方法
14+
15+
### AnimatedNumber
16+
17+
一个简单的数字动画组件,支持数字的上下滑动过渡效果。
18+
19+
```tsx
20+
import { AnimatedNumber } from 'react-number-animation';
21+
22+
function App() {
23+
const [value, setValue] = useState(0);
24+
25+
return (
26+
<div>
27+
<AnimatedNumber value={value} className="text-4xl" />
28+
<button onClick={() => setValue((v) => v + 1)}>增加</button>
29+
<button onClick={() => setValue((v) => v - 1)}>减少</button>
30+
</div>
31+
);
32+
}
33+
```
34+
35+
### Statistic
36+
37+
一个统计数字组件,支持数字的平滑过渡动画,以及格式化选项。
38+
39+
```tsx
40+
import { Statistic } from 'react-number-animation';
41+
42+
function App() {
43+
return (
44+
<div>
45+
{/* 基础用法 */}
46+
<Statistic value={14.56} title="销售额" prefix="¥" />
47+
48+
{/* 带小数点的用法 */}
49+
<Statistic value={1234.56} decimals={2} title="增长率" suffix="%" />
50+
51+
{/* 自定义格式化 */}
52+
<Statistic
53+
value={1234567}
54+
separator=" " // 使用空格作为千位分隔符
55+
title="访问量"
56+
suffix=""
57+
/>
58+
59+
{/* 不使用分组 */}
60+
<Statistic value={123} useGrouping={false} title="ID" />
61+
</div>
62+
);
63+
}
64+
```
65+
66+
## Props
67+
68+
### AnimatedNumber
69+
70+
| 属性名 | 类型 | 默认值 | 说明 |
71+
| --------- | ------ | ------ | ------------ |
72+
| value | number | - | 要显示的数字 |
73+
| className | string | "" | 自定义类名 |
74+
75+
### Statistic
76+
77+
| 属性名 | 类型 | 默认值 | 说明 |
78+
| ----------- | --------- | ------ | -------------------- |
79+
| value | number | - | 要显示的数字 |
80+
| title | ReactNode | - | 标题 |
81+
| prefix | ReactNode | - | 前缀 |
82+
| suffix | ReactNode | - | 后缀 |
83+
| className | string | "" | 自定义类名 |
84+
| duration | number | 2000 | 动画持续时间(毫秒) |
85+
| decimals | number | 0 | 小数位数 |
86+
| separator | string | "," | 千位分隔符 |
87+
| decimal | string | "." | 小数点符号 |
88+
| useGrouping | boolean | true | 是否使用千位分组 |
89+
90+
## 开发
91+
92+
```bash
93+
# 安装依赖
94+
npm install
95+
96+
# 构建
97+
npm run build
98+
99+
# 测试
100+
npm test
101+
```
102+
103+
## License
104+
105+
MIT

eslint.config.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import js from '@eslint/js';
2+
import globals from 'globals';
3+
import reactHooks from 'eslint-plugin-react-hooks';
4+
import reactRefresh from 'eslint-plugin-react-refresh';
5+
import tseslint from 'typescript-eslint';
6+
7+
import eslintConfigPrettier from 'eslint-config-prettier/flat';
8+
9+
export default tseslint.config(
10+
{ ignores: ['dist'] },
11+
{
12+
extends: [js.configs.recommended, ...tseslint.configs.recommended],
13+
files: ['**/*.{ts,tsx}'],
14+
languageOptions: {
15+
ecmaVersion: 2020,
16+
globals: globals.browser,
17+
},
18+
plugins: {
19+
'react-hooks': reactHooks,
20+
'react-refresh': reactRefresh,
21+
},
22+
rules: {
23+
...reactHooks.configs.recommended.rules,
24+
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
25+
},
26+
},
27+
eslintConfigPrettier,
28+
);

package.json

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"name": "@coderlzw/react-number-animation",
3+
"version": "0.0.1",
4+
"description": "A React component for animated number transitions with smooth animations and customizable options",
5+
"type": "module",
6+
"main": "./dist/index.js",
7+
"module": "./dist/index.mjs",
8+
"types": "./dist/index.d.ts",
9+
"exports": {
10+
".": {
11+
"types": "./dist/index.d.ts",
12+
"import": "./dist/index.mjs",
13+
"require": "./dist/index.js"
14+
}
15+
},
16+
"files": [
17+
"dist"
18+
],
19+
"publishConfig": {
20+
"access": "public"
21+
},
22+
"scripts": {
23+
"build": "tsup",
24+
"dev": "tsup --watch",
25+
"lint": "eslint --fix src/**/*.ts",
26+
"lint:check": "eslint src/**/*.ts",
27+
"format": "prettier --write src/**/*.ts",
28+
"format:check": "prettier --check src/**/*.ts"
29+
},
30+
"repository": {
31+
"type": "git",
32+
"url": "https://github.com/coderlzw/react-number-animation"
33+
},
34+
"bugs": {
35+
"url": "https://github.com/coderlzw/react-number-animation/issues"
36+
},
37+
"homepage": "https://github.com/coderlzw/react-number-animation#readme",
38+
"keywords": [
39+
"react",
40+
"animation",
41+
"number",
42+
"statistic",
43+
"transition"
44+
],
45+
"author": "coderlzw",
46+
"license": "MIT",
47+
"peerDependencies": {
48+
"react": ">=16.8.0",
49+
"react-dom": ">=16.8.0"
50+
},
51+
"dependencies": {
52+
"motion": "^12.12.1"
53+
},
54+
"devDependencies": {
55+
"@eslint/js": "^9.25.0",
56+
"@types/react": "^18.0.0",
57+
"@types/react-dom": "^18.0.0",
58+
"eslint": "^9.25.0",
59+
"eslint-config-prettier": "^10.1.5",
60+
"eslint-plugin-react-hooks": "^5.2.0",
61+
"eslint-plugin-react-refresh": "^0.4.19",
62+
"globals": "^16.1.0",
63+
"prettier": "3.5.3",
64+
"tsup": "^8.5.0",
65+
"typescript": "^5.0.0",
66+
"typescript-eslint": "^8.32.1"
67+
}
68+
}

0 commit comments

Comments
 (0)