Skip to content

Commit

Permalink
feat(dialog): add dialog component (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
keiko233 authored Dec 3, 2024
1 parent ab3553a commit 8fad83d
Show file tree
Hide file tree
Showing 6 changed files with 823 additions and 0 deletions.
55 changes: 55 additions & 0 deletions packages/components/src/dialog/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { cn, tcva, type VariantProps } from "@nyanpasu/material-design-libs";

export const dialogOverlayClassName = cn(
"fixed inset-0 z-50",
"backdrop-blur-xl",
"bg-opacity-10 bg-primary",
);

export const dialogContainerClassName = cn(
"fixed inset-0 z-50 grid place-items-center",
);

export const dialogContentVariants = tcva(["bg-surface"], {
variants: {
fullScreen: {
true: "fixed inset-0",
false: "min-w-96 rounded-3xl shadow",
},
},
defaultVariants: {
fullScreen: false,
},
});

export const dialogContentContainerVariants = tcva(["overflow-auto p-4"], {
variants: {
fullScreen: {
true: "",
false: "h-dvh-subtract-40",
},
subtract: {
0: "",
1: "h-dvh-subtract-14",
2: "h-dvh-subtract-28",
},
},
defaultVariants: {
fullScreen: false,
subtract: 0,
},
});

export const dialogHeaderClassName = cn(
"flex h-14 items-center gap-2 border-b p-4 text-xl",
);

export const dialogFooterClassName = cn(
"flex h-14 flex-row-reverse items-center gap-2 border-t p-2",
);

export interface DialogContentContainerVariantsProps
extends VariantProps<typeof dialogContentContainerVariants> {}

export interface DialogContentVariantsProps
extends VariantProps<typeof dialogContentVariants> {}
1 change: 1 addition & 0 deletions packages/components/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./button";
export * from "./dialog";
1 change: 1 addition & 0 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"dependencies": {
"@nyanpasu/material-design-components": "workspace:^",
"@nyanpasu/material-design-libs": "workspace:^",
"@radix-ui/react-dialog": "^1.1.2",
"@radix-ui/react-slot": "^1.1.0",
"ahooks": "^3.8.1",
"framer-motion": "12.0.0-alpha.2",
Expand Down
172 changes: 172 additions & 0 deletions packages/react/src/dialog/dialog.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
import type { Meta, StoryObj } from "@storybook/react";
import { motion } from "framer-motion";
import React from "react";
import { Button } from "../button";
import {
Dialog,
DialogClose,
DialogContent,
DialogFooter,
DialogHeader,
DialogTrigger,
} from "./";

type Story = StoryObj<typeof Dialog>;

export default {
title: "Components/Dialog",
component: Dialog,
} as Meta<typeof Dialog>;

export const Default: Story = {
decorators: [
() => (
<Dialog>
<DialogTrigger asChild>
<Button asChild>
<motion.button>open dialog</motion.button>
</Button>
</DialogTrigger>

<DialogContent
contentPrefix={<DialogHeader>Nyanpasu</DialogHeader>}
contentSuffix={
<DialogFooter>
<Button variant="flat">Submit</Button>
<DialogClose>Close</DialogClose>
</DialogFooter>
}
>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
</DialogContent>
</Dialog>
),
],
};

export const FullScreen: Story = {
decorators: [
() => (
<Dialog>
<DialogTrigger asChild>
<Button asChild>
<motion.button>open dialog</motion.button>
</Button>
</DialogTrigger>

<DialogContent
fullScreen
contentPrefix={<DialogHeader>Nyanpasu</DialogHeader>}
contentSuffix={
<DialogFooter>
<Button variant="flat">Submit</Button>
<DialogClose>Close</DialogClose>
</DialogFooter>
}
>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
<div>my content</div>
</DialogContent>
</Dialog>
),
],
};
Loading

0 comments on commit 8fad83d

Please sign in to comment.