# Separator Component

Separators divide content into clear groups: horizontal rules, vertical dividers, labeled separators, and separators with actions. Tailwind CSS only, no JavaScript. Free component.

## Features

- Horizontal separators as a native `<hr>`, with the separator role built in
- Vertical separators that stretch to the height of their flex row, or take a fixed height for inline text
- Labeled separators with the label centered, at the start or at the end. The lines are `::before` and `::after`, so each separator is a single element
- Five styles: default, strong, dashed, dotted and fade
- Decorative mode (`aria-hidden`) for lines between inline links
- Plain ERB examples for toolbars, chat date separators, unread markers, section headings, insert-between-items buttons, forms and responsive stats

## Implementation Options

| Option | Best for | Files |
|--------|----------|-------|
| ViewComponent | Ruby API with orientation, variant, label and align options | `app/components/separator/` |
| Shared partial | Same options and markup as the ViewComponent, for apps without `view_component` | `app/views/shared/components/separator/` |
| Plain ERB | Full markup control and the special examples (accent glow, ornament, insert-between-items, section headings) | `app/views/components/separator/` |

No installation needed beyond Tailwind CSS.

## ViewComponent

```erb
<%# Horizontal separator between two blocks %>
<%= render Separator::Component.new(classes: "my-4") %>

<%# Vertical separator in a flex row %>
<div class="flex items-center gap-3">
  <span>Docs</span>
  <%= render Separator::Component.new(orientation: :vertical, decorative: true, classes: "h-4") %>
  <span>Blog</span>
</div>

<%# Labeled separators %>
<%= render Separator::Component.new(label: "or continue with") %>
<%= render Separator::Component.new(label: "Account settings", align: :start, variant: :dashed) %>

<%# Rich label as a block %>
<%= render Separator::Component.new do %>
  <span class="rounded-full border border-black/10 px-2.5 py-0.5 text-xs">Step 2 of 4</span>
<% end %>

<%# Date separator, announced as a separator with its label %>
<%= render Separator::Component.new(label: "Today", html: { role: "separator", aria: { label: "Today" } }) %>
```

### `Separator::Component` Options

| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `orientation` | Symbol | `:horizontal` | `:horizontal` renders an `<hr>`. `:vertical` renders a `<div role="separator" aria-orientation="vertical">` |
| `variant` | Symbol | `:default` | `:default`, `:strong`, `:dashed`, `:dotted` or `:fade` |
| `label` | String | `nil` | Text in the middle of a horizontal line. A block works too. Ignored on vertical separators |
| `align` | Symbol | `:center` | Label position: `:center`, `:start` or `:end` |
| `decorative` | Boolean | `false` | Adds `aria-hidden="true"` and drops the separator role |
| `classes` | String | `nil` | Extra classes: spacing (`my-4`), height (`h-4`), width (`flex-1`), full bleed (`-mx-6`) |
| `html` | Hash | `{}` | Extra attributes (`id`, `data`, `role`, `aria`). They override the defaults |

## Shared Partial

The partial takes the same options as locals and renders the same markup.

```erb
<%= render "shared/components/separator/separator", classes: "my-4" %>
<%= render "shared/components/separator/separator", orientation: :vertical, decorative: true, classes: "h-4" %>
<%= render "shared/components/separator/separator", label: "or continue with" %>
<%= render "shared/components/separator/separator", variant: :fade, label: "3 results", align: :end %>

<%= render "shared/components/separator/separator" do %>
  <span class="rounded-full border border-black/10 px-2.5 py-0.5 text-xs">Step 2 of 4</span>
<% end %>
```

## Plain ERB

The examples in `app/views/components/separator/` are self-contained:

1. Basic Separator: an `<hr>` and short vertical separators between links
2. Vertical Separator: toolbar, inline meta and tall content
3. Separator with Label: centered, start, end, eyebrow, pill and icon labels
4. Separator Styles: solid, strong, dashed, dotted, thick, double, fade, fade out, accent glow and ornament
5. Separator with Action: insert-between-items buttons and a "load more" button on the line
6. Date Separator: date pills and an unread marker in a conversation
7. Section Separator: a heading, a count and an action joined by a line
8. Separator in a Form: labeled separator between sign-in methods and a full-bleed footer line
9. Responsive Separator: horizontal on mobile, vertical from `sm:` up

## Accessibility

- Use `<hr>` for a thematic break between blocks of content. It has the `separator` role built in.
- When an `<hr>` does not fit (vertical separators, lines drawn with pseudo-elements), use `role="separator"` with `aria-orientation`.
- Children of a `role="separator"` element are not announced. Give it an `aria-label` when it carries meaning, like a date.
- Purely visual separators, like the lines between inline links, use `aria-hidden="true"` (`decorative: true`).
- When a separator holds readable text or a button, keep the container role-free so the text and the button stay reachable. That is why labeled separators have no role by default.

---

## AI Instructions

### Choose An Implementation

- **Vanilla / plain ERB**: Use for the special examples (accent glow, ornament, insert-between-items, section headings) or when you need full markup control.
- **ERB template partial**: Use for reusable separators driven by locals in apps without `view_component`.
- **ViewComponent**: Use when you want a Ruby API with validated options.

### Quick Reference

- **Vanilla examples**: `app/views/components/separator/`
- **ERB partial files**: `app/views/shared/components/separator/`
- **ERB template**: `render "shared/components/separator/separator", label: "or"`
- **ViewComponent**: `render Separator::Component.new(label: "or")`
- **ViewComponent files**: `app/components/separator/`

### Implementation Checklist

- Pick one implementation path first, then stay consistent within that example.
- Put vertical separators inside a flex row. They use `self-stretch`, so add a height class (`h-4`) for inline text.
- Add spacing with `classes:` (`my-4`, `mx-1`). The separator has no margin of its own.
- Use `decorative: true` for lines between inline links or text, and the default role otherwise.
- For a date separator, pass `html: { role: "separator", aria: { label: "Today" } }`.

### Common Patterns

- **Auth forms**: `label: "or continue with"` between social and email sign-in.
- **Cards**: `classes: "-mx-6"` for a full-bleed line in a card with `p-6`.
- **Toolbars**: `orientation: :vertical, classes: "mx-1 my-1"` between button groups.
- **Chat feeds**: a block label with a pill, plus `role` and `aria-label` through `html:`.

### Common Mistakes

- Do not put `role="separator"` on a separator that holds a button or text that must be read; its children are not announced.
- Do not pass a label to a vertical separator; it is ignored.
- 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.