Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
71 changes: 38 additions & 33 deletions src/components/CodeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { Clipboard, ClipboardCheck } from "lucide-react"

import { Button } from "./ui/buttons/Button"
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
} from "./ui/dialog-modal"
Sheet,
SheetClose,
SheetContent,
SheetDescription,
SheetHeader,
SheetTitle,
} from "./ui/sheet"

import { useClipboard } from "@/hooks/useClipboard"
import { useTranslation } from "@/hooks/useTranslation"
Expand All @@ -28,33 +29,37 @@ const CodeModal = ({ children, isOpen, setIsOpen, title }: CodeModalProps) => {
const { onCopy, hasCopied } = useClipboard()

return (
<Dialog open={isOpen} onOpenChange={setIsOpen}>
<DialogContent className="absolute inset-0 mb-0 mt-auto max-h-[50%] max-w-[100vw]">
<DialogHeader>
<DialogTitle>{title}</DialogTitle>
</DialogHeader>
<DialogDescription asChild>
<div className="overflow-y-auto">{children}</div>
</DialogDescription>
<Button
variant="outline"
onClick={() => onCopy(codeSnippet)}
className="absolute right-19 top-24" // Force right, code always LTR
>
{hasCopied ? (
<>
{t("copied")}
<ClipboardCheck className="ms-1" />
</>
) : (
<>
{t("copy")}
<Clipboard className="ms-1" />
</>
)}
</Button>
</DialogContent>
</Dialog>
<Sheet open={isOpen} onOpenChange={setIsOpen}>
<SheetContent
side="bottom"
className="flex h-[50vh] flex-col rounded-t-2xl"
>
<SheetHeader className="flex-row items-center justify-between space-y-0 p-4 ps-8 pt-6">
<SheetTitle className="text-2xl font-bold">{title}</SheetTitle>
<SheetClose>{t("close")}</SheetClose>
<Button
variant="outline"
onClick={() => onCopy(codeSnippet)}
className="absolute right-8 top-28" // Force right, code always LTR
>
{hasCopied ? (
<>
{t("copied")}
<ClipboardCheck className="ms-1" />
</>
) : (
<>
{t("copy")}
<Clipboard className="ms-1" />
</>
)}
</Button>
</SheetHeader>
<SheetDescription className="flex-1 overflow-y-auto">
{children}
</SheetDescription>
</SheetContent>
</Sheet>
)
}

Expand Down
38 changes: 18 additions & 20 deletions src/components/Homepage/CodeExamples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,26 +147,24 @@ const CodeExamples = ({ title, codeExamples }: CodeExamplesProps) => {
))}
</Accordion>
</WindowBox>
{isModalOpen && (
<CodeModal
isOpen={isModalOpen}
setIsOpen={setModalOpen}
title={codeExamples[activeCode].title}
>
{!fetchedCodes[activeCode] ? (
<SkeletonLines noOfLines={16} />
) : (
<Codeblock
codeLanguage={codeExamples[activeCode].codeLanguage}
allowCollapse={false}
className="[&_pre]:p-6"
fromHomepage
>
{fetchedCodes[activeCode]}
</Codeblock>
)}
</CodeModal>
)}
<CodeModal
isOpen={isModalOpen}
setIsOpen={setModalOpen}
title={codeExamples[activeCode].title}
>
{!fetchedCodes[activeCode] ? (
<SkeletonLines noOfLines={16} />
) : (
<Codeblock
codeLanguage={codeExamples[activeCode].codeLanguage}
allowCollapse={false}
className="[&_pre]:p-6"
fromHomepage
>
{fetchedCodes[activeCode]}
</Codeblock>
)}
</CodeModal>
</div>
)
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/ui/dialog-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { Center, Flex } from "./flex"
const dialogVariant = tv({
slots: {
content:
"data-[state=open]:animate-contentShow w-full grid gap-4 rounded-md bg-background p-8 shadow-[hsl(206_22%_7%_/_35%)_0px_10px_38px_-10px,_hsl(206_22%_7%_/_20%)_0px_10px_20px_-15px] focus:outline-none z-modal",
"data-[state=open]:animate-fade-in w-full grid gap-4 rounded-md bg-background p-8 shadow-[hsl(206_22%_7%_/_35%)_0px_10px_38px_-10px,_hsl(206_22%_7%_/_20%)_0px_10px_20px_-15px] focus:outline-none z-modal",
overlay:
"data-[state=open]:animate-overlayShow overflow-y-auto p-4 grid place-items-center fixed inset-0 bg-black/70 z-overlay",
"data-[state=open]:animate-fade-in overflow-y-auto p-4 grid place-items-center fixed inset-0 bg-black/70 z-overlay",
header: "relative pe-12",
title: "text-2xl",
footer: "pt-8",
Expand Down