Search 71 components and 72 controllers by name, category or description.
Read More
Overflow-aware content preview with first-paint clamping and accessible expansion
Basic usage
Long content is clamped to a 320 pixel preview. The fade and the trigger appear only after the browser confirms the content actually overflows.
Turbo Drive intercepts every same-origin link and form submission on the page, fetches the
response in the background, and swaps the <body> without discarding the
JavaScript runtime. The address bar, the history stack, and the scroll position keep behaving
the way the browser already taught people to expect.
Because the document persists, so does everything attached to it: open WebSocket connections, media that is still playing, and the controllers Stimulus has already connected. A navigation stops being a teardown and becomes a replacement of the parts that actually changed.
Turbo Frames narrow that replacement further. A frame declares a region of the page that responds to its own navigations, so a link inside it updates only that region and leaves the rest of the document untouched. The server keeps rendering complete HTML; the frame decides how much of it reaches the screen.
Turbo Streams invert the direction. Instead of the client asking for a region, the server sends a list of operations — append, prepend, replace, remove — each addressed to an element id. One response can update a counter in the header, insert a row in a table, and dismiss a dialog, without the client knowing those three places were related.
What is left for JavaScript is the part that was always client-side: the behavior that has no server round trip to justify it. That is the seam this package sits on.
<hw:read-more>
<div class="space-y-4 text-2xl leading-10 text-muted-foreground">
<p>
Turbo Drive intercepts every same-origin link and form submission on the page, fetches the
response in the background, and swaps the <code><body></code> without discarding the
JavaScript runtime. The address bar, the history stack, and the scroll position keep behaving
the way the browser already taught people to expect.
</p>
<p>
Because the document persists, so does everything attached to it: open WebSocket connections,
media that is still playing, and the controllers Stimulus has already connected. A navigation
stops being a teardown and becomes a replacement of the parts that actually changed.
</p>
<p>
Turbo Frames narrow that replacement further. A frame declares a region of the page that
responds to its own navigations, so a link inside it updates only that region and leaves the
rest of the document untouched. The server keeps rendering complete HTML; the frame decides
how much of it reaches the screen.
</p>
<p>
Turbo Streams invert the direction. Instead of the client asking for a region, the server
sends a list of operations — append, prepend, replace, remove — each addressed to an element
id. One response can update a counter in the header, insert a row in a table, and dismiss a
dialog, without the client knowing those three places were related.
</p>
<p>
What is left for JavaScript is the part that was always client-side: the behavior that has no
server round trip to justify it. That is the seam this package sits on.
</p>
</div>
</hw:read-more>
Preview height
collapsed-height is measured in pixels rather than lines, so headings, lists, and images can share the same preview without moving the cut.
Why a height and not a line count
A line clamp assumes every line costs the same. Real prose does not: a heading is taller than a paragraph, a list item carries its own spacing, and an image occupies whatever the layout gives it. Clamping by lines on this block would cut at a different visual point depending on which elements happen to come first.
- Headings and paragraphs mix freely inside the preview.
- Lists keep their markers and indentation above and below the cut.
- Images and embeds count toward the measured height like any other block.
The component measures the rendered content against the pixel budget and only then decides whether there is anything to hide. The cut lands in the same place no matter what the content is made of.
Everything below the fold stays in the document and in the accessibility tree the whole time — expanding changes presentation, never what exists.
<hw:read-more :collapsed-height="200">
<div class="space-y-4 text-sm leading-7 text-muted-foreground">
<h3 class="text-base font-semibold text-foreground">Why a height and not a line count</h3>
<p>
A line clamp assumes every line costs the same. Real prose does not: a heading is taller than
a paragraph, a list item carries its own spacing, and an image occupies whatever the layout
gives it. Clamping by lines on this block would cut at a different visual point depending on
which elements happen to come first.
</p>
<ul class="list-disc space-y-2 pl-5">
<li>Headings and paragraphs mix freely inside the preview.</li>
<li>Lists keep their markers and indentation above and below the cut.</li>
<li>Images and embeds count toward the measured height like any other block.</li>
</ul>
<p>
The component measures the rendered content against the pixel budget and only then decides
whether there is anything to hide. The cut lands in the same place no matter what the content
is made of.
</p>
<p>
Everything below the fold stays in the document and in the accessibility tree the whole time —
expanding changes presentation, never what exists.
</p>
</div>
</hw:read-more>
Content that never overflows
Short content settles into data-state="static": no fade, no trigger, and no control flash on the way there.
This paragraph fits well inside the 200 pixel budget, so the browser measures it, finds nothing
to hide, and settles the component into data-state="static". No fade, no trigger,
and no layout shift on the way there — the controls were never rendered visible to begin with.
<hw:read-more :collapsed-height="200">
<p class="text-sm leading-7 text-muted-foreground">
This paragraph fits well inside the 200 pixel budget, so the browser measures it, finds nothing
to hide, and settles the component into <code>data-state="static"</code>. No fade, no trigger,
and no layout shift on the way there — the controls were never rendered visible to begin with.
</p>
</hw:read-more>
Server-rendered initial state
The requested state ships in the markup, so a permalink or a redirect can decide how much the reader lands on. Reload the page through either button to compare.
The requested state is decided on the server and shipped in the markup, so the first paint
already shows the right thing. A page rendered with expanded never flashes a
collapsed preview while the controller boots.
That makes the state addressable: a permalink, a redirect after a form submission, or a Turbo Frame response can all decide how much of the content the reader lands on.
The browser still measures after connecting. If the content turns out not to overflow, the
component settles into static and the requested state stops mattering, because
there is nothing left to reveal.
<hw:read-more :collapsed-height="160" :expanded="$fullArticle">
<div class="space-y-4 text-sm leading-7 text-muted-foreground">
<p>
The requested state is decided on the server and shipped in the markup, so the first paint
already shows the right thing. A page rendered with <code>expanded</code> never flashes a
collapsed preview while the controller boots.
</p>
<p>
That makes the state addressable: a permalink, a redirect after a form submission, or a
Turbo Frame response can all decide how much of the content the reader lands on.
</p>
<p>
The browser still measures after connecting. If the content turns out not to overflow, the
component settles into <code>static</code> and the requested state stops mattering, because
there is nothing left to reveal.
</p>
</div>
</hw:read-more>
Labels, icon, and trigger appearance
Labels are props for translation, and the trigger takes the same variant and size axes as hw:button.
Labels are props so they can carry translated strings, and the trigger takes the same
variant and size axes as hw:button — here an outlined
small button instead of the default inline link.
The icon comes from the set shipped by hw:icon. It rotates when the state flips,
which is a CSS concern in the preset rather than anything the controller has to script. Setting
icon="" removes it entirely.
Whatever the labels say, the button stays a native <button> carrying
aria-expanded and aria-controls, so the control is announced with its
state and its relationship to the content it governs.
<hw:read-more
:collapsed-height="180"
more-label="Continue reading"
less-label="Show less"
icon="arrow-down"
variant="outline"
size="sm"
>
<div class="space-y-4 text-sm leading-7 text-muted-foreground">
<p>
Labels are props so they can carry translated strings, and the trigger takes the same
<code>variant</code> and <code>size</code> axes as <code>hw:button</code> — here an outlined
small button instead of the default inline link.
</p>
<p>
The icon comes from the set shipped by <code>hw:icon</code>. It rotates when the state flips,
which is a CSS concern in the preset rather than anything the controller has to script. Setting
<code>icon=""</code> removes it entirely.
</p>
<p>
Whatever the labels say, the button stays a native <code><button></code> carrying
<code>aria-expanded</code> and <code>aria-controls</code>, so the control is announced with its
state and its relationship to the content it governs.
</p>
</div>
</hw:read-more>
Rich labels and a custom icon
The more, less, and trigger_icon slots replace the props when a label needs markup or the icon comes from outside the package.
When a label needs more than a string — emphasis, a count, a second line of context — the
more and less slots replace the props entirely.
The trigger_icon slot does the same for the glyph, so an icon set outside the one
bundled with the package works without touching the component. Here it is a Lucide icon coming
from the application.
The slots only change what is inside the button. The button itself keeps its wiring: same target, same action, same accessible state.
That separation is why swapping labels never turns into swapping behavior.
<hw:read-more :collapsed-height="180" variant="ghost" size="sm">
<x-slot:more>
<strong class="font-semibold text-foreground">Read the rest</strong>
<span class="text-muted-foreground">— 3 more paragraphs</span>
</x-slot:more>
<x-slot:less>
<strong class="font-semibold text-foreground">Collapse again</strong>
</x-slot:less>
<x-slot:trigger_icon>
<x-lucide-chevrons-down class="size-4" />
</x-slot:trigger_icon>
<div class="space-y-4 text-sm leading-7 text-muted-foreground">
<p>
When a label needs more than a string — emphasis, a count, a second line of context — the
<code>more</code> and <code>less</code> slots replace the props entirely.
</p>
<p>
The <code>trigger_icon</code> slot does the same for the glyph, so an icon set outside the one
bundled with the package works without touching the component. Here it is a Lucide icon coming
from the application.
</p>
<p>
The slots only change what is inside the button. The button itself keeps its wiring: same
target, same action, same accessible state.
</p>
<p>
That separation is why swapping labels never turns into swapping behavior.
</p>
</div>
</hw:read-more>