ray-elements
Web components (Shadow DOM, no dependencies) inspired by shadcn/ui (semantic
tokens, copy-the-code distribution) and Mantine (10-shade color scales, sizes
xs–xl, color + variant on every component).
ray-elements is framework-agnostic. The components are standard custom elements: use them in any web app — plain HTML, React or Vue, in a browser or any webview. Nothing in a component requires raylang.
It comes with extras for raylang apps. It loads as plain ES modules from
ray://app in a std/ui window with no build step, all its tooling (tokens,
contrast checks, docs, webview tests) is written in raylang in tools/, and
the examples are raylang apps. A native bridge (elements/bridge in the program,
core/raylang.js in the page) gives the components what a browser cannot:
system file dialogs with real paths (ray-file-upload native,
ray-path-input), native confirmations (confirmDialog()), native context
menus (ray-menu native), the app's menu bar in the command palette
(native-menus) and the window (ray-app-shell under a transparent title
bar, window colors that follow the theme, trackEdits() for the unsaved
mark). A raylang package (elements) brings @raylang/elements to the pages
of a raylang app by its npm name, without npm. See RAYLANG.md.
Layout
tokens.toml design tokens: the single source of truth
ray-elements.toml npm package metadata (scope, version)
src/core/core.js RayElement base class, css``, define(), theme API
src/core/styles.js shared sizes, radius, color variants, loader
src/core/form.js FormControl / FieldControl (ElementInternals, label/description/error)
src/core/floating.js base of popover/menu/tooltip (Popover API, trigger wiring)
src/core/position.js anchored placement with flip and shift
src/core/focus.js tabbables through shadow roots and slots
src/core/host.js the native host registry components ask (file dialogs, confirm)
src/core/raylang.js the page's half of the raylang bridge: enableRaylang()
src/core/base.css optional document defaults (layer ray.base)
src/core/core.d.ts hand-written types of the core runtime
src/integrations/ React and Vue runtime helpers (createComponent); check/, the markup checker
src/components/<name>/ <name>.js + component.toml (metadata) + example.html
src/index.js generated: imports every component
dist/ generated: tokens.css, tokens.json
docs/ generated: index.html, foundations.html, components.html (the catalog), components/<component>.html (a page each, and all.html with every one), code/<component>.html (each example's code, loaded on demand); llms.txt, llms-full.txt and components/<component>.md (for AI agents)
index.html generated: redirects the server root to docs/
tests/ *.test.js run in the real webview + harness.js
tools/ raylang project: the ray-elements CLI
elements/ raylang package: assets.ray (generated: ray-elements served from the program), bridge.ray
packages/ generated npm packages: elements, react, vue
examples/desktop-form/ std/ui app using components copied with `add`
examples/desktop-app/ std/ui app using the raylang package and the native bridge
examples/starter/ the smallest std/ui app with the raylang package, to copy
examples/lean-app/ loads only the components it uses, and the settings dialog on first open
examples/react-app/ std/ui + Vite + React app using @raylang/react
examples/vue-app/ std/ui + Vite + Vue app using @raylang/vue
examples/extending/ app components on the extension API (+ `wrap` output)
Components
| Category | Tags |
|---|---|
| Buttons | ray-button (incl. raised: a physical key that sinks when pressed), ray-icon-button, ray-toggle (two-state, aria-pressed; a raised one latches down), ray-toggle-group (single or multiple selection, joined or spaced), ray-button-group |
| Inputs | ray-input, ray-number-input (+/− with hold-to-repeat, min/max/step, decimals, prefix/suffix, thousands, durations as m:ss), ray-combobox (a searchable select; multiple chips, creatable tags, clearable, groups), ray-tags-input (free-form tags with the suggestions as buttons under the field, filtered as you type; no dropdown), ray-search, ray-textarea, ray-select, ray-checkbox + ray-checkbox-group (one entry per value, max, required), ray-switch, ray-radio-group + ray-radio / ray-radio-card (a choice drawn as a card: plans, presets), ray-segmented-control, ray-slider (orientation="vertical": a fader), ray-knob (a rotary control: drag, wheel or keys; log scale for frequencies, bipolar for pan), ray-date-picker + ray-calendar, ray-color-picker + ray-color-input (saturation area, hue and opacity sliders, swatches; a text field with the picker in a dropdown and an eyedropper; hex, rgb or hsl with or without alpha), ray-file-upload (drop zone: drag, click or paste; type/size/count checks; files listed as attachments; submitted with the form; native: real paths from the system dialog in a std/ui window), ray-image-crop (frame an image in a rectangle or circle of any aspect: drag, pinch, wheel, keyboard; export the framed part as a Blob or data URL at a chosen size; for profile photos, covers, logos), ray-avatar-picker (a profile picture field: the avatar with Choose / Change / Remove photo and the crop in a sheet; a data URL or Blob, submitted with the form), ray-path-input (a file, folder or save path; Browse… opens the system dialog in a std/ui window), ray-mode-input (a field with a menu of modes that changes the field: text or a file, € or $, by name or ID) |
| Navigation | ray-tabs + ray-tab + ray-tab-panel, ray-doc-tabs + ray-doc-tab (open documents over one shared panel: closable, an unsaved mark, middle click and Delete close), ray-nav-link, ray-sidebar + ray-sidebar-group (icon rail on wide screens, drawer on narrow ones), ray-bottom-nav + ray-bottom-nav-item (a phone app's tab bar: icons, labels, badges, a raised action, hides on scroll), ray-breadcrumbs + ray-breadcrumb (collapsible with max-items), ray-stepper + ray-step (wizards: loading, error, revisit completed steps), ray-pagination |
| Overlays | ray-dialog (+ confirmDialog()), ray-drawer (any edge, modal or modeless), ray-popover, ray-tooltip, ray-menu + ray-menu-item / -label / -divider (also as context menu), ray-command-palette (⌘K) |
| Data display | ray-timeline + ray-timeline-item (reached items, icon or avatar bullets, line variants), ray-qr (a QR code of a text or link as one SVG path; its own encoder, no dependencies; a logo at the middle; to SVG or PNG), ray-icon, ray-badge, ray-avatar, ray-indicator (a dot or label on any element), ray-blockquote, ray-code (copy, line numbers, highlighted and diff lines; a built-in highlighter or any library via setHighlighter()), ray-kbd (raised, filled or outline), ray-accordion + ray-accordion-item, ray-table, ray-stat, ray-carousel (scroll-snap, swipe, autoplay), ray-attachment + ray-attachments, ray-meter (an audio level meter: peak and RMS in dB, peak hold, clip mark, per channel; 60 updates a second with no render) |
| Feedback | ray-alert, ray-spinner, ray-pulse (circles that breathe or ripple: cluster, breathe, ripple, dots), ray-progress, ray-ring-progress (content in the middle: a countdown's clock), ray-step-dots (one dot per step), ray-empty-state, ray-skeleton, ray-notification + ray-toaster (notify() with an optional action, updateNotification(), hideNotification(); a stack that spreads on hover, tap or focus, swipe to dismiss) |
| Layout | ray-app-shell (header, navbar, main, aside, footer; a phone layout with a bottom bar below its breakpoint, measured on itself), ray-app-bar (a phone screen's top bar: back, title, actions; elevates or hides on scroll), ray-stack, ray-group, ray-grid (columns per width of the grid itself, spans, auto-fill), ray-container, ray-center, ray-scroll-area (themed scrollbar, edge shadows, ray-reach-end), ray-card, ray-separator, ray-split (fixed="end": a docked inspector) (resizable panes), ray-statusbar + ray-statusbar-item, ray-aspect-ratio |
Server-rendered pages without JS get <table class="ray-table"> (plus
ray-table-striped, ray-table-bordered) from base.css, and secondary
text gets class="ray-muted".
| Theme | ray-theme-toggle |
Shared conventions (Mantine-style): size = xs…xl (default sm), radius,
color = a palette color or any CSS color (default: primary), variant
(filled, light, outline, subtle, default…). Form controls are
form-associated: they submit under name, validate (required, pattern,
type=email…), reset with the form and follow a disabled <fieldset>; they
take label, description and error and wire the ARIA inside their shadow
root. The value/checked attributes are initial values; the properties hold
the current ones.
Overlays use the platform: ray-dialog is a native modal <dialog>; popovers,
menus, tooltips and the toaster are [popover] elements in the top layer
(never clipped, above everything), positioned in JS (core/position.js: flip +
shift, -start/-end following the writing direction) since CSS anchor
positioning is not in every webview yet. Keyboard
behavior follows the WAI-ARIA patterns (menu button, tabs, accordion, radio
group). While a modal dialog is open, notifications move into it so they stay
clickable (a modal makes the rest of the page inert). Full API: docs/components.html (generated from each
component.toml).
Variants
| Component | variant |
|---|---|
| button, icon-button | filled · light · outline · subtle · default · transparent · gradient |
| badge | light · filled · outline · dot · default · gradient |
| alert | light · filled · outline · default · transparent |
| avatar | light · filled · outline · default |
| card | default · filled · outline |
| checkbox, radio (group or radio) | filled · outline |
| input, textarea, select | default · filled · unstyled |
| tabs | default · outline · pills |
| accordion | default · contained · separated · filled |
| nav-link | light · filled · subtle |
| separator | solid · dashed · dotted |
| statusbar | default · accent |
Color variants take any palette color or CSS color in color; gradient
takes gradient="from to [deg]" (default: the --ray-gradient-* tokens; the
text is white, so keep both ends dark enough). Your own variants:
RayButton.extendStyles(css`[data-variant="brand"] { … }`) — see
EXTENDING.md.
Icons
Every icon a component draws (close, chevrons, check, search, sort…) comes
from one registry. Switch the whole set, or add names for <ray-icon>:
import { setIcons, iconNames } from "@raylang/elements";
setIcons({ close: '<svg viewBox="0 0 24 24">…</svg>', "chevron-down": svgElement, logo: "…" });
Icons are SVG markup (or an SVGElement) drawn with currentColor; mounted
components repaint. An icon may have a filled version for a state (the
active tab, a favorite): <ray-icon name="star" filled>, or
setIcons({ "star:filled": … }) for your own; without one, the outline icon
is drawn. --ray-icon-size and --ray-icon-stroke tune them
system-wide.
The components ask for roles, not glyphs: ui.close (a dialog's ×),
ui.remove (a chip's ×), ui.clear (a field's ×), ui.expand, ui.next,
ui.checked… (iconAliases() lists them with their glyphs). A role draws its
glyph until you register the role itself: setIcons({ close: X }) changes
every ×, setIcons({ "ui.remove": Trash }) only the chips'. The roles that
point along the text (ui.next, ui.previous, ui.first, ui.last,
ui.disclosure, ui.separator) are drawn mirrored under dir="rtl". In your markup: <ray-icon name="info" label="Information">
(decorative without label; mirror mirrors a back arrow right to left). Register icons from your code only — the markup
is inserted as HTML.
More icons. The built-in set is small (45, listed in llms.txt). For the
rest, take them from Lucide (ISC license): the same
24×24 grid and 2px stroke, so they sit with the built-in ones.
lucide-static exports each
icon as SVG markup, which is what setIcons takes, and a bundler keeps only
the ones you import:
import { setIcons } from "@raylang/elements";
import { Trash2, Save, Bookmark } from "lucide-static";
setIcons({ trash: Trash2, save: Save, bookmark: Bookmark });
// <ray-icon name="trash"></ray-icon>
Replacing a built-in name (setIcons({ close: X })) changes it in the
components too. Without a bundler (a raylang app's page), copy the SVG from
lucide-static/icons/<name>.svg or lucide.dev into the setIcons call.
Lucide has no filled versions; for one, register "<name>:filled" from a
family that has them (Phosphor's fill weight, Material Symbols' filled).
ray-elements check finds the names you register in setIcons({ … }), and in
setIcons(ICONS) when ICONS is an object literal of that file or one it
imports from a local module (import { ICONS } from "./icons.js").
Right to left
Set dir="rtl" on the page (<html dir="rtl" lang="ar">) or on any subtree
and the components mirror; nothing to configure, and a dir changed later
applies at once:
- The layout: the CSS is written with logical properties (
inset-inline-start,padding-inline-end,text-align: start), so paddings, labels, adornments, the switch's thumb, vertical tabs and the like follow the direction. - Icons: the roles that point along the text (
ui.next,ui.previous,ui.first,ui.last,ui.disclosure,ui.separator) are drawn mirrored;<ray-icon mirror>mirrors one of yours (a back arrow). - Keyboard and pointer: ArrowLeft goes forward in tabs, radio groups, the
segmented control, toggle groups, the calendar, the carousel and the split;
the split, the carousel,
ray-scroll-area, the slider andray-indicatormeasure and scroll from the right. - Floating panels:
-start/-endplacements line up with the trigger's right edge (abottom-startmenu), a context menu opens to the left of the pointer.top/bottom/left/rightare sides of the screen. - Attributes that name a side take
start/end, which follow the direction, andleft/right, which do not:label-position,chevron-position,ray-timelinealign,ray-drawerposition,ray-sidebarside,ray-toasterposition(bottom-end,top-start…). The defaults are logical: right to left a drawer opens from the left and notifications stack bottom left.
What stays left to right: ray-code (code is left to right in any language)
and the color picker (a color space is a picture, not text).
To see it, the site's RTL button shows every example right to left.
Languages
What the components write themselves (a close button's name, "No matches", "Page 3 of 10", "The minimum is 5.") comes from a catalog of texts, English by default. Set another one once and every element follows, the ones already on the page too:
import { setStrings } from "@raylang/elements/core";
import es from "@raylang/elements/strings/es";
setStrings(es); // every element, whatever its lang
setStrings("es", es); // or only where lang="es" (also "es-AR", "es-MX")
- An element reads its nearest
langattribute (through shadow roots), so one page can mix languages;<html lang="…">sets the page's. Alangchanged later applies at once. - The lookup: the catalog of the element's language, then its language without the region, then the catalog set for any language, then English.
- An attribute still wins for one element:
<ray-dialog close-label="…">,<ray-avatar-picker pick-label="…">. The properties read the catalog when unset (dialog.closeLabelis "Cerrar" underlang="es"). - Ships with Spanish (
strings/es). For another language, give the keys you need:setStrings("fr", { "dialog.close": "Fermer" }); the rest stay English. Each component's page lists its keys ("Texts"), andstringKeys()those of the components loaded, with their English. A catalog set before a component loads applies to it too. A text with a number has plural forms, chosen byIntl.PluralRules:{ one: "{count} file", other: "{count} files" }. - Dates and numbers already follow
lang(Intl): the calendar's months and first day of the week,ray-number-input's spoken durations,ray-step-dots. The texts you write (label,placeholder,description,error) are yours to translate with your app's i18n.
Commands
From anywhere (tools/run.sh runs them from tools/; paths stay yours):
tools/run.sh build # tokens + docs + package
tools/run.sh tokens [--check] # tokens.toml -> dist/tokens.*, docs/foundations.html
tools/run.sh docs # component.toml + *.md -> docs/ (site), src/index.js
tools/run.sh add button input --into ../my-app/assets/ray-elements
tools/run.sh package # packages/{elements,react,vue}
tools/run.sh site --base /ray-elements/ # build, then the site ready to publish in dist/site/
tools/run.sh wrap --components DIR --out DIR # types + wrappers for an app's components
tools/run.sh webtest [FILTER] # tests/*.test.js in a std/ui webview
(cd tools && ray test) # unit tests of the tools
Brand
The mark ("Kit") is three tiles of the raylang ocean palette plus the raylang
emblem as one more piece. docs generates it from tools/src/site/brand.ray
into brand/: logo.svg (light grounds), logo-dark.svg, logo-16.svg
(without Manta's horns, per the raylang brand manual), icon.svg (app icon) and
favicon.svg. The wordmark is "ray" in ray blue, the dot in aqua, "elements" in ink.
The brand manual, brand/manual.html (anatomy, lockup and
clear space, variants, palette, type, misuse, files), is the reference; it
inherits the raylang brand system (ocean palette, icon tile, Manta).
Viewing the docs
Serve the ray-elements directory itself (not docs/) and open the URL it prints:
cd ray-elements
ray serve . --port 0 # prints: serving . at http://127.0.0.1:<port>/
http://127.0.0.1:<port>/ redirects to the site in /docs/: the landing, this
guide, the components, the foundations (token specimen), extending and charts —
all generated by docs/tokens from component.toml, tokens.toml and the
.md files, inside the layout of tools/src/site/layout.ray.html (a compiled
raylang template; its CSS, JS and logo live in site/). The pages load ../dist and ../src, so
served from docs/ (or opened as file://, where ES modules do not load) they
show a banner saying so instead of rendering. --port 0 picks a free port;
--port 8123 works too if you want a fixed one.
tokens fails if a [checks] aa pair is below 4.5:1 in either scheme, and
warns for every palette color whose filled/light/outline variant text is.
In a raylang app, from the package
elements/ is a raylang package, published to its own repository:
elements = "git+https://github.com/ray-language/elements@v0.3.0" in
[dependencies] (or path: to elements/ of a checkout), and the app's pages
import @raylang/elements by its npm name, as with a bundler
(import "@raylang/elements/button"): raylang serves the package at
ray://app/node_modules/@raylang/elements/ with an import map, the same under
ray run and in a native binary, and links it into the app's
node_modules/ for the editor.
examples/starter is the smallest such app; examples/lean-app loads only
the components it uses. See RAYLANG.md.
Adding components to an app
add copies, shadcn-style: the code becomes the app's own.
<into>/tokens.css base.css core/*.js components/<name>/… index.js
It also copies what a component requires (switch brings checkbox),
regenerates index.js with every component present, and never replaces a
file the app has modified unless --overwrite (it reports it instead). --all
adds everything. In a std/ui app, serve the directory with
ui.mount_dir("", "assets") (or ui.mount_embed in a bundle) and load:
<link rel="stylesheet" href="ray-elements/tokens.css">
<script type="module" src="ray-elements/index.js"></script>
See examples/desktop-form (ray run src/main.ray --check fills and submits
its form by script and checks what reaches the raylang side), and
examples/desktop-app for the native bridge: a folder browser under a
transparent title bar, with the system dialogs, a native context menu and the
menu bar in the command palette (cd examples/desktop-app && ray run, or
ray run src/main.ray --check to drive it with scripted dialogs).
React and Vue
package generates three npm packages from the same component.toml files:
| Package | Contents |
|---|---|
@raylang/elements |
the components, tokens.css, base.css, index.js (registers every element, re-exports the API), @raylang/elements/<name> (one component), @raylang/elements/core (the API alone), ray-elements.d.ts (a class per element, HTMLElementTagNameMap, typed detail of events), custom-elements.json, vscode.html-custom-data.json, the ray-elements check command (@raylang/elements/check) |
@raylang/react |
a component per element (RayButton…), each registering only its element: declared props are set as DOM properties, events are on + PascalCase (onRaySelect, onChange); React 18 and 19 |
@raylang/vue |
a component per element with v-model where it makes sense (value, checked, open), app.use(RayElements) and GlobalComponents types |
// React
import "@raylang/elements/tokens.css";
import { RayInput, RayMenu, RayMenuItem, RayButton } from "@raylang/react";
<RayInput label="Name" value={name} onInput={(e) => setName(e.currentTarget.value)} />
<RayMenu onRaySelect={(e) => run(e.detail.value)}>
<RayButton slot="trigger">Actions</RayButton>
<RayMenuItem value="rename">Rename</RayMenuItem>
</RayMenu>
<!-- Vue (app.use(RayElements) in main.ts) -->
<RayInput v-model="name" label="Name" required />
<RaySwitch v-model="enabled" label="Enabled" />
<RayDialog v-model="open" label="Confirm" @ray-close="onClose">…</RayDialog>
Use them from an app with file: dependencies on ray-elements/packages/* and
resolve.preserveSymlinks: true (Vite) / "preserveSymlinks": true (tsconfig),
so react/vue resolve from the app and a re-run of package is picked up
without reinstalling. The examples are raylang apps made with
ray new <name> --frontend react-ts|vue-ts:
cd examples/react-app # or examples/vue-app
npm --prefix frontend install
ray dev # Vite dev server (HMR) inside a std/ui window
npm --prefix frontend run typecheck # the generated .d.ts checked by tsc / vue-tsc
npm --prefix frontend run build && ray run src/main.ray --check
--check drives the built page in the real webview like a user (typing,
choosing, submitting, the menu opening a controlled dialog) and checks both
directions: what reaches raylang through window.ray.request, and the
framework state rendered back into the components. The dev servers use high
ports (45173, 45174).
For AI agents
The site has an llms.txt: the rules an
agent needs to use the components correctly (loading, slots, forms, events,
tokens, theme, React and Vue, the raylang bridge) and a link to each
component's API as Markdown (components/<component>.md).
llms-full.txt is all of it in one
file: every component, the tokens with their values, the icon names and the
core's types. Both describe main; the copies in the npm package
(node_modules/@raylang/elements/llms.txt, llms-full.txt), also in a raylang
app's node_modules/ with the elements package, describe the installed
version. docs generates them from site/llms.md (the rules, hand-written),
the component.toml files, tokens.toml, core/icons.js and core/core.d.ts.
Checking the markup
@raylang/elements brings a checker of the markup that uses it, for people,
CI and agents alike. It reads the installed version's custom-elements.json
and icon set:
npx ray-elements check src/ # in an app with @raylang/elements installed
node node_modules/@raylang/elements/check/cli.js check assets/ # a raylang app (no npm)
It reads HTML, Vue, Svelte, Astro, JSX and TSX (<ray-button> and the
wrappers, <RayButton>) and reports, with the line and a suggestion:
unknown elements, attributes and ray-* events; values outside an
attribute's list (variant="primary"); disabled="false"; slot names a
parent does not have (slot="start"), and <template #name> under a Vue
wrapper; an attribute for a property that has none; unregistered icons; an
icon button without label; and, as warnings, literal colors in CSS. Icons
added with setIcons({ … }) and variants an app styles itself
([variant="brand"], [data-variant="brand"] in its CSS or extendStyles)
count as known; --icons and --allow variant=brand add others,
--manifest adds the custom-elements.json of your own components,
--format json prints the diagnostics as JSON and --rules lists the rules.
It exits with 1 when there is an error. It scans rather than parses each
language, so dynamic values (:size="s", size={s}) are not checked. The
same check from code: import { checkMarkup } from "@raylang/elements/check".
Using it in a page
<link rel="stylesheet" href="ray-elements/dist/tokens.css">
<link rel="stylesheet" href="ray-elements/src/core/base.css"> <!-- optional -->
<script type="module" src="ray-elements/src/index.js"></script>
<ray-input label="Email" name="email" type="email" required></ray-input>
<ray-button type="submit">Save</ray-button>
index.js registers every component. A page that uses a few loads only those
(each brings what it uses: ray-icon-button brings ray-button):
<script type="module">
import "./ray-elements/src/components/button/button.js";
import "./ray-elements/src/components/icon/icon.js";
</script>
Only what you use
With a bundler, @raylang/elements has an entry per component and one for the
API alone; @raylang/react and @raylang/vue leave out the wrappers you do not
import, and their elements. Measured with esbuild (minified, gzip):
| Import | gzip |
|---|---|
import "@raylang/elements" (everything) |
94 KB |
import "@raylang/elements/button" + "@raylang/elements/icon" |
9.5 KB |
import { setIcons } from "@raylang/elements/core" |
4.3 KB |
import { RayButton } from "@raylang/react" |
9.5 KB |
import { RayButton } from "@raylang/elements" still takes everything: that
entry registers every element. A wrapper registers only its own element, so a
plain <ray-*> tag in JSX or a Vue template needs its import
(import "@raylang/elements/badge") or import "@raylang/elements"; Vue's
app.use(RayElements) takes them all. The icons are one registry by name
(setIcons, <ray-icon name>), about 2 KB gzip, always included: a bundler
cannot know which names your markup uses.
Style your own markup with the tokens:
.panel {
background: var(--ray-card);
color: var(--ray-card-foreground);
border: 1px solid var(--ray-border);
border-radius: var(--ray-radius-default);
padding: var(--ray-space-md);
box-shadow: var(--ray-shadow-sm);
}
Tokens
| Kind | Example | Notes |
|---|---|---|
| Palette | --ray-blue-0 … --ray-blue-9 |
12 colors (open-color); scheme independent |
| Variants | --ray-blue-filled, -filled-hover, -light, -light-hover, -light-color, -outline, -outline-hover, -contrast |
per color, light/dark aware |
| Primary | --ray-primary-6, --ray-primary-filled, … |
aliases of the primary color |
| Semantic | --ray-background, --ray-foreground, --ray-primary, --ray-muted, --ray-border, --ray-ring, … |
what components and apps use |
| Scales | --ray-space-*, --ray-radius-*, --ray-font-size-*, --ray-control-height-*, --ray-shadow-*, --ray-duration-*, --ray-z-* |
Breakpoints are exported to dist/tokens.json only (custom properties cannot
be used in @media).
Charts
--ray-chart-1…8 (series, in order), --ray-chart-grid/-axis/-text/-tooltip…
and chartTheme() for canvas libraries: recipes for Chart.js, uPlot and
ECharts in CHARTS.md.
Theme and primary color
-
The theme follows the system by default (
color-scheme: light darkandlight-dark()values). Force it on the page or on any subtree withdata-theme="light"/data-theme="dark". -
Switch the primary color of the page or a subtree with
data-primary="violet"(any palette color). -
From JS:
setTheme("light" | "dark" | "system"),setPrimary("violet"),getTheme(),resolvedTheme(),onThemeChange(cb)fromsrc/core/core.js. The page-level choice is persisted inlocalStoragewhen available and restored whencore.jsloads. -
No flash on load:
core.jsis a module, so it restores the stored theme after the first paint — a page whose stored choice differs from the system flashes the other scheme. Apply it first with an inline script in<head>, before the stylesheets, and hide components until they are defined:<script> try { const t = localStorage.getItem("ray-elements:theme"); if (t === "light" || t === "dark") document.documentElement.dataset.theme = t; const p = localStorage.getItem("ray-elements:primary"); if (p && p !== "custom") document.documentElement.dataset.primary = p; } catch {} </script> <style>:not(:defined) { visibility: hidden; }</style> -
Any brand color:
definePrimary("#7c3aed")(page) ordefinePrimary(color, { el })(subtree) builds ten shades in OKLCH, picks white or black text by contrast (a bright color fills with itself and black text, like yellow), switches todata-primary="custom"and returns{ shades, filled, contrast, ratio, aa }, warning below WCAG AA. Every variant follows the same rules as the palette colors. -
Component defaults:
configure({ defaults: { "ray-button": { variant: "light", size: "md" } } })for whatever the markup and code leave unset.
Browser support: light-dark() and color-mix() — Safari/WebKit 17.5+,
Chrome 123+, Firefox 120+ (WebKitGTK 2.44+, current Android WebView).
Overlay
Modal dialogs, drawers and the command palette darken the page with
--ray-overlay and blur it with --ray-overlay-blur ([overlay] blur in
tokens.toml, 4px by default; 0px turns it off). Change it for the whole app,
a subtree or one element:
:root { --ray-overlay-blur: 8px; --ray-overlay: rgb(0 0 0 / 25%); }
.settings { --ray-overlay-blur: 0px; }
<ray-dialog overlay-blur="none" label="Plain backdrop">…</ray-dialog>
or as a default for every instance: configure({ defaults: { "ray-dialog": { overlayBlur: "12" } } }).
The blur is dropped for users who ask for reduced transparency.
Extending
Components are classes on public bases (RayElement, FormControl,
FieldControl, Floating) and an app can build on them or on any component:
see EXTENDING.md — the contract, the three levels,
extendStyles, configure({ defaults }) and wrap (types and React/Vue
wrappers for an app's own components).
Writing a component
import { RayElement, css, define } from "../../core/core.js";
export class RayThing extends RayElement {
static properties = { size: { type: String, reflect: true, default: "sm" } };
static styles = [css`:host { display: inline-flex; }`];
static template = `<span part="label"><slot></slot></span>`;
update(changed) { /* sync the shadow DOM with the properties */ }
}
define("ray-thing", RayThing);
- Styling hooks: tokens (CSS custom properties pierce the shadow root),
::part()and slots. Document them incomponent.toml. - Events: a value change is a plain
change(andinput), read from the element; anything else isthis.emit("ray-something", detail)(bubbles, composed). See "Events" in EXTENDING.md. - Properties set before the element is defined (React/Vue) are picked up on connection.
- Focus rings: give the focusable element
class="focus-ring". - Shared styles:
sizeStyles,radiusStyles,variantStyles+applyColor(el, color)fromcore/styles.js; form controls extendFieldControlfromcore/form.js. - Add
component.toml(API) andexample.html, runbuild, and cover the behavior intests/*.test.js.
Roadmap
- Foundations — tokens, theme, core runtime, generator, webview tests ✅
- Primitives — buttons, inputs, display, card, separator;
add; component docs ✅ - Overlays and interaction — dialog, popover, tooltip, menu, notifications, tabs, segmented control, accordion ✅
- Integrations — generated React and Vue wrappers,
.d.ts,custom-elements.json, example apps ✅ - App composites — table, command palette, split panes, nav links, status bar, progress, slider, stat, empty state ✅
- Adoption — pilot in ray-remote, then rayauth
Charts: ray-elements draws none (decision: option A). It provides the chart
palette (--ray-chart-1…8 + chrome tokens, checked at build time for
contrast, separation and color blindness) and chartTheme() /
onChartThemeChange() for chart libraries — see CHARTS.md.
Own chart components (SVG primitives; an adapter for dense real-time series)
stay open for later, when an app needs them.
Contributing
See CONTRIBUTING.md and the changelog.