import { ComponentChildren, FunctionComponent, VNode } from 'preact' import { forwardRef, Ref } from 'preact/compat' import { JSXInternal } from 'preact/src/jsx' import { Icon } from '@/Components/Icon' import { Switch, SwitchProps } from '@/Components/Switch' import { IconType } from '@standardnotes/snjs' import { FOCUSABLE_BUT_NOT_TABBABLE } from '@/Constants' export enum MenuItemType { IconButton, RadioButton, SwitchButton, } type MenuItemProps = { type: MenuItemType children: ComponentChildren onClick?: JSXInternal.MouseEventHandler onChange?: SwitchProps['onChange'] onBlur?: (event: { relatedTarget: EventTarget | null }) => void className?: string checked?: boolean icon?: IconType iconClassName?: string tabIndex?: number } export const MenuItem: FunctionComponent = forwardRef( ( { children, onClick, onChange, onBlur, className = '', type, checked, icon, iconClassName, tabIndex, }: MenuItemProps, ref: Ref, ) => { return type === MenuItemType.SwitchButton && typeof onChange === 'function' ? ( ) : ( ) }, ) export const MenuItemSeparator: FunctionComponent = () => (
) type ListElementProps = { isFirstMenuItem: boolean children: ComponentChildren } export const MenuItemListElement: FunctionComponent = forwardRef( ({ children, isFirstMenuItem }: ListElementProps, ref: Ref) => { const child = children as VNode return (
  • {{ ...child, props: { ...(child.props ? { ...child.props } : {}), ...(child.type === MenuItem ? { tabIndex: isFirstMenuItem ? 0 : -1, } : {}), }, }}
  • ) }, )