'use client';
import { Menu, Text, View, XStack } from '@hanzo/gui';
import { Check, ChevronRight } from 'lucide-react';
import * as React from 'react';
import { ink } from './ink';
// The Lux menu, on gui's Menu — the same fifteen parts Radix's dropdown has,
// under the names this package already published.
//
// One thing genuinely got simpler rather than merely moving. Radix splits
// position into `side` + `align`, so the old file carried a `parsePlacement`
// that took `'bottom-start'` apart into `{ side: 'bottom', align: 'start' }`,
// plus a context to carry the two halves down to the content. gui's Menu sits
// on Popper, which takes the floating-ui `placement` string whole and derives
// side and align itself. The parser, the context, and the four props they fed
// are all gone: the caller's string reaches the engine untouched.
const ITEM_HOVER = 'var(--color-popover-item-hover)';
const TEXT = 'var(--color-text-primary)';
/** Resting/highlighted look shared by every selectable row. */
const ROW = {
position: 'relative',
flexDirection: 'row',
alignItems: 'center',
cursor: 'pointer',
userSelect: 'none',
borderRadius: 6,
fontSize: 14,
backgroundColor: 'transparent',
hoverStyle: { backgroundColor: ITEM_HOVER },
focusStyle: { backgroundColor: ITEM_HOVER },
} as const;
// --- MenuRoot ---
interface Positioning {
readonly placement?: string;
readonly offset?: {
readonly mainAxis?: number;
readonly crossAxis?: number;
};
}
export interface MenuRootProps {
readonly children?: React.ReactNode;
readonly open?: boolean;
readonly defaultOpen?: boolean;
readonly onOpenChange?: (details: { open: boolean }) => void;
readonly positioning?: Positioning;
readonly modal?: boolean;
}
export const MenuRoot = ({
children, open, defaultOpen, onOpenChange, positioning, modal = true,
}: MenuRootProps): React.ReactElement => (
);
// --- MenuTrigger ---
export type MenuTriggerProps = React.ComponentProps;
export const MenuTrigger = ({ asChild = false, ...rest }: MenuTriggerProps): React.ReactElement => (
);
// --- MenuContent ---
export type MenuContentProps = React.ComponentProps & {
readonly portalled?: boolean;
readonly minW?: string | number;
};
export const MenuContent = ({
portalled = true, minW, children, ...rest
}: MenuContentProps): React.ReactElement => {
const content = (
{ children }
);
return portalled ? { content } : content;
};
// --- MenuItem ---
export type MenuItemProps = React.ComponentProps & {
/** Informational identifier — the row's own name, not read by the engine. */
readonly value?: string;
};
export const MenuItem = ({ children, value: _value, asChild, ...rest }: MenuItemProps): React.ReactElement => (
// `asChild` means the caller brought its own element and owns the look. Its
// props are then forwarded to that element verbatim, so the skin must NOT be
// applied: `unstyled` and friends are not DOM attributes and React rejects
// them out loud ("Received `true` for a non-boolean attribute `unstyled`").
// Two shapes, said once, rather than one shape that is wrong in one of them.
asChild ? (
{ children }
) : (
{ ink(children, undefined, { fontSize: 14, color: TEXT }) }
)
);
// --- MenuItemText / MenuItemCommand ---
export type MenuItemTextProps = React.ComponentProps;
export const MenuItemText = (props: MenuItemTextProps): React.ReactElement => (
);
export type MenuItemCommandProps = React.ComponentProps;
/** The keyboard shortcut on the trailing edge of a row. */
export const MenuItemCommand = (props: MenuItemCommandProps): React.ReactElement => (
);
// --- MenuSeparator ---
export type MenuSeparatorProps = React.ComponentProps;
export const MenuSeparator = (props: MenuSeparatorProps): React.ReactElement => (
);
// --- MenuItemGroup ---
export type MenuItemGroupProps = React.ComponentProps & {
readonly title?: string;
};
export const MenuItemGroup = ({ title, children, ...rest }: MenuItemGroupProps): React.ReactElement => (
{ title && (
{ title }
) }
{ children }
);
// --- MenuArrow ---
export type MenuArrowProps = React.ComponentProps;
export const MenuArrow = (props: MenuArrowProps): React.ReactElement => (
);
// --- The indicator well, shared by checkbox and radio rows ---
const Indicator = () => (
);
// --- MenuCheckboxItem ---
export type MenuCheckboxItemProps = React.ComponentProps;
export const MenuCheckboxItem = ({ children, ...rest }: MenuCheckboxItemProps): React.ReactElement => (
{ ink(children, undefined, { fontSize: 14, color: TEXT }) }
);
// --- MenuRadioItemGroup / MenuRadioItem ---
export type MenuRadioItemGroupProps = React.ComponentProps;
export const MenuRadioItemGroup = (props: MenuRadioItemGroupProps): React.ReactElement => (
);
export type MenuRadioItemProps = React.ComponentProps;
export const MenuRadioItem = ({ children, ...rest }: MenuRadioItemProps): React.ReactElement => (
{ ink(children, undefined, { fontSize: 14, color: TEXT }) }
);
// --- MenuContextTrigger ---
export type MenuContextTriggerProps = React.ComponentProps & {
readonly asChild?: boolean;
};
/**
* A right-click target. This menu is a DROPDOWN — it opens from its trigger, not
* from a pointer position — so the wrapper passes its children through. gui does
* ship a real `ContextMenu`; a surface that wants one should reach for that
* rather than have this quietly behave like it.
*/
export const MenuContextTrigger = ({ asChild: _asChild, ...rest }: MenuContextTriggerProps): React.ReactElement => (
);
// --- MenuTriggerItem (a submenu's row) ---
export type MenuTriggerItemProps = React.ComponentProps & {
readonly startIcon?: React.ReactNode;
};
export const MenuTriggerItem = ({ startIcon, children, ...rest }: MenuTriggerItemProps): React.ReactElement => (
{ startIcon }
{ ink(children, undefined, { fontSize: 14, color: TEXT }) }
);