-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #724 from smartxworks/feat/remove-component
feat(Editor): not allowed to remove component that is used by others
- Loading branch information
Showing
4 changed files
with
79 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React, { useCallback, useState } from 'react'; | ||
import { | ||
Modal, | ||
ModalOverlay, | ||
ModalContent, | ||
ModalHeader, | ||
ModalCloseButton, | ||
ModalBody, | ||
ModalFooter, | ||
Button, | ||
useDisclosure, | ||
} from '@chakra-ui/react'; | ||
|
||
export type OpenOptions = { | ||
title?: string; | ||
message?: string; | ||
}; | ||
|
||
function useModal() { | ||
const { isOpen, onOpen, onClose } = useDisclosure(); | ||
const [options, setOptions] = useState<Partial<OpenOptions>>({}); | ||
const { title, message } = options; | ||
const open = useCallback( | ||
(options: OpenOptions) => { | ||
setOptions(options); | ||
onOpen(); | ||
}, | ||
[onOpen] | ||
); | ||
|
||
const modal = ( | ||
<Modal onClose={onClose} size="md" isOpen={isOpen}> | ||
<ModalOverlay /> | ||
<ModalContent> | ||
{title ? <ModalHeader>{title}</ModalHeader> : null} | ||
<ModalCloseButton /> | ||
<ModalBody>{message}</ModalBody> | ||
<ModalFooter> | ||
<Button onClick={onClose}>Close</Button> | ||
</ModalFooter> | ||
</ModalContent> | ||
</Modal> | ||
); | ||
|
||
return { | ||
modal, | ||
open, | ||
close: onClose, | ||
}; | ||
} | ||
|
||
export default useModal; |