mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-12 07:09:55 +08:00
34a277cdaa
* docs: delete redundant codes repetitive examples that can make it difficult for developers to read * chore: update snapshot * docs(badge): wrapping documents with `Space` * chore: update snapshot * chore(space): optimize documents easy to read * chore: update badge demo * chore: update demo * Revert "chore(space): optimize documents" This reverts commit 88a4378f16cede5b628f885a48a341d507fd53e3. * chore: update snapshots * chore(button): add debug demo * test(button): update snapshots * docs(button): example document beautify * test(button): update snapshots commit by af04705c8f * test(alert): update snapshots * chore: Reverse format
55 lines
1.3 KiB
TypeScript
55 lines
1.3 KiB
TypeScript
import React, { useState } from 'react';
|
|
import { MinusOutlined, PlusOutlined, QuestionOutlined } from '@ant-design/icons';
|
|
import { Avatar, Badge, Button, Switch, Space } from 'antd';
|
|
|
|
const ButtonGroup = Button.Group;
|
|
|
|
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>
|
|
<ButtonGroup>
|
|
<Button onClick={decline} icon={<MinusOutlined />} />
|
|
<Button onClick={increase} icon={<PlusOutlined />} />
|
|
<Button onClick={random} icon={<QuestionOutlined />} />
|
|
</ButtonGroup>
|
|
</Space>
|
|
<Space size="large">
|
|
<Badge dot={show}>
|
|
<Avatar shape="square" size="large" />
|
|
</Badge>
|
|
<Switch onChange={onChange} checked={show} />
|
|
</Space>
|
|
</Space>
|
|
);
|
|
};
|
|
|
|
export default App;
|