Skip to content

Commit eda686f

Browse files
authored
Merge pull request #14163 from TylerAPfledderer/feat/shadcn-modal
[ShadCN] Migrate Modal component to ShadCN/Tailwind
2 parents eef455a + 23bab1d commit eda686f

File tree

10 files changed

+275
-115
lines changed

10 files changed

+275
-115
lines changed

src/components/FileContributors.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ import type { ChildOnlyProp, FileContributor } from "@/lib/types"
1212

1313
import { Button } from "@/components/Buttons"
1414
import InlineLink from "@/components/Link"
15-
import Modal from "@/components/Modal"
1615
import Text from "@/components/OldText"
1716
import Translation from "@/components/Translation"
1817

1918
import { trackCustomEvent } from "@/lib/utils/matomo"
2019

20+
import Modal from "./ui/dialog-modal"
21+
22+
import { useBreakpointValue } from "@/hooks/useBreakpointValue"
23+
2124
const ContributorList = ({ children }: Required<ChildOnlyProp>) => (
2225
<UnorderedList maxH="2xs" m={0} mt={6} overflowY="scroll">
2326
{children}
@@ -61,12 +64,14 @@ const FileContributors = ({
6164
date: Date.now().toString(),
6265
} as FileContributor)
6366

67+
const modalSize = useBreakpointValue({ base: "xl", md: "md" } as const)
68+
6469
return (
6570
<>
6671
<Modal
67-
isOpen={isModalOpen}
68-
onClose={() => setModalOpen(false)}
69-
size={{ base: "full", md: "xl" }}
72+
open={isModalOpen}
73+
onOpenChange={(open) => setModalOpen(open)}
74+
size={modalSize}
7075
title={<Translation id="contributors" />}
7176
>
7277
<Translation id="contributors-thanks" />

src/components/Modal/index.tsx

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/components/Quiz/QuizzesModal.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { QuizStatus } from "@/lib/types"
22

3-
import Modal from "../Modal"
3+
import Modal, { type ModalProps } from "../ui/dialog-modal"
44
import { Center } from "../ui/flex"
55

6+
import { useBreakpointValue } from "@/hooks/useBreakpointValue"
7+
68
type QuizzesModalProps = {
79
isQuizModalOpen: boolean
8-
onQuizModalClose: () => void
10+
onQuizModalOpenChange: (open: boolean) => void
911
children: React.ReactNode
1012
quizStatus: QuizStatus
1113
}
@@ -14,7 +16,7 @@ const QuizzesModal = ({
1416
children,
1517
quizStatus,
1618
isQuizModalOpen,
17-
onQuizModalClose,
19+
onQuizModalOpenChange,
1820
...props
1921
}: QuizzesModalProps) => {
2022
// TODO: remove bang in utility class names when Modal is migrated
@@ -25,11 +27,13 @@ const QuizzesModal = ({
2527
return "!bg-error-light dark:!bg-error-dark"
2628
}
2729

30+
const size = useBreakpointValue<ModalProps["size"]>({ base: "xl", md: "md" })!
31+
2832
return (
2933
<Modal
30-
isOpen={isQuizModalOpen}
31-
onClose={onQuizModalClose}
32-
size={{ base: "full", md: "xl" }}
34+
open={isQuizModalOpen}
35+
onOpenChange={onQuizModalOpenChange}
36+
size={size}
3337
contentProps={{ className: getStatusColorClass() }}
3438
{...props}
3539
>

src/components/Quiz/stories/QuizModal.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const meta = {
1717
args: {
1818
isQuizModalOpen: true,
1919
quizStatus: "neutral",
20-
onQuizModalClose: fn(),
20+
onQuizModalOpenChange: fn(),
2121
children: "",
2222
widgetProps: {
2323
quizKey: LAYER_2_QUIZ_KEY,
Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,9 @@
11
import React from "react"
2-
import {
3-
type ModalContentProps,
4-
type ModalProps,
5-
UseDisclosureReturn,
6-
} from "@chakra-ui/react"
72

8-
import Modal from "../Modal"
3+
import Modal, { type ModalProps } from "../ui/dialog-modal"
94

10-
type SimulatorModalProps = ModalContentProps &
11-
Pick<ModalProps, "size"> & {
12-
isOpen: UseDisclosureReturn["isOpen"]
13-
onClose: UseDisclosureReturn["onClose"]
14-
children?: React.ReactNode
15-
}
5+
type SimulatorModalProps = Omit<ModalProps, "size">
166

17-
export const SimulatorModal = ({
18-
isOpen,
19-
onClose,
20-
children,
21-
...restProps
22-
}: SimulatorModalProps) => {
23-
return (
24-
<Modal
25-
isOpen={isOpen}
26-
onClose={onClose}
27-
isCentered
28-
size="full"
29-
scrollBehavior="outside"
30-
contentProps={restProps}
31-
>
32-
{children}
33-
</Modal>
34-
)
7+
export const SimulatorModal = (props: SimulatorModalProps) => {
8+
return <Modal size="xl" {...props} isSimulator />
359
}

src/components/Simulator/index.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { Flex, type FlexProps, Grid } from "@chakra-ui/react"
44

55
import { trackCustomEvent } from "@/lib/utils/matomo"
66

7+
import type { ModalProps } from "../ui/dialog-modal"
8+
79
import { PATH_ID_QUERY_PARAM, SIMULATOR_ID } from "./constants"
810
import { Explanation } from "./Explanation"
911
import type {
@@ -41,14 +43,16 @@ export const Simulator = ({ children, data }: SimulatorProps) => {
4143
}
4244

4345
// When simulator closed: log event, clear URL params and close modal
44-
const onClose = (): void => {
45-
trackCustomEvent({
46-
eventCategory: "simulator",
47-
eventAction: `${pathId}_click`,
48-
eventName: `close-from-step-${step + 1}`,
49-
})
50-
// Clearing URL Params will reset pathId, and close modal
51-
clearUrlParams()
46+
const onClose: ModalProps["onOpenChange"] = (open) => {
47+
if (!open) {
48+
trackCustomEvent({
49+
eventCategory: "simulator",
50+
eventAction: `${pathId}_click`,
51+
eventName: `close-from-step-${step + 1}`,
52+
})
53+
// Clearing URL Params will reset pathId, and close modal
54+
clearUrlParams()
55+
}
5256
}
5357

5458
// Remove URL search param if invalid pathId
@@ -181,7 +185,7 @@ export const Simulator = ({ children, data }: SimulatorProps) => {
181185
})}
182186
</Flex>
183187
</Flex>
184-
<SimulatorModal isOpen={isOpen} onClose={onClose}>
188+
<SimulatorModal open={isOpen} onOpenChange={onClose}>
185189
<Template>
186190
{explanation ? (
187191
<Explanation
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import { Meta, StoryObj } from "@storybook/react"
2+
import { fn } from "@storybook/test"
23

3-
import ModalComponent from "."
4+
import ModalComponent from "../dialog-modal"
45

56
const meta = {
67
title: "Molecules/Overlay Content/Modal",
78
component: ModalComponent,
89
args: {
9-
isOpen: true,
10+
defaultOpen: true,
1011
title: "Modal Title",
1112
children:
1213
"This is the base component to be used in the modal window. Please change the text to preview final content for ethereum.org",
13-
actionButtonLabel: "Save",
14-
// Required prop, but not used in the current stories
15-
onClose: () => {},
14+
actionButton: {
15+
label: "Save",
16+
onClick: fn(),
17+
},
1618
},
1719
} satisfies Meta<typeof ModalComponent>
1820

@@ -22,8 +24,8 @@ type Story = StoryObj<typeof meta>
2224

2325
export const Modal: Story = {}
2426

25-
export const Full: Story = {
27+
export const Xl: Story = {
2628
args: {
27-
size: "full",
29+
size: "xl",
2830
},
2931
}

0 commit comments

Comments
 (0)