Modal & Overlay

Protected Card

A card-shaped gate for protecting one section of a page rather than the whole viewport.

cardwidget

Best used for A single gated tile inside a grid of otherwise-public cards, e.g. one locked dashboard widget.

Click "Unlock" to reveal an inline access-code form in place, without leaving the card or navigating away.

Loading preview…
Installation

Add this block to your project

CLI

npx shadcn@latest add http://localhost:3000/r/react/protected-card.json

Running this site somewhere other than localhost? Set NEXT_PUBLIC_SITE_URL and this command switches to that host automatically.

Also installs

  • Knock Codes Core
  • Knock Codes Types
  • useKnockCodes
  • PIN Input
  • cx (classname helper)
  • Gate Wrapper

Files created (10)

  • components/knock-codes/core/hash.ts
  • components/knock-codes/core/verify.ts
  • components/knock-codes/core/session.ts
  • components/knock-codes/core/storage.ts
  • components/knock-codes/react/types.ts
  • components/knock-codes/react/useKnockCodes.ts
  • components/knock-codes/react/PinInput.tsx
  • components/knock-codes/react/cx.ts
  • components/knock-codes/react/GateWrapper.tsx
  • components/knock-codes/react/ProtectedCard.tsx

No CLI? Copy the files by hand

  1. Open the Code tab in the preview above.
  2. Create each path listed below in your project and paste its contents in.
  3. Do the same for anything listed under “Also installs”, if present.

Props

API reference

PropTypeDefaultDescription
expectedHashstringSHA-256 hex hash to verify against, for local mode.
verifyVerifyFnCustom async verification function, for server mode.
children *ReactNodeThe card's content — blurred while locked, revealed once unlocked.
classNamestringExtra classes on the card.
Notes

Accessibility

The blurred preview behind the Unlock button is aria-hidden and inert, matching Protected Modal's approach — it's decorative once the button is shown, not a second interactive surface.

Customization

Locked content stays mounted and blurred behind an Unlock button instead of being replaced outright, so the card's size and position never jump between locked and unlocked. Good fit for a dashboard tile or a gated preview inside a grid of otherwise-public cards.

Compose with

Blocks that pair well with this one

These combine naturally with this block, whether as a shared shell, a shared session, or a common fallback.