mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-22 03:22:31 +08:00

* feat: add reverse for countdown * refactor var * remove unuse logic * feat: support timer component * revert delete countdown * Update components/statistic/utils.ts Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com> Signed-off-by: mr-chenguang <37072324+lcgash@users.noreply.github.com> * update snapshots * refactor countdown * fix md * fix test:site * fix: deprecated & refactor * refactor * add version * refactor: inline of effect * test: update test case * test: back of part * test: back of part * test: back of part * add tests & fix md * fix md& add devusewarnning * fix warning and add test * remove console * remove countdown md --------- Signed-off-by: mr-chenguang <37072324+lcgash@users.noreply.github.com> Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com> Co-authored-by: 二货机器人 <smith3816@gmail.com>
59 lines
1.5 KiB
TypeScript
59 lines
1.5 KiB
TypeScript
import React from 'react';
|
|
import type { StatisticTimerProps } from 'antd';
|
|
import { Col, Row, Statistic } from 'antd';
|
|
|
|
const { Timer } = Statistic;
|
|
|
|
const deadline = Date.now() + 1000 * 60 * 60 * 24 * 2 + 1000 * 30; // Dayjs is also OK
|
|
const before = Date.now() - 1000 * 60 * 60 * 24 * 2 + 1000 * 30;
|
|
|
|
const onFinish: StatisticTimerProps['onFinish'] = () => {
|
|
console.log('finished!');
|
|
};
|
|
|
|
const onChange: StatisticTimerProps['onChange'] = (val) => {
|
|
if (typeof val === 'number' && 4.95 * 1000 < val && val < 5 * 1000) {
|
|
console.log('changed!');
|
|
}
|
|
};
|
|
|
|
const App: React.FC = () => (
|
|
<Row gutter={16}>
|
|
<Col span={12}>
|
|
<Timer type="countdown" value={deadline} onFinish={onFinish} />
|
|
</Col>
|
|
<Col span={12}>
|
|
<Timer type="countdown" title="Million Seconds" value={deadline} format="HH:mm:ss:SSS" />
|
|
</Col>
|
|
<Col span={12}>
|
|
<Timer
|
|
type="countdown"
|
|
title="Countdown"
|
|
value={Date.now() + 10 * 1000}
|
|
onChange={onChange}
|
|
/>
|
|
</Col>
|
|
<Col span={12}>
|
|
<Timer type="countup" title="Countup" value={before} onChange={onChange} />
|
|
</Col>
|
|
<Col span={24} style={{ marginTop: 32 }}>
|
|
<Timer
|
|
type="countdown"
|
|
title="Day Level (Countdown)"
|
|
value={deadline}
|
|
format="D 天 H 时 m 分 s 秒"
|
|
/>
|
|
</Col>
|
|
<Col span={24} style={{ marginTop: 32 }}>
|
|
<Timer
|
|
type="countup"
|
|
title="Day Level (Countup)"
|
|
value={before}
|
|
format="D 天 H 时 m 分 s 秒"
|
|
/>
|
|
</Col>
|
|
</Row>
|
|
);
|
|
|
|
export default App;
|