Secret Field
NewAPI key and token display: masked with the prefix and last characters showing, reveal, copy and regenerate.
Secret key
demo_key_••••••••••••••••••••••••3f9aExample key. Use it on your server only.
Webhook signing secret
demo_whk_•••••••••••••••••••••••8Tt1Installation
$ pnpm dlx shadcn@latest add @synccn/secret-fieldFirst time in this project? Connect synccn with one command.
Usage
import { SecretField } from "@/components/ui/secret-field";<SecretField label="Secret key" value={key} onRegenerate={roll} />API reference
Generated from the component's TypeScript types, so it always matches the code.
SecretField
Read-only field for API keys and tokens: masked by default with the prefix and last characters showing, reveal, copy, and an optional regenerate button.
- valuerequired
stringThe secret, such as an API key or webhook signing secret.
- label
stringLabel shown above the field.
- visibleEnd
numberDefault
4Characters left visible at the end while hidden, like "sk_live_••••3f9a".
- onRegenerate
() => unknownShows a button to roll a new secret. Called when it's clicked; return a promise to show a spinner.
- hint
stringSmall print under the field.
- className
stringExtra classes for the root element.
Dependencies
Read from the component's imports when the site builds. The CLI installs all of these for you.
Helpers
- lib/clipboardcopyText (copies to the clipboard)
- lib/utilscn (merges class names)
npm packages
- clsx for cn()
- tailwind-merge for cn()
- lucide-react for Check, Copy, Eye, EyeOff, RefreshCw
Accessibility
- Hidden secrets are announced as hidden rather than read out as dots. Reveal is a toggle button with aria-pressed.
From the source
Read from this component's code when the site builds, so it can't drift.
- ARIA attributes: aria-label, aria-pressed