Split view

Two or three adjacent panes with hairline dividers that stack on narrow screens.

navigation

Apple: Split views

· Base UI: element

Three columns

import { Mail01Icon } from "@hugeicons/core-free-icons"

import {
  Empty,
  EmptyDescription,
  EmptyIcon,
  EmptyTitle,
} from "@applecn/ui/components/empty"
import { List, ListRow, ListSection } from "@applecn/ui/components/list"
import {
  Sidebar,
  SidebarGroup,
  SidebarItem,
} from "@applecn/ui/components/sidebar"
import {
  SplitView,
  SplitViewContent,
  SplitViewDetail,
  SplitViewSidebar,
} from "@applecn/ui/components/split-view"

export default function SplitViewBasic() {
  return (
    <SplitView
      columns={3}
      className="h-80 overflow-hidden rounded-4xl bg-background"
    >
      <SplitViewSidebar>
        <Sidebar aria-label="Mailboxes" className="w-full">
          <SidebarGroup label="Mailboxes">
            <SidebarItem href="#" current>
              Inbox
            </SidebarItem>
            <SidebarItem href="#">Sent</SidebarItem>
          </SidebarGroup>
        </Sidebar>
      </SplitViewSidebar>
      <SplitViewContent>
        <List aria-label="Messages" style="plain">
          <ListSection>
            <ListRow title="Ada Lovelace" subtitle="Engine notes" href="#" />
            <ListRow title="Grace Hopper" subtitle="Compiler draft" href="#" />
          </ListSection>
        </List>
      </SplitViewContent>
      <SplitViewDetail className="hidden lg:block">
        <Empty className="h-full">
          <EmptyIcon icon={Mail01Icon} />
          <EmptyTitle>No Message Selected</EmptyTitle>
          <EmptyDescription>Select a message to read it here.</EmptyDescription>
        </Empty>
      </SplitViewDetail>
    </SplitView>
  )
}

Install

From the registry this site publishes, with dependencies resolved by the CLI.

npx shadcn@latest add https://applecn.vercel.app/r/split-view.json

Source

packages/ui/src/components/split-view.tsx

import { cn } from "cn"
import type { ComponentProps } from "react"

/**
 * Split views (HIG › Split views): two or three adjacent panes — sidebar, content list, detail —
 * with 1 pt dividers, stacking into a single column below the `lg` breakpoint.
 */
type SplitViewProps = ComponentProps<"div"> & {
  columns?: 2 | 3
}

function SplitView({ className, columns = 2, ...props }: SplitViewProps) {
  return (
    <div
      data-slot="split-view"
      data-columns={columns}
      className={cn(
        "grid min-h-0 grid-cols-1",
        columns === 3
          ? "lg:grid-cols-[var(--split-view-sidebar-width)_var(--split-view-content-width)_1fr]"
          : "lg:grid-cols-[var(--split-view-sidebar-width)_1fr]",
        className
      )}
      {...props}
    />
  )
}

function SplitViewSidebar({
  className,
  "aria-label": label = "Sidebar",
  ...props
}: ComponentProps<"section">) {
  return (
    <section
      data-slot="split-view-sidebar"
      aria-label={label}
      className={cn(
        "min-w-0 bg-sidebar lg:border-e-[0.5px] lg:border-separator",
        className
      )}
      {...props}
    />
  )
}

function SplitViewContent({
  className,
  "aria-label": label = "Content",
  ...props
}: ComponentProps<"section">) {
  return (
    <section
      data-slot="split-view-content"
      aria-label={label}
      className={cn(
        "min-w-0 lg:border-e-[0.5px] lg:border-separator",
        className
      )}
      {...props}
    />
  )
}

function SplitViewDetail({
  className,
  "aria-label": label = "Detail",
  ...props
}: ComponentProps<"section">) {
  return (
    <section
      data-slot="split-view-detail"
      aria-label={label}
      className={cn("min-w-0", className)}
      {...props}
    />
  )
}

export { SplitView, SplitViewContent, SplitViewDetail, SplitViewSidebar }
export type { SplitViewProps }