ant-design/components/spin/demo/percent.tsx

40 lines
1.0 KiB
TypeScript
Raw Normal View History

import React from 'react';
2024-07-07 17:44:21 +08:00
import { Flex, Spin, Switch } from 'antd';
const App: React.FC = () => {
const [auto, setAuto] = React.useState(false);
const [percent, setPercent] = React.useState(-50);
2024-07-07 17:44:21 +08:00
const timerRef = React.useRef<ReturnType<typeof setTimeout>>();
React.useEffect(() => {
2024-07-07 17:44:21 +08:00
timerRef.current = setTimeout(() => {
setPercent((v) => {
const nextPercent = v + 5;
return nextPercent > 150 ? -50 : nextPercent;
});
}, 100);
2024-07-07 17:44:21 +08:00
return () => clearTimeout(timerRef.current);
}, [percent]);
const mergedPercent = auto ? 'auto' : percent;
return (
2024-07-07 17:44:21 +08:00
<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" />
2024-07-07 17:44:21 +08:00
</Flex>
);
};
export default App;