@mzc-fe/design-system 0.0.1-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.husky/pre-push +21 -0
- package/.storybook/main.ts +11 -0
- package/.storybook/preview.tsx +30 -0
- package/.vscode/settings.json +12 -0
- package/.vscode/tailwind.json +105 -0
- package/README.md +136 -0
- package/bitbucket-pipelines.yml +52 -0
- package/components.json +21 -0
- package/eslint.config.js +38 -0
- package/package.json +98 -0
- package/public/vite.svg +1 -0
- package/src/components/accordion.stories.tsx +258 -0
- package/src/components/accordion.test.tsx +390 -0
- package/src/components/accordion.tsx +64 -0
- package/src/components/alert-dialog.stories.tsx +213 -0
- package/src/components/alert-dialog.test.tsx +80 -0
- package/src/components/alert-dialog.tsx +155 -0
- package/src/components/alert.stories.tsx +84 -0
- package/src/components/alert.test.tsx +35 -0
- package/src/components/alert.tsx +66 -0
- package/src/components/aspect-ratio.stories.tsx +97 -0
- package/src/components/aspect-ratio.test.tsx +47 -0
- package/src/components/aspect-ratio.tsx +11 -0
- package/src/components/avatar.stories.tsx +76 -0
- package/src/components/avatar.test.tsx +50 -0
- package/src/components/avatar.tsx +51 -0
- package/src/components/badge.stories.tsx +64 -0
- package/src/components/badge.test.tsx +34 -0
- package/src/components/badge.tsx +46 -0
- package/src/components/breadcrumb.stories.tsx +86 -0
- package/src/components/breadcrumb.test.tsx +74 -0
- package/src/components/breadcrumb.tsx +109 -0
- package/src/components/button-group.stories.tsx +62 -0
- package/src/components/button-group.tsx +83 -0
- package/src/components/button.stories.tsx +118 -0
- package/src/components/button.test.tsx +64 -0
- package/src/components/button.tsx +62 -0
- package/src/components/calendar.stories.tsx +81 -0
- package/src/components/calendar.tsx +220 -0
- package/src/components/card.stories.tsx +110 -0
- package/src/components/card.test.tsx +56 -0
- package/src/components/card.tsx +92 -0
- package/src/components/carousel.stories.tsx +90 -0
- package/src/components/carousel.tsx +239 -0
- package/src/components/chart.tsx +357 -0
- package/src/components/checkbox.stories.tsx +108 -0
- package/src/components/checkbox.test.tsx +67 -0
- package/src/components/checkbox.tsx +32 -0
- package/src/components/collapsible.stories.tsx +106 -0
- package/src/components/collapsible.test.tsx +92 -0
- package/src/components/collapsible.tsx +31 -0
- package/src/components/command.stories.tsx +90 -0
- package/src/components/command.tsx +182 -0
- package/src/components/context-menu.stories.tsx +63 -0
- package/src/components/context-menu.tsx +252 -0
- package/src/components/dialog.stories.tsx +128 -0
- package/src/components/dialog.tsx +141 -0
- package/src/components/drawer.stories.tsx +104 -0
- package/src/components/drawer.tsx +135 -0
- package/src/components/dropdown-menu.stories.tsx +97 -0
- package/src/components/dropdown-menu.tsx +255 -0
- package/src/components/empty.stories.tsx +90 -0
- package/src/components/empty.test.tsx +55 -0
- package/src/components/empty.tsx +104 -0
- package/src/components/field.tsx +246 -0
- package/src/components/form.tsx +168 -0
- package/src/components/hover-card.stories.tsx +66 -0
- package/src/components/hover-card.tsx +44 -0
- package/src/components/input-group.stories.tsx +57 -0
- package/src/components/input-group.test.tsx +40 -0
- package/src/components/input-group.tsx +170 -0
- package/src/components/input-otp.stories.tsx +94 -0
- package/src/components/input-otp.test.tsx +60 -0
- package/src/components/input-otp.tsx +75 -0
- package/src/components/input.stories.tsx +94 -0
- package/src/components/input.test.tsx +53 -0
- package/src/components/input.tsx +21 -0
- package/src/components/item.tsx +193 -0
- package/src/components/kbd.stories.tsx +100 -0
- package/src/components/kbd.test.tsx +28 -0
- package/src/components/kbd.tsx +28 -0
- package/src/components/label.stories.tsx +48 -0
- package/src/components/label.test.tsx +28 -0
- package/src/components/label.tsx +24 -0
- package/src/components/menubar.tsx +274 -0
- package/src/components/navigation-menu.tsx +168 -0
- package/src/components/pagination.stories.tsx +107 -0
- package/src/components/pagination.tsx +127 -0
- package/src/components/popover.stories.tsx +102 -0
- package/src/components/popover.tsx +48 -0
- package/src/components/progress.stories.tsx +76 -0
- package/src/components/progress.test.tsx +36 -0
- package/src/components/progress.tsx +29 -0
- package/src/components/radio-group.stories.tsx +73 -0
- package/src/components/radio-group.test.tsx +74 -0
- package/src/components/radio-group.tsx +45 -0
- package/src/components/resizable.stories.tsx +120 -0
- package/src/components/resizable.tsx +54 -0
- package/src/components/scroll-area.stories.tsx +64 -0
- package/src/components/scroll-area.test.tsx +46 -0
- package/src/components/scroll-area.tsx +58 -0
- package/src/components/select.stories.tsx +111 -0
- package/src/components/select.test.tsx +90 -0
- package/src/components/select.tsx +188 -0
- package/src/components/separator.stories.tsx +76 -0
- package/src/components/separator.test.tsx +24 -0
- package/src/components/separator.tsx +28 -0
- package/src/components/sheet.stories.tsx +122 -0
- package/src/components/sheet.tsx +137 -0
- package/src/components/sidebar.tsx +726 -0
- package/src/components/skeleton.stories.tsx +53 -0
- package/src/components/skeleton.test.tsx +24 -0
- package/src/components/skeleton.tsx +13 -0
- package/src/components/slider.stories.tsx +97 -0
- package/src/components/slider.test.tsx +49 -0
- package/src/components/slider.tsx +63 -0
- package/src/components/sonner.stories.tsx +96 -0
- package/src/components/sonner.tsx +38 -0
- package/src/components/spinner.stories.tsx +54 -0
- package/src/components/spinner.test.tsx +30 -0
- package/src/components/spinner.tsx +16 -0
- package/src/components/switch.stories.tsx +108 -0
- package/src/components/switch.test.tsx +62 -0
- package/src/components/switch.tsx +31 -0
- package/src/components/table.stories.tsx +139 -0
- package/src/components/table.test.tsx +85 -0
- package/src/components/table.tsx +114 -0
- package/src/components/tabs.stories.tsx +99 -0
- package/src/components/tabs.test.tsx +64 -0
- package/src/components/tabs.tsx +66 -0
- package/src/components/textarea.stories.tsx +89 -0
- package/src/components/textarea.test.tsx +53 -0
- package/src/components/textarea.tsx +18 -0
- package/src/components/toggle-group.stories.tsx +108 -0
- package/src/components/toggle-group.test.tsx +66 -0
- package/src/components/toggle-group.tsx +81 -0
- package/src/components/toggle.stories.tsx +98 -0
- package/src/components/toggle.test.tsx +42 -0
- package/src/components/toggle.tsx +45 -0
- package/src/components/tooltip.stories.tsx +111 -0
- package/src/components/tooltip.tsx +61 -0
- package/src/foundations/README.md +141 -0
- package/src/foundations/ThemeProvider.tsx +77 -0
- package/src/foundations/color.css +232 -0
- package/src/foundations/color.stories.tsx +719 -0
- package/src/foundations/palette.css +249 -0
- package/src/foundations/spacing.css +8 -0
- package/src/foundations/typography.css +143 -0
- package/src/foundations/typography.stories.tsx +17 -0
- package/src/hooks/use-mobile.ts +19 -0
- package/src/index.css +176 -0
- package/src/index.ts +336 -0
- package/src/lib/utils.ts +6 -0
- package/src/test/setup.ts +8 -0
- package/src/vite-env.d.ts +1 -0
- package/tsconfig.app.json +33 -0
- package/tsconfig.json +13 -0
- package/tsconfig.node.json +25 -0
- package/vite.config.ts +30 -0
- package/vitest.config.ts +25 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
|
+
import { render } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
import { Checkbox } from "./checkbox";
|
|
5
|
+
|
|
6
|
+
describe("Checkbox", () => {
|
|
7
|
+
it("should render checkbox", () => {
|
|
8
|
+
const { container } = render(<Checkbox />);
|
|
9
|
+
const checkbox = container.querySelector('[data-slot="checkbox"]');
|
|
10
|
+
expect(checkbox).toBeInTheDocument();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("should be checked when checked prop is true", () => {
|
|
14
|
+
const { container } = render(<Checkbox checked />);
|
|
15
|
+
const checkbox = container.querySelector('[data-slot="checkbox"]');
|
|
16
|
+
expect(checkbox).toHaveAttribute("data-state", "checked");
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("should be unchecked by default", () => {
|
|
20
|
+
const { container } = render(<Checkbox />);
|
|
21
|
+
const checkbox = container.querySelector('[data-slot="checkbox"]');
|
|
22
|
+
expect(checkbox).toHaveAttribute("data-state", "unchecked");
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("should call onCheckedChange when clicked", async () => {
|
|
26
|
+
const user = userEvent.setup();
|
|
27
|
+
const handleChange = vi.fn();
|
|
28
|
+
const { container } = render(<Checkbox onCheckedChange={handleChange} />);
|
|
29
|
+
const checkbox = container.querySelector(
|
|
30
|
+
'[data-slot="checkbox"]'
|
|
31
|
+
) as HTMLElement;
|
|
32
|
+
await user.click(checkbox);
|
|
33
|
+
expect(handleChange).toHaveBeenCalledWith(true);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("should toggle checked state when clicked", async () => {
|
|
37
|
+
const user = userEvent.setup();
|
|
38
|
+
const handleChange = vi.fn();
|
|
39
|
+
const { container } = render(
|
|
40
|
+
<Checkbox checked={false} onCheckedChange={handleChange} />
|
|
41
|
+
);
|
|
42
|
+
const checkbox = container.querySelector(
|
|
43
|
+
'[data-slot="checkbox"]'
|
|
44
|
+
) as HTMLElement;
|
|
45
|
+
await user.click(checkbox);
|
|
46
|
+
expect(handleChange).toHaveBeenCalledWith(true);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("should be disabled when disabled prop is true", () => {
|
|
50
|
+
const { container } = render(<Checkbox disabled />);
|
|
51
|
+
const checkbox = container.querySelector('[data-slot="checkbox"]');
|
|
52
|
+
expect(checkbox).toHaveAttribute("data-disabled");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("should not call onCheckedChange when disabled", async () => {
|
|
56
|
+
const user = userEvent.setup();
|
|
57
|
+
const handleChange = vi.fn();
|
|
58
|
+
const { container } = render(
|
|
59
|
+
<Checkbox disabled onCheckedChange={handleChange} />
|
|
60
|
+
);
|
|
61
|
+
const checkbox = container.querySelector(
|
|
62
|
+
'[data-slot="checkbox"]'
|
|
63
|
+
) as HTMLElement;
|
|
64
|
+
await user.click(checkbox);
|
|
65
|
+
expect(handleChange).not.toHaveBeenCalled();
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
|
|
5
|
+
import { CheckIcon } from "lucide-react"
|
|
6
|
+
|
|
7
|
+
import { cn } from "@/lib/utils"
|
|
8
|
+
|
|
9
|
+
function Checkbox({
|
|
10
|
+
className,
|
|
11
|
+
...props
|
|
12
|
+
}: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
|
|
13
|
+
return (
|
|
14
|
+
<CheckboxPrimitive.Root
|
|
15
|
+
data-slot="checkbox"
|
|
16
|
+
className={cn(
|
|
17
|
+
"peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
|
|
18
|
+
className
|
|
19
|
+
)}
|
|
20
|
+
{...props}
|
|
21
|
+
>
|
|
22
|
+
<CheckboxPrimitive.Indicator
|
|
23
|
+
data-slot="checkbox-indicator"
|
|
24
|
+
className="grid place-content-center text-current transition-none"
|
|
25
|
+
>
|
|
26
|
+
<CheckIcon className="size-3.5" />
|
|
27
|
+
</CheckboxPrimitive.Indicator>
|
|
28
|
+
</CheckboxPrimitive.Root>
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { Checkbox }
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import {
|
|
4
|
+
Collapsible,
|
|
5
|
+
CollapsibleContent,
|
|
6
|
+
CollapsibleTrigger,
|
|
7
|
+
} from "./collapsible";
|
|
8
|
+
import { Button } from "./button";
|
|
9
|
+
import { ChevronDownIcon } from "lucide-react";
|
|
10
|
+
|
|
11
|
+
const meta = {
|
|
12
|
+
title: "Components/Collapsible",
|
|
13
|
+
component: Collapsible,
|
|
14
|
+
parameters: {
|
|
15
|
+
layout: "padded",
|
|
16
|
+
},
|
|
17
|
+
tags: ["autodocs"],
|
|
18
|
+
} satisfies Meta<typeof Collapsible>;
|
|
19
|
+
|
|
20
|
+
export default meta;
|
|
21
|
+
type Story = StoryObj<typeof meta>;
|
|
22
|
+
|
|
23
|
+
export const Default: Story = {
|
|
24
|
+
render: () => {
|
|
25
|
+
const [open, setOpen] = useState(false);
|
|
26
|
+
return (
|
|
27
|
+
<Collapsible open={open} onOpenChange={setOpen} className="w-[350px]">
|
|
28
|
+
<div className="flex items-center justify-between space-x-4 px-4">
|
|
29
|
+
<h4 className="text-sm font-semibold">
|
|
30
|
+
@peduarte starred 3 repositories
|
|
31
|
+
</h4>
|
|
32
|
+
<CollapsibleTrigger asChild>
|
|
33
|
+
<Button variant="ghost" size="icon">
|
|
34
|
+
<ChevronDownIcon className="h-4 w-4" />
|
|
35
|
+
<span className="sr-only">Toggle</span>
|
|
36
|
+
</Button>
|
|
37
|
+
</CollapsibleTrigger>
|
|
38
|
+
</div>
|
|
39
|
+
<div className="px-4 py-2 space-y-2">
|
|
40
|
+
<div className="rounded-md border px-4 py-2 text-sm">
|
|
41
|
+
@radix-ui/primitives
|
|
42
|
+
</div>
|
|
43
|
+
</div>
|
|
44
|
+
<CollapsibleContent className="space-y-2">
|
|
45
|
+
<div className="rounded-md border px-4 py-2 text-sm">
|
|
46
|
+
@radix-ui/colors
|
|
47
|
+
</div>
|
|
48
|
+
<div className="rounded-md border px-4 py-2 text-sm">
|
|
49
|
+
@stitches/react
|
|
50
|
+
</div>
|
|
51
|
+
</CollapsibleContent>
|
|
52
|
+
</Collapsible>
|
|
53
|
+
);
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const Simple: Story = {
|
|
58
|
+
render: () => {
|
|
59
|
+
const [open, setOpen] = useState(false);
|
|
60
|
+
return (
|
|
61
|
+
<Collapsible open={open} onOpenChange={setOpen} className="w-[350px]">
|
|
62
|
+
<CollapsibleTrigger asChild>
|
|
63
|
+
<Button variant="outline" className="w-full justify-between">
|
|
64
|
+
Click to {open ? "collapse" : "expand"}
|
|
65
|
+
<ChevronDownIcon
|
|
66
|
+
className={`h-4 w-4 transition-transform ${open ? "rotate-180" : ""}`}
|
|
67
|
+
/>
|
|
68
|
+
</Button>
|
|
69
|
+
</CollapsibleTrigger>
|
|
70
|
+
<CollapsibleContent className="mt-2 space-y-2">
|
|
71
|
+
<div className="rounded-md border p-4">
|
|
72
|
+
<p className="text-sm">
|
|
73
|
+
This is the collapsible content. It can contain any content you
|
|
74
|
+
want.
|
|
75
|
+
</p>
|
|
76
|
+
</div>
|
|
77
|
+
</CollapsibleContent>
|
|
78
|
+
</Collapsible>
|
|
79
|
+
);
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export const DefaultOpen: Story = {
|
|
84
|
+
render: () => (
|
|
85
|
+
<Collapsible defaultOpen className="w-[350px]">
|
|
86
|
+
<div className="flex items-center justify-between space-x-4 px-4">
|
|
87
|
+
<h4 className="text-sm font-semibold">Open by default</h4>
|
|
88
|
+
<CollapsibleTrigger asChild>
|
|
89
|
+
<Button variant="ghost" size="icon">
|
|
90
|
+
<ChevronDownIcon className="h-4 w-4" />
|
|
91
|
+
<span className="sr-only">Toggle</span>
|
|
92
|
+
</Button>
|
|
93
|
+
</CollapsibleTrigger>
|
|
94
|
+
</div>
|
|
95
|
+
<CollapsibleContent className="space-y-2 px-4">
|
|
96
|
+
<div className="rounded-md border px-4 py-2 text-sm">
|
|
97
|
+
This content is visible by default.
|
|
98
|
+
</div>
|
|
99
|
+
<div className="rounded-md border px-4 py-2 text-sm">
|
|
100
|
+
You can collapse it by clicking the button.
|
|
101
|
+
</div>
|
|
102
|
+
</CollapsibleContent>
|
|
103
|
+
</Collapsible>
|
|
104
|
+
),
|
|
105
|
+
};
|
|
106
|
+
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
|
+
import { render } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
import {
|
|
5
|
+
Collapsible,
|
|
6
|
+
CollapsibleTrigger,
|
|
7
|
+
CollapsibleContent,
|
|
8
|
+
} from "./collapsible";
|
|
9
|
+
|
|
10
|
+
describe("Collapsible", () => {
|
|
11
|
+
it("should render collapsible", () => {
|
|
12
|
+
const { container } = render(
|
|
13
|
+
<Collapsible>
|
|
14
|
+
<CollapsibleTrigger>Toggle</CollapsibleTrigger>
|
|
15
|
+
<CollapsibleContent>Content</CollapsibleContent>
|
|
16
|
+
</Collapsible>
|
|
17
|
+
);
|
|
18
|
+
const collapsible = container.querySelector('[data-slot="collapsible"]');
|
|
19
|
+
expect(collapsible).toBeInTheDocument();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("should render trigger and content", () => {
|
|
23
|
+
const { getByText, container } = render(
|
|
24
|
+
<Collapsible>
|
|
25
|
+
<CollapsibleTrigger>Toggle</CollapsibleTrigger>
|
|
26
|
+
<CollapsibleContent>Content</CollapsibleContent>
|
|
27
|
+
</Collapsible>
|
|
28
|
+
);
|
|
29
|
+
expect(getByText("Toggle")).toBeInTheDocument();
|
|
30
|
+
// Content is in DOM but may be hidden when closed
|
|
31
|
+
const content = container.querySelector(
|
|
32
|
+
'[data-slot="collapsible-content"]'
|
|
33
|
+
);
|
|
34
|
+
expect(content).toBeInTheDocument();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("should toggle content visibility when trigger is clicked", async () => {
|
|
38
|
+
const user = userEvent.setup();
|
|
39
|
+
const { getByText, container } = render(
|
|
40
|
+
<Collapsible>
|
|
41
|
+
<CollapsibleTrigger>Toggle</CollapsibleTrigger>
|
|
42
|
+
<CollapsibleContent>Content</CollapsibleContent>
|
|
43
|
+
</Collapsible>
|
|
44
|
+
);
|
|
45
|
+
const trigger = getByText("Toggle");
|
|
46
|
+
const contentElement = container.querySelector(
|
|
47
|
+
'[data-slot="collapsible-content"]'
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
// Content is in DOM but may be hidden when closed
|
|
51
|
+
expect(contentElement).toBeInTheDocument();
|
|
52
|
+
|
|
53
|
+
// Open
|
|
54
|
+
await user.click(trigger);
|
|
55
|
+
expect(contentElement).toBeInTheDocument();
|
|
56
|
+
expect(contentElement).toHaveAttribute("data-state", "open");
|
|
57
|
+
|
|
58
|
+
// Close
|
|
59
|
+
await user.click(trigger);
|
|
60
|
+
expect(contentElement).toBeInTheDocument();
|
|
61
|
+
expect(contentElement).toHaveAttribute("data-state", "closed");
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("should be open by default when defaultOpen is true", () => {
|
|
65
|
+
const { container } = render(
|
|
66
|
+
<Collapsible defaultOpen>
|
|
67
|
+
<CollapsibleTrigger>Toggle</CollapsibleTrigger>
|
|
68
|
+
<CollapsibleContent>Content</CollapsibleContent>
|
|
69
|
+
</Collapsible>
|
|
70
|
+
);
|
|
71
|
+
const content = container.querySelector(
|
|
72
|
+
'[data-slot="collapsible-content"]'
|
|
73
|
+
);
|
|
74
|
+
// Content should be in document and open when defaultOpen is true
|
|
75
|
+
expect(content).toBeInTheDocument();
|
|
76
|
+
expect(content).toHaveAttribute("data-state", "open");
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("should call onOpenChange when state changes", async () => {
|
|
80
|
+
const user = userEvent.setup();
|
|
81
|
+
const handleChange = vi.fn();
|
|
82
|
+
const { getByText } = render(
|
|
83
|
+
<Collapsible onOpenChange={handleChange}>
|
|
84
|
+
<CollapsibleTrigger>Toggle</CollapsibleTrigger>
|
|
85
|
+
<CollapsibleContent>Content</CollapsibleContent>
|
|
86
|
+
</Collapsible>
|
|
87
|
+
);
|
|
88
|
+
const trigger = getByText("Toggle");
|
|
89
|
+
await user.click(trigger);
|
|
90
|
+
expect(handleChange).toHaveBeenCalledWith(true);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as CollapsiblePrimitive from "@radix-ui/react-collapsible"
|
|
2
|
+
|
|
3
|
+
function Collapsible({
|
|
4
|
+
...props
|
|
5
|
+
}: React.ComponentProps<typeof CollapsiblePrimitive.Root>) {
|
|
6
|
+
return <CollapsiblePrimitive.Root data-slot="collapsible" {...props} />
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function CollapsibleTrigger({
|
|
10
|
+
...props
|
|
11
|
+
}: React.ComponentProps<typeof CollapsiblePrimitive.CollapsibleTrigger>) {
|
|
12
|
+
return (
|
|
13
|
+
<CollapsiblePrimitive.CollapsibleTrigger
|
|
14
|
+
data-slot="collapsible-trigger"
|
|
15
|
+
{...props}
|
|
16
|
+
/>
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function CollapsibleContent({
|
|
21
|
+
...props
|
|
22
|
+
}: React.ComponentProps<typeof CollapsiblePrimitive.CollapsibleContent>) {
|
|
23
|
+
return (
|
|
24
|
+
<CollapsiblePrimitive.CollapsibleContent
|
|
25
|
+
data-slot="collapsible-content"
|
|
26
|
+
{...props}
|
|
27
|
+
/>
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { Collapsible, CollapsibleTrigger, CollapsibleContent }
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import {
|
|
4
|
+
Command,
|
|
5
|
+
CommandDialog,
|
|
6
|
+
CommandEmpty,
|
|
7
|
+
CommandGroup,
|
|
8
|
+
CommandInput,
|
|
9
|
+
CommandItem,
|
|
10
|
+
CommandList,
|
|
11
|
+
} from "./command";
|
|
12
|
+
import { Button } from "./button";
|
|
13
|
+
|
|
14
|
+
const meta = {
|
|
15
|
+
title: "Components/Command",
|
|
16
|
+
component: Command,
|
|
17
|
+
parameters: {
|
|
18
|
+
layout: "padded",
|
|
19
|
+
},
|
|
20
|
+
tags: ["autodocs"],
|
|
21
|
+
} satisfies Meta<typeof Command>;
|
|
22
|
+
|
|
23
|
+
export default meta;
|
|
24
|
+
type Story = StoryObj<typeof meta>;
|
|
25
|
+
|
|
26
|
+
export const Default: Story = {
|
|
27
|
+
render: () => (
|
|
28
|
+
<Command className="rounded-lg border shadow-md max-w-[450px]">
|
|
29
|
+
<CommandInput placeholder="Type a command or search..." />
|
|
30
|
+
<CommandList>
|
|
31
|
+
<CommandEmpty>No results found.</CommandEmpty>
|
|
32
|
+
<CommandGroup heading="Suggestions">
|
|
33
|
+
<CommandItem>Calendar</CommandItem>
|
|
34
|
+
<CommandItem>Search Emoji</CommandItem>
|
|
35
|
+
<CommandItem>Calculator</CommandItem>
|
|
36
|
+
</CommandGroup>
|
|
37
|
+
<CommandGroup heading="Settings">
|
|
38
|
+
<CommandItem>Profile</CommandItem>
|
|
39
|
+
<CommandItem>Billing</CommandItem>
|
|
40
|
+
<CommandItem>Settings</CommandItem>
|
|
41
|
+
</CommandGroup>
|
|
42
|
+
</CommandList>
|
|
43
|
+
</Command>
|
|
44
|
+
),
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const Dialog: Story = {
|
|
48
|
+
render: () => {
|
|
49
|
+
const [open, setOpen] = useState(false);
|
|
50
|
+
return (
|
|
51
|
+
<>
|
|
52
|
+
<Button onClick={() => setOpen(true)}>Open Command</Button>
|
|
53
|
+
<CommandDialog open={open} onOpenChange={setOpen}>
|
|
54
|
+
<CommandInput placeholder="Type a command or search..." />
|
|
55
|
+
<CommandList>
|
|
56
|
+
<CommandEmpty>No results found.</CommandEmpty>
|
|
57
|
+
<CommandGroup heading="Suggestions">
|
|
58
|
+
<CommandItem>Calendar</CommandItem>
|
|
59
|
+
<CommandItem>Search Emoji</CommandItem>
|
|
60
|
+
<CommandItem>Calculator</CommandItem>
|
|
61
|
+
</CommandGroup>
|
|
62
|
+
<CommandGroup heading="Settings">
|
|
63
|
+
<CommandItem>Profile</CommandItem>
|
|
64
|
+
<CommandItem>Billing</CommandItem>
|
|
65
|
+
<CommandItem>Settings</CommandItem>
|
|
66
|
+
</CommandGroup>
|
|
67
|
+
</CommandList>
|
|
68
|
+
</CommandDialog>
|
|
69
|
+
</>
|
|
70
|
+
);
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export const WithIcons: Story = {
|
|
75
|
+
render: () => (
|
|
76
|
+
<Command className="rounded-lg border shadow-md max-w-[450px]">
|
|
77
|
+
<CommandInput placeholder="Type a command or search..." />
|
|
78
|
+
<CommandList>
|
|
79
|
+
<CommandEmpty>No results found.</CommandEmpty>
|
|
80
|
+
<CommandGroup heading="Fruits">
|
|
81
|
+
<CommandItem>🍎 Apple</CommandItem>
|
|
82
|
+
<CommandItem>🍌 Banana</CommandItem>
|
|
83
|
+
<CommandItem>🍊 Orange</CommandItem>
|
|
84
|
+
<CommandItem>🍇 Grape</CommandItem>
|
|
85
|
+
</CommandGroup>
|
|
86
|
+
</CommandList>
|
|
87
|
+
</Command>
|
|
88
|
+
),
|
|
89
|
+
};
|
|
90
|
+
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Command as CommandPrimitive } from "cmdk";
|
|
3
|
+
import { SearchIcon } from "lucide-react";
|
|
4
|
+
|
|
5
|
+
import { cn } from "@/lib/utils";
|
|
6
|
+
import {
|
|
7
|
+
Dialog,
|
|
8
|
+
DialogContent,
|
|
9
|
+
DialogDescription,
|
|
10
|
+
DialogHeader,
|
|
11
|
+
DialogTitle,
|
|
12
|
+
} from "@/components/dialog";
|
|
13
|
+
|
|
14
|
+
function Command({
|
|
15
|
+
className,
|
|
16
|
+
...props
|
|
17
|
+
}: React.ComponentProps<typeof CommandPrimitive>) {
|
|
18
|
+
return (
|
|
19
|
+
<CommandPrimitive
|
|
20
|
+
data-slot="command"
|
|
21
|
+
className={cn(
|
|
22
|
+
"bg-popover text-popover-foreground flex h-full w-full flex-col overflow-hidden rounded-md",
|
|
23
|
+
className
|
|
24
|
+
)}
|
|
25
|
+
{...props}
|
|
26
|
+
/>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function CommandDialog({
|
|
31
|
+
title = "Command Palette",
|
|
32
|
+
description = "Search for a command to run...",
|
|
33
|
+
children,
|
|
34
|
+
className,
|
|
35
|
+
showCloseButton = true,
|
|
36
|
+
...props
|
|
37
|
+
}: React.ComponentProps<typeof Dialog> & {
|
|
38
|
+
title?: string;
|
|
39
|
+
description?: string;
|
|
40
|
+
className?: string;
|
|
41
|
+
showCloseButton?: boolean;
|
|
42
|
+
}) {
|
|
43
|
+
return (
|
|
44
|
+
<Dialog {...props}>
|
|
45
|
+
<DialogHeader className="sr-only">
|
|
46
|
+
<DialogTitle>{title}</DialogTitle>
|
|
47
|
+
<DialogDescription>{description}</DialogDescription>
|
|
48
|
+
</DialogHeader>
|
|
49
|
+
<DialogContent
|
|
50
|
+
className={cn("overflow-hidden p-0", className)}
|
|
51
|
+
showCloseButton={showCloseButton}
|
|
52
|
+
>
|
|
53
|
+
<Command className="[&_[cmdk-group-heading]]:text-muted-foreground **:data-[slot=command-input-wrapper]:h-12 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5">
|
|
54
|
+
{children}
|
|
55
|
+
</Command>
|
|
56
|
+
</DialogContent>
|
|
57
|
+
</Dialog>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function CommandInput({
|
|
62
|
+
className,
|
|
63
|
+
...props
|
|
64
|
+
}: React.ComponentProps<typeof CommandPrimitive.Input>) {
|
|
65
|
+
return (
|
|
66
|
+
<div
|
|
67
|
+
data-slot="command-input-wrapper"
|
|
68
|
+
className="flex h-9 items-center gap-2 border-b px-3"
|
|
69
|
+
>
|
|
70
|
+
<SearchIcon className="size-4 shrink-0 opacity-50" />
|
|
71
|
+
<CommandPrimitive.Input
|
|
72
|
+
data-slot="command-input"
|
|
73
|
+
className={cn(
|
|
74
|
+
"placeholder:text-muted-foreground flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-hidden disabled:cursor-not-allowed disabled:opacity-50",
|
|
75
|
+
className
|
|
76
|
+
)}
|
|
77
|
+
{...props}
|
|
78
|
+
/>
|
|
79
|
+
</div>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function CommandList({
|
|
84
|
+
className,
|
|
85
|
+
...props
|
|
86
|
+
}: React.ComponentProps<typeof CommandPrimitive.List>) {
|
|
87
|
+
return (
|
|
88
|
+
<CommandPrimitive.List
|
|
89
|
+
data-slot="command-list"
|
|
90
|
+
className={cn(
|
|
91
|
+
"max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto",
|
|
92
|
+
className
|
|
93
|
+
)}
|
|
94
|
+
{...props}
|
|
95
|
+
/>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function CommandEmpty({
|
|
100
|
+
...props
|
|
101
|
+
}: React.ComponentProps<typeof CommandPrimitive.Empty>) {
|
|
102
|
+
return (
|
|
103
|
+
<CommandPrimitive.Empty
|
|
104
|
+
data-slot="command-empty"
|
|
105
|
+
className="py-6 text-center text-sm"
|
|
106
|
+
{...props}
|
|
107
|
+
/>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function CommandGroup({
|
|
112
|
+
className,
|
|
113
|
+
...props
|
|
114
|
+
}: React.ComponentProps<typeof CommandPrimitive.Group>) {
|
|
115
|
+
return (
|
|
116
|
+
<CommandPrimitive.Group
|
|
117
|
+
data-slot="command-group"
|
|
118
|
+
className={cn(
|
|
119
|
+
"text-foreground [&_[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium",
|
|
120
|
+
className
|
|
121
|
+
)}
|
|
122
|
+
{...props}
|
|
123
|
+
/>
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function CommandSeparator({
|
|
128
|
+
className,
|
|
129
|
+
...props
|
|
130
|
+
}: React.ComponentProps<typeof CommandPrimitive.Separator>) {
|
|
131
|
+
return (
|
|
132
|
+
<CommandPrimitive.Separator
|
|
133
|
+
data-slot="command-separator"
|
|
134
|
+
className={cn("bg-border -mx-1 h-px", className)}
|
|
135
|
+
{...props}
|
|
136
|
+
/>
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function CommandItem({
|
|
141
|
+
className,
|
|
142
|
+
...props
|
|
143
|
+
}: React.ComponentProps<typeof CommandPrimitive.Item>) {
|
|
144
|
+
return (
|
|
145
|
+
<CommandPrimitive.Item
|
|
146
|
+
data-slot="command-item"
|
|
147
|
+
className={cn(
|
|
148
|
+
"data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
149
|
+
className
|
|
150
|
+
)}
|
|
151
|
+
{...props}
|
|
152
|
+
/>
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function CommandShortcut({
|
|
157
|
+
className,
|
|
158
|
+
...props
|
|
159
|
+
}: React.ComponentProps<"span">) {
|
|
160
|
+
return (
|
|
161
|
+
<span
|
|
162
|
+
data-slot="command-shortcut"
|
|
163
|
+
className={cn(
|
|
164
|
+
"text-muted-foreground ml-auto text-xs tracking-widest",
|
|
165
|
+
className
|
|
166
|
+
)}
|
|
167
|
+
{...props}
|
|
168
|
+
/>
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export {
|
|
173
|
+
Command,
|
|
174
|
+
CommandDialog,
|
|
175
|
+
CommandInput,
|
|
176
|
+
CommandList,
|
|
177
|
+
CommandEmpty,
|
|
178
|
+
CommandGroup,
|
|
179
|
+
CommandItem,
|
|
180
|
+
CommandShortcut,
|
|
181
|
+
CommandSeparator,
|
|
182
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
2
|
+
import {
|
|
3
|
+
ContextMenu,
|
|
4
|
+
ContextMenuContent,
|
|
5
|
+
ContextMenuItem,
|
|
6
|
+
ContextMenuLabel,
|
|
7
|
+
ContextMenuSeparator,
|
|
8
|
+
ContextMenuTrigger,
|
|
9
|
+
} from "./context-menu";
|
|
10
|
+
|
|
11
|
+
const meta = {
|
|
12
|
+
title: "Components/ContextMenu",
|
|
13
|
+
component: ContextMenu,
|
|
14
|
+
parameters: {
|
|
15
|
+
layout: "padded",
|
|
16
|
+
},
|
|
17
|
+
tags: ["autodocs"],
|
|
18
|
+
} satisfies Meta<typeof ContextMenu>;
|
|
19
|
+
|
|
20
|
+
export default meta;
|
|
21
|
+
type Story = StoryObj<typeof meta>;
|
|
22
|
+
|
|
23
|
+
export const Default: Story = {
|
|
24
|
+
render: () => (
|
|
25
|
+
<ContextMenu>
|
|
26
|
+
<ContextMenuTrigger className="flex h-[150px] w-[300px] items-center justify-center rounded-md border border-dashed text-sm">
|
|
27
|
+
Right click here
|
|
28
|
+
</ContextMenuTrigger>
|
|
29
|
+
<ContextMenuContent>
|
|
30
|
+
<ContextMenuItem>Back</ContextMenuItem>
|
|
31
|
+
<ContextMenuItem>Forward</ContextMenuItem>
|
|
32
|
+
<ContextMenuItem>Reload</ContextMenuItem>
|
|
33
|
+
<ContextMenuSeparator />
|
|
34
|
+
<ContextMenuItem>Save As...</ContextMenuItem>
|
|
35
|
+
<ContextMenuItem>Print</ContextMenuItem>
|
|
36
|
+
<ContextMenuSeparator />
|
|
37
|
+
<ContextMenuItem>View Page Source</ContextMenuItem>
|
|
38
|
+
</ContextMenuContent>
|
|
39
|
+
</ContextMenu>
|
|
40
|
+
),
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const WithGroups: Story = {
|
|
44
|
+
render: () => (
|
|
45
|
+
<ContextMenu>
|
|
46
|
+
<ContextMenuTrigger className="flex h-[150px] w-[300px] items-center justify-center rounded-md border border-dashed text-sm">
|
|
47
|
+
Right click for grouped menu
|
|
48
|
+
</ContextMenuTrigger>
|
|
49
|
+
<ContextMenuContent>
|
|
50
|
+
<ContextMenuLabel>File</ContextMenuLabel>
|
|
51
|
+
<ContextMenuItem>New</ContextMenuItem>
|
|
52
|
+
<ContextMenuItem>Open</ContextMenuItem>
|
|
53
|
+
<ContextMenuItem>Save</ContextMenuItem>
|
|
54
|
+
<ContextMenuSeparator />
|
|
55
|
+
<ContextMenuLabel>Edit</ContextMenuLabel>
|
|
56
|
+
<ContextMenuItem>Cut</ContextMenuItem>
|
|
57
|
+
<ContextMenuItem>Copy</ContextMenuItem>
|
|
58
|
+
<ContextMenuItem>Paste</ContextMenuItem>
|
|
59
|
+
</ContextMenuContent>
|
|
60
|
+
</ContextMenu>
|
|
61
|
+
),
|
|
62
|
+
};
|
|
63
|
+
|