# Menubar

shadcn menubar with Win95 menus.

Source: https://www.ui95.dev/ui/menubar

## Examples

```tsx
import { useState } from "react"

import {
  Menubar,
  MenubarCheckboxItem,
  MenubarContent,
  MenubarGroup,
  MenubarItem,
  MenubarLabel,
  MenubarMenu,
  MenubarRadioGroup,
  MenubarRadioItem,
  MenubarSeparator,
  MenubarShortcut,
  MenubarSub,
  MenubarSubContent,
  MenubarSubTrigger,
  MenubarTrigger,
} from "@/components/ui/menubar"

import type { ShowcaseDemo } from "../types"

function PaintMenubar() {
  const [isToolboxVisible, setIsToolboxVisible] = useState(true)
  const [isColorBoxVisible, setIsColorBoxVisible] = useState(false)
  const [brush, setBrush] = useState("round")

  return (
    <Menubar>
      <MenubarMenu>
        <MenubarTrigger>File</MenubarTrigger>
        <MenubarContent>
          <MenubarGroup>
            <MenubarItem>
              New
              <MenubarShortcut>Ctrl+N</MenubarShortcut>
            </MenubarItem>
            <MenubarItem>
              Open...
              <MenubarShortcut>Ctrl+O</MenubarShortcut>
            </MenubarItem>
            <MenubarItem disabled>Save</MenubarItem>
          </MenubarGroup>
          <MenubarSeparator />
          <MenubarSub>
            <MenubarSubTrigger>Recent</MenubarSubTrigger>
            <MenubarSubContent>
              <MenubarItem>eye1.png</MenubarItem>
              <MenubarItem>untitled.bmp</MenubarItem>
            </MenubarSubContent>
          </MenubarSub>
          <MenubarSeparator />
          <MenubarItem variant="destructive">Exit</MenubarItem>
        </MenubarContent>
      </MenubarMenu>
      <MenubarMenu>
        <MenubarTrigger>View</MenubarTrigger>
        <MenubarContent>
          <MenubarCheckboxItem checked={isToolboxVisible} onCheckedChange={setIsToolboxVisible}>
            Tool box
          </MenubarCheckboxItem>
          <MenubarCheckboxItem checked={isColorBoxVisible} onCheckedChange={setIsColorBoxVisible}>
            Color box
          </MenubarCheckboxItem>
          <MenubarSeparator />
          <MenubarLabel inset>Brush</MenubarLabel>
          <MenubarRadioGroup value={brush} onValueChange={setBrush}>
            <MenubarRadioItem value="round">Round</MenubarRadioItem>
            <MenubarRadioItem value="square">Square</MenubarRadioItem>
          </MenubarRadioGroup>
        </MenubarContent>
      </MenubarMenu>
      <MenubarMenu>
        <MenubarTrigger>Help</MenubarTrigger>
        <MenubarContent>
          <MenubarItem inset>Help topics</MenubarItem>
          <MenubarItem inset>About Paint</MenubarItem>
        </MenubarContent>
      </MenubarMenu>
    </Menubar>
  )
}

export const demo: ShowcaseDemo = {
  span: "wide",
  variants: [{ label: "items, checkbox, radio, submenu, destructive", render: () => <PaintMenubar /> }],
}
```

## Installation

```bash
npx shadcn@latest add https://www.ui95.dev/r/menubar.json
```

Run it in a Radix shadcn project that already has the UI95 theme.

Dependencies:

```bash
npm install cn radix-ui
```

Add these items first:

