Copy to clipboard: clipboard/1, a button that copies a text, and clipboard_input/1, a
field with a copy button joined to it.
<.clipboard id="copy-ref" value="LDG-2026-1043" icon>Copiar</.clipboard>
<.clipboard id="copy-cmd" from="#cmd" icon_only variant="ghost" aria-label="Copiar comando" />
<.clipboard_input id="api-key" value={@api_key} field_label="Chave de API" readonly />The buttons are lu-b buttons (lu-b c-<color> v-<variant> s-<size>). The hook
LedgerUI.Clipboard (priv/static/ledger_ui/hooks/clipboard.js) does the copy
(navigator.clipboard, with a execCommand fallback), then for two seconds:
- turns the button into the copied state (
c-success v-soft,data-copied) and showscopied_labelin place of the label when given; - dispatches
ledger:toastonwindowwith%{message, kind}(kindis"success"or"error") when atoastis set. Passtoast={nil}for none; - runs
on_copy: an event name (pushed with%{"id" => id}, totargetif given) or a%JS{}.
value is the text to copy; from is a selector whose field value (or text) is copied instead.
copied renders the button already in the copied state.
Summary
Functions
Attributes
id(:string) (required) - Needed by the hook.value(:string) - The text to copy. Defaults tonil.from(:string) - Selector of the field or element whose text is copied. Defaults tonil.locale(:string) - Defaults to"en". Must be one of"en", or"pt_BR".toast(:any) - Shown after a copy;nilor""for none. By default the locale's text. Defaults to:default.error_toast(:string) - Defaults tonil.copied(:boolean) - Renders the copied state. Defaults tofalse.on_copy(:any) - An event name or a%JS{}. Defaults tonil.target(:any) - Defaults tonil.copied_label(:string) - Defaults tonil.icon(:boolean) - A copy icon before the text (a check while copied). Defaults tofalse.icon_only(:boolean) - Just the icon; give it anaria-label. Defaults tofalse.color(:string) - Defaults to"primary". Must be one of"neutral","primary","secondary","info","success","warning", or"error".variant(:string) - Defaults to"solid". Must be one of"solid","glow","outline","soft","bordered","flat", or"ghost".size(:string) - Defaults to"md". Must be one of"xs","sm","md","lg", or"xl".class(:any) - Defaults tonil.- Global attributes are accepted.
Slots
inner_block
Attributes
id(:string) (required) - The id of the input; the button is<id>-copy.name(:string) - Defaults tonil.value(:string) - Defaults tonil.placeholder(:string) - Defaults tonil.label(:string) - The button's text; by default the locale's. Defaults tonil.field_label(:string) - The label above the field. Defaults tonil.leading_icon(:string) - An icon at the start of the field. Defaults tonil.copied_label(:string) - Defaults tonil.icon(:boolean) - A copy icon before the label. Defaults totrue.locale(:string) - Defaults to"en". Must be one of"en", or"pt_BR".toast(:any) - Defaults to:default.error_toast(:string) - Defaults tonil.on_copy(:any) - Defaults tonil.target(:any) - Defaults tonil.class(:any) - Merged into the wrapper. Defaults tonil.- Global attributes are accepted. Supports all globals plus:
["readonly", "disabled", "autocomplete", "form", "phx-debounce"].