SecretValue
Masks a credential or PIN until the user reveals it, loads the value on demand, and offers copy only after reveal.
- Frameworks
- Astro · React · Elements · Dioxus
- Registry
lumen add SecretValue- Interaction
- Enhanced runtime
See it and copy it
Framework example
Choose Astro, React, Elements, or Dioxus to compare native usage against the shared visual output. Each example assumes the framework-level setup is already complete.
View SecretValue code
Framework usage
Switch targets to compare the adapter code. This live preview runs the Astro example. Before copying an example, complete the matching framework setup; React, Elements, and Dioxus use their own behavior APIs.Width controls resize the preview container. Resize your browser to test viewport breakpoints.---
import { SecretValue, Stack } from '@santi020k/lumen-astro'
---
<Stack gap="related">
<SecretValue id="demo-api-key" label="Sandbox API key" autoHideAfter={30000} />
<SecretValue label="Demo door PIN" mask="••••" embedValue value="0000" />
</Stack>
<script>
import type { LumenSecretValueRequestDetail } from '@santi020k/lumen-core'
// Illustrative only: a real app requests the value from its server on reveal.
const isRequest = (event: Event): event is CustomEvent<LumenSecretValueRequestDetail> => (
event instanceof CustomEvent && event.target instanceof HTMLElement && event.target.id === 'demo-api-key'
)
document.addEventListener('ui:secret-value-request', event => {
if (!isRequest(event)) return
event.detail.respondWith(new Promise<string>(resolve => {
setTimeout(() => {
resolve('demo_sk_0000_not_a_real_key')
}, 600)
}))
})
</script>import { SecretValue, Stack } from '@santi020k/lumen-react'
// Illustrative only: request the value from your server when the user reveals it.
const loadDemoKey = () => new Promise<string>(resolve => {
setTimeout(() => {
resolve('demo_sk_0000_not_a_real_key')
}, 600)
})
export const Example = () => (
<Stack gap="related">
<SecretValue autoHideAfter={30000} label="Sandbox API key" loadValue={loadDemoKey} />
<SecretValue label="Demo door PIN" mask="••••" value="0000" />
</Stack>
)<script type="module">
import { defineLumenElements } from '@santi020k/lumen-elements/define'
defineLumenElements()
</script>
<lumen-secret-value id="demo-api-key" label="Sandbox API key" auto-hide-after="30000"></lumen-secret-value>
<lumen-secret-value label="Demo door PIN" mask="••••">
<!-- Opt-in: template content is present in page source. -->
<template data-slot="secret-value-source">0000</template>
</lumen-secret-value>
<script type="module">
// Illustrative only: request the value from your server on reveal.
document.querySelector('#demo-api-key').addEventListener('ui:secret-value-request', event => {
event.detail.respondWith(new Promise(resolve => {
setTimeout(() => resolve('demo_sk_0000_not_a_real_key'), 600)
}))
})
</script>use dioxus::prelude::*;
use lumen_dioxus::prelude::*;
#[component]
fn Example() -> Element {
rsx! {
SecretValue { label: "API key", value: "sk_test_example", auto_hide_after: 30_000.0 }
}
}Choose your target
Add this component
Choose the package for your runtime. All adapters share the Lumen stylesheet. Use the matching registry command when you want a local wrapper for that framework.
pnpm add @santi020k/lumen-astrolumen add SecretValuepnpm add @santi020k/lumen-reactlumen add SecretValue --target reactpnpm add @santi020k/lumen-elementslumen add SecretValue --target elementsAPI reference
Lumen-specific props and runtime attributes for the Astro primitive. Use the framework differences above and the copyable examples for React composition and Elements attributes; the public adapter types define their supported contracts.
| Attribute | Values | Default | Description |
|---|---|---|---|
| label | string | - | Names the value group, the reveal toggle, and the copy action. |
| mask, maskLength | string, number | -, 8 | Sets the fixed placeholder shown while hidden. The mask never reflects the length of the secret. Elements uses mask and mask-length. |
| labels | Partial<LumenSecretValueLabels> | English defaults | Localizes show, hide, hidden, loading, error, retry, copy, copied, and copyError text. Elements uses show-label, hide-label, and the matching *-label attributes. |
| loadValue | () => Promise<string> | - | Loads the value on reveal, with a busy state and a retryable alert on failure. |
| value | string | - | React: a value already on the client. Astro: requires embedValue. |
| embedValue | boolean | false | Writes value into page source inside an inert template. Use it only for values every viewer may read; otherwise answer ui:secret-value-request. |
| cacheOnHide | boolean | false | Keeps a loaded value in memory after hiding so the next reveal skips the request. By default the value is discarded on hide. |
| autoHideAfter | number | - | Hides a revealed value after the given milliseconds and announces that it was hidden. Elements uses auto-hide-after. |
| copy | boolean | true | Shows a CopyButton after reveal. It copies the value, never the mask. |
| class, className | string | "" | Merges custom classes with the generated ui-* root classes. |
| ...native attributes | HTML attributes | - | Forwards standard attributes to the root element unless the component consumes them. |
Customize SecretValue
Start with semantic theme tokens and a class on the public component. Keep its accessible name, focus treatment, and interaction state intact.
.product-secret-value {
--surface: 0 0% 100%;
--ink: 220 20% 15%;
--line: 220 15% 82%;
}Apply product-secret-value through Astro's class, React's className, or the custom element's class. Verify foreground and background contrast in both schemes.
Documented styling parts: secret-value secret-value-label secret-value-display secret-value-mask secret-value-text secret-value-copy secret-value-error
| Hook | Values | Default | Contract |
|---|---|---|---|
| class, className | string | "" | Merges custom classes with the generated ui-* root classes. |
Use the documented hooks above and adapter types when targeting component states. Theme guide · Accessibility verification scope
Keyboard interactions
Keyboard behavior provided by the Astro UIPrimitives runtime for this component.
| Key | Action |
|---|---|
| Tab | Move between the Show or Hide toggle, the Copy action after reveal, and Try again after a failure. |
| Enter / Space | Reveal or hide the value, copy it, or retry loading it. |
Runtime events
CustomEvents dispatched by the Astro UIPrimitives runtime for this component.
| Event | Target | Detail | When |
|---|---|---|---|
| ui:secret-value-request | SecretValue root ([data-ui-secret-value] or lumen-secret-value) | LumenSecretValueRequestDetail: { respondWith(value: Promise<string> | string): void } | Fires on reveal when no value is cached or embedded. Call respondWith synchronously with the value or a Promise; call preventDefault to cancel the reveal. React uses loadValue instead. |
| ui:secret-value-change | SecretValue root | { state: "error" | "hidden" | "loading" | "revealed" } | Fires after the reveal state changes. The event never includes the value. |