Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ShadCN] Migrate Modal component to ShadCN/Tailwind #14163

Merged
merged 20 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0003319
feat: create ShadCN modal with temporary dialog
TylerAPfledderer Oct 14, 2024
85ec946
chore(ui/Modal): rename "Full" story to "Xl"
TylerAPfledderer Oct 16, 2024
3c246ef
refactor(ui/dialog-modal): create provider for variant styles
TylerAPfledderer Oct 17, 2024
8b9bc21
refactor(QuizzesModal): migrate to dialog-modal
TylerAPfledderer Nov 11, 2024
27fd3f8
refactor(Simulator): migrate to dialog-modal
TylerAPfledderer Nov 11, 2024
a8405f2
refactor(FileContributors): migrate to dialog-modal
TylerAPfledderer Nov 11, 2024
66a0516
fix(dialog-modal): set dynamic bg color to modal content
TylerAPfledderer Nov 11, 2024
902f28c
refactor(pages/developers/tutorials): migrate to dialog-modal
TylerAPfledderer Nov 11, 2024
081c879
Merge remote-tracking branch 'upstream/dev' into feat/shadcn-modal
TylerAPfledderer Nov 12, 2024
9e26eae
refactor: remove old Modal and replace stories
TylerAPfledderer Nov 12, 2024
be315b2
refactor(dialog-modal): remove internal disclosure from `Modal`
TylerAPfledderer Nov 13, 2024
c159b9b
Merge remote-tracking branch 'upstream/dev' into feat/shadcn-modal
TylerAPfledderer Dec 1, 2024
aecb15c
chore(Simulator): remove console.log
TylerAPfledderer Dec 2, 2024
2dd4937
fix(dialog-modal): set default left/right space around container
TylerAPfledderer Dec 13, 2024
2f5d51d
fix(dialog-modal): allow vertical overflow scrolling
TylerAPfledderer Dec 13, 2024
a5fde9c
fix(dialog-model): increase close button icon size
TylerAPfledderer Dec 13, 2024
f4aa42e
fix(dialog-modal): wrap overlay component around content
TylerAPfledderer Dec 27, 2024
4e43cfb
Merge remote-tracking branch 'upstream/dev' into feat/shadcn-modal
TylerAPfledderer Dec 27, 2024
d050268
fix(dialog-modal): set full width to content
TylerAPfledderer Dec 29, 2024
23bab1d
chore(dialog-modal): remove comment above content style
TylerAPfledderer Dec 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/components/FileContributors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChildOnlyProp>) => (
<UnorderedList maxH="2xs" m={0} mt={6} overflowY="scroll">
{children}
Expand Down Expand Up @@ -61,12 +64,14 @@ const FileContributors = ({
date: Date.now().toString(),
} as FileContributor)

const modalSize = useBreakpointValue({ base: "xl", md: "md" } as const)

return (
<>
<Modal
isOpen={isModalOpen}
onClose={() => setModalOpen(false)}
size={{ base: "full", md: "xl" }}
open={isModalOpen}
onOpenChange={(open) => setModalOpen(open)}
size={modalSize}
title={<Translation id="contributors" />}
>
<Translation id="contributors-thanks" />
Expand Down
51 changes: 0 additions & 51 deletions src/components/Modal/index.tsx

This file was deleted.

16 changes: 10 additions & 6 deletions src/components/Quiz/QuizzesModal.tsx
Original file line number Diff line number Diff line change
@@ -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
}
Expand All @@ -14,7 +16,7 @@ const QuizzesModal = ({
children,
quizStatus,
isQuizModalOpen,
onQuizModalClose,
onQuizModalOpenChange,
...props
}: QuizzesModalProps) => {
// TODO: remove bang in utility class names when Modal is migrated
Expand All @@ -25,11 +27,13 @@ const QuizzesModal = ({
return "!bg-error-light dark:!bg-error-dark"
}

const size = useBreakpointValue<ModalProps["size"]>({ base: "xl", md: "md" })!

return (
<Modal
isOpen={isQuizModalOpen}
onClose={onQuizModalClose}
size={{ base: "full", md: "xl" }}
open={isQuizModalOpen}
onOpenChange={onQuizModalOpenChange}
size={size}
contentProps={{ className: getStatusColorClass() }}
{...props}
>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Quiz/stories/QuizModal.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const meta = {
args: {
isQuizModalOpen: true,
quizStatus: "neutral",
onQuizModalClose: fn(),
onQuizModalOpenChange: fn(),
children: "",
widgetProps: {
quizKey: LAYER_2_QUIZ_KEY,
Expand Down
34 changes: 4 additions & 30 deletions src/components/Simulator/SimulatorModal.tsx
Original file line number Diff line number Diff line change
@@ -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<ModalProps, "size"> & {
isOpen: UseDisclosureReturn["isOpen"]
onClose: UseDisclosureReturn["onClose"]
children?: React.ReactNode
}
type SimulatorModalProps = Omit<ModalProps, "size">

export const SimulatorModal = ({
isOpen,
onClose,
children,
...restProps
}: SimulatorModalProps) => {
return (
<Modal
isOpen={isOpen}
onClose={onClose}
isCentered
size="full"
scrollBehavior="outside"
contentProps={restProps}
>
{children}
</Modal>
)
export const SimulatorModal = (props: SimulatorModalProps) => {
return <Modal size="xl" {...props} isSimulator />
}
22 changes: 13 additions & 9 deletions src/components/Simulator/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -181,7 +185,7 @@ export const Simulator = ({ children, data }: SimulatorProps) => {
})}
</Flex>
</Flex>
<SimulatorModal isOpen={isOpen} onClose={onClose}>
<SimulatorModal open={isOpen} onOpenChange={onClose}>
<Template>
{explanation ? (
<Explanation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { Meta, StoryObj } from "@storybook/react"
import { fn } from "@storybook/test"

import ModalComponent from "."
import ModalComponent from "../dialog-modal"

const meta = {
title: "Molecules/Overlay Content/Modal",
component: ModalComponent,
args: {
isOpen: true,
defaultOpen: true,
title: "Modal Title",
children:
"This is the base component to be used in the modal window. Please change the text to preview final content for ethereum.org",
actionButtonLabel: "Save",
// Required prop, but not used in the current stories
onClose: () => {},
actionButton: {
label: "Save",
onClick: fn(),
},
},
} satisfies Meta<typeof ModalComponent>

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

export const Modal: Story = {}

export const Full: Story = {
export const Xl: Story = {
args: {
size: "full",
size: "xl",
},
}
Loading
Loading