Skip to content

Commit c5a0626

Browse files
committed
update README.md
1 parent 06e0622 commit c5a0626

File tree

1 file changed

+87
-63
lines changed

1 file changed

+87
-63
lines changed

README.md

Lines changed: 87 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,129 @@
1-
# React Number Animation
1+
# @coderlzw/react-number-animation
22

3-
一个用于数字动画过渡的 React 组件库,提供了两种组件:`AnimatedNumber``Statistic`
3+
一个用于数字动画过渡的 React 组件库,提供了两种不同的数字动画效果
44

55
## 安装
66

77
```bash
8-
npm install react-number-animation
8+
npm install @coderlzw/react-number-animation
99
#
10-
yarn add react-number-animation
10+
yarn add @coderlzw/react-number-animation
11+
#
12+
pnpm add @coderlzw/react-number-animation
1113
```
1214

13-
## 使用方法
15+
## 组件
1416

15-
### AnimatedNumber
17+
### Statistic
18+
19+
一个带有标题、前缀和后缀的统计数字组件,支持数字格式化和平滑过渡动画。
20+
21+
#### 属性
1622

17-
一个简单的数字动画组件,支持数字的上下滑动过渡效果。
23+
| 属性名 | 类型 | 默认值 | 描述 |
24+
|--------|------|--------|------|
25+
| value | number | - | 要显示的数字值 |
26+
| title | React.ReactNode | - | 统计数字的标题 |
27+
| prefix | React.ReactNode | - | 数字前缀 |
28+
| suffix | React.ReactNode | - | 数字后缀 |
29+
| className | string | '' | 自定义类名 |
30+
| duration | number | 2000 | 动画持续时间(毫秒) |
31+
| decimals | number | 0 | 小数位数 |
32+
| separator | string | ',' | 千位分隔符 |
33+
| decimal | string | '.' | 小数点符号 |
34+
| useGrouping | boolean | true | 是否使用千位分组 |
35+
36+
#### 示例
1837

1938
```tsx
20-
import { AnimatedNumber } from 'react-number-animation';
39+
import { Statistic } from '@coderlzw/react-number-animation';
2140

2241
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-
);
42+
return (
43+
<Statistic
44+
value={1234567.89}
45+
title="总销售额"
46+
prefix="$"
47+
suffix=""
48+
decimals={2}
49+
duration={1500}
50+
/>
51+
);
3252
}
3353
```
3454

35-
### Statistic
55+
### AnimatedNumber
56+
57+
一个纯数字动画组件,支持数字的上下滚动动画效果。
58+
59+
#### 属性
3660

37-
一个统计数字组件,支持数字的平滑过渡动画,以及格式化选项。
61+
| 属性名 | 类型 | 默认值 | 描述 |
62+
|--------|------|--------|------|
63+
| value | number | - | 要显示的数字值 |
64+
| className | string | '' | 自定义类名 |
65+
66+
#### 示例
3867

3968
```tsx
40-
import { Statistic } from 'react-number-animation';
69+
import { AnimatedNumber } from '@coderlzw/react-number-animation';
4170

4271
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-
);
72+
return (
73+
<AnimatedNumber
74+
value={1234}
75+
className="custom-animation"
76+
/>
77+
);
6378
}
6479
```
6580

66-
## Props
81+
## 样式
6782

68-
### AnimatedNumber
83+
组件使用原生 CSS 进行样式设置,你可以通过自定义类名来覆盖默认样式。
6984

70-
| 属性名 | 类型 | 默认值 | 说明 |
71-
| --------- | ------ | ------ | ------------ |
72-
| value | number | - | 要显示的数字 |
73-
| className | string | "" | 自定义类名 |
85+
### Statistic 样式类
7486

75-
### Statistic
87+
- `.statistic`: 统计组件容器
88+
- `.statistic-title`: 标题样式
89+
- `.statistic-content`: 内容容器
90+
- `.statistic-prefix`: 前缀样式
91+
- `.statistic-suffix`: 后缀样式
92+
- `.statistic-value`: 数值样式
93+
94+
### AnimatedNumber 样式类
95+
96+
- `.animated-number`: 动画数字容器
97+
- `.digit-container`: 单个数字容器
7698

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 | 是否使用千位分组 |
99+
## 特性
100+
101+
- 🎯 高性能:使用 React.memo 优化渲染
102+
- 🎨 可定制:支持自定义样式和动画参数
103+
- 📦 轻量级:无额外依赖(除了 motion 库)
104+
- 🎭 平滑动画:使用 easeOutExpo 缓动函数
105+
- 🔢 数字格式化:支持千位分隔和小数点设置
106+
107+
## 浏览器支持
108+
109+
- Chrome >= 60
110+
- Firefox >= 60
111+
- Safari >= 12
112+
- Edge >= 79
89113

90114
## 开发
91115

92116
```bash
93117
# 安装依赖
94118
npm install
95119

120+
# 开发模式
121+
npm run dev
122+
96123
# 构建
97124
npm run build
98-
99-
# 测试
100-
npm test
101125
```
102126

103-
## License
127+
## 许可证
104128

105129
MIT

0 commit comments

Comments
 (0)