- [pixel-glyphs](https://www.ui95.dev/ui/pixel-glyphs)

`components/ui/menubar.tsx`

```tsx
"use client"

import { cn } from "cn"
import { Menubar as MenubarPrimitive } from "radix-ui"
import * as React from "react"

import { ArrowGlyph, CheckGlyph, DotGlyph } from "@/components/ui/pixel-glyphs"

function Menubar({
  className,
  ...props
}: React.ComponentProps<typeof MenubarPrimitive.Root>) {
  return (
    <MenubarPrimitive.Root
      data-slot="menubar"
      className={cn(
        "flex h-9 items-stretch gap-2 border-b-(length:--pixel) border-border bg-card px-2 py-(--pixel) text-card-foreground",
        className
      )}
      {...props}
    />
  )
}

function MenubarMenu({
  ...props
}: React.ComponentProps<typeof MenubarPrimitive.Menu>) {
  return <MenubarPrimitive.Menu data-slot="menubar-menu" {...props} />
}

function MenubarGroup({
  ...props
}: React.ComponentProps<typeof MenubarPrimitive.Group>) {
  return <MenubarPrimitive.Group data-slot="menubar-group" {...props} />
}

function MenubarPortal({
  ...props
}: React.ComponentProps<typeof MenubarPrimitive.Portal>) {
  return <MenubarPrimitive.Portal data-slot="menubar-portal" {...props} />
}

function MenubarRadioGroup({
  ...props
}: React.ComponentProps<typeof MenubarPrimitive.RadioGroup>) {
  return (
    <MenubarPrimitive.RadioGroup data-slot="menubar-radio-group" {...props} />
  )
}

function MenubarTrigger({
  className,
  ...props
}: React.ComponentProps<typeof MenubarPrimitive.Trigger>) {
  return (
    <MenubarPrimitive.Trigger
      data-slot="menubar-trigger"
      className={cn(
        "block content-center px-2 text-xl leading-none outline-hidden select-none first-letter:underline first-letter:decoration-(length:--pixel) first-letter:underline-offset-2 hover:bg-foreground hover:text-card focus-visible:bg-foreground focus-visible:text-card disabled:text-muted-foreground data-[state=open]:bg-foreground data-[state=open]:text-card",
        className
      )}
      {...props}
    />
  )
}

function MenubarContent({
  className,
  align = "start",
  alignOffset = -2,
  sideOffset = 4,
  ...props
}: React.ComponentProps<typeof MenubarPrimitive.Content>) {
  return (
    <MenubarPortal>
      <MenubarPrimitive.Content
        data-slot="menubar-content"
        align={align}
        alignOffset={alignOffset}
        sideOffset={sideOffset}
        className={cn(
          "z-50 min-w-40 overflow-hidden pixel-border border-border bg-popover p-(--pixel) text-popover-foreground offset-shadow-2",
          className
        )}
        {...props}
      />
    </MenubarPortal>
  )
}

function MenubarItem({
  className,
  inset,
  variant = "default",
  ...props
}: React.ComponentProps<typeof MenubarPrimitive.Item> & {
  inset?: boolean
  variant?: "default" | "destructive"
}) {
  return (
    <MenubarPrimitive.Item
      data-slot="menubar-item"
      data-inset={inset}
      data-variant={variant}
      className={cn(
        "group/menubar-item relative flex h-8 items-center gap-2 px-2 text-xl leading-none outline-hidden select-none focus:bg-foreground focus:text-popover data-inset:pl-7 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive data-[variant=destructive]:focus:text-popover data-disabled:pointer-events-none data-disabled:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5",
        className
      )}
      {...props}
    />
  )
}

function MenubarCheckboxItem({
  className,
  children,
  checked,
  inset,
  ...props
}: React.ComponentProps<typeof MenubarPrimitive.CheckboxItem> & {
  inset?: boolean
}) {
  return (
    <MenubarPrimitive.CheckboxItem
      data-slot="menubar-checkbox-item"
      data-inset={inset}
      className={cn(
        "relative flex h-8 items-center gap-2 pr-2 pl-7 text-xl leading-none outline-hidden select-none focus:bg-foreground focus:text-popover data-disabled:pointer-events-none data-disabled:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0",
        className
      )}
      checked={checked}
      {...props}
    >
      <span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
        <MenubarPrimitive.ItemIndicator>
          <CheckGlyph />
        </MenubarPrimitive.ItemIndicator>
      </span>
      {children}
    </MenubarPrimitive.CheckboxItem>
  )
}

function MenubarRadioItem({
  className,
  children,
  inset,
  ...props
}: React.ComponentProps<typeof MenubarPrimitive.RadioItem> & {
  inset?: boolean
}) {
  return (
    <MenubarPrimitive.RadioItem
      data-slot="menubar-radio-item"
      data-inset={inset}
      className={cn(
        "relative flex h-8 items-center gap-2 pr-2 pl-7 text-xl leading-none outline-hidden select-none focus:bg-foreground focus:text-popover data-disabled:pointer-events-none data-disabled:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0",
        className
      )}
      {...props}
    >
      <span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
        <MenubarPrimitive.ItemIndicator>
          <DotGlyph />
        </MenubarPrimitive.ItemIndicator>
      </span>
      {children}
    </MenubarPrimitive.RadioItem>
  )
}

function MenubarLabel({
  className,
  inset,
  ...props
}: React.ComponentProps<typeof MenubarPrimitive.Label> & {
  inset?: boolean
}) {
  return (
    <MenubarPrimitive.Label
      data-slot="menubar-label"
      data-inset={inset}
      className={cn(
        "px-2 pt-2 pb-1 font-pixel text-sm leading-none text-muted-foreground uppercase data-inset:pl-7",
        className
      )}
      {...props}
    />
  )
}

function MenubarSeparator({
  className,
  ...props
}: React.ComponentProps<typeof MenubarPrimitive.Separator>) {
  return (
    <MenubarPrimitive.Separator
      data-slot="menubar-separator"
      className={cn(
        "mx-1 my-1 border-t-(length:--pixel) border-b-(length:--pixel) border-t-bevel-lo border-b-bevel-hi",
        className
      )}
      {...props}
    />
  )
}

function MenubarShortcut({
  className,
  ...props
}: React.ComponentProps<"span">) {
  return (
    <span
      data-slot="menubar-shortcut"
      className={cn(
        "ml-auto pl-4 text-lg leading-none text-muted-foreground group-focus/menubar-item:text-popover",
        className
      )}
      {...props}
    />
  )
}

function MenubarSub({
  ...props
}: React.ComponentProps<typeof MenubarPrimitive.Sub>) {
  return <MenubarPrimitive.Sub data-slot="menubar-sub" {...props} />
}

function MenubarSubTrigger({
  className,
  inset,
  children,
  ...props
}: React.ComponentProps<typeof MenubarPrimitive.SubTrigger> & {
  inset?: boolean
}) {
  return (
    <MenubarPrimitive.SubTrigger
      data-slot="menubar-sub-trigger"
      data-inset={inset}
      className={cn(
        "flex h-8 items-center gap-2 px-2 text-xl leading-none outline-hidden select-none focus:bg-foreground focus:text-popover data-inset:pl-7 data-open:bg-foreground data-open:text-popover [&_svg:not([class*='size-'])]:size-3.5",
        className
      )}
      {...props}
    >
      {children}
      <ArrowGlyph direction="right" className="ml-auto" />
    </MenubarPrimitive.SubTrigger>
  )
}

function MenubarSubContent({
  className,
  ...props
}: React.ComponentProps<typeof MenubarPrimitive.SubContent>) {
  return (
    <MenubarPrimitive.SubContent
      data-slot="menubar-sub-content"
      className={cn(
        "z-50 min-w-32 overflow-hidden pixel-border border-border bg-popover p-(--pixel) text-popover-foreground offset-shadow-2",
        className
      )}
      {...props}
    />
  )
}

export {
  Menubar,
  MenubarCheckboxItem,
  MenubarContent,
  MenubarGroup,
  MenubarItem,
  MenubarLabel,
  MenubarMenu,
  MenubarPortal,
  MenubarRadioGroup,
  MenubarRadioItem,
  MenubarSeparator,
  MenubarShortcut,
  MenubarSub,
  MenubarSubContent,
  MenubarSubTrigger,
  MenubarTrigger,
}
```

## API reference

### Menubar

No props of its own. It forwards the props of the element or primitive it wraps.

### MenubarCheckboxItem

| Prop | Type | Default |
| --- | --- | --- |
| `inset` | `boolean` | - |

### MenubarContent

No props of its own. It forwards the props of the element or primitive it wraps.

### MenubarGroup

No props of its own. It forwards the props of the element or primitive it wraps.

### MenubarItem

| Prop | Type | Default |
| --- | --- | --- |
| `inset` | `boolean` | - |
| `variant` | `"default" \| "destructive"` | `"default"` |

### MenubarLabel

| Prop | Type | Default |
| --- | --- | --- |
| `inset` | `boolean` | - |

### MenubarMenu

No props of its own. It forwards the props of the element or primitive it wraps.

### MenubarPortal

No props of its own. It forwards the props of the element or primitive it wraps.

### MenubarRadioGroup

No props of its own. It forwards the props of the element or primitive it wraps.

### MenubarRadioItem

| Prop | Type | Default |
| --- | --- | --- |
| `inset` | `boolean` | - |

### MenubarSeparator

No props of its own. It forwards the props of the element or primitive it wraps.

### MenubarShortcut

No props of its own. It forwards the props of the element or primitive it wraps.

### MenubarSub

No props of its own. It forwards the props of the element or primitive it wraps.

### MenubarSubContent

No props of its own. It forwards the props of the element or primitive it wraps.

### MenubarSubTrigger

| Prop | Type | Default |
| --- | --- | --- |
| `inset` | `boolean` | - |

### MenubarTrigger

No props of its own. It forwards the props of the element or primitive it wraps.

## Sounds

- `menu.select`
