-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Placeholder Get Started modal to Singleton
- Loading branch information
H
authored and
H
committed
Jul 19, 2023
1 parent
47b6da1
commit 1cde93b
Showing
2 changed files
with
45 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,63 @@ | ||
import { createContext, useState, useContext } from 'react'; | ||
|
||
import { useDisclosure } from '@chakra-ui/react' | ||
import { Modal, ModalOverlay, ModalContent, ModalHeader, ModalFooter, ModalBody, ModalCloseButton } from '@chakra-ui/react' | ||
import { Text, Icon, Spacer, Button } from '@chakra-ui/react' | ||
|
||
// Create a context | ||
const SingletonContext = createContext(); | ||
|
||
// Create a provider | ||
export function SingletonContextProvider({ children }) { | ||
const [state, setState] = useState('singleton'); | ||
const [state, setState] = useState('singleton'); // dummy example | ||
|
||
const getStartedDisclosure = useDisclosure(); | ||
|
||
// make sure state is only created once | ||
let contextValue = useContext(SingletonContext); | ||
if (!contextValue) { | ||
contextValue = { state, setState }; | ||
contextValue = { state, setState, openGetStartedModal }; | ||
} | ||
|
||
function openGetStartedModal() { | ||
console.log('openGetStartedModal()'); | ||
getStartedDisclosure.onOpen(); | ||
} | ||
|
||
return ( | ||
<SingletonContext.Provider value={contextValue}> | ||
{children} | ||
<GetStartedModal | ||
isOpen={getStartedDisclosure.isOpen} | ||
onOpen={getStartedDisclosure.onOpen} | ||
onClose={getStartedDisclosure.onClose} | ||
/> | ||
</SingletonContext.Provider> | ||
); | ||
} | ||
|
||
// Create a hook to use the SingletonContext, this is just to simplify using the context. | ||
export function useSingletonContext() { | ||
return useContext(SingletonContext); | ||
} | ||
|
||
export function GetStartedModal( {isOpen, onOpen, onClose}) { | ||
return ( | ||
<Modal isOpen={isOpen} onOpen={onOpen} onClose={onClose} size="full"> | ||
<ModalOverlay /> | ||
<ModalContent m={8} borderRadius={16}> | ||
<ModalHeader>Title - Get Started</ModalHeader> | ||
<ModalCloseButton /> | ||
<ModalBody> | ||
<Text>Modal Body</Text> | ||
</ModalBody> | ||
|
||
<ModalFooter> | ||
<Button colorScheme='blue' mr={3} onClick={onClose}> | ||
Close | ||
</Button> | ||
</ModalFooter> | ||
</ModalContent> | ||
</Modal> | ||
) | ||
} |