Skip to content

Commit

Permalink
chore: update command K
Browse files Browse the repository at this point in the history
  • Loading branch information
potts99 committed Jun 10, 2024
1 parent 4d2fc2b commit 33f7006
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 34 deletions.
64 changes: 64 additions & 0 deletions apps/client/@/shadcn/block/GlobalShortcut.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import * as React from "react";
import {
Calculator,
Calendar,
CreditCard,
Settings,
Smile,
User,
} from "lucide-react";

import {
CommandDialog,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
CommandSeparator,
CommandShortcut,
} from "@/shadcn/ui/command";

export default function GlobalShortcut() {
const [open, setOpen] = React.useState(false);

React.useEffect(() => {
const down = (e: KeyboardEvent) => {
if (e.key === "k" && (e.metaKey || e.ctrlKey)) {
e.preventDefault();
setOpen((open) => !open);
}
};

document.addEventListener("keydown", down);
return () => document.removeEventListener("keydown", down);
}, []);

return (
<>
<CommandDialog open={open} onOpenChange={setOpen} >
<CommandInput className="" placeholder="Type a command or search..." />
<CommandList>
<CommandEmpty>No results found.</CommandEmpty>
<CommandGroup heading="Tickets">

<CommandItem>
<Calendar className="mr-2 h-4 w-4" />
<span>All Tickets</span>
</CommandItem>
<CommandItem>
<Smile className="mr-2 h-4 w-4" />
<span>Open Tickets</span>
</CommandItem>
<CommandItem>
<Calculator className="mr-2 h-4 w-4" />
<span>Closed Tickets</span>
</CommandItem>
</CommandGroup>
<CommandSeparator />

</CommandList>
</CommandDialog>
</>
);
}
58 changes: 29 additions & 29 deletions apps/client/@/shadcn/ui/command.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as React from "react"
import { type DialogProps } from "@radix-ui/react-dialog"
import { Command as CommandPrimitive } from "cmdk"
import { Search } from "lucide-react"
import * as React from "react";
import { type DialogProps } from "@radix-ui/react-dialog";
import { Command as CommandPrimitive } from "cmdk";
import { Search } from "lucide-react";

import { cn } from "@/shadcn/lib/utils"
import { Dialog, DialogContent } from "@/shadcn/ui/dialog"
import { cn } from "@/shadcn/lib/utils";
import { Dialog, DialogContent } from "@/shadcn/ui/dialog";

const Command = React.forwardRef<
React.ElementRef<typeof CommandPrimitive>,
Expand All @@ -18,22 +18,22 @@ const Command = React.forwardRef<
)}
{...props}
/>
))
Command.displayName = CommandPrimitive.displayName
));
Command.displayName = CommandPrimitive.displayName;

interface CommandDialogProps extends DialogProps {}

const CommandDialog = ({ children, ...props }: CommandDialogProps) => {
return (
<Dialog {...props}>
<DialogContent className="overflow-hidden p-0 shadow-lg">
<Dialog {...props} >
<DialogContent className="overflow-hidden p-1 shadow-lg ">
<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>
</DialogContent>
</Dialog>
)
}
);
};

const CommandInput = React.forwardRef<
React.ElementRef<typeof CommandPrimitive.Input>,
Expand All @@ -44,15 +44,15 @@ const CommandInput = React.forwardRef<
<CommandPrimitive.Input
ref={ref}
className={cn(
"flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",
"flex w-full rounded-md bg-transparent border-none focus:shadow-none focus:ring-0 focus:border-none py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed focus:outline-none disabled:opacity-50",
className
)}
{...props}
/>
</div>
))
));

CommandInput.displayName = CommandPrimitive.Input.displayName
CommandInput.displayName = CommandPrimitive.Input.displayName;

const CommandList = React.forwardRef<
React.ElementRef<typeof CommandPrimitive.List>,
Expand All @@ -63,9 +63,9 @@ const CommandList = React.forwardRef<
className={cn("max-h-[300px] overflow-y-auto overflow-x-hidden", className)}
{...props}
/>
))
));

CommandList.displayName = CommandPrimitive.List.displayName
CommandList.displayName = CommandPrimitive.List.displayName;

