LCD Display
A dot-matrix screen for labelled readouts and settings, backlit in the light theme and glowing in the dark one, with dropdown values.
Installation
$ pnpm dlx shadcn-svelte@latest add https://juddisjudd.github.io/audiocn-svelte/r/lcd-display.json$ npx shadcn-svelte@latest add https://juddisjudd.github.io/audiocn-svelte/r/lcd-display.json$ yarn dlx shadcn-svelte@latest add https://juddisjudd.github.io/audiocn-svelte/r/lcd-display.json$ bunx --bun shadcn-svelte@latest add https://juddisjudd.github.io/audiocn-svelte/r/lcd-display.jsonUsage
<script lang="ts">
import {
LcdDisplay,
LcdDisplayLabel,
LcdDisplayRow,
LcdDisplayValue,
} from "#lib/components/ui/lcd-display/index.js";
</script>
<LcdDisplay>
<LcdDisplayRow>
<LcdDisplayLabel>Tempo</LcdDisplayLabel>
<LcdDisplayValue>128.0</LcdDisplayValue>
</LcdDisplayRow>
</LcdDisplay>The screen follows your theme. Its ink is the theme's --primary, so it takes the colour of any theme. In light mode it is a backlit LCD: pale glass tinted by the ink, with dark pixels, like a calculator. In dark mode it is dark glass where the ink itself glows. Labels are dim, values are bright, and a value dims for a moment when its text changes, like segments redrawing.
Set appearance="light" or appearance="dark" to keep one look in both modes, for example a dark screen on a light page.
Anatomy
<LcdDisplay>
<LcdDisplayRow>
<LcdDisplayLabel />
<LcdDisplaySelect type="single">
<LcdDisplaySelectTrigger />
<LcdDisplaySelectContent>
<LcdDisplaySelectItem />
</LcdDisplaySelectContent>
</LcdDisplaySelect>
</LcdDisplayRow>
<LcdDisplaySeparator />
<LcdDisplayRow>
<LcdDisplayLabel />
<LcdDisplayValue />
</LcdDisplayRow>
<LcdDisplayStatus />
</LcdDisplay>A row holds a label and either a read-only LcdDisplayValue or an LcdDisplaySelect. LcdDisplaySelect is bits-ui's Select, so it takes the same props: type, value (bindable), onValueChange and items. Pass items to show each value's label in the trigger.
<script lang="ts">
const efforts = [
{ label: "Low", value: "low" },
{ label: "High", value: "high" },
];
let effort = $state("high");
</script>
<LcdDisplayRow>
<LcdDisplayLabel>Effort</LcdDisplayLabel>
<LcdDisplaySelect type="single" items={efforts} bind:value={effort}>
<LcdDisplaySelectTrigger />
<LcdDisplaySelectContent>
{#each efforts as item (item.value)}
<LcdDisplaySelectItem value={item.value} label={item.label} />
{/each}
</LcdDisplaySelectContent>
</LcdDisplaySelect>
</LcdDisplayRow>Examples
Inks
The ink is the theme's --primary by default (variant="primary"), so the screen changes with your theme. Switch the theme in the sidebar to see the demo above follow it. For a fixed hardware look, variant also takes amber, green, cyan or red.
For any other colour, set --lcd-display-ink. The glass, the lit, dim and unlit pixels and the glow are mixed from it, in both themes. The select's popup copies the display's variables when it opens, so it takes the same colour.
<LcdDisplay class="[--lcd-display-ink:var(--color-violet-400)]" />A dot-matrix font
The screen breaks any font into dots with a CSS mask, so it looks like an LCD with the font you already have. For true 5 × 7 characters, load a dot-matrix face such as Doto, point --lcd-display-font at it and turn the mask off with matrix={false}.
This site loads Doto from Fontsource at its heaviest weight, so the dots fill out. The browser fetches the font only on a page that uses it.
@import "@fontsource/doto/latin-900.css";
@theme {
--font-doto: "Doto", monospace;
}<LcdDisplay class="[--lcd-display-font:var(--font-doto)]" matrix={false} />A level meter
For a level meter on the same screen, add an LCD Meter. It takes the display's ink, appearance and size.
<LcdDisplay>
<LcdDisplayRow>
<LcdDisplayLabel>Input</LcdDisplayLabel>
<LcdDisplayValue>USB Mic</LcdDisplayValue>
</LcdDisplayRow>
<LcdDisplaySeparator />
<LcdMeter aria-label="Input level" source={analyser.meter} />
</LcdDisplay>Theming
| Variable or attribute | Meaning |
|---|---|
--lcd-display-ink | The display's colour, set by variant. Default: var(--primary) |
--lcd-display-lit | Lit pixels. Light: the ink darkened. Dark: the ink |
--lcd-display-ink-dim | Labels and the separator. Default: the lit pixels at 40% |
--lcd-display-ink-unlit | The unlit dots behind the text. Default: the lit pixels at 7% |
--lcd-display-glass | The screen. Light: a pale glass in the ink's hue. Dark: near black |
--lcd-display-glow | The halo around lit text. Light: a faint shadow. Dark: the ink at 60% |
--lcd-display-bezel, --lcd-display-bezel-edge | The frame's gradient, top to bottom |
--lcd-display-font | The font. Default var(--font-mono) |
--lcd-display-pitch | The dot grid's spacing. Default 2px |
data-appearance | On the display and the select's popup: auto, light or dark |
data-size | On the display, set by size |
data-variant | On the display and the select's popup |
data-matrix | On the display while the dot mask is on |
data-changed | On a value or trigger for a moment after its text changes |
data-state | On LcdDisplayStatus: idle, busy or off. On the select's trigger: open or closed |
size sets the text size: sm, default or lg. The rows and the select's popup follow it.
Accessibility
The display is a group. Each select's trigger is a combobox named by its row's LcdDisplayLabel, including one with its own id, and bits-ui handles the keyboard and the listbox semantics. Give a value live to announce its changes to screen readers. The status pixel is decorative. Blinking and the change flicker stop when the user prefers reduced motion.
API reference
LcdDisplay
| Prop | Type | Default |
|---|---|---|
variant The ink colour. primary follows the theme's --primary; the others are fixed hardware inks. | "primary" | "amber" | "green" | "cyan" | "red" | "primary" |
appearance light is a backlit screen with dark pixels, dark is dark glass with glowing ink, auto follows the theme. | "auto" | "light" | "dark" | "auto" |
matrix Breaks the text into dots on a --lcd-display-pitch grid. | boolean | true |
scanlines Faint horizontal lines over the glass. | boolean | true |
size The text size. | "sm" | "default" | "lg" | "default" |
LcdDisplayValue
| Prop | Type | Default |
|---|---|---|
live Announces changes to screen readers with aria-live="polite". | boolean | false |
LcdDisplayStatus
| Prop | Type | Default |
|---|---|---|
state idle blinks slowly, busy quickly, off stays unlit. | "idle" | "busy" | "off" | "idle" |
LcdDisplaySelectTrigger
| Prop | Type | Default |
|---|---|---|
placeholder Shown while nothing is selected. Children replace the value text. | string | — |
LcdDisplaySelectContent
Takes bits-ui's Select.Content props, with these defaults.
| Prop | Type | Default |
|---|---|---|
side | "top" | "bottom" | "left" | "right" | "bottom" |
sideOffset | number | 8 |
align | "start" | "center" | "end" | "end" |
alignOffset | number | 0 |
LcdDisplaySelectItem
Takes bits-ui's Select.Item props. Without children it shows label, or value when there is no label.