ant-design/components/badge/demo/change.tsx
Guo Yunhe d98b0c0210
feat(Button): deprecate Button.Group, prefer Space.Compact (#52572)
* feat(Button): deprecate Button.Group, prefer Space.Compact

* test: update snap

---------

Signed-off-by: afc163 <afc163@gmail.com>
Co-authored-by: afc163 <afc163@gmail.com>
Co-authored-by: thinkasany <480968828@qq.com>
2025-01-26 13:51:40 +08:00

53 lines
1.3 KiB
TypeScript

import React, { useState } from 'react';
import { MinusOutlined, PlusOutlined, QuestionOutlined } from '@ant-design/icons';
import { Avatar, Badge, Button, Space, Switch } from 'antd';
const App: React.FC = () => {
const [count, setCount] = useState(5);
const [show, setShow] = useState(true);
const increase = () => {
setCount(count + 1);
};
const decline = () => {
let newCount = count - 1;
if (newCount < 0) {
newCount = 0;
}
setCount(newCount);
};
const random = () => {
const newCount = Math.floor(Math.random() * 100);
setCount(newCount);
};
const onChange = (checked: boolean) => {
setShow(checked);
};
return (
<Space direction="vertical">
<Space size="large">
<Badge count={count}>
<Avatar shape="square" size="large" />
</Badge>
<Space.Compact>
<Button onClick={decline} icon={<MinusOutlined />} />
<Button onClick={increase} icon={<PlusOutlined />} />
<Button onClick={random} icon={<QuestionOutlined />} />
</Space.Compact>
</Space>
<Space size="large">
<Badge dot={show}>
<Avatar shape="square" size="large" />
</Badge>
<Switch onChange={onChange} checked={show} />
</Space>
</Space>
);
};
export default App;