Skip to content

Commit a42a312

Browse files
committed
refactor the Modal component and improve Auth Modal
1 parent 2a23308 commit a42a312

7 files changed

Lines changed: 90 additions & 53 deletions

File tree

src/assets/App.css

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,29 +1406,37 @@ Modal
14061406
.modalHeader {
14071407
display: flex;
14081408
flex-direction: row;
1409+
align-items: center;
14091410
justify-content: space-between;
14101411
margin-bottom: 16px;
1412+
position: relative;
14111413
}
14121414

14131415
.modalTitle {
14141416
margin: 0;
14151417
padding: 0;
14161418
color: var(--primary-text-color);
1419+
font-size: 1.3em;
1420+
display: inline-flex;
1421+
width: 100%;
1422+
column-gap: 8px;
1423+
align-items: center;
14171424
}
14181425
.modalCloseBtn {
14191426
align-items: center;
1427+
position: absolute;
14201428
background-color: transparent;
14211429
border-radius: 50%;
1430+
top: 0;
1431+
right: 0;
14221432
border: none;
14231433
color: var(--primary-text-color);
14241434
cursor: pointer;
14251435
display: flex;
1426-
height: 40px;
14271436
justify-content: center;
14281437
margin: 0;
14291438
padding: 0;
14301439
text-align: center;
1431-
width: 40px;
14321440
}
14331441
.modalCloseBtn:hover {
14341442
opacity: 0.7;

src/components/Elements/Button/Button.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ button.small {
2222
font-size: 0.875rem;
2323
}
2424
button.medium {
25-
padding: 0.5rem 1rem;
26-
font-size: 1rem;
25+
padding: 0.75rem 1.2rem;
26+
font-size: 1.1rem;
2727
}
2828
button.large {
2929
padding: 1rem 2rem;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import clsx from 'clsx'
2+
import { VscClose } from 'react-icons/vsc'
3+
import ReactModal from 'react-modal'
4+
type ModalProps = {
5+
showModal: boolean
6+
onClose: () => void
7+
className?: string
8+
header: {
9+
title: string
10+
className?: string
11+
icon?: React.ReactNode
12+
}
13+
children: React.ReactNode
14+
}
15+
export const Modal = ({ showModal, className, header, onClose, children }: ModalProps) => {
16+
return (
17+
<ReactModal
18+
isOpen={showModal}
19+
ariaHideApp={false}
20+
shouldCloseOnEsc={true}
21+
shouldCloseOnOverlayClick={true}
22+
shouldFocusAfterRender={false}
23+
onRequestClose={onClose}
24+
className={clsx('Modal', className)}
25+
style={{
26+
overlay: {
27+
zIndex: 3,
28+
},
29+
}}
30+
overlayClassName="Overlay">
31+
<div>
32+
<header className="modalHeader">
33+
<h1 className={clsx('modalTitle', header.className)}>
34+
{header.icon}
35+
{header.title}
36+
</h1>
37+
<button
38+
className="modalCloseBtn"
39+
onClick={() => onClose()}
40+
aria-label="Close share modal">
41+
<VscClose size="24" />
42+
</button>
43+
</header>
44+
45+
{children}
46+
</div>
47+
</ReactModal>
48+
)
49+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './Modal'

src/components/Elements/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export * from './ClickableItem'
88
export * from './ColoredLanguagesBadges'
99
export * from './FloatingFilter'
1010
export * from './InlineTextFilter'
11+
export * from './Modal'
1112
export * from './Panel'
1213
export * from './SearchBar'
1314
export * from './SearchBarWithLogo'
Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { AuthProvider, OAuthProvider, signInWithPopup } from 'firebase/auth'
2-
import { FaGithub, FaHeart } from 'react-icons/fa'
2+
import { FaGithub } from 'react-icons/fa'
33
import { FcGoogle } from 'react-icons/fc'
4-
import { IoMdClose } from 'react-icons/io'
5-
import ReactModal from 'react-modal'
4+
import { IoHeartCircle } from 'react-icons/io5'
65
import toast from 'react-simple-toasts'
7-
import { Button } from 'src/components/Elements'
6+
import { Button, Modal } from 'src/components/Elements'
87
import { useAuth } from 'src/features/auth'
98
import { trackUserConnect } from 'src/lib/analytics'
109
import { firebaseAuth, githubAuthProvider, googleAuthProvider } from 'src/lib/firebase'
@@ -45,51 +44,32 @@ export const AuthModal = ({ showAuth }: AuthModalProps) => {
4544
}
4645

4746
return (
48-
<ReactModal
49-
isOpen={showAuth}
50-
ariaHideApp={false}
51-
shouldCloseOnEsc={true}
52-
shouldCloseOnOverlayClick={true}
53-
shouldFocusAfterRender={false}
54-
onRequestClose={closeAuthModal}
55-
contentLabel="Auth"
56-
className="Modal authModal"
57-
style={{
58-
overlay: {
59-
zIndex: 3,
60-
},
47+
<Modal
48+
showModal={showAuth}
49+
onClose={closeAuthModal}
50+
header={{
51+
className: 'header',
52+
title: 'Join Hackertab',
53+
icon: <IoHeartCircle style={{ fontSize: '1.2em' }} />,
6154
}}
62-
overlayClassName="Overlay">
63-
<div className="authModal">
64-
<div className="titleAndCloseBtn">
65-
<h3>
66-
<FaHeart /> Join the community
67-
</h3>
68-
<button className="extraBtn" onClick={closeAuthModal}>
69-
<IoMdClose />
70-
</button>
71-
</div>
55+
className="authModal">
56+
<div>
57+
<p className="description">Create an account to sync, save bookmarks, and earn rewards.</p>
7258
<div className="buttons">
7359
<Button
74-
startIcon={<FaGithub style={{ fontSize: '1.6em' }} />}
60+
startIcon={<FaGithub className="blockHeaderWhite" style={{ fontSize: '1.5em' }} />}
7561
onClick={() => signIn(githubAuthProvider)}
76-
className="blockHeaderWhite"
7762
size="medium">
7863
Connect with Github
7964
</Button>
80-
8165
<Button
82-
startIcon={<FcGoogle style={{ fontSize: '1.6em' }} />}
66+
startIcon={<FcGoogle style={{ fontSize: '1.5em' }} />}
8367
onClick={() => signIn(googleAuthProvider)}
8468
size="medium">
8569
Connect with Google
8670
</Button>
8771
</div>
88-
<p className="description">
89-
We use your account to save your settings and track streaks for rowards 🎁 ... or risk
90-
losing them like unusaved code!
91-
</p>
9272
</div>
93-
</ReactModal>
73+
</Modal>
9474
)
9575
}
Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
.authModal {
2-
display: flex;
3-
flex-direction: column;
4-
row-gap: 30px;
5-
overflow-y: hidden;
2+
width: 400px;
63
}
74

8-
.authModal .titleAndCloseBtn {
9-
display: flex;
10-
flex-direction: row;
11-
align-items: center;
12-
justify-content: space-between;
5+
.authModal .header {
6+
text-align: center;
7+
justify-content: center;
138
}
14-
159
.authModal .buttons {
16-
display: flex;
10+
display: inline-flex;
11+
align-items: center;
12+
justify-items: center;
1713
flex-direction: column;
1814
row-gap: 16px;
19-
margin: auto;
15+
width: 100%;
16+
margin: 0 0 20px 0;
2017
}
2118

2219
.authModal .description {
23-
margin: 20px 100px;
20+
padding: 20px;
2421
text-align: center;
22+
font-size: 1em;
2523
}

0 commit comments

Comments
 (0)