UIPackage

Menubar

React navigation
Edit on GitHub

Top-level menu bar — File / Edit / View — for desktop-style apps. Same primitives as Dropdown Menu but laid out horizontally and keyboard-navigable across siblings (left/right arrows).

Also available for Vue ->

Installation

$ npx shadcn@latest add https://react.uipkge.dev/r/react/menubar.json

Or with the named registry: npx shadcn@latest add @uipkge-react/menubar

Examples

Dependencies

Files (2)

  • components/ui/menubar/menubar.tsx 10 kB
    'use client'
    
    import * as React from 'react'
    import * as MenubarPrimitive from '@radix-ui/react-menubar'
    import { Check, ChevronRight, Circle } from 'lucide-react'
    import { cn } from '@/lib/utils'
    
    const Menubar = React.forwardRef<
      React.ElementRef<typeof MenubarPrimitive.Root>,
      React.ComponentPropsWithoutRef<typeof MenubarPrimitive.Root>
    >(({ className, ...props }, ref) => (
      <MenubarPrimitive.Root
        ref={ref}
        data-uipkge=""
        data-slot="menubar"
        className={cn('bg-background flex h-9 items-center gap-1 rounded-md border p-1 shadow-xs', className)}
        {...props}
      />
    ))
    Menubar.displayName = MenubarPrimitive.Root.displayName
    
    function MenubarMenu(props: React.ComponentProps<typeof MenubarPrimitive.Menu>) {
      return <MenubarPrimitive.Menu data-uipkge="" data-slot="menubar-menu" {...props} />
    }
    
    function MenubarGroup(props: React.ComponentProps<typeof MenubarPrimitive.Group>) {
      return <MenubarPrimitive.Group data-uipkge="" data-slot="menubar-group" {...props} />
    }
    
    function MenubarRadioGroup(props: React.ComponentProps<typeof MenubarPrimitive.RadioGroup>) {
      return <MenubarPrimitive.RadioGroup data-uipkge="" data-slot="menubar-radio-group" {...props} />
    }
    
    function MenubarSub(props: React.ComponentProps<typeof MenubarPrimitive.Sub>) {
      return <MenubarPrimitive.Sub data-uipkge="" data-slot="menubar-sub" {...props} />
    }
    
    const MenubarPortal = MenubarPrimitive.Portal
    
    const MenubarTrigger = React.forwardRef<
      React.ElementRef<typeof MenubarPrimitive.Trigger>,
      React.ComponentPropsWithoutRef<typeof MenubarPrimitive.Trigger>
    >(({ className, ...props }, ref) => (
      <MenubarPrimitive.Trigger
        ref={ref}
        data-uipkge=""
        data-slot="menubar-trigger"
        className={cn(
          'focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground flex items-center rounded-sm px-2 py-1 text-sm font-medium outline-hidden select-none',
          className,
        )}
        {...props}
      />
    ))
    MenubarTrigger.displayName = MenubarPrimitive.Trigger.displayName
    
    const MenubarContent = React.forwardRef<
      React.ElementRef<typeof MenubarPrimitive.Content>,
      React.ComponentPropsWithoutRef<typeof MenubarPrimitive.Content>
    >(({ className, align = 'start', alignOffset = -4, sideOffset = 8, ...props }, ref) => (
      <MenubarPrimitive.Portal>
        <MenubarPrimitive.Content
          ref={ref}
          data-uipkge=""
          data-slot="menubar-content"
          align={align}
          alignOffset={alignOffset}
          sideOffset={sideOffset}
          className={cn(
            'bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[12rem] origin-(--radix-menubar-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-md',
            className,
          )}
          {...props}
        />
      </MenubarPrimitive.Portal>
    ))
    MenubarContent.displayName = MenubarPrimitive.Content.displayName
    
    const MenubarItem = React.forwardRef<
      React.ElementRef<typeof MenubarPrimitive.Item>,
      React.ComponentPropsWithoutRef<typeof MenubarPrimitive.Item> & {
        inset?: boolean
        variant?: 'default' | 'destructive'
      }
    >(({ className, inset, variant = 'default', ...props }, ref) => (
      <MenubarPrimitive.Item
        ref={ref}
        data-uipkge=""
        data-slot="menubar-item"
        data-inset={inset ? '' : undefined}
        data-variant={variant}
        className={cn(
          "focus:bg-accent focus:text-accent-foreground focus-visible:ring-ring data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/40 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus-visible:ring-2 focus-visible:ring-inset data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
          className,
        )}
        {...props}
      />
    ))
    MenubarItem.displayName = MenubarPrimitive.Item.displayName
    
    const MenubarCheckboxItem = React.forwardRef<
      React.ElementRef<typeof MenubarPrimitive.CheckboxItem>,
      React.ComponentPropsWithoutRef<typeof MenubarPrimitive.CheckboxItem>
    >(({ className, children, checked, ...props }, ref) => (
      <MenubarPrimitive.CheckboxItem
        ref={ref}
        data-uipkge=""
        data-slot="menubar-checkbox-item"
        checked={checked}
        className={cn(
          "focus:bg-accent focus:text-accent-foreground focus-visible:ring-ring relative flex cursor-default items-center gap-2 rounded-xs py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus-visible:ring-2 focus-visible:ring-inset data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
          className,
        )}
        {...props}
      >
        <span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
          <MenubarPrimitive.ItemIndicator>
            <Check className="size-4" aria-hidden="true" />
          </MenubarPrimitive.ItemIndicator>
        </span>
        {children}
      </MenubarPrimitive.CheckboxItem>
    ))
    MenubarCheckboxItem.displayName = MenubarPrimitive.CheckboxItem.displayName
    
    const MenubarRadioItem = React.forwardRef<
      React.ElementRef<typeof MenubarPrimitive.RadioItem>,
      React.ComponentPropsWithoutRef<typeof MenubarPrimitive.RadioItem>
    >(({ className, children, ...props }, ref) => (
      <MenubarPrimitive.RadioItem
        ref={ref}
        data-uipkge=""
        data-slot="menubar-radio-item"
        className={cn(
          "focus:bg-accent focus:text-accent-foreground focus-visible:ring-ring relative flex cursor-default items-center gap-2 rounded-xs py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus-visible:ring-2 focus-visible:ring-inset data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
          className,
        )}
        {...props}
      >
        <span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
          <MenubarPrimitive.ItemIndicator>
            <Circle className="size-2 fill-current" />
          </MenubarPrimitive.ItemIndicator>
        </span>
        {children}
      </MenubarPrimitive.RadioItem>
    ))
    MenubarRadioItem.displayName = MenubarPrimitive.RadioItem.displayName
    
    const MenubarLabel = React.forwardRef<
      React.ElementRef<typeof MenubarPrimitive.Label>,
      React.ComponentPropsWithoutRef<typeof MenubarPrimitive.Label> & { inset?: boolean }
    >(({ className, inset, ...props }, ref) => (
      <MenubarPrimitive.Label
        ref={ref}
        data-uipkge=""
        data-slot="menubar-label"
        data-inset={inset ? '' : undefined}
        className={cn('px-2 py-1.5 text-sm font-medium data-[inset]:pl-8', className)}
        {...props}
      />
    ))
    MenubarLabel.displayName = MenubarPrimitive.Label.displayName
    
    const MenubarSeparator = React.forwardRef<
      React.ElementRef<typeof MenubarPrimitive.Separator>,
      React.ComponentPropsWithoutRef<typeof MenubarPrimitive.Separator>
    >(({ className, ...props }, ref) => (
      <MenubarPrimitive.Separator
        ref={ref}
        data-uipkge=""
        data-slot="menubar-separator"
        className={cn('bg-border -mx-1 my-1 h-px', className)}
        {...props}
      />
    ))
    MenubarSeparator.displayName = MenubarPrimitive.Separator.displayName
    
    function MenubarShortcut({ className, ...props }: React.HTMLAttributes<HTMLSpanElement>) {
      return (
        <span
          data-uipkge=""
          data-slot="menubar-shortcut"
          className={cn('text-muted-foreground ml-auto text-xs tracking-widest', className)}
          {...props}
        />
      )
    }
    
    const MenubarSubTrigger = React.forwardRef<
      React.ElementRef<typeof MenubarPrimitive.SubTrigger>,
      React.ComponentPropsWithoutRef<typeof MenubarPrimitive.SubTrigger> & { inset?: boolean }
    >(({ className, inset, children, ...props }, ref) => (
      <MenubarPrimitive.SubTrigger
        ref={ref}
        data-uipkge=""
        data-slot="menubar-sub-trigger"
        data-inset={inset ? '' : undefined}
        className={cn(
          'focus:bg-accent focus:text-accent-foreground focus-visible:ring-ring data-[state=open]:bg-accent data-[state=open]:text-accent-foreground flex cursor-default items-center rounded-sm px-2 py-1.5 text-sm outline-none select-none focus-visible:ring-2 focus-visible:ring-inset data-[inset]:pl-8',
          className,
        )}
        {...props}
      >
        {children}
        <ChevronRight className="ml-auto size-4" />
      </MenubarPrimitive.SubTrigger>
    ))
    MenubarSubTrigger.displayName = MenubarPrimitive.SubTrigger.displayName
    
    const MenubarSubContent = React.forwardRef<
      React.ElementRef<typeof MenubarPrimitive.SubContent>,
      React.ComponentPropsWithoutRef<typeof MenubarPrimitive.SubContent>
    >(({ className, ...props }, ref) => (
      <MenubarPrimitive.Portal>
        <MenubarPrimitive.SubContent
          ref={ref}
          data-uipkge=""
          data-slot="menubar-sub-content"
          className={cn(
            'bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] origin-(--radix-menubar-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-lg',
            className,
          )}
          {...props}
        />
      </MenubarPrimitive.Portal>
    ))
    MenubarSubContent.displayName = MenubarPrimitive.SubContent.displayName
    
    export {
      Menubar,
      MenubarMenu,
      MenubarTrigger,
      MenubarContent,
      MenubarItem,
      MenubarCheckboxItem,
      MenubarRadioGroup,
      MenubarRadioItem,
      MenubarLabel,
      MenubarSeparator,
      MenubarShortcut,
      MenubarSub,
      MenubarSubTrigger,
      MenubarSubContent,
      MenubarGroup,
      MenubarPortal,
    }
  • components/ui/menubar/index.ts 0.3 kB
    export {
      Menubar,
      MenubarMenu,
      MenubarTrigger,
      MenubarContent,
      MenubarItem,
      MenubarCheckboxItem,
      MenubarRadioGroup,
      MenubarRadioItem,
      MenubarLabel,
      MenubarSeparator,
      MenubarShortcut,
      MenubarSub,
      MenubarSubTrigger,
      MenubarSubContent,
      MenubarGroup,
      MenubarPortal,
    } from './menubar'

Raw manifest: https://react.uipkge.dev/r/react/menubar.json