mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-19 03:54:28 +08:00
863f61d908
Co-authored-by: afc163 <afc163@gmail.com>
60 lines
1.6 KiB
TypeScript
60 lines
1.6 KiB
TypeScript
import React, { useMemo } from 'react';
|
|
import { Button, Divider, InputNumber, notification, Space, Switch } from 'antd';
|
|
|
|
const Context = React.createContext({ name: 'Default' });
|
|
|
|
const App: React.FC = () => {
|
|
const [enabled, setEnabled] = React.useState(true);
|
|
const [threshold, setThreshold] = React.useState(3);
|
|
const [api, contextHolder] = notification.useNotification({
|
|
stack: enabled
|
|
? {
|
|
threshold,
|
|
}
|
|
: false,
|
|
});
|
|
|
|
const openNotification = () => {
|
|
api.open({
|
|
message: 'Notification Title',
|
|
description: `${new Array(Math.round(Math.random() * 5) + 1)
|
|
.fill('This is the content of the notification.')
|
|
.join('\n')}`,
|
|
duration: null,
|
|
});
|
|
};
|
|
|
|
const contextValue = useMemo(() => ({ name: 'Ant Design' }), []);
|
|
|
|
return (
|
|
<Context.Provider value={contextValue}>
|
|
{contextHolder}
|
|
<div>
|
|
<Space size="large">
|
|
<Space style={{ width: '100%' }}>
|
|
<span>Enabled: </span>
|
|
<Switch checked={enabled} onChange={(v) => setEnabled(v)} />
|
|
</Space>
|
|
<Space style={{ width: '100%' }}>
|
|
<span>Threshold: </span>
|
|
<InputNumber
|
|
disabled={!enabled}
|
|
value={threshold}
|
|
step={1}
|
|
min={1}
|
|
max={10}
|
|
onChange={(v) => setThreshold(v || 0)}
|
|
/>
|
|
</Space>
|
|
</Space>
|
|
<Divider />
|
|
<Button type="primary" onClick={openNotification}>
|
|
Open the notification box
|
|
</Button>
|
|
</div>
|
|
</Context.Provider>
|
|
);
|
|
};
|
|
|
|
export default App;
|