# `LedgerUI.Components.Clipboard`
[🔗](https://github.com/devaction-labs/ledger_ui/blob/v0.2.0/lib/ledger_ui/components/clipboard.ex#L1)

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 shows
    `copied_label` in place of the label when given;
  * dispatches `ledger:toast` on `window` with `%{message, kind}` (`kind` is `"success"` or
    `"error"`) when a `toast` is set. Pass `toast={nil}` for none;
  * runs `on_copy`: an event name (pushed with `%{"id" => id}`, to `target` if 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.

# `clipboard`

## Attributes

* `id` (`:string`) (required) - Needed by the hook.
* `value` (`:string`) - The text to copy. Defaults to `nil`.
* `from` (`:string`) - Selector of the field or element whose text is copied. Defaults to `nil`.
* `locale` (`:string`) - Defaults to `"en"`. Must be one of `"en"`, or `"pt_BR"`.
* `toast` (`:any`) - Shown after a copy; `nil` or `""` for none. By default the locale's text. Defaults to `:default`.
* `error_toast` (`:string`) - Defaults to `nil`.
* `copied` (`:boolean`) - Renders the copied state. Defaults to `false`.
* `on_copy` (`:any`) - An event name or a `%JS{}`. Defaults to `nil`.
* `target` (`:any`) - Defaults to `nil`.
* `copied_label` (`:string`) - Defaults to `nil`.
* `icon` (`:boolean`) - A copy icon before the text (a check while copied). Defaults to `false`.
* `icon_only` (`:boolean`) - Just the icon; give it an `aria-label`. Defaults to `false`.
* `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 to `nil`.
* Global attributes are accepted.
## Slots

* `inner_block`

# `clipboard_input`

## Attributes

* `id` (`:string`) (required) - The id of the input; the button is `<id>-copy`.
* `name` (`:string`) - Defaults to `nil`.
* `value` (`:string`) - Defaults to `nil`.
* `placeholder` (`:string`) - Defaults to `nil`.
* `label` (`:string`) - The button's text; by default the locale's. Defaults to `nil`.
* `field_label` (`:string`) - The label above the field. Defaults to `nil`.
* `leading_icon` (`:string`) - An icon at the start of the field. Defaults to `nil`.
* `copied_label` (`:string`) - Defaults to `nil`.
* `icon` (`:boolean`) - A copy icon before the label. Defaults to `true`.
* `locale` (`:string`) - Defaults to `"en"`. Must be one of `"en"`, or `"pt_BR"`.
* `toast` (`:any`) - Defaults to `:default`.
* `error_toast` (`:string`) - Defaults to `nil`.
* `on_copy` (`:any`) - Defaults to `nil`.
* `target` (`:any`) - Defaults to `nil`.
* `class` (`:any`) - Merged into the wrapper. Defaults to `nil`.
* Global attributes are accepted. Supports all globals plus: `["readonly", "disabled", "autocomplete", "form", "phx-debounce"]`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
