# Island

> The signature surface container, with a label above, a note below and list rows that light up on hover only when they do something.

Docs: https://plumbago.ochotzas.com/components/island

## Installation

```sh
npx plumbago add island
```

This copies `components/ui/island.tsx` into your project, along with `cn`, and installs `@base-ui/react`.

## Usage

```tsx
import { Island, ListRow, ListRowText, ListRowTitle, ListRowValue } from "@/components/ui/island"

<Island variant="list">
  <ListRow>
    <ListRowText>
      <ListRowTitle>Opening hours</ListRowTitle>
    </ListRowText>
    <ListRowValue>12:00 – 23:00</ListRowValue>
  </ListRow>
</Island>
```

## Examples

### Preview

```tsx
import { Island, IslandLabel, ListRow, ListRowChevron, ListRowIcon, ListRowText, ListRowTitle, ListRowValue } from "@/components/ui/island"
import { CookingPot, CupSoda, Flame, Leaf } from "lucide-react"

const sections = [
  { href: "#starters", title: "Starters", count: 8, icon: Leaf },
  { href: "#mains", title: "Mains", count: 14, icon: CookingPot },
  { href: "#grill", title: "From the grill", count: 6, icon: Flame },
  { href: "#drinks", title: "Drinks", count: 22, icon: CupSoda },
]

export default function IslandDemo() {
  return (
    <div className="w-full max-w-md">
      <IslandLabel>Menu</IslandLabel>
      <Island variant="list">
        {sections.map((section) => (
          <ListRow key={section.href} render={<a href={section.href} />}>
            <ListRowIcon>
              <section.icon strokeWidth={1.75} aria-hidden="true" />
            </ListRowIcon>
            <ListRowText>
              <ListRowTitle>{section.title}</ListRowTitle>
            </ListRowText>
            <ListRowValue>
              {section.count}
              <ListRowChevron />
            </ListRowValue>
          </ListRow>
        ))}
      </Island>
    </div>
  )
}
```

### Rows with subtitles

```tsx
import { Island, IslandLabel, ListRow, ListRowChevron, ListRowSubtitle, ListRowText, ListRowThumb, ListRowTitle, ListRowValue } from "@/components/ui/island"

const specials = [
  { name: "Burrata and charred peach", note: "Basil oil, toasted hazelnuts", price: "€14", photo: "/dishes/burrata.webp", soldOut: false },
  { name: "Beef tartare", note: "Capers, egg yolk, sourdough", price: "€18", photo: "/dishes/tartare.webp", soldOut: false },
  { name: "Tagliatelle with ragù", note: "Sold out for tonight", price: "€19", photo: "/dishes/tagliatelle.webp", soldOut: true },
]

export default function IslandRowsWithSubtitles() {
  return (
    <div className="w-full max-w-md">
      <IslandLabel>Today's specials</IslandLabel>
      <Island variant="list">
        {specials.map((dish) => (
          <ListRow key={dish.name} done={dish.soldOut} render={dish.soldOut ? undefined : <button type="button" />}>
            <ListRowThumb>
              <img src={dish.photo} alt="" />
            </ListRowThumb>
            <ListRowText>
              <ListRowTitle>{dish.name}</ListRowTitle>
              <ListRowSubtitle>{dish.note}</ListRowSubtitle>
            </ListRowText>
            <ListRowValue>
              {dish.price}
              {!dish.soldOut && <ListRowChevron />}
            </ListRowValue>
          </ListRow>
        ))}
      </Island>
    </div>
  )
}
```

### Settings

