Clipboard Text
A read-only value with a button to copy it to the clipboard.
Installation
Included in poetry-ui — available as
poetry_clipboard_text
the moment you've installed Poetry,
with no per-component step. To own the source and edit it, copy it into your app:
bin/rails g poetry:add clipboard-text
Default
<%= poetry_clipboard_text(value: "gem install poetry-ui", label: "Install command", class: "w-96") %>
Truncated copy
<%# text_to_copy: puts the FULL value on the clipboard while the field
displays the short form. %>
<div class="w-96">
<%= poetry_clipboard_text(value: "pk_live_51Nx…9fQ2", label: "API key",
text_to_copy: "pk_live_51NxAbCdEfGhIjKlMnOpQrStUvWxYz0123456789fQ2") %>
</div>
API
Poetry::Ui::ClipboardText::Component — options are
constructor keywords (the poetry_* helper forwards them);
slots are composed inside the block. Generated from the gem's source documentation.
| Option | Type | Details | Description |
|---|---|---|---|
| described_by: | String | Ids for the input's aria-describedby (hint or error text). | |
| disabled: | Boolean | defaults to false |
Disables the input and the copy button together. |
| id: | String | The readonly input's DOM id (auto-generated when omitted) - the Field/Label for= target. | |
| label: | String | The readonly input's accessible name when no Label/Field association exists. | |
| text_to_copy: | String | Overrides what lands on the clipboard when the displayed value truncates: display short, copy full. | |
| value: | String | required | The displayed text - also what copies, unless text_to_copy: overrides it. |
Styling
Every part carries a stable data-slot attribute — target
[data-slot=…] from your own CSS to restyle it. State rides
data attributes on the parts below. This contract is verified against rendered DOM in CI.
| Part | Description |
|---|---|
| [data-slot=clipboard-text] | Root - the controller rides here |
| [data-slot=clipboard-text-group] | The bordered field surface - InputGroup's chrome |
| [data-slot=input-group-control] | The readonly mono <input> showing the value - selectable, never editable; InputGroup's control slot |
| [data-slot=input-group-addon] | The trailing cell holding the copy affordance - InputGroup's addon vocabulary |
State attributes
| Part | Attribute | Condition | Values |
|---|---|---|---|
| clipboard-text | data-copied | stamped for a beat after a successful copy (the stacked copy/check glyphs swap off it) | — |
| input-group-addon | data-align | always - inline-end holds the copy button | inline-end |
Wiring
The Stimulus surface each element carries — declared in the component, verified against rendered DOM in CI. Bare actions fire on the element's default event.
| Element | Controller | Wiring |
|---|---|---|
| root | poetry--core--clipboard-text | registers · value message · value text (if) |
| input | poetry--core--clipboard-text | target input |
| copy_button | poetry--core--clipboard-text | copy on click |