Skip to content

Commit

Permalink
feat: Storybook update and Dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
EdenComp committed Nov 3, 2024
1 parent ca36750 commit 12f9335
Show file tree
Hide file tree
Showing 20 changed files with 606 additions and 1,242 deletions.
10 changes: 7 additions & 3 deletions front/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@ function getAbsolutePath(value: string): any {
return dirname(require.resolve(join(value, "package.json")));
}
const config: StorybookConfig = {
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
addons: [
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
addons: [
getAbsolutePath("@storybook/addon-onboarding"),
getAbsolutePath("@storybook/addon-links"),
getAbsolutePath("@storybook/addon-essentials"),
getAbsolutePath("@chromatic-com/storybook"),
getAbsolutePath("@storybook/addon-interactions"),
],
framework: {
framework: {
name: getAbsolutePath("@storybook/nextjs"),
options: {},
},
docs: {},
typescript: {
reactDocgen: "react-docgen-typescript"
}
};
export default config;
3 changes: 2 additions & 1 deletion front/.storybook/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import type { Preview } from "@storybook/react";
import "../src/app/globals.css";

const preview: Preview = {
parameters: {
parameters: {
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
},
},
},
tags: ["autodocs"]
};

export default preview;
22 changes: 11 additions & 11 deletions front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,25 @@
"zod": "^3.23.8"
},
"devDependencies": {
"@chromatic-com/storybook": "^1.9.0",
"@storybook/addon-essentials": "^8.3.5",
"@storybook/addon-interactions": "^8.3.5",
"@storybook/addon-links": "^8.3.5",
"@storybook/addon-onboarding": "^8.3.5",
"@storybook/blocks": "^8.3.5",
"@storybook/nextjs": "^8.3.5",
"@storybook/react": "^8.3.5",
"@storybook/test": "^8.3.5",
"@chromatic-com/storybook": "^3.2.2",
"@storybook/addon-essentials": "^8.4.1",
"@storybook/addon-interactions": "^8.4.1",
"@storybook/addon-links": "^8.4.1",
"@storybook/addon-onboarding": "^8.4.1",
"@storybook/blocks": "^8.4.1",
"@storybook/nextjs": "^8.4.1",
"@storybook/react": "^8.4.1",
"@storybook/test": "^8.4.1",
"@types/node": "^20.16.11",
"@types/react": "^18.3.11",
"@types/react-dom": "^18.3.0",
"eslint": "^8.57.1",
"eslint-config-next": "14.2.15",
"eslint-plugin-perfectionist": "^3.8.0",
"eslint-plugin-storybook": "^0.9.0",
"eslint-plugin-storybook": "^0.10.2",
"postcss": "^8.4.47",
"prettier": "^3.3.3",
"storybook": "^8.3.5",
"storybook": "^8.4.1",
"tailwindcss": "^3.4.13",
"typescript": "^5.6.3",
"webpack": "^5.95.0"
Expand Down
2 changes: 1 addition & 1 deletion front/src/components/ui/avatar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Story = StoryObj<AvatarProps>;

const Render = (args: AvatarProps) => <Avatar {...args} />;

export const Default: Story = {
export const LightMode: Story = {
args: {
src: "https://avatars.githubusercontent.com/u/33784129?v=4",
alt: "EdenComp",
Expand Down
2 changes: 1 addition & 1 deletion front/src/components/ui/badge.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type Story = StoryObj<BadgeProps>;

const Render = (args: BadgeProps) => <Badge {...args} />;

export const Default: Story = {
export const LightMode: Story = {
args: {
variant: "default",
size: "default",
Expand Down
2 changes: 1 addition & 1 deletion front/src/components/ui/breadcrumb.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const Render = (args: object) => (
</Breadcrumb>
);

export const Default: Story = {
export const LightMode: Story = {
args: {
className: "",
},
Expand Down
2 changes: 1 addition & 1 deletion front/src/components/ui/button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Story = StoryObj<ButtonProps>;

const Render = (args: ButtonProps) => <Button {...args} />;

export const Default: Story = {
export const LightMode: Story = {
args: {
variant: "default",
disabled: false,
Expand Down
2 changes: 1 addition & 1 deletion front/src/components/ui/card.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const Render = (args: object) => (
</Card>
);

export const Default: Story = {
export const LightMode: Story = {
args: {
className: "",
},
Expand Down
2 changes: 1 addition & 1 deletion front/src/components/ui/checkbox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Story = StoryObj<CheckboxProps>;

const Render = (args: CheckboxProps) => <Checkbox {...args} />;

export const Default: Story = {
export const LightMode: Story = {
args: {
className: "",
disabled: false,
Expand Down
2 changes: 1 addition & 1 deletion front/src/components/ui/context-menu.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const Render = (args: DarkModeMeta) => (
</ContextMenu>
);

export const Default: Story = {
export const LightMode: Story = {
args: {
className: "",
},
Expand Down
78 changes: 78 additions & 0 deletions front/src/components/ui/dialog.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { Meta, StoryObj } from "@storybook/react";

import { Button } from "@/components/ui/button";
import {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";

const meta: Meta = {
component: Dialog,
title: "Dialog",
args: {
className: "",
},
argTypes: {
className: {
type: "string",
control: "text",
},
},
};
type Story = StoryObj;
type DarkModeMeta = { dark?: boolean };

const Render = (args: DarkModeMeta) => (
<Dialog>
<DialogTrigger>
<Button variant="outline">Open</Button>
</DialogTrigger>
<DialogContent className={args.dark ? "dark" : ""}>
<DialogHeader>
<DialogTitle>Are you absolutely sure?</DialogTitle>
<DialogDescription>This action cannot be undone.</DialogDescription>
</DialogHeader>
<DialogFooter>
<DialogClose asChild>
<Button>Confirm</Button>
</DialogClose>
</DialogFooter>
</DialogContent>
</Dialog>
);

export const LightMode: Story = {
args: {
className: "",
},
parameters: {
backgrounds: {
default: "light",
},
},
render: Render,
};

export const DarkMode: Story = {
args: {
className: "",
},
parameters: {
backgrounds: {
default: "dark",
},
},
render: (args) => (
<div className="dark">
<Render {...args} dark />
</div>
),
};

export default meta;
93 changes: 93 additions & 0 deletions front/src/components/ui/dialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
"use client";

import { Root, Trigger, Portal, Close, Overlay, Content, Title, Description } from "@radix-ui/react-dialog";
import { Cross2Icon } from "@radix-ui/react-icons";
import React from "react";

import { cn } from "@/lib/utils";

const Dialog = Root;
const DialogTrigger = Trigger;
const DialogPortal = Portal;
const DialogClose = Close;

const DialogOverlay = React.forwardRef<
React.ElementRef<typeof Overlay>,
React.ComponentPropsWithoutRef<typeof Overlay>
>(({ className, ...props }, ref) => (
<Overlay
ref={ref}
className={cn(
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
className,
)}
{...props}
/>
));
DialogOverlay.displayName = Overlay.displayName;

const DialogContent = React.forwardRef<
React.ElementRef<typeof Content>,
React.ComponentPropsWithoutRef<typeof Content>
>(({ className, children, ...props }, ref) => (
<DialogPortal>
<DialogOverlay />
<Content
ref={ref}
className={cn(
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
className,
)}
{...props}
>
{children}
<Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground text-primary">
<Cross2Icon className="h-4 w-4" />
<span className="sr-only">Close</span>
</Close>
</Content>
</DialogPortal>
));
DialogContent.displayName = Content.displayName;

const DialogHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
<div className={cn("flex flex-col space-y-1.5 text-center sm:text-left", className)} {...props} />
);
DialogHeader.displayName = "DialogHeader";

const DialogFooter = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
<div className={cn("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2", className)} {...props} />
);
DialogFooter.displayName = "DialogFooter";

const DialogTitle = React.forwardRef<React.ElementRef<typeof Title>, React.ComponentPropsWithoutRef<typeof Title>>(
({ className, ...props }, ref) => (
<Title
ref={ref}
className={cn("text-lg font-semibold leading-none tracking-tight text-primary", className)}
{...props}
/>
),
);
DialogTitle.displayName = Title.displayName;

const DialogDescription = React.forwardRef<
React.ElementRef<typeof Description>,
React.ComponentPropsWithoutRef<typeof Description>
>(({ className, ...props }, ref) => (
<Description ref={ref} className={cn("text-sm text-muted-foreground", className)} {...props} />
));
DialogDescription.displayName = Description.displayName;

export {
Dialog,
DialogPortal,
DialogOverlay,
DialogTrigger,
DialogClose,
DialogContent,
DialogHeader,
DialogFooter,
DialogTitle,
DialogDescription,
};
7 changes: 5 additions & 2 deletions front/src/components/ui/dropdown-menu.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { Button } from "@/components/ui/button";

const meta: Meta = {
component: DropdownMenu,
Expand All @@ -27,7 +28,9 @@ type DarkModeMeta = { dark?: boolean };

const Render = (args: DarkModeMeta) => (
<DropdownMenu {...args}>
<DropdownMenuTrigger>Open</DropdownMenuTrigger>
<DropdownMenuTrigger>
<Button variant="outline">Open</Button>
</DropdownMenuTrigger>
<DropdownMenuContent className={args.dark ? "dark" : ""}>
<DropdownMenuLabel>My Account</DropdownMenuLabel>
<DropdownMenuSeparator />
Expand All @@ -38,7 +41,7 @@ const Render = (args: DarkModeMeta) => (
</DropdownMenu>
);

export const Default: Story = {
export const LightMode: Story = {
args: {
className: "",
},
Expand Down
2 changes: 1 addition & 1 deletion front/src/components/ui/input.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Story = StoryObj<InputProps>;

const Render = (args: InputProps) => <Input {...args} />;

export const Default: Story = {
export const LightMode: Story = {
args: {
value: "Text input",
disabled: false,
Expand Down
2 changes: 1 addition & 1 deletion front/src/components/ui/label.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const Render = (args: LabelProps) => (
</div>
);

export const Default: Story = {
export const LightMode: Story = {
args: {
className: "",
},
Expand Down
2 changes: 1 addition & 1 deletion front/src/components/ui/separator.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const Render = (args: SeparatorProps) => (
</div>
);

export const Default: Story = {
export const LightMode: Story = {
args: {
orientation: "horizontal",
className: "",
Expand Down
2 changes: 1 addition & 1 deletion front/src/components/ui/sheet.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const Render = (args: DarkModeMeta) => (
</Sheet>
);

export const Default: Story = {
export const LightMode: Story = {
args: {
className: "",
},
Expand Down
2 changes: 1 addition & 1 deletion front/src/components/ui/skeleton.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const Render = (args: object) => (
</div>
);

export const Default: Story = {
export const LightMode: Story = {
args: {
className: "",
},
Expand Down
2 changes: 1 addition & 1 deletion front/src/components/ui/tooltip.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const Render = (args: TooltipProps) => (
</Tooltip>
);

export const Default: Story = {
export const LightMode: Story = {
args: {
delayDuration: 0,
},
Expand Down
Loading

0 comments on commit 12f9335

Please sign in to comment.