From 7b02884ed5ed809be514a578605ea4f683e4e6ea Mon Sep 17 00:00:00 2001 From: Daryl Lim Date: Mon, 11 Mar 2024 22:28:23 -0700 Subject: [PATCH] feat(ui): Add aux click menu --- frontend/src/components/aux-click-menu.tsx | 165 +++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 frontend/src/components/aux-click-menu.tsx diff --git a/frontend/src/components/aux-click-menu.tsx b/frontend/src/components/aux-click-menu.tsx new file mode 100644 index 000000000..ded839374 --- /dev/null +++ b/frontend/src/components/aux-click-menu.tsx @@ -0,0 +1,165 @@ +import React, { useState } from "react" + +import { cn } from "@/lib/utils" +import { + ContextMenu, + ContextMenuCheckboxItem, + ContextMenuContent, + ContextMenuItem, + ContextMenuLabel, + ContextMenuRadioGroup, + ContextMenuRadioItem, + ContextMenuSeparator, + ContextMenuShortcut, + ContextMenuSub, + ContextMenuSubContent, + ContextMenuSubTrigger, + ContextMenuTrigger, +} from "@/components/ui/context-menu" + +export interface BaseAuxClickMenuOption { + type: "item" | "sub" | "radio" | "checkbox" | "separator" + icon?: React.ReactNode + children?: React.ReactNode + shortcut?: React.ReactNode + onClick?: () => void +} + +export interface AuxClickMenuItemProps extends BaseAuxClickMenuOption { + type: "item" +} + +export interface AuxClickMenuSubProps extends BaseAuxClickMenuOption { + type: "sub" + items?: AuxClickMenuOptionProps[] +} +interface AuxClickMenuRadioProps extends BaseAuxClickMenuOption { + type: "radio" + defaultValue?: string + items?: { title: string; value: string }[] +} +interface AuxClickMenuCheckboxProps extends BaseAuxClickMenuOption { + type: "checkbox" +} +interface AuxClickMenuSeparatorProps extends BaseAuxClickMenuOption { + type: "separator" +} + +export type AuxClickMenuOptionProps = + | AuxClickMenuItemProps + | AuxClickMenuSubProps + | AuxClickMenuRadioProps + | AuxClickMenuCheckboxProps + | AuxClickMenuSeparatorProps + +export interface AuxClickMenuProps + extends React.PropsWithChildren> { + options?: AuxClickMenuOptionProps[] +} +export default function AuxClickMenu({ + className, + children, + options, +}: AuxClickMenuProps) { + return options ? ( + + {children} + + {options.map((option, idx) => ( + + ))} + + + ) : ( + children + ) +} +function DynamicAuxClickMenuOption(option: AuxClickMenuOptionProps) { + switch (option.type) { + case "item": + return + case "sub": + return + case "radio": + return + case "checkbox": + return + case "separator": + return + default: + return null + } +} + +export function AuxClickMenuItem({ + children, + shortcut, + icon, + onClick, +}: AuxClickMenuItemProps) { + return ( + + {children} + {shortcut && {shortcut}} + + ) +} + +export function AuxClickMenuSub({ children, items }: AuxClickMenuSubProps) { + return ( + + + {children} + + + {items?.map((item, idx) => ( + + ))} + + + ) +} + +export function AuxClickMenuRadio({ + children, + defaultValue = "", + items, + ...props +}: AuxClickMenuRadioProps) { + const [currValue, setCurrValue] = useState(defaultValue) + return ( + + {children} + + {items?.map(({ title, value }, idx) => ( + setCurrValue(value)} + className="hover:cursor-pointer" + > + {title} + + ))} + + ) +} + +export function AuxClickMenuCheckbox({ + children, + shortcut, + ...props +}: AuxClickMenuCheckboxProps) { + return ( + + {children} + {shortcut && {shortcut}} + + ) +} + +export const AuxClickMenuSeparator = ContextMenuSeparator