Skip to main content
239

Search Lumen

Find components, APIs, guides, and recipes.

GitHub
Themes
Web docs
Data display

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
01

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.

AstroCode target · live preview uses Astro
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.
astro
---
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>
Edit SecretValue in browser
02

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.

bash@santi020k/lumen-astro
pnpm add @santi020k/lumen-astro
bashAstro wrapper
lumen add SecretValue

API 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.

AttributeValuesDefaultDescription
labelstring-Names the value group, the reveal toggle, and the copy action.
mask, maskLengthstring, number-, 8Sets the fixed placeholder shown while hidden. The mask never reflects the length of the secret. Elements uses mask and mask-length.
labelsPartial<LumenSecretValueLabels>English defaultsLocalizes 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.
valuestring-React: a value already on the client. Astro: requires embedValue.
embedValuebooleanfalseWrites value into page source inside an inert template. Use it only for values every viewer may read; otherwise answer ui:secret-value-request.
cacheOnHidebooleanfalseKeeps a loaded value in memory after hiding so the next reveal skips the request. By default the value is discarded on hide.
autoHideAfternumber-Hides a revealed value after the given milliseconds and announces that it was hidden. Elements uses auto-hide-after.
copybooleantrueShows a CopyButton after reveal. It copies the value, never the mask.
class, classNamestring""Merges custom classes with the generated ui-* root classes.
...native attributesHTML 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.

cssScoped theme overrides
.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

HookValuesDefaultContract
class, classNamestring""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.

KeyAction
TabMove between the Show or Hide toggle, the Copy action after reveal, and Try again after a failure.
Enter / SpaceReveal or hide the value, copy it, or retry loading it.

Runtime events

CustomEvents dispatched by the Astro UIPrimitives runtime for this component.

EventTargetDetailWhen
ui:secret-value-requestSecretValue 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-changeSecretValue root{ state: "error" | "hidden" | "loading" | "revealed" }Fires after the reveal state changes. The event never includes the value.

Web docsFull catalog