diff --git a/src/components/FileContributors.tsx b/src/components/FileContributors.tsx index f98e4c6eefe..1e727925591 100644 --- a/src/components/FileContributors.tsx +++ b/src/components/FileContributors.tsx @@ -12,12 +12,15 @@ import type { ChildOnlyProp, FileContributor } from "@/lib/types" import { Button } from "@/components/Buttons" import InlineLink from "@/components/Link" -import Modal from "@/components/Modal" import Text from "@/components/OldText" import Translation from "@/components/Translation" import { trackCustomEvent } from "@/lib/utils/matomo" +import Modal from "./ui/dialog-modal" + +import { useBreakpointValue } from "@/hooks/useBreakpointValue" + const ContributorList = ({ children }: Required) => ( {children} @@ -61,12 +64,14 @@ const FileContributors = ({ date: Date.now().toString(), } as FileContributor) + const modalSize = useBreakpointValue({ base: "xl", md: "md" } as const) + return ( <> setModalOpen(false)} - size={{ base: "full", md: "xl" }} + open={isModalOpen} + onOpenChange={(open) => setModalOpen(open)} + size={modalSize} title={} > diff --git a/src/components/Modal/index.tsx b/src/components/Modal/index.tsx deleted file mode 100644 index 11d2e80c59b..00000000000 --- a/src/components/Modal/index.tsx +++ /dev/null @@ -1,51 +0,0 @@ -import React from "react" -import { - Button, - HStack, - Modal as ChakraModal, - ModalBody, - ModalCloseButton, - ModalContent, - ModalContentProps, - ModalFooter, - ModalHeader, - ModalOverlay, - type ModalProps as ChakraModalProps, -} from "@chakra-ui/react" - -export type ModalProps = ChakraModalProps & { - children?: React.ReactNode - title?: React.ReactNode - actionButtonLabel?: string - contentProps?: ModalContentProps -} - -const Modal = ({ - children, - title, - actionButtonLabel, - contentProps, - ...restProps -}: ModalProps) => { - return ( - - - - - - {title} - - - {children} - {actionButtonLabel && ( - - - - - )} - - - ) -} - -export default Modal diff --git a/src/components/Quiz/QuizzesModal.tsx b/src/components/Quiz/QuizzesModal.tsx index 38298e49467..8b0580606ce 100644 --- a/src/components/Quiz/QuizzesModal.tsx +++ b/src/components/Quiz/QuizzesModal.tsx @@ -1,11 +1,13 @@ import { QuizStatus } from "@/lib/types" -import Modal from "../Modal" +import Modal, { type ModalProps } from "../ui/dialog-modal" import { Center } from "../ui/flex" +import { useBreakpointValue } from "@/hooks/useBreakpointValue" + type QuizzesModalProps = { isQuizModalOpen: boolean - onQuizModalClose: () => void + onQuizModalOpenChange: (open: boolean) => void children: React.ReactNode quizStatus: QuizStatus } @@ -14,7 +16,7 @@ const QuizzesModal = ({ children, quizStatus, isQuizModalOpen, - onQuizModalClose, + onQuizModalOpenChange, ...props }: QuizzesModalProps) => { // TODO: remove bang in utility class names when Modal is migrated @@ -25,11 +27,13 @@ const QuizzesModal = ({ return "!bg-error-light dark:!bg-error-dark" } + const size = useBreakpointValue({ base: "xl", md: "md" })! + return ( diff --git a/src/components/Quiz/stories/QuizModal.stories.tsx b/src/components/Quiz/stories/QuizModal.stories.tsx index b8f61dc6b3c..df64747c900 100644 --- a/src/components/Quiz/stories/QuizModal.stories.tsx +++ b/src/components/Quiz/stories/QuizModal.stories.tsx @@ -17,7 +17,7 @@ const meta = { args: { isQuizModalOpen: true, quizStatus: "neutral", - onQuizModalClose: fn(), + onQuizModalOpenChange: fn(), children: "", widgetProps: { quizKey: LAYER_2_QUIZ_KEY, diff --git a/src/components/Simulator/SimulatorModal.tsx b/src/components/Simulator/SimulatorModal.tsx index 1d2d7dea07f..c38ef765efd 100644 --- a/src/components/Simulator/SimulatorModal.tsx +++ b/src/components/Simulator/SimulatorModal.tsx @@ -1,35 +1,9 @@ import React from "react" -import { - type ModalContentProps, - type ModalProps, - UseDisclosureReturn, -} from "@chakra-ui/react" -import Modal from "../Modal" +import Modal, { type ModalProps } from "../ui/dialog-modal" -type SimulatorModalProps = ModalContentProps & - Pick & { - isOpen: UseDisclosureReturn["isOpen"] - onClose: UseDisclosureReturn["onClose"] - children?: React.ReactNode - } +type SimulatorModalProps = Omit -export const SimulatorModal = ({ - isOpen, - onClose, - children, - ...restProps -}: SimulatorModalProps) => { - return ( - - {children} - - ) +export const SimulatorModal = (props: SimulatorModalProps) => { + return } diff --git a/src/components/Simulator/index.tsx b/src/components/Simulator/index.tsx index 64acaea2863..d324c1d467d 100644 --- a/src/components/Simulator/index.tsx +++ b/src/components/Simulator/index.tsx @@ -4,6 +4,8 @@ import { Flex, type FlexProps, Grid } from "@chakra-ui/react" import { trackCustomEvent } from "@/lib/utils/matomo" +import type { ModalProps } from "../ui/dialog-modal" + import { PATH_ID_QUERY_PARAM, SIMULATOR_ID } from "./constants" import { Explanation } from "./Explanation" import type { @@ -41,14 +43,16 @@ export const Simulator = ({ children, data }: SimulatorProps) => { } // When simulator closed: log event, clear URL params and close modal - const onClose = (): void => { - trackCustomEvent({ - eventCategory: "simulator", - eventAction: `${pathId}_click`, - eventName: `close-from-step-${step + 1}`, - }) - // Clearing URL Params will reset pathId, and close modal - clearUrlParams() + const onClose: ModalProps["onOpenChange"] = (open) => { + if (!open) { + trackCustomEvent({ + eventCategory: "simulator", + eventAction: `${pathId}_click`, + eventName: `close-from-step-${step + 1}`, + }) + // Clearing URL Params will reset pathId, and close modal + clearUrlParams() + } } // Remove URL search param if invalid pathId @@ -181,7 +185,7 @@ export const Simulator = ({ children, data }: SimulatorProps) => { })} - +