Brand

Side drifts

ASCII drifts at a wide section's sides: from 1440 wide a column crop fades in from the left edge and a mass crop from the right, each 40% of the section's height and as wide as the margin beside the content.

Install

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

npx spyglass-ds add side-drifts
<script type="module" src="/spyglass-ds/elements/side-drifts.js"></script>
A wide section

How it works

Ask in plain words. Acme's library answers with the ads that fit, ranked by how long they ran.

Usage

Full-width sections on wide screens, where the content column leaves empty margins; inside a positioned section, behind the content.

Never

  • Inside a card or a narrow column
  • Over the content: they live in the margins

Adds with it: ascii-drift

Props

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

<SideDrifts>

PropTypeDefault
leftSideDriftPlace | false

Where the left drift sits (top 8%, middle 30%, bottom 52%), or false for none.

'top'
rightSideDriftPlace | false

Where the right drift sits, or false for none.

'bottom'
classNamestring

Examples

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

react/examples/side-drifts/Section.tsx
import { SideDrifts } from '@/react/components/visuals/SideDrifts'
// A full-width section with drifts at both sides (shown from 1440 wide): the left one at the top, the right one lower.

export default function Section() {
  return (
    <section className="relative isolate flex min-h-[640px] flex-col items-center justify-center gap-4 overflow-clip bg-surface px-6 text-center">
      <SideDrifts left="top" right="bottom" />
      <h2 className="type-heading-2 text-fg">How it works</h2>
      <p className="max-w-xl type-body text-fg-muted">Ask in plain words. Acme's library answers with the ads that fit, ranked by how long they ran.</p>
    </section>
  )
}
elements/examples/side-drifts/Section.html
<!-- A full-width section with drifts at both sides (shown from 1440 wide): the left one at the top, the right one lower. -->
<section class="relative isolate flex min-h-[640px] flex-col items-center justify-center gap-4 overflow-clip bg-surface px-6 text-center">
  <spyglass-side-drifts left="top" right="bottom"></spyglass-side-drifts>
  <h2 class="type-heading-2 text-fg">How it works</h2>
  <p class="max-w-xl type-body text-fg-muted">Ask in plain words. Acme's library answers with the ads that fit, ranked by how long they ran.</p>
</section>

Source

react/components/visuals/SideDrifts.tsx
import { AsciiDrift } from '@/react/components/visuals/AsciiDrift'
import { cn } from '@/react/lib/cn'

// The site's side drifts (ui/SideDrifts): from 1440 wide, where the content column leaves room at the sides, a column
// crop of the ASCII texture fades in from the left edge and a mass crop from the right, each 40% of the section's height
// and as wide as the margin beside the content less 16px. Below 1440 they are gone. Put it inside a positioned section
// (`relative isolate`); the drifts sit behind the content and never move. Decoration: hidden from assistive tech.
export type SideDriftPlace = 'top' | 'middle' | 'bottom'
export interface SideDriftsProps {
  /** Where the left drift sits (top 8%, middle 30%, bottom 52%), or false for none. */
  left?: SideDriftPlace | false
  /** Where the right drift sits, or false for none. */
  right?: SideDriftPlace | false
  className?: string
}

const SIDE = 'hidden min-[1440px]:block min-[1440px]:h-[40%] min-[1440px]:w-[calc((100vw-var(--ds-layout-content))/2-var(--ds-space-lg))]'
const PLACE: Record<SideDriftPlace, string> = { top: 'min-[1440px]:top-[8%]', middle: 'min-[1440px]:top-[30%]', bottom: 'min-[1440px]:top-[52%]' }

export function SideDrifts({ left = 'top', right = 'bottom', className }: SideDriftsProps) {
  return (
    <span data-ds="side-drifts" aria-hidden="true" className={cn('contents', className)}>
      {left ? <AsciiDrift crop="column" from="left" className={cn(SIDE, 'min-[1440px]:left-0', PLACE[left])} /> : null}
      {right ? <AsciiDrift crop="mass" from="right" className={cn(SIDE, 'min-[1440px]:right-0', PLACE[right])} /> : null}
    </span>
  )
}

export default SideDrifts
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/side-drifts.ts
import { html, nothing } from 'lit'
import { DsElement, define } from '@/elements/lib/element'
import '@/elements/components/visuals/ascii-drift'
import styles from 'virtual:tw'

// SideDrifts.tsx as <spyglass-side-drifts>: from 1440 wide, a column crop of the ASCII texture fades in from the left
// edge and a mass crop from the right, 40% of the section's height, as wide as the margin beside the content less 16px.
// `left` and `right`: top, middle, bottom or false. Put it inside a positioned section. Decoration: aria-hidden.

const SIDE = 'hidden min-[1440px]:block min-[1440px]:h-[40%] min-[1440px]:w-[calc((100vw-var(--ds-layout-content))/2-var(--ds-space-lg))]'
const PLACE: Record<string, string> = { top: 'min-[1440px]:top-[8%]', middle: 'min-[1440px]:top-[30%]', bottom: 'min-[1440px]:top-[52%]' }
const side = { fromAttribute: (v: string | null) => (v === 'false' ? false : v) }

/**
 * @summary The ASCII drifts at a wide section's sides.
 */
export class SideDrifts extends DsElement {
	static styles = [DsElement.styles, styles]
	static properties = { left: { converter: side }, right: { converter: side } }
	/** top, middle, bottom or false. */
	left: string | false = 'top'
	/** top, middle, bottom or false. */
	right: string | false = 'bottom'

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

	render() {
		const l = this.left && PLACE[this.left] ? this.left : false
		const r = this.right && PLACE[this.right] ? this.right : false
		return html`<span data-ds="side-drifts" class="contents">${l ? html`<spyglass-ascii-drift crop="column" from="left" class=${`${SIDE} min-[1440px]:left-0 ${PLACE[l]}`}></spyglass-ascii-drift>` : nothing}${r ? html`<spyglass-ascii-drift crop="mass" from="right" class=${`${SIDE} min-[1440px]:right-0 ${PLACE[r]}`}></spyglass-ascii-drift>` : nothing}</span>`
	}
}

define('side-drifts', SideDrifts)

Reference: Site ui/SideDrifts (SideDrifts.module.css): hidden below 1440; width calc((100vw - --content-max) / 2 - 16px), height 40%, top 8%, 30% or 52%.