```tsx
import { Island, IslandFooter, IslandLabel, ListRow, ListRowText, ListRowTitle } from "@/components/ui/island"
import { Switch } from "@/components/ui/switch"

export default function IslandSettings() {
  return (
    <div className="w-full max-w-md">
      <IslandLabel>Service</IslandLabel>
      <Island variant="list">
        <ListRow render={<label />}>
          <ListRowText>
            <ListRowTitle>Take reservations</ListRowTitle>
          </ListRowText>
          <Switch defaultChecked />
        </ListRow>
        <ListRow render={<label />}>
          <ListRowText>
            <ListRowTitle>Print kitchen tickets</ListRowTitle>
          </ListRowText>
          <Switch defaultChecked />
        </ListRow>
        <ListRow render={<label />}>
          <ListRowText>
            <ListRowTitle>Walk-ins only on Sundays</ListRowTitle>
          </ListRowText>
          <Switch />
        </ListRow>
      </Island>
      <IslandFooter>Turning off reservations hides the booking button on your website.</IslandFooter>
    </div>
  )
}
```

### Plain rows

```tsx
import { Island, IslandFooter, IslandLabel, ListRow, ListRowText, ListRowTitle, ListRowValue } from "@/components/ui/island"

const details = [
  { title: "Opening hours", value: "12:00–23:00" },
  { title: "Last orders", value: "22:30" },
  { title: "Tables", value: "18" },
]

export default function IslandPlainRows() {
  return (
    <div className="w-full max-w-md">
      <IslandLabel>Restaurant</IslandLabel>
      <Island variant="list">
        {details.map((row) => (
          <ListRow key={row.title}>
            <ListRowText>
              <ListRowTitle>{row.title}</ListRowTitle>
            </ListRowText>
            <ListRowValue>{row.value}</ListRowValue>
          </ListRow>
        ))}
      </Island>
      <IslandFooter>Guests see these hours on your booking page.</IslandFooter>
    </div>
  )
}
```

### Content island

```tsx
import { Button } from "@/components/ui/button"
import { Island } from "@/components/ui/island"

export default function IslandContent() {
  return (
    <Island className="flex w-full max-w-md flex-col gap-4">
      <div className="flex flex-col gap-1">
        <span className="text-footnote font-medium text-ink-2">Covers tonight</span>
        <span className="text-stat font-semibold tabular-nums">86</span>
      </div>
      <div className="flex gap-3">
        <Button size="sm">Open floor plan</Button>
        <Button size="sm" variant="secondary">
          Export
        </Button>
      </div>
    </Island>
  )
}
```

## Built on Base UI

Island wraps these Base UI parts and keeps their props:

