forked from ant-design/ant-design
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Watermark support nest Modal & Drawer (ant-design#44104)
* docs: add demo * refactor: init * refactor: of it * refactor: simple content * chore: unique func * chore: refactor * chore: support modal watermark * feat: support nest watermark * test: add test case * chore: fix lint * chore: bump rc-image * test: add test case * refactor: use same func
- Loading branch information
Showing
20 changed files
with
571 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { useEvent } from 'rc-util'; | ||
import * as React from 'react'; | ||
|
||
export interface WatermarkContextProps { | ||
add: (ele: HTMLElement) => void; | ||
remove: (ele: HTMLElement) => void; | ||
} | ||
|
||
function voidFunc() {} | ||
|
||
const WatermarkContext = React.createContext<WatermarkContextProps>({ | ||
add: voidFunc, | ||
remove: voidFunc, | ||
}); | ||
|
||
export function usePanelRef(panelSelector?: string) { | ||
const watermark = React.useContext(WatermarkContext); | ||
|
||
const panelEleRef = React.useRef<HTMLElement>(); | ||
const panelRef = useEvent((ele: HTMLElement | null) => { | ||
if (ele) { | ||
const innerContentEle = panelSelector ? ele.querySelector<HTMLElement>(panelSelector)! : ele; | ||
watermark.add(innerContentEle); | ||
panelEleRef.current = innerContentEle; | ||
} else { | ||
watermark.remove(panelEleRef.current!); | ||
} | ||
}); | ||
|
||
return panelRef; | ||
} | ||
|
||
export default WatermarkContext; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## zh-CN | ||
|
||
在 Modal 与 Drawer 中使用。 | ||
|
||
## en-US | ||
|
||
Use in Modal and Drawer. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React from 'react'; | ||
import { Watermark, Modal, Drawer, Button, Space } from 'antd'; | ||
|
||
const placeholder = ( | ||
<div | ||
style={{ | ||
height: 300, | ||
display: 'flex', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
background: 'rgba(150, 150, 150, 0.2)', | ||
}} | ||
> | ||
A mock height | ||
</div> | ||
); | ||
|
||
const App: React.FC = () => { | ||
const [showModal, setShowModal] = React.useState(false); | ||
const [showDrawer, setShowDrawer] = React.useState(false); | ||
|
||
const closeModal = () => setShowModal(false); | ||
const closeDrawer = () => setShowDrawer(false); | ||
|
||
return ( | ||
<> | ||
<Space> | ||
<Button onClick={() => setShowModal(true)}>Show Modal</Button> | ||
<Button onClick={() => setShowDrawer(true)}>Show Drawer</Button> | ||
</Space> | ||
|
||
<Watermark content="Ant Design"> | ||
<Modal | ||
destroyOnClose | ||
open={showModal} | ||
title="Modal" | ||
onCancel={closeModal} | ||
onOk={closeModal} | ||
> | ||
{placeholder} | ||
</Modal> | ||
<Drawer destroyOnClose open={showDrawer} title="Drawer" onClose={closeDrawer}> | ||
{placeholder} | ||
</Drawer> | ||
</Watermark> | ||
</> | ||
); | ||
}; | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.