Detent web components
By Shane Logsdon

Data & tables

Code Snippet Deck

Implemented

Multi-language code runner snippet deck with live variable tuning

detent-code-snippet-deck

Port status
Catalog status
implemented
Origin
upstream
Phase
3
Wave
phase-3-data
Group
Data & tables

5.3 KB gzip for the class module

Variants

The primary deck is a three-runtime deck with the parameter drawer open (path, limit, verbose); the one in this section is the same component with line numbers and the window bar turned off. Switching a runtime or a parameter regenerates the code as text — nothing is highlighted by a parser and nothing is executed. Snippets are local strings; no request leaves the page.

Recorded states

  • active recorded state; no setter
  • collapsed recorded state; no setter
  • expanded recorded state; no setter
  • copied recorded state; no setter
  • empty recorded state; no setter
  • reduced motion recorded state; no setter

Usage

Import

import '/components/code-snippet-deck/define.js';

// or register it yourself
import { DetentCodeSnippetDeck } from '/components/code-snippet-deck/code-snippet-deck.js';

Attributes

  • default-language
  • show-line-numbers
  • show-window-bar

Properties

  • parameters
  • snippets

Slots

No slots are recorded for this component.

Events

No events are recorded for this component.

Example

Runnable example: site/examples/code-snippet-deck.ts. The snippet below is generated from the catalogued attributes.

<detent-code-snippet-deck
  default-language
  show-line-numbers
  show-window-bar
></detent-code-snippet-deck>

Property-only values

const element = document.querySelector('detent-code-snippet-deck');
if (element !== null) {
  // snippets: SnippetItem[]
  element.snippets = [];
  // parameters: SnippetParameter[]
  element.parameters = [];
}

Source

The pinned upstream source for this row:

  • src/components/ui/CodeSnippetDeck.tsx sha256 5d61698b8e20…

Native files

The native module and its artifacts:

  • src/components/code-snippet-deck/code-snippet-deck.ts
  • src/components/code-snippet-deck/styles.css
  • src/components/code-snippet-deck/define.ts
  • docs/components/code-snippet-deck.md
  • site/examples/code-snippet-deck.ts
  • tests/browser/code-snippet-deck.spec.ts
  • evidence/components/code-snippet-deck.md

API

Boolean attributes follow HTML presence semantics: present means true, absent means false, and disabled="false" still means disabled.

Attributes

Attributes
AttributePropertyTypeDefaultNotes
default-languagedefaultLanguagestringsnippets[0]?.languageKebab-case attribute; camelCase property.
show-line-numbersshowLineNumbersbooleantruePresence semantics: present means true, absent means false.
show-window-barshowWindowBarbooleantruePresence semantics: present means true, absent means false.

Properties

Properties
PropertyTypeDefaultNotes
parametersSnippetParameter[][]Property-only: assign from script; not accepted as an attribute.
snippetsSnippetItem[][]Property-only: assign from script; not accepted as an attribute.

Events

No custom events are recorded for this component.

Slots

No slots are recorded for this component.

CSS customisation

  • `className` prop is replaced by documented CSS parts/custom properties; no Tailwind in consumers.
  • Framer Motion springs/AnimatePresence ported to CSS transitions, WAAPI or the shared rAF spring helper.
  • `lucide-react` icon components replaced with local SVG assets (ISC notice retained).
  • React state/hooks replaced by element-owned state with pre-upgrade property preservation.
  • Upstream's code field may be a (params) => string function; the native component keeps that form as a property-only hook (PC-3.1) and calls it with a plain snapshot of the tuned values. A throwing function renders an empty snippet with a development warning instead of breaking the element.
  • The deck is not dark-only: the upstream hard-coded #0E0E0E/#FAFAFA palette is replaced by --detent-color-* tokens, so light and dark both work (PC-9.5). The macOS traffic dots keep the neutral tint rather than three colours so they stay legible in both schemes.
  • Framer Motion's layoutId tab pill (springSnappy) becomes a CSS transition on tab background/colour/border; there is no shared spring helper, because the animated properties are colours, not values the helper can drive. Under reduced motion the transition duration is 0s (PC-10.5).
  • showLineNumbers / showWindowBar default to true and are reflected as attributes with the property as the opt-out (PC-3.2), instead of React-only boolean props.
  • Copy uses navigator.clipboard.writeText with a rejected promise swallowed; upstream calls copyToClipboard from src/lib/utils.ts. No dependency is added.
  • The row records states: []; the state vocabulary was derived from the pinned source and is documented here: active (selected runtime), collapsed/expanded (parameter drawer), copied (copy acknowledgement), empty (no snippets) and reduced motion.
  • className is replaced by the documented parts and custom properties; there is no Tailwind in consumers.

What it does

A multi-runtime code deck: macOS-style window bar, one tab per language, an optional parameter drawer that regenerates the snippet as values change, a copy button, optional line numbers with selective line highlighting, and a footer with the runtime label and line count.

Upstream behaviour
  • Seamless multi-runtime tab switching (cURL, TypeScript, Python, Go, Rust)
  • Dynamic parameter tuning drawer that updates generated code in real time
  • Configurable line numbers and selective line highlighting
  • macOS terminal-inspired window header with traffic dots and copy system
  • Zero layout shift spring transition on tab changes
Differences from upstream
  • `className` prop is replaced by documented CSS parts/custom properties; no Tailwind in consumers.
  • Framer Motion springs/AnimatePresence ported to CSS transitions, WAAPI or the shared rAF spring helper.
  • `lucide-react` icon components replaced with local SVG assets (ISC notice retained).
  • React state/hooks replaced by element-owned state with pre-upgrade property preservation.
  • Upstream's code field may be a (params) => string function; the native component keeps that form as a property-only hook (PC-3.1) and calls it with a plain snapshot of the tuned values. A throwing function renders an empty snippet with a development warning instead of breaking the element.
  • The deck is not dark-only: the upstream hard-coded #0E0E0E/#FAFAFA palette is replaced by --detent-color-* tokens, so light and dark both work (PC-9.5). The macOS traffic dots keep the neutral tint rather than three colours so they stay legible in both schemes.
  • Framer Motion's layoutId tab pill (springSnappy) becomes a CSS transition on tab background/colour/border; there is no shared spring helper, because the animated properties are colours, not values the helper can drive. Under reduced motion the transition duration is 0s (PC-10.5).
  • showLineNumbers / showWindowBar default to true and are reflected as attributes with the property as the opt-out (PC-3.2), instead of React-only boolean props.
  • Copy uses navigator.clipboard.writeText with a rejected promise swallowed; upstream calls copyToClipboard from src/lib/utils.ts. No dependency is added.
  • The row records states: []; the state vocabulary was derived from the pinned source and is documented here: active (selected runtime), collapsed/expanded (parameter drawer), copied (copy acknowledgement), empty (no snippets) and reduced motion.
  • className is replaced by the documented parts and custom properties; there is no Tailwind in consumers.
Previous: Circular Orbit Next: Combobox

Docs

Components

Project