mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-24 15:46:10 +08:00
40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import React from 'react';
|
|
import { Flex, Spin, Switch } from 'antd';
|
|
|
|
const App: React.FC = () => {
|
|
const [auto, setAuto] = React.useState(false);
|
|
const [percent, setPercent] = React.useState(-50);
|
|
const timerRef = React.useRef<ReturnType<typeof setTimeout>>();
|
|
|
|
React.useEffect(() => {
|
|
timerRef.current = setTimeout(() => {
|
|
setPercent((v) => {
|
|
const nextPercent = v + 5;
|
|
return nextPercent > 150 ? -50 : nextPercent;
|
|
});
|
|
}, 100);
|
|
return () => clearTimeout(timerRef.current);
|
|
}, [percent]);
|
|
|
|
const mergedPercent = auto ? 'auto' : percent;
|
|
|
|
return (
|
|
<Flex align="center" gap="middle">
|
|
<Switch
|
|
checkedChildren="Auto"
|
|
unCheckedChildren="Auto"
|
|
checked={auto}
|
|
onChange={() => {
|
|
setAuto(!auto);
|
|
setPercent(-50);
|
|
}}
|
|
/>
|
|
<Spin percent={mergedPercent} size="small" />
|
|
<Spin percent={mergedPercent} />
|
|
<Spin percent={mergedPercent} size="large" />
|
|
</Flex>
|
|
);
|
|
};
|
|
|
|
export default App;
|