Skip to content

Commit

Permalink
Modal functionality abstracted in hook, esc to close the modal
Browse files Browse the repository at this point in the history
  • Loading branch information
nirnejak committed Oct 24, 2024
1 parent 3049806 commit 7ccda27
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 15 deletions.
3 changes: 2 additions & 1 deletion components/illustration/Alerts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { motion, useAnimation } from "framer-motion"

import ExpandButton from "components/ExpandButton"
import PlayButton from "components/PlayButton"
import useModal from "hooks/useModal"
import classNames from "utils/classNames"

const Alerts: React.FC = () => {
const [isModalOpen, setIsModalOpen] = React.useState(false)
const [isModalOpen, setIsModalOpen] = useModal()

const controls = useAnimation()

Expand Down
3 changes: 2 additions & 1 deletion components/illustration/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { motion, useAnimation } from "framer-motion"

import ExpandButton from "components/ExpandButton"
import PlayButton from "components/PlayButton"
import useModal from "hooks/useModal"
import classNames from "utils/classNames"

const Dashboard: React.FC = () => {
const [isModalOpen, setIsModalOpen] = React.useState(false)
const [isModalOpen, setIsModalOpen] = useModal()

const controls = useAnimation()

Expand Down
3 changes: 2 additions & 1 deletion components/illustration/DataChangeAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { motion, useAnimation } from "framer-motion"

import ExpandButton from "components/ExpandButton"
import PlayButton from "components/PlayButton"
import useModal from "hooks/useModal"
import classNames from "utils/classNames"

const DataChangeAlert: React.FC = () => {
const [isModalOpen, setIsModalOpen] = React.useState(false)
const [isModalOpen, setIsModalOpen] = useModal()

const controls = useAnimation()

Expand Down
3 changes: 2 additions & 1 deletion components/illustration/DataExport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { motion, useAnimation } from "framer-motion"

import ExpandButton from "components/ExpandButton"
import PlayButton from "components/PlayButton"
import useModal from "hooks/useModal"
import classNames from "utils/classNames"

const DataExport: React.FC = () => {
const [isModalOpen, setIsModalOpen] = React.useState(false)
const [isModalOpen, setIsModalOpen] = useModal()

const controls = useAnimation()

Expand Down
3 changes: 2 additions & 1 deletion components/illustration/DataSourceConnection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { motion, useAnimation } from "framer-motion"

import ExpandButton from "components/ExpandButton"
import PlayButton from "components/PlayButton"
import useModal from "hooks/useModal"
import classNames from "utils/classNames"

const DataSourceConnection: React.FC = () => {
const [isModalOpen, setIsModalOpen] = React.useState(false)
const [isModalOpen, setIsModalOpen] = useModal()

const controls = useAnimation()

Expand Down
3 changes: 2 additions & 1 deletion components/illustration/DataThresholdAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { motion, useAnimation } from "framer-motion"

import ExpandButton from "components/ExpandButton"
import PlayButton from "components/PlayButton"
import useModal from "hooks/useModal"
import classNames from "utils/classNames"

const DataThresholdAlert: React.FC = () => {
const [isModalOpen, setIsModalOpen] = React.useState(false)
const [isModalOpen, setIsModalOpen] = useModal()

const controls = useAnimation()

Expand Down
3 changes: 2 additions & 1 deletion components/illustration/GroupDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { motion, useAnimation } from "framer-motion"

import ExpandButton from "components/ExpandButton"
import PlayButton from "components/PlayButton"
import useModal from "hooks/useModal"
import classNames from "utils/classNames"

const GroupDashboard: React.FC = () => {
const [isModalOpen, setIsModalOpen] = React.useState(false)
const [isModalOpen, setIsModalOpen] = useModal()

const controls = useAnimation()

Expand Down
3 changes: 2 additions & 1 deletion components/illustration/Permissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { motion, useAnimation } from "framer-motion"

import ExpandButton from "components/ExpandButton"
import PlayButton from "components/PlayButton"
import useModal from "hooks/useModal"
import classNames from "utils/classNames"

const Permissions: React.FC = () => {
const [isModalOpen, setIsModalOpen] = React.useState(false)
const [isModalOpen, setIsModalOpen] = useModal()

const controls = useAnimation()

Expand Down
3 changes: 2 additions & 1 deletion components/illustration/QueryBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { motion, useAnimation } from "framer-motion"

import ExpandButton from "components/ExpandButton"
import PlayButton from "components/PlayButton"
import useModal from "hooks/useModal"
import classNames from "utils/classNames"

const QueryBuilder: React.FC = () => {
const [isModalOpen, setIsModalOpen] = React.useState(false)
const [isModalOpen, setIsModalOpen] = useModal()

const controls = useAnimation()

Expand Down
3 changes: 2 additions & 1 deletion components/illustration/SavedQuery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { motion, useAnimation } from "framer-motion"

import ExpandButton from "components/ExpandButton"
import PlayButton from "components/PlayButton"
import useModal from "hooks/useModal"
import classNames from "utils/classNames"

const SavedQuery: React.FC = () => {
const [isModalOpen, setIsModalOpen] = React.useState(false)
const [isModalOpen, setIsModalOpen] = useModal()

const controls = useAnimation()

Expand Down
3 changes: 2 additions & 1 deletion components/illustration/SetAlerts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { motion, useAnimation } from "framer-motion"

import ExpandButton from "components/ExpandButton"
import PlayButton from "components/PlayButton"
import useModal from "hooks/useModal"
import classNames from "utils/classNames"

const SetAlerts: React.FC = () => {
const [isModalOpen, setIsModalOpen] = React.useState(false)
const [isModalOpen, setIsModalOpen] = useModal()

const controls = useAnimation()

Expand Down
3 changes: 2 additions & 1 deletion components/illustration/Sharing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { motion, useAnimation } from "framer-motion"

import ExpandButton from "components/ExpandButton"
import PlayButton from "components/PlayButton"
import useModal from "hooks/useModal"
import classNames from "utils/classNames"

const Sharing: React.FC = () => {
const [isModalOpen, setIsModalOpen] = React.useState(false)
const [isModalOpen, setIsModalOpen] = useModal()

const controls = useAnimation()

Expand Down
3 changes: 2 additions & 1 deletion components/illustration/SlackAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { motion, useAnimation } from "framer-motion"

import ExpandButton from "components/ExpandButton"
import PlayButton from "components/PlayButton"
import useModal from "hooks/useModal"
import classNames from "utils/classNames"

const SlackAlert: React.FC = () => {
const [isModalOpen, setIsModalOpen] = React.useState(false)
const [isModalOpen, setIsModalOpen] = useModal()

const controls = useAnimation()

Expand Down
3 changes: 2 additions & 1 deletion components/illustration/TimelyUpdates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { motion, useAnimation } from "framer-motion"

import ExpandButton from "components/ExpandButton"
import PlayButton from "components/PlayButton"
import useModal from "hooks/useModal"
import classNames from "utils/classNames"

const TimelyUpdates: React.FC = () => {
const [isModalOpen, setIsModalOpen] = React.useState(false)
const [isModalOpen, setIsModalOpen] = useModal()

const controls = useAnimation()

Expand Down
3 changes: 2 additions & 1 deletion components/illustration/Visualize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { motion, useAnimation } from "framer-motion"

import ExpandButton from "components/ExpandButton"
import PlayButton from "components/PlayButton"
import useModal from "hooks/useModal"
import classNames from "utils/classNames"

const Visualize: React.FC = () => {
const [isModalOpen, setIsModalOpen] = React.useState(false)
const [isModalOpen, setIsModalOpen] = useModal()

const controls = useAnimation()

Expand Down
28 changes: 28 additions & 0 deletions hooks/useModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as React from "react"

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

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

if (isOpen) {
document.addEventListener("keydown", handleEsc)
}

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

return [isOpen, setIsOpen]
}

export default useModal

0 comments on commit 7ccda27

Please sign in to comment.