Skip to content
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
20 changes: 17 additions & 3 deletions components/shadcn/command.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,26 @@ function Command({
);
}

interface CommandDialogProps extends DialogProps {}
interface CommandDialogProps extends DialogProps {
className?: string;
containerClassName?: string;
position?: "top" | "center" | "bottom";
}

function CommandDialog({ children, ...props }: CommandDialogProps) {
function CommandDialog({
children,
className,
containerClassName,
position,
...props
}: CommandDialogProps) {
return (
<Dialog {...props}>
<DialogContent className="overflow-hidden p-0">
<DialogContent
className={cn("overflow-hidden p-0", className)}
position={position}
containerClassName={containerClassName}
>
<Command className="[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-group]]:px-2 [&_[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">
{children}
</Command>
Expand Down
24 changes: 22 additions & 2 deletions components/shadcn/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,35 @@ function DialogOverlay({
);
}

interface DialogContentProps
extends React.ComponentProps<typeof DialogPrimitive.Content> {
position?: "top" | "center" | "bottom";
containerClassName?: string;
}

function DialogContent({
className,
children,
position = "center",
containerClassName,
...props
}: React.ComponentProps<typeof DialogPrimitive.Content>) {
}: DialogContentProps) {
const positionClasses = {
top: "items-start pt-[5vh]",
center: "items-center",
bottom: "items-end pb-[5vh]",
};

return (
<DialogPortal>
<DialogOverlay />
<div className="fixed inset-0 z-50 flex items-center justify-center">
<div
className={cn(
"fixed inset-0 z-50 flex justify-center",
positionClasses[position],
containerClassName,
)}
>
<DialogPrimitive.Content
className={cn(
"data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-100 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-top-[-2%] data-[state=open]:slide-in-from-top-[-2%] relative grid w-full max-w-lg translate-y-[0%] gap-4 border bg-background p-6 duration-200 data-[state=closed]:animate-out data-[state=open]:animate-in",
Expand Down
146 changes: 146 additions & 0 deletions stories/Command.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import type { Meta, StoryObj } from "@storybook/react-vite";

import {
Calculator,
Calendar,
CreditCard,
Settings,
Smile,
User,
} from "lucide-react";
import React from "react";
import { Button } from "../components/shadcn/button.js";
import {
Command,
CommandDialog,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
CommandSeparator,
CommandShortcut,
} from "../components/shadcn/command.js";

const meta = {
title: "Components/Command",
component: Command,
parameters: {
layout: "centered",
},
tags: ["autodocs"],
} satisfies Meta<typeof Command>;

export default meta;
type Story = StoryObj<typeof meta>;

export const Default: Story = {
render: () => (
<Command className="rounded-lg border shadow-md">
<CommandInput placeholder="Type a command or search..." />
<CommandList>
<CommandEmpty>No results found.</CommandEmpty>
<CommandGroup heading="Suggestions">
<CommandItem>
<Calendar className="mr-2 h-4 w-4" />
<span>Calendar</span>
</CommandItem>
<CommandItem>
<Smile className="mr-2 h-4 w-4" />
<span>Search Emoji</span>
</CommandItem>
<CommandItem disabled>
<Calculator className="mr-2 h-4 w-4" />
<span>Calculator</span>
</CommandItem>
</CommandGroup>
<CommandSeparator />
<CommandGroup heading="Settings">
<CommandItem>
<User className="mr-2 h-4 w-4" />
<span>Profile</span>
<CommandShortcut>⌘P</CommandShortcut>
</CommandItem>
<CommandItem>
<CreditCard className="mr-2 h-4 w-4" />
<span>Billing</span>
<CommandShortcut>⌘B</CommandShortcut>
</CommandItem>
<CommandItem>
<Settings className="mr-2 h-4 w-4" />
<span>Settings</span>
<CommandShortcut>⌘S</CommandShortcut>
</CommandItem>
</CommandGroup>
</CommandList>
</Command>
),
};

export const WithDialog: Story = {
render: () => {
const [open, setOpen] = React.useState(false);

return (
<>
<Button onClick={() => setOpen(true)}>Open Command Menu</Button>
<CommandDialog position="center" open={open} onOpenChange={setOpen}>
<CommandInput placeholder="Type a command or search..." />
<CommandList>
<CommandEmpty>No results found.</CommandEmpty>
<CommandGroup heading="Suggestions">
<CommandItem>
<Calendar className="mr-2 h-4 w-4" />
<span>Calendar</span>
</CommandItem>
<CommandItem>
<Smile className="mr-2 h-4 w-4" />
<span>Search Emoji</span>
</CommandItem>
<CommandItem>
<Calculator className="mr-2 h-4 w-4" />
<span>Calculator</span>
</CommandItem>
</CommandGroup>
<CommandSeparator />
<CommandGroup heading="Settings">
<CommandItem>
<User className="mr-2 h-4 w-4" />
<span>Profile</span>
<CommandShortcut>⌘P</CommandShortcut>
</CommandItem>
<CommandItem>
<CreditCard className="mr-2 h-4 w-4" />
<span>Billing</span>
<CommandShortcut>⌘B</CommandShortcut>
</CommandItem>
<CommandItem>
<Settings className="mr-2 h-4 w-4" />
<span>Settings</span>
<CommandShortcut>⌘S</CommandShortcut>
</CommandItem>
</CommandGroup>
</CommandList>
</CommandDialog>
</>
);
},
};

export const Simple: Story = {
render: () => (
<Command className="max-w-[300px] rounded-lg border shadow-md">
<CommandInput placeholder="Search..." />
<CommandList>
<CommandEmpty>No results found.</CommandEmpty>
<CommandGroup>
<CommandItem>Apple</CommandItem>
<CommandItem>Banana</CommandItem>
<CommandItem>Cherry</CommandItem>
<CommandItem>Date</CommandItem>
<CommandItem>Elderberry</CommandItem>
</CommandGroup>
</CommandList>
</Command>
),
};