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' export type TextOption = { type: 'text' label: ReactNode onSelect?: () => any children?: ContentMenuOption[] } 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 } export type ContentMenuOption = (TextOption | SeparatorOption | CheckboxOption | RadioOption) & WithCommons export interface IContextMenu { options?: ContentMenuOption[] isNested?: boolean } export const ContextMenu: FC = ({ children, options, isNested }) => { return ( {isNested ? ( {children} ) : ( {children} )} {options && !!options.length && ( {options.map(({ key, ...option }) => { if (option.type === 'text') { const { children, label, onSelect } = 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