Brand

Instrument marks

Four hairline corner brackets in the text colour around a target, a few pixels outside its edges, like a viewfinder locking on: the site's instrument mark for the item a figure is reading.

Install

React apps get the React files; every other stack gets the web component.

npx spyglass-ds add instrument-marks
<script type="module" src="/spyglass-ds/elements/brackets.js"></script>
Around a target
1,284 ads

Usage

Marking the tile, figure or row a diagram is pointing at, in the site's instrument figures.

Never

  • Around controls or text people read, as a focus or selection state
  • In a color: they are the text colour, hairline

Props

The web component takes the same as attributes or properties (<spyglass-brackets>); title is heading there.

<Brackets>

PropTypeDefault
offsetnumber

How far outside the target's edges, in px.

armnumber

Each arm's length, in px.

classNamestring

Examples

The same example in React and as web components; both render identically.

react/examples/instrument-marks/Target.tsx
import { Brackets } from '@/react/components/visuals/Brackets'
// Brackets locking on to a tile, and a wider pair with longer arms around a figure.

export default function Target() {
  return (
    <div className="flex flex-wrap items-center gap-16">
      <div className="relative size-32 rounded-container bg-surface-raised">
        <Brackets />
      </div>
      <div className="relative px-4 py-2">
        <span className="font-heading text-heading-2 text-fg">1,284 ads</span>
        <Brackets offset={8} arm={12} />
      </div>
    </div>
  )
}
elements/examples/instrument-marks/Target.html
<!-- Brackets locking on to a tile, and a wider pair with longer arms around a figure. -->
<div class="flex flex-wrap items-center gap-16">
  <div class="relative size-32 rounded-container bg-surface-raised">
    <spyglass-brackets></spyglass-brackets>
  </div>
  <div class="relative px-4 py-2">
    <span class="font-heading text-heading-2 text-fg">1,284 ads</span>
    <spyglass-brackets offset="8" arm="12"></spyglass-brackets>
  </div>
</div>

Source

react/components/visuals/Brackets.tsx
import type { CSSProperties } from 'react'
import { cn } from '@/react/lib/cn'

// The site's instrument marks (instrument/marks): four hairline corner brackets in the text colour around a target,
// `offset` outside its edges (4px), each arm `arm` long (8px), like a viewfinder locking on. Put it inside a positioned
// box (the target); it sits above it (z 2) and takes no pointer. Decoration: hidden from assistive tech.
export type Strength = 'subtle' | 'stronger'
export interface BracketsProps {
  /** How far outside the target's edges, in px. */
  offset?: number
  /** Each arm's length, in px. */
  arm?: number
  className?: string
}

const ARM = 'absolute size-[var(--b-arm,var(--ds-space-sm))] border-0 border-solid border-fg'

export function Brackets({ offset, arm, className }: BracketsProps) {
  const style = { ...(offset !== undefined && { '--b-off': `${offset}px` }), ...(arm !== undefined && { '--b-arm': `${arm}px` }) } as CSSProperties
  return (
    <span data-ds="brackets" data-brackets="" aria-hidden="true" style={style} className={cn('pointer-events-none absolute inset-[calc(-1*var(--b-off,var(--ds-space-xs)))] z-2 origin-center', className)}>
      <i className={cn(ARM, 'top-0 left-0 border-t border-l')} />
      <i className={cn(ARM, 'top-0 right-0 border-t border-r')} />
      <i className={cn(ARM, 'bottom-0 left-0 border-b border-l')} />
      <i className={cn(ARM, 'right-0 bottom-0 border-r border-b')} />
    </span>
  )
}

export default Brackets
react/lib/cn.ts
// 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(' ')
}
elements/components/visuals/brackets.ts
import { html } from 'lit'
import { DsElement, define } from '@/elements/lib/element'
import styles from 'virtual:tw'

// Brackets.tsx as <spyglass-brackets>: four hairline corner brackets around the positioned box it sits in, `offset`
// outside its edges (4px), arms `arm` long (8px). Decoration: aria-hidden.

const ARM = 'absolute size-[var(--b-arm,var(--ds-space-sm))] border-0 border-solid border-fg'

/**
 * @summary Corner brackets around a target, like a viewfinder.
 */
export class Brackets extends DsElement {
	static styles = [DsElement.styles, styles]
	static properties = { offset: { type: Number }, arm: { type: Number } }
	/** How far outside the target's edges, in px. */
	offset?: number
	/** Each arm's length, in px. */
	arm?: number

	connectedCallback() {
		super.connectedCallback()
		this.setAttribute('aria-hidden', 'true')
	}

	render() {
		const style = [this.offset !== undefined ? `--b-off: ${this.offset}px` : '', this.arm !== undefined ? `--b-arm: ${this.arm}px` : ''].filter(Boolean).join('; ')
		return html`<span data-ds="brackets" data-brackets="" style=${style} class="pointer-events-none absolute inset-[calc(-1*var(--b-off,var(--ds-space-xs)))] z-2 origin-center"><i class=${`${ARM} top-0 left-0 border-t border-l`}></i><i class=${`${ARM} top-0 right-0 border-t border-r`}></i><i class=${`${ARM} bottom-0 left-0 border-b border-l`}></i><i class=${`${ARM} right-0 bottom-0 border-r border-b`}></i></span>`
	}
}

define('brackets', Brackets)

Reference: Site instrument/marks (Brackets) and instrument.module.css (.brackets): inset -4px (--b-off), 8px arms (--b-arm), 1px hairline in --text, z 2.