-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
131d80d
commit 75c9e69
Showing
8 changed files
with
219 additions
and
12 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,107 @@ | ||
import useEscClose from 'hooks/useEscKey'; | ||
import styled from 'styled-components'; | ||
import { media } from 'utils/media'; | ||
import Button from './Button'; | ||
import CloseIcon from './CloseIcon'; | ||
import Container from './Container'; | ||
import Input from './Input'; | ||
import Overlay from './Overlay'; | ||
|
||
export interface NewsletterModalProps { | ||
onClose: () => void; | ||
} | ||
|
||
export default function NewsletterModal({ onClose }: NewsletterModalProps) { | ||
useEscClose({ onClose }); | ||
|
||
return ( | ||
<Overlay> | ||
<Container> | ||
<Card> | ||
<CloseIconContainer> | ||
<CloseIcon onClick={onClose} /> | ||
</CloseIconContainer> | ||
<Title>Are you ready to enroll to the best newsletter ever?</Title> | ||
<Row> | ||
<CustomInput placeholder="Enter your email..." /> | ||
<CustomButton>Submit</CustomButton> | ||
</Row> | ||
</Card> | ||
</Container> | ||
</Overlay> | ||
); | ||
} | ||
|
||
const Card = styled.div` | ||
display: flex; | ||
position: relative; | ||
flex-direction: column; | ||
margin: auto; | ||
padding: 10rem 5rem; | ||
background: rgb(var(--modalBackground)); | ||
border-radius: 0.6rem; | ||
max-width: 70rem; | ||
overflow: hidden; | ||
${media('<=tablet')} { | ||
padding: 7.5rem 2.5rem; | ||
} | ||
`; | ||
|
||
const CloseIconContainer = styled.div` | ||
position: absolute; | ||
right: 2rem; | ||
top: 2rem; | ||
svg { | ||
cursor: pointer; | ||
width: 2rem; | ||
} | ||
`; | ||
|
||
const Title = styled.div` | ||
font-size: 3.2rem; | ||
font-weight: bold; | ||
line-height: 1.1; | ||
letter-spacing: -0.03em; | ||
text-align: center; | ||
color: rgb(var(--text)); | ||
${media('<=tablet')} { | ||
font-size: 2.6rem; | ||
} | ||
`; | ||
|
||
const Row = styled.div` | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100%; | ||
width: 100%; | ||
margin-top: 3rem; | ||
${media('<=tablet')} { | ||
flex-direction: column; | ||
} | ||
`; | ||
|
||
const CustomButton = styled(Button)` | ||
height: 100%; | ||
padding: 1.8rem; | ||
margin-left: 1.5rem; | ||
box-shadow: var(--shadow-lg); | ||
${media('<=tablet')} { | ||
width: 100%; | ||
margin-left: 0; | ||
margin-top: 1rem; | ||
} | ||
`; | ||
|
||
const CustomInput = styled(Input)` | ||
width: 60%; | ||
${media('<=tablet')} { | ||
width: 100%; | ||
} | ||
`; |
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,15 @@ | ||
import styled from 'styled-components'; | ||
|
||
const Overlay = styled.div` | ||
position: fixed; | ||
inset: 0; | ||
background: rgba(var(--secondary), 0.997); | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
z-index: var(--z-modal); | ||
color: rgb(var(--textSecondary)); | ||
`; | ||
|
||
export default Overlay; |
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,31 @@ | ||
import React, { Dispatch, PropsWithChildren, SetStateAction, useContext, useState } from 'react'; | ||
|
||
interface NewsletterModalContextProps { | ||
isModalOpened: boolean; | ||
setIsModalOpened: Dispatch<SetStateAction<boolean>>; | ||
} | ||
|
||
export const NewsletterModalContext = React.createContext<NewsletterModalContextProps | null>(null); | ||
|
||
export function NewsletterModalContextProvider<T>({ children }: PropsWithChildren<T>) { | ||
const [isModalOpened, setIsModalOpened] = useState(false); | ||
|
||
return ( | ||
<NewsletterModalContext.Provider | ||
value={{ | ||
isModalOpened, | ||
setIsModalOpened, | ||
}} | ||
> | ||
{children} | ||
</NewsletterModalContext.Provider> | ||
); | ||
} | ||
|
||
export function useNewsletterModalContext() { | ||
const context = useContext(NewsletterModalContext); | ||
if (!context) { | ||
throw new Error('useNewsletterModalContext can only be used inside NewsletterModalContextProvider'); | ||
} | ||
return context; | ||
} |
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,25 @@ | ||
import { useCallback, useEffect } from 'react'; | ||
|
||
export interface UseEscCloseProps { | ||
onClose: () => void; | ||
} | ||
|
||
export default function useEscClose({ onClose }: UseEscCloseProps) { | ||
const handleUserKeyPress = useCallback( | ||
(event) => { | ||
const { keyCode } = event; | ||
const escapeKeyCode = 27; | ||
if (keyCode === escapeKeyCode) { | ||
onClose(); | ||
} | ||
}, | ||
[onClose], | ||
); | ||
|
||
useEffect(() => { | ||
window.addEventListener('keydown', handleUserKeyPress); | ||
return () => { | ||
window.removeEventListener('keydown', handleUserKeyPress); | ||
}; | ||
}, [handleUserKeyPress]); | ||
} |
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
75c9e69
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
next-saas-starter – ./
next-saas-starter-git-master-blazity.vercel.app
next-saas-starter-blazity.vercel.app
next-saas-starter-ashy.vercel.app