Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/components/ui/command.tsx
T

133 lines
6.0 KiB
TypeScript

import { requestScopedT as i18nT } from "~/locale/request-scoped-t";
("use client");
import * as React from "react";
import { Command as CommandPrimitive } from "cmdk";
import { SearchIcon } from "~/components/ui/icons/vendor";
import { cn } from "~/lib/utils";
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "~/components/ui/dialog";
function Command({ className, ...props }: React.ComponentProps<typeof CommandPrimitive>) {
return (
<CommandPrimitive
data-slot="command"
className={cn("bg-surface-neutral-primary text-text-neutral-primary flex h-full w-full flex-col overflow-hidden rounded-md", className)}
{...props}
/>
);
}
function CommandDialog({
title = i18nT("components.command.title"),
description = i18nT("components.command.description"),
children,
dataUiId,
onCloseAutoFocus,
shouldFilter,
onCommandKeyDownCapture,
...props
}: React.ComponentProps<typeof Dialog> & {
title?: string;
description?: string;
dataUiId?: string;
onCloseAutoFocus?: (event: Event) => void;
shouldFilter?: boolean;
onCommandKeyDownCapture?: React.KeyboardEventHandler<HTMLDivElement>;
}) {
return (
<Dialog {...props}>
<DialogHeader className="sr-only">
<DialogTitle>{title}</DialogTitle>
<DialogDescription>{description}</DialogDescription>
</DialogHeader>
<DialogContent
data-ui-id={dataUiId}
onCloseAutoFocus={onCloseAutoFocus}
overlayClassName="bg-black/35 backdrop-blur-[2px]"
closeButtonClassName="sm:hidden"
positioning="custom"
className="bg-surface-neutral-primary top-0 right-0 bottom-0 left-0 h-dvh max-h-none w-screen max-w-none min-w-0 overflow-hidden rounded-none border-0 p-0 shadow-2xl sm:top-[16vh] sm:right-auto sm:bottom-auto sm:left-1/2 sm:h-auto sm:max-h-[68vh] sm:w-[min(44rem,calc(100%-2rem))] sm:-translate-x-1/2 sm:translate-y-0 sm:rounded-lg sm:border"
>
<Command
shouldFilter={shouldFilter}
onKeyDownCapture={onCommandKeyDownCapture}
className="[&_[cmdk-group-heading]]:text-text-neutral-tertiary rounded-none sm:rounded-lg [&_[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-item]]:px-2 [&_[cmdk-item]]:py-2 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5"
>
{children}
</Command>
</DialogContent>
</Dialog>
);
}
function CommandInput({ className, style, ...props }: React.ComponentProps<typeof CommandPrimitive.Input>) {
return (
<div
data-slot="command-input-wrapper"
className="group/command-search border-border-strong bg-surface-neutral-primary hover:bg-surface-neutral-secondary focus-within:bg-surface-neutral-secondary focus-within:shadow-focus m-2 flex h-10 items-center gap-2.5 rounded-sm border border-solid px-3 pr-10"
>
<SearchIcon className="text-icon-neutral-tertiary size-4 shrink-0" />
<CommandPrimitive.Input
data-slot="command-input"
className={cn(
"placeholder:text-text-neutral-subtle text-text-neutral-secondary text-body-default-regular-0 font-body-default-regular-0 flex h-full w-full border-0 bg-transparent py-0 outline-none focus:outline-none focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50",
className
)}
style={{ boxShadow: "none", ...style }}
{...props}
/>
</div>
);
}
function CommandList({ className, ...props }: React.ComponentProps<typeof CommandPrimitive.List>) {
return (
<CommandPrimitive.List
data-slot="command-list"
className={cn("max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto overscroll-contain", className)}
{...props}
/>
);
}
function CommandEmpty({ ...props }: React.ComponentProps<typeof CommandPrimitive.Empty>) {
return <CommandPrimitive.Empty data-slot="command-empty" className="py-6 text-center text-sm" {...props} />;
}
function CommandGroup({ className, ...props }: React.ComponentProps<typeof CommandPrimitive.Group>) {
return (
<CommandPrimitive.Group
data-slot="command-group"
className={cn(
"text-text-neutral-primary [&_[cmdk-group-heading]]:text-text-neutral-tertiary [&_[cmdk-group-heading]]:text-body-extra-small-medium-0 [&_[cmdk-group-heading]]:font-body-extra-small-medium-0 overflow-hidden px-1 py-1.5 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5",
className
)}
{...props}
/>
);
}
function CommandSeparator({ className, ...props }: React.ComponentProps<typeof CommandPrimitive.Separator>) {
return <CommandPrimitive.Separator data-slot="command-separator" className={cn("bg-border-default -mx-1 h-px", className)} {...props} />;
}
function CommandItem({ className, ...props }: React.ComponentProps<typeof CommandPrimitive.Item>) {
return (
<CommandPrimitive.Item
data-slot="command-item"
className={cn(
"group/command-item hover:bg-surface-neutral-tertiary active:bg-surface-neutral-secondary data-[selected=true]:bg-surface-ui-subtle-blue-default data-[selected=true]:text-text-neutral-primary [&_svg:not([class*='text-'])]:text-text-neutral-tertiary text-body-small-medium-150 font-body-small-medium-150 relative flex cursor-pointer items-center gap-2 rounded-md px-2 py-2 outline-hidden transition-colors 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",
className
)}
{...props}
/>
);
}
function CommandShortcut({ className, ...props }: React.ComponentProps<"span">) {
return <span data-slot="command-shortcut" className={cn("text-text-neutral-tertiary ml-auto text-xs tracking-widest", className)} {...props} />;
}
export { Command, CommandDialog, CommandInput, CommandList, CommandEmpty, CommandGroup, CommandItem, CommandShortcut, CommandSeparator };