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

feat(dialog): add dialog component #39

Merged
merged 1 commit into from
Dec 3, 2024
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
feat(dialog): add dialog component
  • Loading branch information
keiko233 committed Dec 3, 2024
commit 4de7570ab80b1ab3014359a2df7ed91302a35290
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