import { CaretRight, Check, Circle } from "phosphor-react"; import { FC, Fragment, ReactNode } from "react"; import { Flex, Text } from "../"; import { ContextMenuCheckboxItem, ContextMenuContent, ContextMenuItem, ContextMenuItemIndicator, ContextMenuLabel, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuRoot, ContextMenuSeparator, ContextMenuTrigger, ContextMenuTriggerItem, } from "./primitive"; [ { label: "Show bookmarks", type: "checkbox", checked: true, indicator: "*", onCheckedChange: () => {}, }, { type: "radio", label: "People", value: "pedro", onValueChange: () => {}, options: [ { value: "pedro", label: "Pedro Duarte", }, { value: "colm", label: "Colm Tuite", }, ], }, ]; export type TextOption = { type: "text"; label: ReactNode; onClick?: () => any; children?: Option[]; }; export type SeparatorOption = { type: "separator" }; export type CheckboxOption = { type: "checkbox"; label: ReactNode; checked?: boolean; onCheckedChange?: (isChecked: boolean) => any; }; export type RadioOption = { type: "radio"; label: ReactNode; onValueChange?: (value: string) => any; value: T; options?: { value: T; label?: ReactNode }[]; }; type WithCommons = { key: string; disabled?: boolean }; type Option = (TextOption | SeparatorOption | CheckboxOption | RadioOption) & WithCommons; interface IContextMenu { options?: Option[]; isNested?: boolean; } export const ContextMenu: FC = ({ children, options, isNested, }) => { return ( {isNested ? ( {children} ) : ( {children} )} {options && ( {options.map(({ key, ...option }) => { if (option.type === "text") { const { children, label } = option; if (children) return ( {label} ); return {label}; } if (option.type === "checkbox") { const { label, checked, onCheckedChange } = option; return ( {label} ); } if (option.type === "radio") { const { label, options, onValueChange, value } = option; return ( {label} {options?.map(({ value: v, label }) => { return ( {label} ); })} ); } return ; })} )} ); }; export default ContextMenu;