- [Merge props](https://base-ui.com/react/utils/merge-props)
- [Use render](https://base-ui.com/react/utils/use-render)

## Source

```tsx
import { mergeProps } from "@base-ui/react/merge-props"
import { useRender } from "@base-ui/react/use-render"
import { cn } from "@/lib/cn"
import type { ComponentProps } from "react"

type PartProps<T extends keyof React.JSX.IntrinsicElements = "div"> = Omit<ComponentProps<T>, "className"> & { className?: string }

export type IslandProps = PartProps<"div"> & {
  variant?: "content" | "list"
}

export function Island({ variant = "content", className, ...props }: IslandProps) {
  return (
    <div data-slot="island" className={cn("on-surface rounded-lg bg-surface", variant === "list" ? "overflow-hidden" : "p-island-pad", className)} {...props} />
  )
}

export function IslandLabel({ className, ...props }: PartProps<"div">) {
  return <div data-slot="island-label" className={cn("mb-2 ml-1 text-caption font-semibold text-ink-2", className)} {...props} />
}

export function IslandFooter({ className, ...props }: PartProps<"p">) {
  return <p data-slot="island-footer" className={cn("mt-2 px-4 text-footnote text-ink-2", className)} {...props} />
}

export type ListRowProps = Omit<useRender.ComponentProps<"div">, "className"> & {
  done?: boolean
  className?: string
}

export function ListRow({ render, done, className, ...props }: ListRowProps) {
  const dataAttributes = { "data-slot": "list-row", "data-done": done ? "" : undefined }
  return useRender({
    defaultTagName: "div",
    render,
    props: mergeProps<"div">(
      {
        ...dataAttributes,
        className: cn(
          "group/row relative flex min-h-row-min w-full items-center gap-3 px-4 py-row-py text-left text-body text-ink",
          "transition-colors duration-fast ease-out [&:is(a,button,label,[data-interactive])]:hover:bg-press [&:is(a,button,label,[data-interactive])]:active:bg-line [-webkit-tap-highlight-color:transparent]",
          "[&:is(a,button,label)]:cursor-pointer [&:is(label):has([data-disabled])]:cursor-default [&:is(label):has([data-disabled])]:hover:bg-transparent [&:is(label):has([data-disabled])]:active:bg-transparent",
          "focus-visible:-outline-offset-2 focus-visible:rounded-md first:focus-visible:rounded-t-lg last:focus-visible:rounded-b-lg",
          "[:is([data-slot=list-row],[data-slot=swipe-row],[data-slot=reorder-row])+&]:before:absolute [:is([data-slot=list-row],[data-slot=swipe-row],[data-slot=reorder-row])+&]:before:inset-x-0 [:is([data-slot=list-row],[data-slot=swipe-row],[data-slot=reorder-row])+&]:before:top-0 [:is([data-slot=list-row],[data-slot=swipe-row],[data-slot=reorder-row])+&]:before:ml-4 [:is([data-slot=list-row],[data-slot=swipe-row],[data-slot=reorder-row])+&]:before:h-px",
          "[:is([data-slot=list-row],[data-slot=swipe-row],[data-slot=reorder-row])+&]:before:bg-line [:is([data-slot=list-row],[data-slot=swipe-row],[data-slot=reorder-row])+&]:before:transition-opacity [:is([data-slot=list-row],[data-slot=swipe-row],[data-slot=reorder-row])+&]:before:duration-fast",
          "[:is([data-slot=list-row],[data-slot=swipe-row],[data-slot=reorder-row])+&:is(a,button,label,[data-interactive])]:hover:before:opacity-0 [&:is(a,button,label,[data-interactive]):hover+:is([data-slot=list-row],[data-slot=swipe-row],[data-slot=reorder-row])]:before:opacity-0",
          className,
        ),
      },
      props,
    ),
  })
}

export function ListRowIcon({ className, ...props }: PartProps<"span">) {
  return <span data-slot="list-row-icon" className={cn("grid size-6 shrink-0 place-items-center text-ink-2 [&_svg]:size-6", className)} {...props} />
}

export function ListRowThumb({ className, ...props }: PartProps<"span">) {
  return (
    <span
      data-slot="list-row-thumb"
      className={cn(
        "grid size-9 shrink-0 place-items-center overflow-hidden rounded-sm bg-track text-ink-2 [&_svg]:size-5 [&_img]:size-full [&_img]:object-cover",
        className,
      )}
      {...props}
    />
  )
}

export function ListRowText({ className, ...props }: PartProps<"span">) {
  return <span data-slot="list-row-text" className={cn("min-w-0 flex-1", className)} {...props} />
}

export function ListRowTitle({ className, ...props }: PartProps<"span">) {
  return (
    <span
      data-slot="list-row-title"
      className={cn(
        "block text-body/[22px] font-medium transition-colors duration-base group-data-done/row:text-ink-3 in-[label:has([data-disabled])]:text-ink-3",
        className,
      )}
      {...props}
    />
  )
}

export function ListRowSubtitle({ className, ...props }: PartProps<"span">) {
  return <span data-slot="list-row-subtitle" className={cn("block text-footnote font-medium text-ink-2", className)} {...props} />
}

export function ListRowValue({ className, ...props }: PartProps<"span">) {
  return (
    <span
      data-slot="list-row-value"
      className={cn("flex shrink-0 items-center gap-1 text-footnote font-medium text-ink-2 tabular-nums", className)}
      {...props}
    />
  )
}

export function ListRowChevron({ className, ...props }: PartProps<"svg">) {
  return (
    <svg
      data-slot="list-row-chevron"
      viewBox="0 0 24 24"
      aria-hidden="true"
      className={cn("size-4 shrink-0 fill-none stroke-ink-3", className)}
      strokeWidth="2.2"
      strokeLinecap="round"
      strokeLinejoin="round"
      {...props}
    >
      <path d="m9 5 7 7-7 7" />
    </svg>
  )
}
```
