Components
Separator
The hairline: 1px in the #262626 edge step, across or down. Spyglass separates with a fill or a hairline, never a shadow.
Install
React apps get the React files; every other stack gets the web component.
npx spyglass-ds add separator<script type="module" src="/spyglass-ds/elements/separator.js"></script>Usage
Splitting a card's head from its body, or links in a row. Decorative by default; mark it semantic when it splits content a screen reader should hear as split.
Never
- A shadow or a thicker rule to separate
- A rule where spacing already separates
- A colored or glowing line: the spectrum belongs to the light
Props
The web component takes the same as attributes or properties (<spyglass-separator>); title is heading there.
<Separator>
| Prop | Type | Default |
|---|---|---|
orientation | 'horizontal' | 'vertical' Across (horizontal) or down (vertical, it stretches to its row's height). | 'horizontal' |
semantic | boolean A real separator for assistive tech, not only a line. | |
className | string |
Examples
The same example in React and as web components; both render identically.
import { Separator } from '@/react/components/ui/Separator'
// A board's title over a hairline, and its links split by short vertical lines.
export default function Profile() {
return (
<div className="flex w-80 max-w-full flex-col">
<div className="flex flex-col gap-1">
<p className="type-ui-strong text-fg">Acme hooks</p>
<p className="type-caption text-fg-muted">48 creatives from 12 brands.</p>
</div>
<Separator className="my-4" />
<div className="flex h-5 items-center gap-4 type-ui text-fg-soft">
<span>Ads</span>
<Separator orientation="vertical" />
<span>Posts</span>
<Separator orientation="vertical" />
<span>Product shots</span>
</div>
</div>
)
}<!-- A board's title over a hairline, and its links split by short vertical lines. -->
<div class="flex w-80 max-w-full flex-col">
<div class="flex flex-col gap-1">
<p class="type-ui-strong text-fg">Acme hooks</p>
<p class="type-caption text-fg-muted">48 creatives from 12 brands.</p>
</div>
<spyglass-separator class="my-4"></spyglass-separator>
<div class="flex h-5 items-center gap-4 type-ui text-fg-soft">
<span>Ads</span>
<spyglass-separator orientation="vertical"></spyglass-separator>
<span>Posts</span>
<spyglass-separator orientation="vertical"></spyglass-separator>
<span>Product shots</span>
</div>
</div>Source
import { cn } from '@/react/lib/cn'
// The hairline as its own part: 1px in the #262626 edge step, across or down. Spyglass separates with a fill or a
// hairline, never a shadow. Decorative by default (role none); pass `semantic` when it splits content a screen reader
// should hear as split.
export interface SeparatorProps {
/** Across (horizontal) or down (vertical, it stretches to its row's height). */
orientation?: 'horizontal' | 'vertical'
/** A real separator for assistive tech, not only a line. */
semantic?: boolean
className?: string
}
export function Separator({ orientation = 'horizontal', semantic, className }: SeparatorProps) {
return (
<div
data-ds="separator"
role={semantic ? 'separator' : 'none'}
aria-orientation={semantic ? orientation : undefined}
className={cn('shrink-0 bg-edge', orientation === 'vertical' ? 'w-px self-stretch' : 'h-px w-full', className)}
/>
)
}
export default Separator// Joins class names, skipping falsy ones: cn('a', on && 'b', ['c', undefined]). It does not merge conflicting
// utilities (no tailwind-merge), as Vue's class binding does not: the library's classes are written not to compete,
// and a className from the caller is appended after them, as Vue appends a fallthrough class.
export type ClassValue = string | false | null | undefined | 0 | ClassValue[]
export function cn(...values: ClassValue[]): string {
const out: string[] = []
for (const v of values) {
if (!v) continue
if (Array.isArray(v)) {
const s = cn(...v)
if (s) out.push(s)
}
else out.push(v)
}
return out.join(' ')
}import { type PropertyValues } from 'lit'
import { DsElement, define } from '@/elements/lib/element'
import styles from 'virtual:tw'
// Separator.tsx as <spyglass-separator>: the hairline, 1px in the #262626 edge step, across or down. The host is the
// line (React's root div), so a class on the element (a margin) lands on it. Decorative by default; `semantic` makes it
// a separator for assistive tech.
/** @summary The hairline, across or down. */
export class Separator extends DsElement {
static styles = [DsElement.styles, styles]
static properties = { orientation: { reflect: true }, semantic: { type: Boolean } }
/** horizontal (across) or vertical (down). */
orientation: 'horizontal' | 'vertical' = 'horizontal'
/** A real separator for assistive tech, not only a line. */
semantic = false
protected updated(changed: PropertyValues) {
super.updated(changed)
this.setAttribute('role', this.semantic ? 'separator' : 'none')
if (this.semantic) this.setAttribute('aria-orientation', this.orientation)
else this.removeAttribute('aria-orientation')
}
render() {
return null
}
}
define('separator', Separator)/* The host is the line (Separator.tsx's root div): across by default, down with orientation="vertical". A class on the
element wins over these, as a class on <Separator> does. */
:host { @apply block shrink-0 bg-edge h-px w-full; }
:host([orientation="vertical"]) { @apply h-auto w-px self-stretch; }Reference: Derived from the brand guidelines (no separator in the brand assets): the neutral steps for the hairline.