Skip to content

Commit

Permalink
Added Placeholder Get Started modal to Singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
H authored and H committed Jul 19, 2023
1 parent 47b6da1 commit 1cde93b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/components/Hero.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,15 @@ export const FancyUnderline = ({ className, children, ...props }) => {

export function Hero() {

// const { state, setState } = useSingletonContext();
const { openGetStartedModal } = useSingletonContext();

return (
<Container className="pb-16 pt-20 text-center lg:pt-32">
{/*<h1 onClick={() => {
openGetStartedModal();
}}>
Test Button
</h1>*/}
<h1 className="mx-auto max-w-4xl font-display text-5xl font-medium tracking-tight text-slate-900 sm:text-7xl">
The {" "}
<span className="relative whitespace-nowrap">
Expand Down
41 changes: 39 additions & 2 deletions src/pages/SingletonContextProvider.jsx
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>
)
}

0 comments on commit 1cde93b

Please sign in to comment.