Skip to content

Commit 25a7652

Browse files
committed
docs(statistic): add formatter and value style demos
1 parent 94affee commit 25a7652

3 files changed

Lines changed: 68 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<demo>
2+
3+
### Custom Formatter
4+
5+
Use `formatter` to fully customize the value display.
6+
7+
```jsx live
8+
() => {
9+
return (
10+
<div style={{ display: 'flex', gap: '48px' }}>
11+
<Statistic
12+
title="Countdown"
13+
value={Date.now() + 86400000}
14+
formatter={(val) => {
15+
const diff = Math.max(0, Math.floor((Number(val) - Date.now()) / 3600000));
16+
return `${diff}h remaining`;
17+
}}
18+
/>
19+
<Statistic
20+
title="Score"
21+
value={9.8}
22+
formatter={(val) => <span style={{ color: '#52c41a' }}>{val} / 10</span>}
23+
/>
24+
</div>
25+
);
26+
}
27+
```
28+
29+
</demo>

components/statistic/demo/style.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<demo>
2+
3+
### Value Style
4+
5+
Customize value appearance with `valueStyle` and `groupSeparator`.
6+
7+
```jsx live
8+
() => {
9+
return (
10+
<div style={{ display: 'flex', gap: '48px' }}>
11+
<Statistic
12+
title="Revenue"
13+
value={1128930}
14+
prefix="$"
15+
valueStyle={{ color: '#52c41a' }}
16+
/>
17+
<Statistic
18+
title="Loss"
19+
value={93120}
20+
prefix="$"
21+
valueStyle={{ color: '#f5222d' }}
22+
/>
23+
<Statistic
24+
title="No Separator"
25+
value={9999999}
26+
groupSeparator=""
27+
/>
28+
</div>
29+
);
30+
}
31+
```
32+
33+
</demo>

components/statistic/index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import Basic from './demo/basic.md'
2+
import Formatter from './demo/formatter.md'
3+
import Style from './demo/style.md'
24

35
# Statistic
46

@@ -19,6 +21,10 @@ import { Statistic } from 'tiny-ui';
1921
<layout>
2022
<column>
2123
<Basic/>
24+
<Formatter/>
25+
</column>
26+
<column>
27+
<Style/>
2228
</column>
2329
</layout>
2430

0 commit comments

Comments
 (0)