const CommandEmpty = React.forwardRef<
React.ElementRef<typeof CommandPrimitive.Empty>,
Expand All @@ -76,9 +76,9 @@ const CommandEmpty = React.forwardRef<
className="py-6 text-center text-sm"
{...props}
/>
))
));

CommandEmpty.displayName = CommandPrimitive.Empty.displayName
CommandEmpty.displayName = CommandPrimitive.Empty.displayName;

const CommandGroup = React.forwardRef<
React.ElementRef<typeof CommandPrimitive.Group>,
Expand All @@ -92,9 +92,9 @@ const CommandGroup = React.forwardRef<
)}
{...props}
/>
))
));

CommandGroup.displayName = CommandPrimitive.Group.displayName
CommandGroup.displayName = CommandPrimitive.Group.displayName;

const CommandSeparator = React.forwardRef<
React.ElementRef<typeof CommandPrimitive.Separator>,
Expand All @@ -105,8 +105,8 @@ const CommandSeparator = React.forwardRef<
className={cn("-mx-1 h-px bg-border", className)}
{...props}
/>
))
CommandSeparator.displayName = CommandPrimitive.Separator.displayName
));
CommandSeparator.displayName = CommandPrimitive.Separator.displayName;

const CommandItem = React.forwardRef<
React.ElementRef<typeof CommandPrimitive.Item>,
Expand All @@ -120,9 +120,9 @@ const CommandItem = React.forwardRef<
)}
{...props}
/>
))
));

CommandItem.displayName = CommandPrimitive.Item.displayName
CommandItem.displayName = CommandPrimitive.Item.displayName;

const CommandShortcut = ({
className,
Expand All @@ -136,9 +136,9 @@ const CommandShortcut = ({
)}
{...props}
/>
)
}
CommandShortcut.displayName = "CommandShortcut"
);
};
CommandShortcut.displayName = "CommandShortcut";

export {
Command,
Expand All @@ -150,4 +150,4 @@ export {
CommandItem,
CommandShortcut,
CommandSeparator,
}
};
4 changes: 2 additions & 2 deletions apps/client/@/shadcn/ui/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ const DialogContent = React.forwardRef<
<DialogPrimitive.Content
ref={ref}
className={cn(
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-xl translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
className
)}
{...props}
>
{children}
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
<X className="h-4 w-4" />
<X className="h-4 w-4 mt-1" />
<span className="sr-only">Close</span>
</DialogPrimitive.Close>
</DialogPrimitive.Content>
Expand Down
4 changes: 2 additions & 2 deletions apps/client/layouts/newLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -896,12 +896,12 @@ export default function NewLayout({ children }: any) {
{user.isAdmin && (
<Link href="https://github.com/Peppermint-Lab/peppermint/releases">
<span className="inline-flex items-center rounded-md bg-green-700/10 px-3 py-2 text-xs font-medium text-green-600 ring-1 ring-inset ring-green-500/20">
Version 0.4.8
Version 0.4.9
</span>
</Link>
)}

<CommandModal />
{/* <CommandModal /> */}
</div>

<div className="flex w-full justify-end items-center gap-x-2 lg:gap-x-2 ">
Expand Down
4 changes: 3 additions & 1 deletion apps/client/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//@ts-nocheck
import "@radix-ui/themes/styles.css";
import "../styles/globals.css";

import { ThemeProvider } from "next-themes";
import "../styles/globals.css";

import {
DocumentCheckIcon,
Expand All @@ -25,6 +25,7 @@ import NewLayout from "../layouts/newLayout";
import NoteBookLayout from "../layouts/notebook";
import PortalLayout from "../layouts/portalLayout";
import Settings from "../layouts/settings";
import GlobalShortcut from '@/shadcn/block/GlobalShortcut'

const queryClient = new QueryClient();

Expand Down Expand Up @@ -215,6 +216,7 @@ function MyApp({ Component, pageProps: { session, ...pageProps } }: any) {
<QueryClientProvider client={queryClient}>
<Auth>
<NewLayout>
<GlobalShortcut />
<Notifications position="top-right" />
<Component {...pageProps} />
</NewLayout>
Expand Down

0 comments on commit 33f7006

Please sign in to comment.