Skip to content

Commit

Permalink
useModal moved inside modal component
Browse files Browse the repository at this point in the history
  • Loading branch information
nirnejak committed Oct 24, 2024
1 parent 478a024 commit 760c8bc
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 40 deletions.
3 changes: 1 addition & 2 deletions components/DetailsGallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import * as React from "react"

import { motion } from "framer-motion"

import Modal from "./Modal"
import Modal, { useModal } from "./Modal"
import ExpandButton from "components/ExpandButton"
import DataChangeAlertIllustration from "components/illustration/DataChangeAlert"
import DataSourceConnectionIllustration from "components/illustration/DataSourceConnection"
import DataThresholdAlertIllustration from "components/illustration/DataThresholdAlert"
import GroupDashboardIllustration from "components/illustration/GroupDashboard"
import TimelyUpdatesIllustration from "components/illustration/TimelyUpdates"
import useModal from "hooks/useModal"
import { gridContainerVariants, gridItemVariants } from "utils/animationConfig"

const DetailsGallery: React.FC = () => {
Expand Down
3 changes: 1 addition & 2 deletions components/HomeGallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as React from "react"

import { motion } from "framer-motion"

import Modal from "./Modal"
import Modal, { useModal } from "./Modal"
import ExpandButton from "components/ExpandButton"
import AlertsIllustration from "components/illustration/Alerts"
import DashboardIllustration from "components/illustration/Dashboard"
Expand All @@ -13,7 +13,6 @@ import QueryBuilderIllustration from "components/illustration/QueryBuilder"
import SavedQueryIllustration from "components/illustration/SavedQuery"
import SharingIllustration from "components/illustration/Sharing"
import VisualizeIllustration from "components/illustration/Visualize"
import useModal from "hooks/useModal"
import { gridContainerVariants, gridItemVariants } from "utils/animationConfig"

const HomeGallery: React.FC = () => {
Expand Down
31 changes: 31 additions & 0 deletions components/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,34 @@ const Modal: React.FC<Props> = ({ isOpen, onClose, children }) => {
}

export default Modal

export const useModal = (): [
boolean,
React.Dispatch<React.SetStateAction<boolean>>,
React.ReactNode,
React.Dispatch<React.SetStateAction<React.ReactNode>>,
] => {
const [isOpen, setIsOpen] = React.useState(false)
const [content, setContent] = React.useState<React.ReactNode>(null)

React.useEffect(() => {
const handleEsc = (event: KeyboardEvent): void => {
if (event.key === "Escape") {
setIsOpen(false)
setContent(null)
}
}

if (isOpen) {
document.body.style.overflowY = "hidden"
document.addEventListener("keydown", handleEsc)
}

return () => {
document.body.style.overflowY = "unset"
document.removeEventListener("keydown", handleEsc)
}
}, [isOpen, setIsOpen])

return [isOpen, setIsOpen, content, setContent]
}
3 changes: 1 addition & 2 deletions components/OthersGallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import * as React from "react"

import { motion } from "framer-motion"

import Modal from "./Modal"
import Modal, { useModal } from "./Modal"
import ExpandButton from "components/ExpandButton"
import SetAlertsIllustration from "components/illustration/SetAlerts"
import SlackAlertIllustration from "components/illustration/SlackAlert"
import useModal from "hooks/useModal"
import { gridContainerVariants, gridItemVariants } from "utils/animationConfig"

const OthersGallery: React.FC = () => {
Expand Down
34 changes: 0 additions & 34 deletions hooks/useModal.tsx

This file was deleted.

0 comments on commit 760c8bc

Please sign in to comment.