Skip to main content
Clever Ops

Preview Mode Banner

Floating preview-mode pill for React sites, hatched draft swatch, mono PREVIEW label, save meta, and a real Exit button. A fixed Tailwind-token capsule; dismissal causes zero layout shift.

Preview & code

Loading Preview Mode Banner preview

Installation

pnpm dlx shadcn@latest add @cleverui/banner-preview-mode

Requires the @cleverui registry in your components.json, a one-off, two-line setup.

Usage

tsx
import { BannerPreviewMode } from '@/components/blocks/banner-preview-mode'
Exampletsx
'use client'

import { useState } from 'react'
import { BannerPreviewMode } from '@/components/blocks/banner-preview-mode'

export default function BannerPreviewModeDemo() {
  const [key, setKey] = useState(0)

  return (
    <div className="relative flex min-h-[320px] flex-col justify-end">
      {/* framed page chrome so the floating pill has something to sit on */}
      <div className="mx-auto w-full max-w-3xl flex-1 px-4 pt-10 sm:px-6">
        <p className="font-mono text-[11px] uppercase tracking-[0.2em] text-muted-foreground">
          Field Notes · Draft
        </p>
        <h2 className="mt-3 font-sans text-xl font-semibold tracking-tight text-balance text-foreground sm:text-2xl">
          Autumn harvest guide for community gardens
        </h2>
        <p className="mt-2 max-w-xl text-sm leading-relaxed text-muted-foreground">
          Editors are reviewing soil-test tables and the frost-date map before
          publish. Exit preview to return to the live site.
        </p>
        <div
          aria-hidden="true"
          className="mt-8 h-28 rounded-2xl border border-border/60 bg-muted"
        />
      </div>

      <BannerPreviewMode
        key={key}
        docked={false}
        label="Preview"
        message="Viewing an unpublished draft."
        meta="Saved 2 min ago"
        exitLabel="Exit preview"
        onExit={() => {
          window.setTimeout(() => setKey((k) => k + 1), 400)
        }}
      />
    </div>
  )
}

API reference

BannerPreviewMode accepts the following props.

PropTypeDefaultDescription
labelstring'Preview'the mode word, rendered as the mono micro-label
messagestring'Viewing an unpublished draft.'one plain-language line; hidden below sm so the pill never wraps
meta*stringPREFORMATTED status note, e.g. 'Saved 2 min ago', never built from Date in render
exitLabelstring'Exit preview'
onExit*() => voidfired when Exit is pressed; parent clears the draft cookie/route, the pill exits and unmounts
dockedbooleantruefixed bottom-center overlay when true; renders in-flow for previews/embeds when false

…plus everything from Omit< React.HTMLAttributes<HTMLDivElement>, 'onDrag' | 'onDragStart' | 'onDragEnd' | 'onAnimationStart' >: className, event handlers, aria attributes and the rest pass straight through.

Frequently asked questions

How do I install the Preview Mode Banner component?

Register the @cleverui registry in your components.json ("@cleverui": "https://cleverops.com.au/r/{name}.json"), then run `npx shadcn@latest add @cleverui/banner-preview-mode`. The shadcn CLI copies the source into your project, you own the code from that point. You can also copy the source directly from this page.

What dependencies does Preview Mode Banner require?

Preview Mode Banner uses motion on top of React and Tailwind CSS. You don't need to install it manually, the shadcn CLI resolves and installs npm dependencies automatically when you add the component.

Can I theme Preview Mode Banner to match my brand?

Yes. The component is styled entirely with Tailwind utilities over standard design tokens (primary, background, muted, border), so it inherits your existing shadcn/ui theme automatically. Change your CSS variables and the component follows, no source edits needed for palette, radius, or fonts.

Want this built for you?

CleverUI is built by the Clever Ops web team. If you'd rather ship a hand-coded, fast, custom website than assemble one, we build them for Australian businesses every week.

Explore web development services