# Marker Component
Markers are the small lines between messages in a conversation: inline statuses, system notes, bordered activity rows, and labeled separators. Use them to show what an assistant or teammate is doing without interrupting the thread. Static markers are plain HTML and Tailwind CSS; one dependency-free Stimulus controller adds live states and expandable details. Free component.
## Features
- Three layouts: an inline note (`:default`), a label between two lines (`:separator`) and a row with a bottom border (`:border`)
- Decorative icons, tinted to signal an outcome while the text still says it
- Progress markers with `role="status"`, spinners, pulsing dots and a CSS-only text shimmer that stays still for reduced motion
- Trailing content: times, counters and small actions like Restore or Retry
- Link and button markers that are real `<a>` and `<button>` elements
- Expandable markers that reveal details with an interruptible height animation and a synced `aria-expanded`
- Live markers that swap between running, done and failed views with an elapsed-time counter, settled from a Turbo Stream or a controller action
## Implementation Options
| Option | Best for | Files |
|--------|----------|-------|
| ViewComponent | Ruby API with variant, icon, trailing and details slots | `app/components/marker/` |
| Shared partial | Same options and markup as the ViewComponent, for apps without `view_component` | `app/views/shared/components/marker/` |
| Plain ERB | Full markup control and the live marker (running, done and failed views with a timer) | `app/views/components/marker/` |
## Installation
Static markers need only Tailwind CSS. The shimmer uses the `animate-marker-shimmer` utility from the Rails Blocks stylesheet:
```css
@theme {
/* Marker shimmer: slides a text-clipped gradient. Override the speed with [--marker-shimmer-duration:3s]. */
--animate-marker-shimmer: marker-shimmer var(--marker-shimmer-duration, 1.8s) linear infinite;
@keyframes marker-shimmer {
from { background-position: 100% 0; }
to { background-position: 0 0; }
}
}
```
Expandable and live markers need `app/javascript/controllers/marker_controller.js`. It has no dependencies.
## ViewComponent
```erb
<%# Inline note with a decorative icon %>
<%= render Marker::Component.new(text: "Explored 4 files") do |marker| %>
<% marker.with_icon do %>
<svg class="size-4 shrink-0" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true">…</svg>
<% end %>
<% end %>
<%# Layouts %>
<%= render Marker::Component.new(text: "Today", variant: :separator) %>
<%= render Marker::Component.new(text: "Conversation compacted", variant: :separator, align: :start) %>
<%= render Marker::Component.new(text: "Reviewed 8 related files", variant: :border) %>
<%# Progress: announced, with a shimmer %>
<%= render Marker::Component.new(text: "Thinking…", status: true, shimmer: true) %>
<%# Trailing counter %>
<%= render Marker::Component.new(text: "Running tests", status: true) do |marker| %>
<% marker.with_icon do %><svg class="size-4 shrink-0 animate-spin" aria-hidden="true">…</svg><% end %>
<% marker.with_trailing do %><span class="text-xs tabular-nums text-neutral-400">12 of 128</span><% end %>
<% end %>
<%# Rich text goes in the block %>
<%= render Marker::Component.new do %>
Switched to <span class="font-medium text-neutral-800 dark:text-neutral-200">fix/invoice-rounding</span>
<% end %>
<%# Checkpoint: a separator with a Restore button %>
<%= render Marker::Component.new(text: "Checkpoint", variant: :separator) do |marker| %>
<% marker.with_trailing do %><button type="button" class="rounded-md px-1.5 py-1 text-xs font-medium">Restore</button><% end %>
<% end %>
<%# Link marker %>
<%= render Marker::Component.new(text: "View the pull request", href: pull_request_path(@pull_request)) %>
<%# Expandable marker (needs marker_controller.js) %>
<%= render Marker::Component.new(text: "Explored 4 files") do |marker| %>
<% marker.with_details do %>
<ul class="space-y-2">
<li class="truncate font-mono text-xs">app/models/invoice.rb</li>
</ul>
<% end %>
<% end %>
```
### `Marker::Component` Options
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `text` | String | `nil` | The marker text. A block works too (links, code, bold names) |
| `variant` | Symbol | `:default` | `:default` (inline note), `:separator` (label between two lines) or `:border` (row with a bottom border) |
| `align` | Symbol | `:center` | Separator label position: `:center`, `:start` or `:end` |
| `status` | Boolean | `false` | Adds `role="status"` so the marker is announced when it appears or changes |
| `shimmer` | Boolean | `false` | Slides a shimmer across the text. Needs the `animate-marker-shimmer` utility |
| `href` | String | `nil` | Renders the marker as a link (`:default` and `:border` variants) |
| `open` | Boolean | `false` | Whether the details start expanded |
| `classes` | String | `nil` | Extra classes on the outer element |
| `html` | Hash | `{}` | Extra attributes on the outer element (`id`, `data`, `aria`). They override the defaults |
### Slots
| Slot | Description |
|------|-------------|
| `with_icon` | Decorative icon before the text. Use `size-4 shrink-0` (`size-3.5` in separators) and `aria-hidden="true"` |
| `with_trailing` | Content after the text: a time, a counter or a small button. Pushed to the end of default and border markers, next to the label in separators |
| `with_details` | Hidden content revealed by clicking the marker. Turns the marker into a disclosure button and adds the marker controller |
## Shared Partial
The partial takes the same options as locals. Pass the icon, trailing content and details as captured HTML, and the text as a block or `text:`.
```erb
<%= render "shared/components/marker/marker", text: "Today", variant: :separator %>
<%= render "shared/components/marker/marker", text: "Thinking…", status: true, shimmer: true %>
<% spinner = capture do %>
<svg class="size-4 shrink-0 animate-spin" aria-hidden="true">…</svg>
<% end %>
<%= render "shared/components/marker/marker", text: "Running tests", status: true, icon: spinner %>
<% explored_files = capture do %>
<ul class="space-y-2"><li class="truncate font-mono text-xs">app/models/invoice.rb</li></ul>
<% end %>
<%= render "shared/components/marker/marker", text: "Explored 4 files", details: explored_files %>
```
## Plain ERB
The examples in `app/views/components/marker/` are self-contained:
1. Basic Marker: an icon and a short line of text
2. Marker Variants: default, separator and border layouts
3. Marker with Icon: branch, command and tinted outcome icons, plus a stacked layout
4. Status Marker: spinners, a progress counter and a pulsing dot
5. Shimmer Marker: CSS-only shimmering text
6. Separator Marker: date, icon, left-aligned, unread and checkpoint separators
7. Border Marker: bordered activity rows with times
8. Link and Button Markers: a link, an action and a disabled action
9. Live Marker: running, done and failed views with an elapsed-time counter
10. Expandable Marker: a disclosure with animated details
11. Markers in a Conversation: every variant together in a thread
## Stimulus Controller
Add `data-controller="marker"` only to markers that change over time.
| Name | Type | Description |
|------|------|-------------|
| `data-marker-state-value` | Value (String) | Shows the `view` target whose `data-marker-state` matches. `"running"` also starts the timer |
| `data-marker-started-at-value` | Value (Number) | Epoch milliseconds the work started at, so a server-rendered marker keeps counting from the right moment |
| `data-marker-open-value` | Value (Boolean) | Whether the details panel is open |
| `view` | Target | One per state, each with `data-marker-state` |
| `elapsed` | Target | Receives the elapsed time (`8s`, `1m 12s`) and keeps the final duration |
| `trigger` / `panel` | Targets | The disclosure button and its details panel |
| `marker#start`, `marker#complete`, `marker#fail`, `marker#toggle` | Actions | Change the state or toggle the details |
| `marker:change` | Event | Dispatched after the state changes, with `state` and `previousState` in `event.detail` |
To settle a live marker from the server, replace it with a Turbo Stream or update `data-marker-state-value` to `"done"` or `"failed"`.
## Accessibility
- Markers are presentational by default. Add `role="status"` (`status: true`) only to markers that report progress, so they are announced when they appear or change.
- Do not add `role="separator"` to a separator marker: its text would stop being announced. The lines are decorative pseudo-elements.
- Icons are decorative and use `aria-hidden="true"`. An icon-only marker needs an `aria-label`.
- Markers that navigate or act are real `<a>` and `<button>` elements. Expandable markers keep `aria-expanded` and `aria-controls` in sync.
- The ticking elapsed counter is hidden from assistive tech while running, so only the state change is announced.
- The shimmer and the panel animation respect `prefers-reduced-motion`.
---
## AI Instructions
### Choose An Implementation
- **Vanilla / plain ERB**: Use for live markers (running, done and failed views with a timer) or when you need full markup control.
- **ERB template partial**: Use for reusable markers driven by locals in apps without `view_component`.
- **ViewComponent**: Use when you want a Ruby API with slots for the icon, trailing content and details.
### Quick Reference
- **Vanilla examples**: `app/views/components/marker/`
- **ERB partial files**: `app/views/shared/components/marker/`
- **ERB template**: `render "shared/components/marker/marker", text: "Explored 4 files"`
- **ViewComponent**: `render Marker::Component.new(text: "Explored 4 files")`
- **ViewComponent files**: `app/components/marker/`
- **Stimulus controller**: `app/javascript/controllers/marker_controller.js` (expandable and live markers only)
### Implementation Checklist
- Pick one implementation path first, then stay consistent within that example.
- Keep markers quiet: `text-sm text-neutral-500` for notes, `text-xs font-medium` for separators. They sit between messages and should not compete with them.
- Add `status: true` only to progress markers, never to static notes.
- Size icons `size-4 shrink-0` (`size-3.5` inside separators) and mark them `aria-hidden="true"`.
- Add the `animate-marker-shimmer` utility to your Tailwind theme before using `shimmer: true`.
- Install `marker_controller.js` before using `with_details` / `details:` or a live marker.
### Common Patterns
- **AI chat**: a shimmering "Thinking…" status while streaming, then a "Worked for 42s" separator with a Restore button.
- **Activity feeds**: `variant: :border` rows with an icon and a trailing `<time>`.
- **Chat threads**: `variant: :separator` with a `<time>` for dates, or a red unread divider via `classes:`.
- **Tool calls**: an expandable "Explored 4 files" marker listing the files in its details.
### Common Mistakes
- Do not put `role="separator"` on a separator marker; its label would not be announced.
- Do not add `status: true` to every marker; screen readers would announce static notes as updates.
- Do not use `href:` with `variant: :separator` or with details; it is ignored there.
- Do not invent variants or align values beyond the documented ones; unknown values fall back to the defaults.
- Do not mix ERB partial locals with ViewComponent initializer arguments in the same example.