Secret Field
Shows an API key or other secret masked, with buttons to reveal it, copy it and ask for a new one.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
value | string | — | The secret. Copy always copies all of it. |
label | string | — | Label when the label slot is empty. Names the field for assistive technology. |
revealed | boolean | false | Shows the whole secret instead of the mask. The show button toggles it. |
reveal-start | number | 0 | Leading characters left visible in the mask, e.g. 10 for an acme_live_ prefix. |
reveal-end | number | 4 | Trailing characters left visible in the mask. |
regenerable | boolean | false | Adds a regenerate button, which fires regenerate. |
hide-reveal | boolean | false | Leaves out the show button, for a secret that should only ever be copied. |
Slots
| Name | Description |
|---|---|
label | Label above the field. Falls back to the label attribute. |
help | Text under the field, such as "You won't be able to see this key again." |
Events
| Name | Type | Description |
|---|---|---|
reveal-change | Event | The user showed or hid the secret; read revealed. |
regenerate | Event | The user asked for a new secret. Confirm it, then set value. |
copied | Event | The secret was copied. It has no detail: the secret does not travel with the event. |
copy-error | Event | The clipboard refused the copy. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
label | Container of the label. |
field | The box holding the value and the buttons. |
value | The secret, masked or shown. |
mask | The bullets standing for the hidden part. |
actions | The row of buttons. |
help | Container of the help slot; hidden while it is empty. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-secret-field--gap | pixel | 6px | Space between the label, the field and the help text. |
--c2-secret-field--width | pixel | 100% | Width of the host, a block by default. |
--c2-secret-field__label--color | color | #18181b | |
--c2-secret-field__label--font-size | font-size | 14px | |
--c2-secret-field__label--font-weight | font-weight | 500 | |
--c2-secret-field__field--min-height | pixel | 36px | |
--c2-secret-field__field--border | border | 1px solid #bcbcc6 | |
--c2-secret-field__field--border-radius | border-radius | 6px | |
--c2-secret-field__field--background-color | color | #fafafa | Read-only surface. |
--c2-secret-field__field--padding-left | padding | 12px | |
--c2-secret-field__field--padding-right | padding | 4px | |
--c2-secret-field__value--color | color | #18181b | |
--c2-secret-field__value--font-family | font-family | ui-monospace, SFMono-Regular, Menlo, Consolas, monospace | |
--c2-secret-field__value--font-size | font-size | 14px | |
--c2-secret-field__mask--color | color | #71717a | Colour of the bullets. |
--c2-secret-field__action--size | pixel | 28px | Width and height of each button. |
--c2-secret-field__action--icon-size | pixel | 16px | |
--c2-secret-field__action--border-radius | border-radius | 6px | |
--c2-secret-field__action--color | color | #71717a | Icon colour of the buttons. |
--c2-secret-field__action__hover--color | color | #18181b | |
--c2-secret-field__action__hover--background-color | color | #f4f4f5 | |
--c2-secret-field__action__selected--background-color | color | #e4e4e7 | Show button while the secret is shown. |
--c2-secret-field__actions--gap | pixel | 2px | |
--c2-secret-field__help--color | color | #71717a | |
--c2-secret-field__help--font-size | font-size | 12px | |
Text and languages
The text the component shows, in English. It shows another language when the app adds one with addTranslations, under secret-field, and the nearest lang asks for it; any message not translated stays in English. {0}, {1}… stand for the values a message carries. Languages guide.
| Key | English | Values |
|---|---|---|
show | Show secret | — |
copy | Copy secret | — |
copied | Copied | — |
regenerate | Regenerate secret | — |
hidden | Hidden | — |
hiddenEnding | Hidden, ends with {0} | {0} end |
hiddenStarting | Starts with {0}, hidden | {0} start |
hiddenBetween | Starts with {0}, hidden, ends with {1} | {0} start {1} end |
empty | No secret | — |