Skip to content

Commit f6c8656

Browse files
committed
Show modal dynamically
1 parent d3b34cc commit f6c8656

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

src/components/AppHeader.js

+29
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,29 @@ import useThemeSwitcher from '../hooks/useThemeSwitcher';
55
import logoLight from '../images/logo-light.svg';
66
import logoDark from '../images/logo-dark.svg';
77
import { useState } from 'react';
8+
import HireMeModal from './HireMeModal';
89

910
const AppHeader = () => {
1011
const [showMenu, setShowMenu] = useState(false);
12+
const [showModal, setShowModal] = useState(false);
1113
const [activeTheme, setTheme] = useThemeSwitcher();
1214

1315
const toggleMenu = showMenu === false ? true : false;
1416

17+
function showHireMeModal() {
18+
if (!showModal) {
19+
document
20+
.getElementsByTagName('html')[0]
21+
.classList.add('overflow-y-hidden');
22+
setShowModal(true);
23+
} else {
24+
document
25+
.getElementsByTagName('html')[0]
26+
.classList.remove('overflow-y-hidden');
27+
setShowModal(false);
28+
}
29+
}
30+
1531
return (
1632
<div>
1733
<nav id="nav" className="sm:container sm:mx-auto">
@@ -107,6 +123,7 @@ const AppHeader = () => {
107123
</Link>
108124
<div className="border-t-2 pt-3 sm:pt-0 sm:border-t-0 border-primary-light dark:border-secondary-dark">
109125
<button
126+
onClick={showHireMeModal}
110127
className="sm:hidden block text-left text-md font-medium bg-indigo-500 hover:bg-indigo-600 text-white shadow-sm rounded-md px-4 py-2 mt-2"
111128
aria-label="Hire Me Button"
112129
>
@@ -121,6 +138,7 @@ const AppHeader = () => {
121138
{/* Hire me button start */}
122139
<div>
123140
<button
141+
onClick={showHireMeModal}
124142
className="text-md font-medium bg-indigo-500 hover:bg-indigo-600 text-white shadow-sm rounded-lg px-5 py-2.5"
125143
aria-label="Hire Me Button"
126144
>
@@ -144,6 +162,17 @@ const AppHeader = () => {
144162
{/* Theme switcher large screen start */}
145163
</div>
146164
</div>
165+
{/* Hire me modal start */}
166+
<div>
167+
{showModal ? (
168+
<HireMeModal
169+
onClose={showHireMeModal}
170+
onRequest={showHireMeModal}
171+
/>
172+
) : null}
173+
{showModal ? showHireMeModal : null}
174+
</div>
175+
{/* Hire me modal end */}
147176
</nav>
148177
</div>
149178
);

src/components/HireMeModal.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
const HireMeModal = () => {
1+
import { FiX } from 'react-icons/fi';
2+
3+
const HireMeModal = ({ onClose, onRequest }) => {
24
return (
3-
<div className="fixed inset-0 z-30">
5+
<div className="fixed inset-0 z-30 transition-all duration-500">
46
{/* Modal Background */}
57
<div className="bg-filter bg-black bg-opacity-50 fixed inset-0 w-full h-full z-20"></div>
68

@@ -12,8 +14,11 @@ const HireMeModal = () => {
1214
<h5 className=" text-primary-dark dark:text-primary-light text-2xl">
1315
What project are you looking for?
1416
</h5>
15-
<button className="px-4 font-bold text-primary-dark dark:text-primary-light">
16-
X
17+
<button
18+
onClick={onClose}
19+
className="px-4 font-bold text-primary-dark dark:text-primary-light"
20+
>
21+
<FiX className="text-3xl" />
1722
</button>
1823
</div>
1924
<div className="modal-body p-5 w-full h-full">
@@ -67,6 +72,7 @@ const HireMeModal = () => {
6772

6873
<div className="mt-6 pb-4 sm:pb-1">
6974
<button
75+
onClick={onRequest}
7076
className="px-4
7177
sm:px-6
7278
py-2
@@ -79,7 +85,7 @@ const HireMeModal = () => {
7985
rounded-md
8086
sm:rounded-lg
8187
focus:ring-1 focus:ring-indigo-900"
82-
type="submit"
88+
type="button"
8389
aria-label="Submit Request"
8490
>
8591
Send Request
@@ -89,6 +95,8 @@ const HireMeModal = () => {
8995
</div>
9096
<div className="modal-footer mt-2 sm:mt-0 py-5 px-8 border0-t text-right">
9197
<button
98+
onClick={onClose}
99+
type="button"
92100
className=" px-4
93101
sm:px-6
94102
py-2

0 commit comments

Comments
 (0)