mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-21 13:18:04 +08:00
b072d3a02c
* docs: move demo to useModal * docs: reorder * chore: update ts def * test: test case * chore: fix compile
64 lines
1.6 KiB
TypeScript
64 lines
1.6 KiB
TypeScript
import React, { createContext } from 'react';
|
|
import { Button, Modal, Space } from 'antd';
|
|
|
|
const ReachableContext = createContext<string | null>(null);
|
|
const UnreachableContext = createContext<string | null>(null);
|
|
|
|
const config = {
|
|
title: 'Use Hook!',
|
|
content: (
|
|
<>
|
|
<ReachableContext.Consumer>{(name) => `Reachable: ${name}!`}</ReachableContext.Consumer>
|
|
<br />
|
|
<UnreachableContext.Consumer>{(name) => `Unreachable: ${name}!`}</UnreachableContext.Consumer>
|
|
</>
|
|
),
|
|
};
|
|
|
|
const App: React.FC = () => {
|
|
const [modal, contextHolder] = Modal.useModal();
|
|
|
|
return (
|
|
<ReachableContext.Provider value="Light">
|
|
<Space>
|
|
<Button
|
|
onClick={async () => {
|
|
const confirmed = await modal.confirm(config);
|
|
console.log('Confirmed: ', confirmed);
|
|
}}
|
|
>
|
|
Confirm
|
|
</Button>
|
|
<Button
|
|
onClick={() => {
|
|
modal.warning(config);
|
|
}}
|
|
>
|
|
Warning
|
|
</Button>
|
|
<Button
|
|
onClick={async () => {
|
|
modal.info(config);
|
|
}}
|
|
>
|
|
Info
|
|
</Button>
|
|
<Button
|
|
onClick={async () => {
|
|
modal.error(config);
|
|
}}
|
|
>
|
|
Error
|
|
</Button>
|
|
</Space>
|
|
{/* `contextHolder` should always be placed under the context you want to access */}
|
|
{contextHolder}
|
|
|
|
{/* Can not access this context since `contextHolder` is not in it */}
|
|
<UnreachableContext.Provider value="Bamboo" />
|
|
</ReachableContext.Provider>
|
|
);
|
|
};
|
|
|
|
export default App;
|