-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: refine usePortalManager example
- Loading branch information
Showing
2 changed files
with
61 additions
and
46 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
packages/react-docs/pages/components/portal-manager/usePortalManager.js
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,60 @@ | ||
import { | ||
Button, | ||
Modal, | ||
ModalBody, | ||
ModalContent, | ||
ModalFooter, | ||
ModalHeader, | ||
ModalOverlay, | ||
usePortalManager, | ||
} from '@tonic-ui/react'; | ||
import React, { forwardRef, useCallback } from 'react'; | ||
|
||
const MyModal = forwardRef(( | ||
{ | ||
onClose, | ||
...rest | ||
}, | ||
ref, | ||
) => ( | ||
<Modal | ||
closeOnEsc | ||
closeOnOutsideClick | ||
isOpen | ||
onClose={onClose} | ||
size="sm" | ||
{...rest} | ||
> | ||
<ModalOverlay /> | ||
<ModalContent> | ||
<ModalHeader> | ||
Modal Header | ||
</ModalHeader> | ||
<ModalBody> | ||
Modal Body | ||
</ModalBody> | ||
<ModalFooter> | ||
<Button onClick={onClose}>Close</Button> | ||
</ModalFooter> | ||
</ModalContent> | ||
</Modal> | ||
)); | ||
|
||
MyModal.displayName = 'MyModal'; | ||
|
||
const App = () => { | ||
const portal = usePortalManager(); | ||
const openModal = useCallback(() => { | ||
portal((close) => ( | ||
<MyModal onClose={close} /> | ||
)); | ||
}, [portal]); | ||
|
||
return ( | ||
<Button onClick={openModal}> | ||
Open Modal | ||
</Button> | ||
); | ||
}; | ||
|
||
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