Modal & Overlay

Protected Modal

Content stays mounted and blurred behind a modal Unlock Dialog instead of being replaced.

modal

Best used for A paywall-style preview where the blurred content itself is part of the pitch.

Content and gate coexist in the DOM at all times — only the modal's visibility changes, which keeps layout shifts to zero on unlock.

Loading preview…
Installation

Add this block to your project

CLI

npx shadcn@latest add http://localhost:3000/r/react/protected-modal.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
  • Unlock Dialog

Files created (9)

  • 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/UnlockDialog.tsx
  • components/knock-codes/react/ProtectedModal.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 *ReactNodeStays mounted, blurred while locked.
labelsKnockCodesLabelsOverrides for every user-facing string.
classNamestringExtra classes on the outer relative container.
Notes

Accessibility

The blurred content is marked aria-hidden and pointer-events-none while locked, so screen readers and keyboard tabbing skip straight past it to the dialog — it's visually present but not reachable, which is the correct behavior for inert background content.

Customization

Best for cases where the protected content's layout should stay stable underneath the prompt — a preview behind a paywall-style modal — rather than collapsing to a bare access-code screen the way Knock Codes does.

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.