Layout

Scroll Area.

A scroll container with a thin custom scrollbar that turns orange on hover.

Firmware tags

v1.40.0
v1.39.0
v1.38.0
v1.37.0
v1.36.0
v1.35.0
v1.34.0
v1.33.0
v1.32.0
v1.31.0
v1.30.0
v1.29.0
v1.28.0
v1.27.0
v1.26.0
v1.25.0
v1.24.0
v1.23.0
v1.22.0
v1.21.0
v1.20.0
v1.19.0
v1.18.0
v1.17.0
v1.16.0
v1.15.0
v1.14.0
v1.13.0
v1.12.0
v1.11.0
v1.10.0
v1.9.0
v1.8.0
v1.7.0
v1.6.0
v1.5.0
v1.4.0
v1.3.0
v1.2.0
v1.1.0

Installation#

With the CLI

$npx lanterncn add scroll-area

This also installs the Lantern theme and any Lantern UI components it depends on. The shadcn CLI works directly too: npx shadcn@latest add httptim/lantern-ui/scroll-area. See Installation if your project is not set up yet.

Manually

  1. Install the dependencies

    npm install radix-ui
  2. Copy the source into your project

    components/ui/scroll-area.tsx
    "use client";
    
    import * as React from "react";
    import { ScrollArea as ScrollAreaPrimitive } from "radix-ui";
    
    import { cn } from "@/lib/utils";
    
    function ScrollArea({ className, children, ...props }: React.ComponentProps<typeof ScrollAreaPrimitive.Root>) {
      return (
        <ScrollAreaPrimitive.Root data-slot="scroll-area" className={cn("relative", className)} {...props}>
          <ScrollAreaPrimitive.Viewport
            data-slot="scroll-area-viewport"
            className="size-full rounded-[inherit] transition-[box-shadow] outline-none focus-visible:ring-2 focus-visible:ring-ring/25"
          >
            {children}
          </ScrollAreaPrimitive.Viewport>
          <ScrollBar />
          <ScrollAreaPrimitive.Corner />
        </ScrollAreaPrimitive.Root>
      );
    }
    
    function ScrollBar({
      className,
      orientation = "vertical",
      ...props
    }: React.ComponentProps<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>) {
      return (
        <ScrollAreaPrimitive.ScrollAreaScrollbar
          data-slot="scroll-area-scrollbar"
          orientation={orientation}
          className={cn(
            "group/scrollbar flex touch-none p-0.5 transition-colors select-none",
            orientation === "vertical" && "h-full w-2 border-l border-l-transparent",
            orientation === "horizontal" && "h-2 flex-col border-t border-t-transparent",
            className,
          )}
          {...props}
        >
          <ScrollAreaPrimitive.ScrollAreaThumb
            data-slot="scroll-area-thumb"
            className="relative flex-1 rounded-full bg-border transition-colors group-hover/scrollbar:bg-primary/80 active:bg-primary"
          />
        </ScrollAreaPrimitive.ScrollAreaScrollbar>
      );
    }
    
    export { ScrollArea, ScrollBar };
  3. Update the import paths to match your project

    The source imports cn from @/lib/utils.

Usage#

import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
<ScrollArea className="h-72 w-48 rounded-lg border">
  {items}
</ScrollArea>

For sideways scrolling add <ScrollBar orientation="horizontal" /> inside the ScrollArea and give the content w-max.

Examples#

Horizontal

North hub
miner-02
Relay tower
computer 17
Turtle yard
farmer-07
Archive
computer 58
Arcade
computer 9
Shell club
computer 33