From e82ed197c7c89767be50b7ee7aaab1c7e9e9d3b4 Mon Sep 17 00:00:00 2001 From: lloydrichards Date: Sun, 15 Oct 2023 12:14:12 +0200 Subject: [PATCH] refactor(storybook): :memo: add stories for ui components --- src/components/ui/badge.stories.tsx | 39 ++++++ src/components/ui/button.stories.tsx | 77 +++++++++++ src/components/ui/card.stories.tsx | 88 +++++++++++++ src/components/ui/dialog.stories.tsx | 60 +++++++++ src/components/ui/menubar.stories.tsx | 120 ++++++++++++++++++ src/components/ui/navigation-menu.stories.tsx | 45 +++++++ src/components/ui/sheet.stories.tsx | 62 +++++++++ src/components/ui/skeleton.stories.tsx | 26 ++++ src/components/ui/toast.stories.tsx | 81 ++++++++++++ 9 files changed, 598 insertions(+) create mode 100644 src/components/ui/badge.stories.tsx create mode 100644 src/components/ui/button.stories.tsx create mode 100644 src/components/ui/card.stories.tsx create mode 100644 src/components/ui/dialog.stories.tsx create mode 100644 src/components/ui/menubar.stories.tsx create mode 100644 src/components/ui/navigation-menu.stories.tsx create mode 100644 src/components/ui/sheet.stories.tsx create mode 100644 src/components/ui/skeleton.stories.tsx create mode 100644 src/components/ui/toast.stories.tsx diff --git a/src/components/ui/badge.stories.tsx b/src/components/ui/badge.stories.tsx new file mode 100644 index 0000000..05b77a6 --- /dev/null +++ b/src/components/ui/badge.stories.tsx @@ -0,0 +1,39 @@ +import { Meta, StoryObj } from "@storybook/react"; + +import { Badge } from "@/components/ui/badge"; + +const meta: Meta = { + title: "ui/Badge", + component: Badge, + tags: ["autodocs"], + argTypes: {}, +}; +export default meta; + +type Story = StoryObj; + +export const Base: Story = { + render: (args) => Badge, + args: {}, +}; + +export const Secondary: Story = { + render: (args) => Badge, + args: { + variant: "secondary", + }, +}; + +export const Destructive: Story = { + render: (args) => Badge, + args: { + variant: "destructive", + }, +}; + +export const Outline: Story = { + render: (args) => Badge, + args: { + variant: "outline", + }, +}; diff --git a/src/components/ui/button.stories.tsx b/src/components/ui/button.stories.tsx new file mode 100644 index 0000000..50ca4b4 --- /dev/null +++ b/src/components/ui/button.stories.tsx @@ -0,0 +1,77 @@ +import { Meta, StoryObj } from "@storybook/react"; +import { Loader2, Mail } from "lucide-react"; + +import { Button } from "@/components/ui/button"; + +const meta: Meta = { + title: "ui/Button", + component: Button, + tags: ["autodocs"], + argTypes: {}, +}; +export default meta; + +type Story = StoryObj; + +export const Base: Story = { + render: (args) => , + args: {}, +}; + +export const Outline: Story = { + render: (args) => , + args: { + variant: "outline", + }, +}; + +export const Ghost: Story = { + render: (args) => , + args: { + variant: "ghost", + }, +}; + +export const Secondary: Story = { + render: (args) => , + args: { + variant: "secondary", + }, +}; + +export const Destructive: Story = { + render: (args) => , + args: { + variant: "destructive", + }, +}; + +export const Link: Story = { + render: (args) => , + args: { + variant: "link", + }, +}; + +export const Loading: Story = { + render: (args) => ( + + ), + args: { + variant: "outline", + }, +}; + +export const WithIcon: Story = { + render: (args) => ( + + ), + args: { + variant: "secondary", + }, +}; diff --git a/src/components/ui/card.stories.tsx b/src/components/ui/card.stories.tsx new file mode 100644 index 0000000..8287763 --- /dev/null +++ b/src/components/ui/card.stories.tsx @@ -0,0 +1,88 @@ +import { Meta, StoryObj } from "@storybook/react"; +import { BellRing, Check } from "lucide-react"; + +import { cn } from "@/lib/utils"; +import { Button } from "@/components/ui/button"; +import { + Card, + CardContent, + CardDescription, + CardFooter, + CardHeader, + CardTitle, +} from "@/components/ui/card"; +import { Switch } from "@/components/ui/switch"; + +const meta: Meta = { + title: "ui/Card", + component: Card, + tags: ["autodocs"], + argTypes: {}, +}; +export default meta; + +type Story = StoryObj; + +const notifications = [ + { + title: "Your call has been confirmed.", + description: "1 hour ago", + }, + { + title: "You have a new message!", + description: "1 hour ago", + }, + { + title: "Your subscription is expiring soon!", + description: "2 hours ago", + }, +]; + +export const Base: Story = { + render: (args) => ( + + + Notifications + You have 3 unread messages. + + +
+ +
+

+ Push Notifications +

+

+ Send notifications to device. +

+
+ +
+
+ {notifications.map((notification, index) => ( +
+ +
+

+ {notification.title} +

+

+ {notification.description} +

+
+
+ ))} +
+
+ + + +
+ ), + args: {}, +}; diff --git a/src/components/ui/dialog.stories.tsx b/src/components/ui/dialog.stories.tsx new file mode 100644 index 0000000..b9d8581 --- /dev/null +++ b/src/components/ui/dialog.stories.tsx @@ -0,0 +1,60 @@ +import { Meta, StoryObj } from "@storybook/react"; + +import { Button } from "@/components/ui/button"; +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; + +const meta: Meta = { + title: "ui/Dialog", + component: Dialog, + tags: ["autodocs"], + argTypes: {}, +}; +export default meta; + +type Story = StoryObj; + +export const Base: Story = { + render: (args) => ( + + + + + + + Edit profile + + Make changes to your profile here. Click save when you're done. + + +
+
+ + +
+
+ + +
+
+ + + +
+
+ ), + args: {}, +}; diff --git a/src/components/ui/menubar.stories.tsx b/src/components/ui/menubar.stories.tsx new file mode 100644 index 0000000..8595e5d --- /dev/null +++ b/src/components/ui/menubar.stories.tsx @@ -0,0 +1,120 @@ +import { Meta, StoryObj } from "@storybook/react"; + +import { + Menubar, + MenubarCheckboxItem, + MenubarContent, + MenubarItem, + MenubarMenu, + MenubarRadioGroup, + MenubarRadioItem, + MenubarSeparator, + MenubarShortcut, + MenubarSub, + MenubarSubContent, + MenubarSubTrigger, + MenubarTrigger, +} from "@/components/ui/menubar"; + +const meta: Meta = { + title: "ui/Menubar", + component: Menubar, + tags: ["autodocs"], + argTypes: {}, +}; +export default meta; + +type Story = StoryObj; + +export const Base: Story = { + render: (args) => ( + + + File + + + New Tab ⌘T + + + New Window ⌘N + + New Incognito Window + + + Share + + Email link + Messages + Notes + + + + + Print... ⌘P + + + + + Edit + + + Undo ⌘Z + + + Redo ⇧⌘Z + + + + Find + + Search the web + + Find... + Find Next + Find Previous + + + + Cut + Copy + Paste + + + + View + + Always Show Bookmarks Bar + + Always Show Full URLs + + + + Reload ⌘R + + + Force Reload ⇧⌘R + + + Toggle Fullscreen + + Hide Sidebar + + + + Profiles + + + Andy + Benoit + Luis + + + Edit... + + Add Profile... + + + + ), + args: {}, +}; diff --git a/src/components/ui/navigation-menu.stories.tsx b/src/components/ui/navigation-menu.stories.tsx new file mode 100644 index 0000000..ecc43c0 --- /dev/null +++ b/src/components/ui/navigation-menu.stories.tsx @@ -0,0 +1,45 @@ +import Link from "next/link"; +import { Meta, StoryObj } from "@storybook/react"; + +import { + NavigationMenu, + NavigationMenuItem, + NavigationMenuLink, + NavigationMenuList, + navigationMenuTriggerStyle, +} from "@/components/ui/navigation-menu"; + +const meta: Meta = { + title: "ui/NavigationMenu", + component: NavigationMenu, + tags: ["autodocs"], + argTypes: {}, +}; +export default meta; + +type Story = StoryObj; + +export const Base: Story = { + render: (args) => ( + + + + + + Documentation + + + + + + External + + + + + ), + args: {}, +}; diff --git a/src/components/ui/sheet.stories.tsx b/src/components/ui/sheet.stories.tsx new file mode 100644 index 0000000..07dea7a --- /dev/null +++ b/src/components/ui/sheet.stories.tsx @@ -0,0 +1,62 @@ +import { Meta, StoryObj } from "@storybook/react"; + +import { Button } from "@/components/ui/button"; +import { Label } from "@/components/ui/label"; +import { + Sheet, + SheetClose, + SheetContent, + SheetDescription, + SheetFooter, + SheetHeader, + SheetTitle, + SheetTrigger, +} from "@/components/ui/sheet"; + +const meta: Meta = { + title: "ui/Sheet", + component: Sheet, + tags: ["autodocs"], + argTypes: {}, +}; +export default meta; + +type Story = StoryObj; + +export const Base: Story = { + render: (args) => ( + + + + + + + Edit profile + + Make changes to your profile here. Click save when youre done. + + +
+
+ + +
+
+ + +
+
+ + + + + +
+
+ ), + args: {}, +}; diff --git a/src/components/ui/skeleton.stories.tsx b/src/components/ui/skeleton.stories.tsx new file mode 100644 index 0000000..d9a4525 --- /dev/null +++ b/src/components/ui/skeleton.stories.tsx @@ -0,0 +1,26 @@ +import { Meta, StoryObj } from "@storybook/react"; + +import { Skeleton } from "@/components/ui/skeleton"; + +const meta: Meta = { + title: "ui/Skeleton", + component: Skeleton, + tags: ["autodocs"], + argTypes: {}, +}; +export default meta; + +type Story = StoryObj; + +export const Base: Story = { + render: (args) => ( +
+ +
+ + +
+
+ ), + args: {}, +}; diff --git a/src/components/ui/toast.stories.tsx b/src/components/ui/toast.stories.tsx new file mode 100644 index 0000000..95323db --- /dev/null +++ b/src/components/ui/toast.stories.tsx @@ -0,0 +1,81 @@ +import { Meta, StoryObj } from "@storybook/react"; + +import { Button } from "@/components/ui/button"; +import { + Toast, + ToastAction, + ToastActionElement, + ToastProps, +} from "@/components/ui/toast"; +import { Toaster } from "@/components/ui/toaster"; +import { useToast } from "@/components/ui/use-toast"; + +const meta: Meta = { + title: "ui/Toast", + component: Toast, + tags: ["autodocs"], + argTypes: {}, +}; +export default meta; + +type Story = Omit, "args"> & { + args: Omit; +}; + +type ToasterToast = ToastProps & { + id: string; + title?: string; + description?: string; + action?: ToastActionElement; +}; + +const ToastExample = (args: Story["args"]) => { + const { toast } = useToast(); + return ( +
+ + +
+ ); +}; + +export const Simple: Story = { + render: (args) => , + args: { + description: "Your message has been sent.", + }, +}; + +export const WithTitle: Story = { + render: (args) => , + args: { + title: "Uh oh! Something went wrong.", + description: "There was a problem with your request.", + }, +}; + +export const WithAction: Story = { + render: (args) => , + args: { + title: "Uh oh! Something went wrong.", + description: "There was a problem with your request.", + action: Try again, + }, +}; + +export const Destructive: Story = { + render: (args) => , + args: { + variant: "destructive", + title: "Uh oh! Something went wrong.", + description: "There was a problem with your request.", + action: Try again, + }, +};