Skip to content

KMenu

A versatile menu for navigation.

Install

bash
pnpm add @ikun-ui/menu
bash
yarn add @ikun-ui/menu
bash
npm install @ikun-ui/menu

Basic usage

Horizontal top navigation menu.

Vertical mode

Vertical menu

Inline mode

Vertical menu with inline submenus.

Collapsed inline menu

Inline menu could be collapsed.

Theme

There are two built-in themes: light and dark. The default value is light. When theme is specified, it takes precedence over unocss's dark theme.

dark

Switch the menu type

Show the dynamic switching mode (between inline and vertical).

change style
change style

Custom Render

Implement custom rendering through various slots

Implement custom rendering through various slots

NameTypeDefaultDescription
ctxKeystring-Context key, used for component internal logic, should be a globally unique value, KMenuItem and KMenu share the same value.
expandIconstringi-carbon-chevron-downExpand Icon,following the unocss standard
inlineIndentnumber24Menu indent width in inline mode
inlineCollapsedbooleanfalseWhether the menu is collapsed in inline or vertical mode
modevertical | horizontal | inlineverticalMenu rendering mode
openUidsstring[][]Default open menu uid array
selectedUidsstring[][]Default select menu uid array
selectablebooleantrueWhether the menu can be selected. Setting it to false will not trigger select related events
subMenuCloseDelaynumber100The closing delay after the user leaves the submenu, unit: milliseconds
subMenuOpenDelaynumber0The delay after the user mouse enters the submenu, unit: milliseconds
themelight | dark-Theme style
multiplebooleanfalseWhether to allow multiple selections
triggerSubMenuActionhover | clickhoverSub menu expand/close trigger behavior
clsstring-Additional class
attrsRecord<string, string>{}Additional attributes
NameDescriptionType
clickTriggered when the menu item is clicked(e: CustomEvent<ClickEvtPa>)=> void
openChangeSub menu expand/close callback, the parameter is the currently opened uid array(e: CustomEvent<string[]>)=> void
selectTriggered when the menu item is seleced(e: CustomEvent<SelectEvtPa>)=> void
deSelectFired when the menu item is deselected(e: CustomEvent<SelectEvtPa>)=> void

ClickEvtPa

typescript
export type ClickEvtPa = {
	// The clicked item object
	item: SubMenuType;
	// The uid of the item object clicked
	uid: string;
	// An array of uid paths starting from the root menu object to the clicked item
	uidPath: string[];
	e: MouseEvent;
};

SelectEvtPa

typescript
export type SelectEvtPa = {
	// The selected/deSelected item object
	item: SubMenuType;
	// The uid of the item object selected/deSelected
	uid: string;
	// An array of uid paths starting from the root menu object to the selected/deSelected item
	uidPath: string[];
	// An array of uids selected in multi-select mode
	selectedUids: string[];
	// An array of items selected in multi-select mode
	selectedItems: SubMenuType[];
	// An array of uid paths selected in multi-select mode
	selectedUidPaths: string[][];
	e: MouseEvent;
};
NameTypeDefaultDescription
ctxKeystring-Context key, used for component internal logic, should be a globally unique value, KMenuItem and KMenu share the same value.
itemsSubMenuType[]-Menu configuration object
clsstring-Additional class
attrsRecord<string, string>{}Additional attributes
typescript
export type SubMenuType = {
	/**
	 * @en Display error state style
	 * @default false
	 */
	danger?: boolean;
	/**
	 * @en Render as groups or dividers
	 */
	type?: 'group' | 'divider';
	/**
	 * @en Menu Icon
	 */
	icon?: string;
	/**
	 * @en Menu Label
	 */
	label?: string;
	/**
	 * @en The unique value of the menu item.
	 * It should be a unique value in the entire menu tree.
	 */
	uid?: string;
	/**
	 * @en Indicates whether it is disabled. Its priority is higher than danger,
	 * and its child nodes are also disabled.
	 * @default false
	 */
	disabled?: boolean;
	/**
	 * @en title
	 */
	title?: string;
	/**
	 * @en Menu items in submenus
	 */
	children?: SubMenuType[];
	/**
	 * @en Submenu popover style
	 */
	popupClassName?: string;
};
NameDescriptionType
titleClickTriggered when the submenu title is clicked(e: CustomEvent<TitleClickEvtPa>)=> void

TitleClickEvtPa

typescript
type TitleClickEvtPa = {
	// The clicked item object
	item: SubMenuType;
	e: MouseEvent;
};
NameDescription
labelCustomize menu item's label content
iconCustomize menu item's icon content
expandIconCustomize menu item's expandIcon content
itemCustomize menu item content, When setting the item slot, the other three slots will not take effect

label slot params

typescript
//  render item object
type item = SubMenuType;
//  render item class
type cls = string;

icon slot params

typescript
//  render item object
type item = SubMenuType;
//  render item class
type cls = string;

expandIcon slot params

typescript
//  render item object
type item = SubMenuType;
//  render item class
type cls = string;

item slot params

typescript
//  render item object
type item = SubMenuType;
//  render item class
type cls = string;

MIT Licensed