mirror of
https://github.com/cosscom/coss.git
synced 2026-09-14 20:06:50 +08:00
9302c06311
* update biome config + resolve issues * improve the ui:sync command to run organizeImports on packages * reformat * build registry * exclude base-ui stuff * fix useExportsLast * further improvements * silence errors * exclude examples app * update biome + reformat * format all the other files * include examples app * improve copyable-field * remove unwanted comment * remove a few unneeded biome comments * avoid nested ternary * refactored some shared components * upgrade base ui to 1.2.0 * fix
177 lines
4.5 KiB
TypeScript
177 lines
4.5 KiB
TypeScript
"use client";
|
|
|
|
import { Command as CommandPrimitive } from "cmdk";
|
|
import { SearchIcon } from "lucide-react";
|
|
import type * as React from "react";
|
|
import { cn } from "@/registry/default/lib/utils";
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
} from "@/registry/default/ui/dialog";
|
|
|
|
function Command({
|
|
className,
|
|
...props
|
|
}: React.ComponentProps<typeof CommandPrimitive>) {
|
|
return (
|
|
<CommandPrimitive
|
|
className={cn(
|
|
"flex size-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",
|
|
className,
|
|
)}
|
|
data-slot="command"
|
|
{...props}
|
|
/>
|
|
);
|
|
}
|
|
|
|
function CommandDialog({
|
|
title = "Command Palette",
|
|
description = "Search for a command to run...",
|
|
children,
|
|
...props
|
|
}: React.ComponentProps<typeof Dialog> & {
|
|
title?: string;
|
|
description?: string;
|
|
}) {
|
|
return (
|
|
<Dialog {...props}>
|
|
<DialogHeader className="sr-only">
|
|
<DialogTitle>{title}</DialogTitle>
|
|
<DialogDescription>{description}</DialogDescription>
|
|
</DialogHeader>
|
|
<DialogContent className="overflow-hidden p-0 sm:max-w-lg [&>button:last-child]:hidden">
|
|
<Command className="max-h-[100svh] **:data-[slot=command-input-wrapper]:h-12 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]]:px-2 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-3 [&_[cmdk-item]]:py-2">
|
|
{children}
|
|
</Command>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
}
|
|
|
|
function CommandInput({
|
|
className,
|
|
...props
|
|
}: React.ComponentProps<typeof CommandPrimitive.Input>) {
|
|
return (
|
|
<div
|
|
className="flex items-center border-input border-b px-5"
|
|
cmdk-input-wrapper=""
|
|
>
|
|
<SearchIcon className="me-3 text-muted-foreground/80" size={20} />
|
|
<CommandPrimitive.Input
|
|
className={cn(
|
|
"flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-hidden placeholder:text-muted-foreground/70 disabled:cursor-not-allowed disabled:opacity-50",
|
|
className,
|
|
)}
|
|
data-slot="command-input-wrapper"
|
|
{...props}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function CommandList({
|
|
className,
|
|
...props
|
|
}: React.ComponentProps<typeof CommandPrimitive.List>) {
|
|
return (
|
|
<CommandPrimitive.List
|
|
className={cn(
|
|
"max-h-80 flex-1 overflow-y-auto overflow-x-hidden",
|
|
className,
|
|
)}
|
|
data-slot="command-list"
|
|
{...props}
|
|
/>
|
|
);
|
|
}
|
|
|
|
function CommandEmpty({
|
|
...props
|
|
}: React.ComponentProps<typeof CommandPrimitive.Empty>) {
|
|
return (
|
|
<CommandPrimitive.Empty
|
|
className="py-6 text-center text-sm"
|
|
data-slot="command-empty"
|
|
{...props}
|
|
/>
|
|
);
|
|
}
|
|
|
|
function CommandGroup({
|
|
className,
|
|
...props
|
|
}: React.ComponentProps<typeof CommandPrimitive.Group>) {
|
|
return (
|
|
<CommandPrimitive.Group
|
|
className={cn(
|
|
"overflow-hidden p-2 text-foreground [&_[cmdk-group-heading]]:px-3 [&_[cmdk-group-heading]]:py-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group-heading]]:text-xs",
|
|
className,
|
|
)}
|
|
data-slot="command-group"
|
|
{...props}
|
|
/>
|
|
);
|
|
}
|
|
|
|
function CommandSeparator({
|
|
className,
|
|
...props
|
|
}: React.ComponentProps<typeof CommandPrimitive.Separator>) {
|
|
return (
|
|
<CommandPrimitive.Separator
|
|
className={cn("-mx-1 h-px bg-border", className)}
|
|
data-slot="command-separator"
|
|
{...props}
|
|
/>
|
|
);
|
|
}
|
|
|
|
function CommandItem({
|
|
className,
|
|
...props
|
|
}: React.ComponentProps<typeof CommandPrimitive.Item>) {
|
|
return (
|
|
<CommandPrimitive.Item
|
|
className={cn(
|
|
"relative flex cursor-default select-none items-center gap-3 rounded-md px-2 py-1.5 text-sm outline-hidden data-[disabled=true]:pointer-events-none data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
|
className,
|
|
)}
|
|
data-slot="command-item"
|
|
{...props}
|
|
/>
|
|
);
|
|
}
|
|
|
|
function CommandShortcut({
|
|
className,
|
|
...props
|
|
}: React.ComponentProps<"span">) {
|
|
return (
|
|
<kbd
|
|
className={cn(
|
|
"ms-auto -me-1 inline-flex h-5 max-h-full items-center rounded border bg-background px-1 font-[inherit] font-medium text-[0.625rem] text-muted-foreground/70",
|
|
className,
|
|
)}
|
|
data-slot="command-shortcut"
|
|
{...props}
|
|
/>
|
|
);
|
|
}
|
|
|
|
export {
|
|
Command,
|
|
CommandDialog,
|
|
CommandEmpty,
|
|
CommandGroup,
|
|
CommandInput,
|
|
CommandItem,
|
|
CommandList,
|
|
CommandSeparator,
|
|
CommandShortcut,
|
|
};
|