mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 19:19:57 +08:00
c5bed69883
* feat: notification stack * feat: notification support stack * docs: add demo * fix: message animation * chore: better imports * test: fix pure panel * feat: code optimize * chore: update snapshot * chore: update test case * test: update test * chore: update deps * chore: bump rc-notification * feat: add backdrop filter * chore * feat: add token colorBgBlur * chore: bump * feat: update colorBgBlur in dark mode * fix: compatible with safari --------- Signed-off-by: MadCcc <1075746765@qq.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: `${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;
|