feat(ui): @xenia/ui design tokens, Tailwind preset and base components
Platform-v2 step 2.3 (APPS_PLATFORM D-15 §9): - tokens.css: --x- prefixed colours (light/dark/system + 5 venue accent themes), spacing, radius, type scale, shadows, motion, z-index; variables only - components.css: .x-* classes only, no element selectors (new rule CS-16) - Button, IconButton, Dialog, Sheet, Toast, PinPad, InfoTip, EmptyState, Spinner, Field/Input/Textarea/Select, Switch (accessible: focus trap and restore, ARIA wiring, 44px targets) - tailwind-preset.js (adds names only); manager uses it + styles.css, the waiter imports tokens.css; existing screens unchanged - dev-only /ui-gallery in the manager; e2e suite tests/e2e/ui.mjs; unit tests for PIN rules and WCAG AA contrast of every token pair, both in run-all Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,297 @@
|
||||
/*
|
||||
* @xenia/ui component styles. Uses only the tokens (tokens.css) and .x-* classes:
|
||||
* no element selectors and no resets, so loading it never restyles an app's own screens.
|
||||
* Text inherits the app's font; sizes and colours come from the tokens.
|
||||
*/
|
||||
|
||||
.x-visually-hidden {
|
||||
position: absolute !important;
|
||||
width: 1px; height: 1px; padding: 0; margin: -1px;
|
||||
overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
|
||||
}
|
||||
|
||||
.x-dialog, .x-sheet, .x-toast, .x-input, .x-select__control { color-scheme: var(--x-color-scheme); }
|
||||
|
||||
/* ── Spinner ─────────────────────────────────────────────────────────────── */
|
||||
.x-spinner { display: inline-flex; flex-shrink: 0; color: currentColor; }
|
||||
.x-spinner svg { width: 100%; height: 100%; animation: x-spin 0.8s linear infinite; }
|
||||
.x-spinner--sm { width: 16px; height: 16px; }
|
||||
.x-spinner--md { width: 24px; height: 24px; }
|
||||
.x-spinner--lg { width: 40px; height: 40px; }
|
||||
@keyframes x-spin { to { transform: rotate(360deg); } }
|
||||
@media (prefers-reduced-motion: reduce) { .x-spinner svg { animation-duration: 2.4s; } }
|
||||
|
||||
/* ── Button ──────────────────────────────────────────────────────────────── */
|
||||
.x-btn {
|
||||
display: inline-flex; align-items: center; justify-content: center; gap: var(--x-space-2);
|
||||
box-sizing: border-box;
|
||||
min-height: var(--x-control-md); padding: 0 var(--x-space-4);
|
||||
border: 1px solid transparent; border-radius: var(--x-radius-control);
|
||||
font: inherit; font-size: var(--x-text-body); line-height: var(--x-leading-body); font-weight: var(--x-weight-semibold);
|
||||
white-space: nowrap; cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
|
||||
transition: background-color var(--x-duration-fast) var(--x-ease), border-color var(--x-duration-fast) var(--x-ease),
|
||||
color var(--x-duration-fast) var(--x-ease), transform var(--x-duration-fast) var(--x-ease);
|
||||
}
|
||||
.x-btn:focus-visible { outline: none; box-shadow: var(--x-focus-ring); }
|
||||
.x-btn:active:not(:disabled) { transform: scale(0.98); }
|
||||
.x-btn:disabled { opacity: 0.45; cursor: not-allowed; }
|
||||
.x-btn[aria-busy="true"] { opacity: 0.8; cursor: progress; }
|
||||
.x-btn > svg { flex-shrink: 0; }
|
||||
|
||||
.x-btn--sm { min-height: var(--x-control-sm); padding: 0 var(--x-space-3); font-size: var(--x-text-label); }
|
||||
.x-btn--lg { min-height: var(--x-control-lg); padding: 0 var(--x-space-6); font-size: var(--x-text-body-lg); }
|
||||
.x-btn--block { display: flex; width: 100%; }
|
||||
|
||||
.x-btn--primary { background: var(--x-accent); color: var(--x-accent-fg); }
|
||||
.x-btn--primary:hover:not(:disabled) { background: var(--x-accent-strong); }
|
||||
.x-btn--secondary { background: var(--x-surface); color: var(--x-ink); border-color: var(--x-line-strong); }
|
||||
.x-btn--secondary:hover:not(:disabled) { background: var(--x-surface-2); }
|
||||
.x-btn--ghost { background: transparent; color: var(--x-ink-2); }
|
||||
.x-btn--ghost:hover:not(:disabled) { background: var(--x-surface-2); color: var(--x-ink); }
|
||||
.x-btn--danger { background: var(--x-danger); color: var(--x-danger-fg); }
|
||||
.x-btn--danger:hover:not(:disabled) { background: rgb(var(--x-danger-rgb) / 0.88); }
|
||||
|
||||
.x-btn--icon { padding: 0; width: var(--x-control-md); }
|
||||
.x-btn--icon.x-btn--sm { width: var(--x-control-sm); }
|
||||
.x-btn--icon.x-btn--lg { width: var(--x-control-lg); }
|
||||
|
||||
/* ── Overlay, Dialog, Sheet ──────────────────────────────────────────────── */
|
||||
.x-overlay {
|
||||
position: fixed; inset: 0; z-index: var(--x-z-overlay);
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
padding: var(--x-space-4);
|
||||
background: rgb(var(--x-scrim-rgb) / 0.5);
|
||||
animation: x-fade-in var(--x-duration-base) var(--x-ease);
|
||||
}
|
||||
.x-overlay--bottom { align-items: flex-end; padding: 0; }
|
||||
.x-overlay--right { justify-content: flex-end; align-items: stretch; padding: 0; }
|
||||
|
||||
.x-dialog, .x-sheet {
|
||||
display: flex; flex-direction: column;
|
||||
box-sizing: border-box; max-height: 100%;
|
||||
background: var(--x-surface); color: var(--x-ink);
|
||||
box-shadow: var(--x-shadow-overlay);
|
||||
outline: none;
|
||||
}
|
||||
.x-dialog {
|
||||
width: 100%; max-height: calc(100vh - 2 * var(--x-space-4));
|
||||
border-radius: var(--x-radius-dialog);
|
||||
animation: x-pop-in var(--x-duration-base) var(--x-ease);
|
||||
}
|
||||
.x-dialog--sm { max-width: 400px; }
|
||||
.x-dialog--md { max-width: 520px; }
|
||||
.x-dialog--lg { max-width: 720px; }
|
||||
|
||||
.x-sheet--bottom {
|
||||
width: 100%; max-width: 640px; max-height: 90vh;
|
||||
border-radius: var(--x-radius-dialog) var(--x-radius-dialog) 0 0;
|
||||
padding-bottom: env(safe-area-inset-bottom);
|
||||
animation: x-slide-up var(--x-duration-base) var(--x-ease);
|
||||
}
|
||||
.x-sheet--right {
|
||||
width: min(480px, 100vw); height: 100%;
|
||||
border-radius: var(--x-radius-dialog) 0 0 var(--x-radius-dialog);
|
||||
animation: x-slide-left var(--x-duration-base) var(--x-ease);
|
||||
}
|
||||
.x-sheet__grip {
|
||||
width: 40px; height: 4px; margin: var(--x-space-2) auto 0;
|
||||
border-radius: var(--x-radius-full); background: var(--x-line-strong);
|
||||
}
|
||||
|
||||
.x-modal__header {
|
||||
display: flex; align-items: flex-start; gap: var(--x-space-3);
|
||||
padding: var(--x-space-5) var(--x-space-5) var(--x-space-2) var(--x-space-6);
|
||||
}
|
||||
.x-modal__titles { flex: 1; min-width: 0; padding-top: var(--x-space-1-5); }
|
||||
.x-modal__title { margin: 0; font-size: var(--x-text-title); line-height: var(--x-leading-title); font-weight: var(--x-weight-semibold); }
|
||||
.x-modal__description { margin: var(--x-space-1) 0 0; font-size: var(--x-text-body); line-height: var(--x-leading-body); color: var(--x-ink-2); }
|
||||
.x-modal__close { margin: calc(-1 * var(--x-space-1)) calc(-1 * var(--x-space-1)) 0 0; }
|
||||
.x-modal__body {
|
||||
flex: 1; min-height: 0; overflow-y: auto;
|
||||
padding: var(--x-space-2) var(--x-space-6) var(--x-space-6);
|
||||
font-size: var(--x-text-body); line-height: var(--x-leading-body); color: var(--x-ink-2);
|
||||
}
|
||||
.x-modal__footer {
|
||||
display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--x-space-2);
|
||||
padding: var(--x-space-4) var(--x-space-6);
|
||||
border-top: 1px solid var(--x-line);
|
||||
}
|
||||
.x-modal__header + .x-modal__footer { border-top: 0; }
|
||||
|
||||
@keyframes x-fade-in { from { opacity: 0; } }
|
||||
@keyframes x-pop-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
|
||||
@keyframes x-slide-up { from { transform: translateY(100%); } }
|
||||
@keyframes x-slide-left { from { transform: translateX(100%); } }
|
||||
|
||||
/* ── Toast ───────────────────────────────────────────────────────────────── */
|
||||
.x-toasts {
|
||||
position: fixed; z-index: var(--x-z-toast);
|
||||
display: flex; flex-direction: column; gap: var(--x-space-2);
|
||||
width: min(380px, calc(100vw - 2 * var(--x-space-4)));
|
||||
pointer-events: none;
|
||||
}
|
||||
.x-toasts--top-right { top: var(--x-space-4); right: var(--x-space-4); }
|
||||
.x-toasts--top-center { top: var(--x-space-4); left: 50%; transform: translateX(-50%); }
|
||||
.x-toasts--bottom-center {
|
||||
bottom: calc(var(--x-space-4) + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
|
||||
flex-direction: column-reverse;
|
||||
}
|
||||
.x-toast {
|
||||
position: relative; overflow: hidden;
|
||||
display: flex; align-items: flex-start; gap: var(--x-space-3);
|
||||
padding: var(--x-space-3) var(--x-space-2) var(--x-space-3) var(--x-space-4);
|
||||
background: var(--x-surface); color: var(--x-ink);
|
||||
border: 1px solid var(--x-line); border-radius: var(--x-radius-card);
|
||||
box-shadow: var(--x-shadow-popover);
|
||||
pointer-events: auto;
|
||||
animation: x-pop-in var(--x-duration-base) var(--x-ease);
|
||||
}
|
||||
.x-toast__bar { position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--x-ink-3); }
|
||||
.x-toast--success .x-toast__bar { background: var(--x-success); }
|
||||
.x-toast--warning .x-toast__bar { background: var(--x-warning); }
|
||||
.x-toast--danger .x-toast__bar { background: var(--x-danger); }
|
||||
.x-toast--info .x-toast__bar { background: var(--x-info); }
|
||||
.x-toast__text { flex: 1; min-width: 0; padding: var(--x-space-0-5) 0; }
|
||||
.x-toast__title { font-size: var(--x-text-body); line-height: var(--x-leading-body); font-weight: var(--x-weight-semibold); }
|
||||
.x-toast__description { margin-top: var(--x-space-0-5); font-size: var(--x-text-label); line-height: var(--x-leading-label); color: var(--x-ink-2); }
|
||||
.x-toast__action, .x-toast__close {
|
||||
flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
|
||||
min-height: 32px; border: 0; border-radius: var(--x-radius-sm); background: transparent;
|
||||
font: inherit; cursor: pointer;
|
||||
}
|
||||
.x-toast__action { padding: 0 var(--x-space-2); font-size: var(--x-text-label); font-weight: var(--x-weight-semibold); color: var(--x-accent-ink); }
|
||||
.x-toast__action:hover { background: var(--x-accent-soft); }
|
||||
.x-toast__close { width: 32px; color: var(--x-ink-3); }
|
||||
.x-toast__close:hover { background: var(--x-surface-2); color: var(--x-ink); }
|
||||
.x-toast__action:focus-visible, .x-toast__close:focus-visible { outline: none; box-shadow: var(--x-focus-ring); }
|
||||
|
||||
/* ── PinPad ──────────────────────────────────────────────────────────────── */
|
||||
.x-pinpad { display: flex; flex-direction: column; align-items: center; gap: var(--x-space-4); color: var(--x-ink); }
|
||||
.x-pinpad__title { font-size: var(--x-text-body-lg); line-height: var(--x-leading-body-lg); font-weight: var(--x-weight-semibold); }
|
||||
.x-pinpad__dots { display: flex; gap: var(--x-space-3); }
|
||||
.x-pinpad__dots--shake { animation: x-shake 0.36s var(--x-ease); }
|
||||
.x-pinpad__dot {
|
||||
width: 14px; height: 14px; border-radius: var(--x-radius-full);
|
||||
border: 2px solid var(--x-line-strong);
|
||||
transition: background-color var(--x-duration-fast) var(--x-ease), border-color var(--x-duration-fast) var(--x-ease);
|
||||
}
|
||||
.x-pinpad__dot--filled { background: var(--x-accent); border-color: var(--x-accent); }
|
||||
.x-pinpad__dot--error { border-color: var(--x-danger); }
|
||||
.x-pinpad__status { min-height: 20px; display: flex; align-items: center; color: var(--x-ink-3); }
|
||||
.x-pinpad__error { font-size: var(--x-text-label); line-height: var(--x-leading-label); color: var(--x-danger-ink); }
|
||||
.x-pinpad__keys { display: grid; grid-template-columns: repeat(3, 72px); gap: var(--x-space-3); }
|
||||
.x-pinpad__key {
|
||||
height: 60px; border: 0; border-radius: var(--x-radius-card);
|
||||
background: var(--x-surface-2); color: var(--x-ink);
|
||||
font: inherit; font-size: var(--x-text-heading); font-weight: var(--x-weight-medium);
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
|
||||
transition: background-color var(--x-duration-fast) var(--x-ease), transform var(--x-duration-fast) var(--x-ease);
|
||||
}
|
||||
.x-pinpad__key:hover:not(:disabled) { background: var(--x-surface-3); }
|
||||
.x-pinpad__key:active:not(:disabled) { transform: scale(0.95); }
|
||||
.x-pinpad__key:focus-visible { outline: none; box-shadow: var(--x-focus-ring); }
|
||||
.x-pinpad__key:disabled { opacity: 0.5; cursor: not-allowed; }
|
||||
.x-pinpad__key--backspace { background: transparent; color: var(--x-ink-2); }
|
||||
@keyframes x-shake {
|
||||
20% { transform: translateX(-8px); } 40% { transform: translateX(7px); }
|
||||
60% { transform: translateX(-5px); } 80% { transform: translateX(3px); }
|
||||
}
|
||||
|
||||
/* ── InfoTip ─────────────────────────────────────────────────────────────── */
|
||||
.x-infotip {
|
||||
display: inline-flex; align-items: center; justify-content: center; vertical-align: middle;
|
||||
width: 24px; height: 24px; margin: -4px 0; padding: 0;
|
||||
border: 0; border-radius: var(--x-radius-full); background: transparent;
|
||||
color: var(--x-ink-3); cursor: pointer; -webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
.x-infotip:hover, .x-infotip--open { color: var(--x-accent); background: var(--x-accent-soft); }
|
||||
.x-infotip:focus-visible { outline: none; box-shadow: var(--x-focus-ring); }
|
||||
.x-infotip__popover {
|
||||
position: fixed; z-index: var(--x-z-popover);
|
||||
box-sizing: border-box; max-width: min(320px, calc(100vw - 16px));
|
||||
padding: var(--x-space-2-5) var(--x-space-3);
|
||||
background: var(--x-ink); color: var(--x-canvas);
|
||||
border-radius: var(--x-radius-sm); box-shadow: var(--x-shadow-popover);
|
||||
font-size: var(--x-text-label); line-height: var(--x-leading-label); font-weight: var(--x-weight-regular);
|
||||
animation: x-fade-in var(--x-duration-fast) var(--x-ease);
|
||||
}
|
||||
.x-infotip__popover::after {
|
||||
content: ""; position: absolute; left: var(--x-arrow-x, 50%);
|
||||
width: 10px; height: 10px; background: inherit; transform: translateX(-50%) rotate(45deg);
|
||||
}
|
||||
.x-infotip__popover--above::after { bottom: -4px; }
|
||||
.x-infotip__popover--below::after { top: -4px; }
|
||||
|
||||
/* ── EmptyState ──────────────────────────────────────────────────────────── */
|
||||
.x-empty {
|
||||
display: flex; flex-direction: column; align-items: center; text-align: center;
|
||||
padding: var(--x-space-12) var(--x-space-6); color: var(--x-ink-2);
|
||||
}
|
||||
.x-empty--compact { padding: var(--x-space-6) var(--x-space-4); }
|
||||
.x-empty__icon {
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
width: 48px; height: 48px; margin-bottom: var(--x-space-3);
|
||||
border-radius: var(--x-radius-card); background: var(--x-surface-2); color: var(--x-ink-3);
|
||||
}
|
||||
.x-empty__icon svg { width: 24px; height: 24px; }
|
||||
.x-empty__title { font-size: var(--x-text-body-lg); line-height: var(--x-leading-body-lg); font-weight: var(--x-weight-semibold); color: var(--x-ink); }
|
||||
.x-empty__description { max-width: 360px; margin-top: var(--x-space-1); font-size: var(--x-text-body); line-height: var(--x-leading-body); }
|
||||
.x-empty__action { margin-top: var(--x-space-4); }
|
||||
|
||||
/* ── Field, Input, Select ────────────────────────────────────────────────── */
|
||||
.x-field { display: flex; flex-direction: column; gap: var(--x-space-1-5); }
|
||||
.x-field__label-row { display: flex; align-items: center; gap: var(--x-space-1); }
|
||||
.x-field__label { font-size: var(--x-text-label); line-height: var(--x-leading-label); font-weight: var(--x-weight-medium); color: var(--x-ink); }
|
||||
.x-field__required { color: var(--x-danger-ink); }
|
||||
.x-field__hint { font-size: var(--x-text-caption); line-height: var(--x-leading-caption); color: var(--x-ink-3); }
|
||||
.x-field__error { font-size: var(--x-text-caption); line-height: var(--x-leading-caption); color: var(--x-danger-ink); }
|
||||
|
||||
.x-input, .x-select__control {
|
||||
box-sizing: border-box; width: 100%;
|
||||
min-height: var(--x-control-md); padding: 0 var(--x-space-3);
|
||||
background: var(--x-surface); color: var(--x-ink);
|
||||
border: 1px solid var(--x-line-strong); border-radius: var(--x-radius-control);
|
||||
font: inherit; font-size: var(--x-text-body-lg); /* 16px: phones don't zoom in on focus */
|
||||
transition: border-color var(--x-duration-fast) var(--x-ease), box-shadow var(--x-duration-fast) var(--x-ease);
|
||||
}
|
||||
.x-input::placeholder { color: var(--x-ink-3); }
|
||||
.x-input:hover:not(:disabled), .x-select__control:hover:not(:disabled) { border-color: var(--x-ink-3); }
|
||||
.x-input:focus, .x-select__control:focus { outline: none; border-color: var(--x-accent); box-shadow: var(--x-focus-ring); }
|
||||
.x-input:disabled, .x-select__control:disabled { background: var(--x-surface-2); color: var(--x-ink-3); cursor: not-allowed; }
|
||||
.x-input[aria-invalid="true"], .x-select__control[aria-invalid="true"] { border-color: var(--x-danger); }
|
||||
.x-input[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px rgb(var(--x-danger-rgb) / 0.3); }
|
||||
.x-input--sm, .x-select--sm .x-select__control { min-height: var(--x-control-sm); font-size: var(--x-text-body); }
|
||||
.x-input--lg, .x-select--lg .x-select__control { min-height: var(--x-control-lg); }
|
||||
.x-textarea { padding: var(--x-space-2-5) var(--x-space-3); resize: vertical; min-height: 88px; }
|
||||
|
||||
.x-select { position: relative; display: block; }
|
||||
.x-select__control { appearance: none; -webkit-appearance: none; padding-right: var(--x-space-10); cursor: pointer; }
|
||||
.x-select__chevron { position: absolute; right: var(--x-space-3); top: 50%; transform: translateY(-50%); color: var(--x-ink-3); pointer-events: none; }
|
||||
|
||||
/* ── Switch ──────────────────────────────────────────────────────────────── */
|
||||
.x-switch {
|
||||
position: relative; flex-shrink: 0;
|
||||
width: 44px; height: 26px; padding: 0;
|
||||
border: 0; border-radius: var(--x-radius-full);
|
||||
background: var(--x-ink-3); cursor: pointer; /* off track: 3:1 against the surface (contrast test) */
|
||||
transition: background-color var(--x-duration-base) var(--x-ease);
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
.x-switch::before { content: ""; position: absolute; inset: -9px 0; } /* 44px touch target */
|
||||
.x-switch__thumb {
|
||||
position: absolute; top: 3px; left: 3px;
|
||||
width: 20px; height: 20px; border-radius: var(--x-radius-full);
|
||||
background: #fff; box-shadow: var(--x-shadow-raised);
|
||||
transition: transform var(--x-duration-base) var(--x-ease);
|
||||
}
|
||||
.x-switch--on { background: var(--x-accent); }
|
||||
.x-switch--on .x-switch__thumb { transform: translateX(18px); }
|
||||
.x-switch:focus-visible { outline: none; box-shadow: var(--x-focus-ring); }
|
||||
.x-switch:disabled { opacity: 0.45; cursor: not-allowed; }
|
||||
|
||||
.x-switch-row { display: flex; align-items: center; gap: var(--x-space-4); }
|
||||
.x-switch-row__text { flex: 1; min-width: 0; }
|
||||
.x-switch-row__label { display: block; font-size: var(--x-text-body); line-height: var(--x-leading-body); font-weight: var(--x-weight-medium); color: var(--x-ink); cursor: pointer; }
|
||||
.x-switch-row__description { margin-top: var(--x-space-0-5); font-size: var(--x-text-label); line-height: var(--x-leading-label); color: var(--x-ink-2); }
|
||||
.x-switch-row--disabled .x-switch-row__label { cursor: not-allowed; opacity: 0.6; }
|
||||
@@ -0,0 +1,46 @@
|
||||
import { cx } from '../internal/cx.js'
|
||||
import { Spinner } from './Spinner.jsx'
|
||||
|
||||
/**
|
||||
* variant: 'primary' | 'secondary' | 'ghost' | 'danger'
|
||||
* size: 'sm' (36px) | 'md' (44px, the touch minimum) | 'lg' (52px)
|
||||
* loading: shows a spinner, disables the button and sets aria-busy
|
||||
* icon / iconEnd: an element (e.g. a lucide icon) before / after the label
|
||||
*/
|
||||
export function Button({
|
||||
variant = 'primary', size = 'md', loading = false, block = false,
|
||||
icon, iconEnd, type = 'button', disabled, className, children, ref, ...rest
|
||||
}) {
|
||||
return (
|
||||
<button
|
||||
ref={ref}
|
||||
type={type}
|
||||
className={cx('x-btn', `x-btn--${variant}`, `x-btn--${size}`, block && 'x-btn--block', className)}
|
||||
disabled={disabled || loading}
|
||||
aria-busy={loading || undefined}
|
||||
{...rest}
|
||||
>
|
||||
{loading ? <Spinner size="sm" label={null} /> : icon}
|
||||
{children != null && children !== false && <span className="x-btn__label">{children}</span>}
|
||||
{iconEnd}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
/** A square button with only an icon. `label` is required: it becomes aria-label and the tooltip. */
|
||||
export function IconButton({
|
||||
label, variant = 'ghost', size = 'md', type = 'button', className, children, ref, ...rest
|
||||
}) {
|
||||
return (
|
||||
<button
|
||||
ref={ref}
|
||||
type={type}
|
||||
aria-label={label}
|
||||
title={label}
|
||||
className={cx('x-btn', 'x-btn--icon', `x-btn--${variant}`, `x-btn--${size}`, className)}
|
||||
{...rest}
|
||||
>
|
||||
{children}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { cx } from '../internal/cx.js'
|
||||
import { ModalFrame } from '../internal/ModalFrame.jsx'
|
||||
|
||||
/**
|
||||
* Centered modal dialog.
|
||||
*
|
||||
* <Dialog open={open} onClose={() => setOpen(false)} title="Delete product?"
|
||||
* footer={<><Button variant="secondary" onClick={close}>Cancel</Button>
|
||||
* <Button variant="danger" onClick={remove}>Delete</Button></>}>
|
||||
* This can't be undone.
|
||||
* </Dialog>
|
||||
*
|
||||
* Escape, the backdrop and the × close it; focus moves in, is trapped, and returns
|
||||
* to where it was. dismissible={false} for steps that must be finished (no ×, no Escape).
|
||||
* size: 'sm' (400px) | 'md' (520px) | 'lg' (720px). closeLabel: the × text (translate it).
|
||||
* initialFocus: a ref to focus first (default: the first field or button in the body).
|
||||
*/
|
||||
export function Dialog({ size = 'md', className, ...props }) {
|
||||
return <ModalFrame {...props} panelClass={cx('x-dialog', `x-dialog--${size}`, className)} />
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { cx } from '../internal/cx.js'
|
||||
|
||||
/**
|
||||
* What a list or page shows when there's nothing in it yet.
|
||||
* <EmptyState icon={<Inbox />} title="No online orders yet"
|
||||
* description="New orders from the QR menu appear here." action={<Button>Open menu settings</Button>} />
|
||||
* compact: less padding, for use inside cards.
|
||||
*/
|
||||
export function EmptyState({ icon, title, description, action, compact = false, className }) {
|
||||
return (
|
||||
<div className={cx('x-empty', compact && 'x-empty--compact', className)}>
|
||||
{icon && <div className="x-empty__icon" aria-hidden="true">{icon}</div>}
|
||||
{title && <div className="x-empty__title">{title}</div>}
|
||||
{description && <div className="x-empty__description">{description}</div>}
|
||||
{action && <div className="x-empty__action">{action}</div>}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
import { Children, cloneElement, isValidElement, useId } from 'react'
|
||||
import { cx } from '../internal/cx.js'
|
||||
|
||||
/**
|
||||
* Label + control + hint/error, wired for screen readers (id, aria-describedby,
|
||||
* aria-invalid, required). Wrap exactly one control:
|
||||
*
|
||||
* <Field label="Name" hint="Shown on tickets" error={errors.name} required>
|
||||
* <Input value={name} onChange={e => setName(e.target.value)} />
|
||||
* </Field>
|
||||
*
|
||||
* info: optional element placed after the label, usually an <InfoTip>.
|
||||
*/
|
||||
export function Field({ label, hint, error, required = false, info, id, className, children }) {
|
||||
const auto = useId()
|
||||
const controlId = id || auto
|
||||
const hintId = `${controlId}-hint`
|
||||
const errorId = `${controlId}-error`
|
||||
// The error replaces the hint while there is one
|
||||
const describedBy = error ? errorId : hint ? hintId : undefined
|
||||
|
||||
const only = Children.only(children)
|
||||
const control = isValidElement(only)
|
||||
? cloneElement(only, {
|
||||
id: only.props.id || controlId,
|
||||
'aria-describedby': cx(only.props['aria-describedby'], describedBy) || undefined,
|
||||
'aria-invalid': error ? true : only.props['aria-invalid'],
|
||||
required: required || only.props.required,
|
||||
})
|
||||
: only
|
||||
|
||||
return (
|
||||
<div className={cx('x-field', error && 'x-field--error', className)}>
|
||||
{label && (
|
||||
<div className="x-field__label-row">
|
||||
<label className="x-field__label" htmlFor={controlId}>
|
||||
{label}{required && <span className="x-field__required" aria-hidden="true"> *</span>}
|
||||
</label>
|
||||
{info}
|
||||
</div>
|
||||
)}
|
||||
{control}
|
||||
{error
|
||||
? <div id={errorId} className="x-field__error">{error}</div>
|
||||
: hint && <div id={hintId} className="x-field__hint">{hint}</div>}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** Text input styled with the tokens. All <input> props pass through; size: 'sm' | 'md' | 'lg'. */
|
||||
export function Input({ size = 'md', className, ref, ...rest }) {
|
||||
return <input ref={ref} className={cx('x-input', `x-input--${size}`, className)} {...rest} />
|
||||
}
|
||||
|
||||
/** Multi-line text input. */
|
||||
export function Textarea({ className, rows = 3, ref, ...rest }) {
|
||||
return <textarea ref={ref} rows={rows} className={cx('x-input', 'x-textarea', className)} {...rest} />
|
||||
}
|
||||
|
||||
/**
|
||||
* Native <select> (best on phones and with screen readers), styled.
|
||||
* <Select value={v} onChange={e => setV(e.target.value)} options={[{ value: 'el', label: 'Ελληνικά' }]} />
|
||||
* or pass <option> children. placeholder adds a first, disabled, empty option.
|
||||
*/
|
||||
export function Select({ options, placeholder, size = 'md', className, children, ref, ...rest }) {
|
||||
return (
|
||||
<span className={cx('x-select', `x-select--${size}`, className)}>
|
||||
<select ref={ref} className="x-select__control" {...rest}>
|
||||
{placeholder != null && <option value="" disabled>{placeholder}</option>}
|
||||
{options
|
||||
? options.map(o => <option key={o.value} value={o.value} disabled={o.disabled}>{o.label}</option>)
|
||||
: children}
|
||||
</select>
|
||||
<svg className="x-select__chevron" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
|
||||
<path d="M6 9l6 6 6-6" />
|
||||
</svg>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
import { useCallback, useEffect, useId, useLayoutEffect, useRef, useState } from 'react'
|
||||
import { cx } from '../internal/cx.js'
|
||||
import { Portal } from '../internal/Portal.jsx'
|
||||
|
||||
const GAP = 8
|
||||
const MARGIN = 8
|
||||
|
||||
/**
|
||||
* The "(i)" help tip next to a setting or label (D-12: every manager page gets them).
|
||||
* Opens on click/tap (works on touch screens), closes on Escape, a click outside, or
|
||||
* a second click. Placed above the button, or below when there's no room.
|
||||
*
|
||||
* <label>Alert after failures <InfoTip>How many failed print attempts before managers are notified. 0 turns it off.</InfoTip></label>
|
||||
*
|
||||
* label: the button's accessible name (translate it). side: 'top' | 'bottom' (preferred side).
|
||||
*/
|
||||
export function InfoTip({ children, label = 'More info', side = 'top', className }) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const [pos, setPos] = useState(null)
|
||||
const button = useRef(null)
|
||||
const tip = useRef(null)
|
||||
const id = useId()
|
||||
|
||||
const place = useCallback(() => {
|
||||
const b = button.current?.getBoundingClientRect()
|
||||
const t = tip.current?.getBoundingClientRect()
|
||||
if (!b || !t) return
|
||||
const roomAbove = b.top - GAP - MARGIN >= t.height
|
||||
const roomBelow = window.innerHeight - b.bottom - GAP - MARGIN >= t.height
|
||||
const above = side === 'top' ? (roomAbove || !roomBelow) : !(roomBelow || !roomAbove)
|
||||
const top = above ? b.top - GAP - t.height : b.bottom + GAP
|
||||
const left = Math.min(Math.max(MARGIN, b.left + b.width / 2 - t.width / 2), window.innerWidth - MARGIN - t.width)
|
||||
setPos({ top, left, above, arrow: b.left + b.width / 2 - left })
|
||||
}, [side])
|
||||
|
||||
useLayoutEffect(() => { if (open) place() }, [open, place])
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return
|
||||
const close = () => setOpen(false)
|
||||
const onKey = e => { if (e.key === 'Escape') { e.stopPropagation(); close(); button.current?.focus() } }
|
||||
const onDown = e => {
|
||||
if (button.current?.contains(e.target) || tip.current?.contains(e.target)) return
|
||||
close()
|
||||
}
|
||||
document.addEventListener('keydown', onKey, true)
|
||||
document.addEventListener('pointerdown', onDown)
|
||||
window.addEventListener('resize', place)
|
||||
window.addEventListener('scroll', place, true)
|
||||
return () => {
|
||||
document.removeEventListener('keydown', onKey, true)
|
||||
document.removeEventListener('pointerdown', onDown)
|
||||
window.removeEventListener('resize', place)
|
||||
window.removeEventListener('scroll', place, true)
|
||||
}
|
||||
}, [open, place])
|
||||
|
||||
return (
|
||||
<>
|
||||
<button
|
||||
ref={button}
|
||||
type="button"
|
||||
className={cx('x-infotip', open && 'x-infotip--open', className)}
|
||||
aria-label={label}
|
||||
aria-expanded={open}
|
||||
aria-describedby={open ? id : undefined}
|
||||
onClick={() => setOpen(o => !o)}
|
||||
>
|
||||
<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true">
|
||||
<circle cx="8" cy="8" r="7" fill="none" stroke="currentColor" strokeWidth="1.5" />
|
||||
<circle cx="8" cy="4.75" r="1" fill="currentColor" />
|
||||
<path d="M8 7.25v4.5" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
|
||||
</svg>
|
||||
</button>
|
||||
{open && (
|
||||
<Portal>
|
||||
<div
|
||||
ref={tip}
|
||||
id={id}
|
||||
role="tooltip"
|
||||
className={cx('x-infotip__popover', pos && (pos.above ? 'x-infotip__popover--above' : 'x-infotip__popover--below'))}
|
||||
style={pos ? { top: pos.top, left: pos.left, '--x-arrow-x': `${pos.arrow}px` } : { top: 0, left: 0, visibility: 'hidden' }}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</Portal>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react'
|
||||
import { cx } from '../internal/cx.js'
|
||||
import { Spinner } from './Spinner.jsx'
|
||||
import { nextPin, pinAction } from './pin.js'
|
||||
|
||||
const KEYS = ['1', '2', '3', '4', '5', '6', '7', '8', '9', null, '0', 'Backspace']
|
||||
|
||||
/**
|
||||
* Numeric PIN entry: dots + a 3×4 keypad, also driven by the physical keyboard.
|
||||
*
|
||||
* <PinPad length={4} onComplete={async pin => { await unlock(pin) }} />
|
||||
*
|
||||
* onComplete(pin) runs when `length` digits are in. If it returns a promise the pad
|
||||
* shows a spinner until it settles. If it throws / rejects (or returns false), the pad
|
||||
* shakes, shows `error` text if given, and clears for another try. On success it clears too.
|
||||
*
|
||||
* error: text under the dots (e.g. "Wrong PIN"); a change of it also shakes the pad.
|
||||
* captureKeyboard (default true): digits/Backspace typed anywhere go to the pad,
|
||||
* except while the user is typing in a field.
|
||||
* Labels for translation: backspaceLabel, progressLabel(n, length).
|
||||
*/
|
||||
export function PinPad({
|
||||
length = 4, onComplete, onChange, disabled = false, error, title,
|
||||
captureKeyboard = true, backspaceLabel = 'Delete',
|
||||
progressLabel = (n, total) => `${n} of ${total} digits entered`,
|
||||
className,
|
||||
}) {
|
||||
const [value, setValue] = useState('')
|
||||
const [busy, setBusy] = useState(false)
|
||||
const [shake, setShake] = useState(0)
|
||||
const latest = useRef({ value, busy, disabled })
|
||||
useLayoutEffect(() => { latest.current = { value, busy, disabled } })
|
||||
|
||||
const fail = useCallback(() => {
|
||||
setShake(n => n + 1)
|
||||
setValue('')
|
||||
onChange?.('')
|
||||
}, [onChange])
|
||||
|
||||
const submit = useCallback(async pin => {
|
||||
let ok = true
|
||||
try {
|
||||
const result = onComplete?.(pin)
|
||||
if (result && typeof result.then === 'function') {
|
||||
setBusy(true)
|
||||
ok = (await result) !== false
|
||||
} else {
|
||||
ok = result !== false
|
||||
}
|
||||
} catch {
|
||||
ok = false
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
if (ok) { setValue(''); onChange?.('') } else fail()
|
||||
}, [onComplete, onChange, fail])
|
||||
|
||||
const press = useCallback(key => {
|
||||
const { value: current, busy: isBusy, disabled: isDisabled } = latest.current
|
||||
const action = pinAction(key)
|
||||
if (!action || isBusy || isDisabled) return
|
||||
const next = nextPin(current, action, length)
|
||||
if (next === current) return
|
||||
setValue(next)
|
||||
onChange?.(next)
|
||||
if (next.length === length) submit(next)
|
||||
}, [length, onChange, submit])
|
||||
|
||||
useEffect(() => {
|
||||
if (!captureKeyboard) return
|
||||
const onKey = e => {
|
||||
if (e.ctrlKey || e.metaKey || e.altKey) return
|
||||
const t = e.target
|
||||
if (t && (t.tagName === 'INPUT' || t.tagName === 'TEXTAREA' || t.isContentEditable)) return
|
||||
if (pinAction(e.key)) { e.preventDefault(); press(e.key) }
|
||||
}
|
||||
document.addEventListener('keydown', onKey)
|
||||
return () => document.removeEventListener('keydown', onKey)
|
||||
}, [captureKeyboard, press])
|
||||
|
||||
return (
|
||||
<div className={cx('x-pinpad', disabled && 'x-pinpad--disabled', className)}>
|
||||
{title && <div className="x-pinpad__title">{title}</div>}
|
||||
{/* Re-keyed on every failed attempt and on every new error text, which replays the shake */}
|
||||
<div key={`${shake}:${error || ''}`} className={cx('x-pinpad__dots', (shake > 0 || error) && 'x-pinpad__dots--shake')} aria-hidden="true">
|
||||
{Array.from({ length }, (_, i) => (
|
||||
<span key={i} className={cx('x-pinpad__dot', i < value.length && 'x-pinpad__dot--filled', error && 'x-pinpad__dot--error')} />
|
||||
))}
|
||||
</div>
|
||||
<div className="x-visually-hidden" aria-live="polite">{progressLabel(value.length, length)}</div>
|
||||
<div className="x-pinpad__status">
|
||||
{busy ? <Spinner size="sm" /> : error ? <span className="x-pinpad__error" role="alert">{error}</span> : null}
|
||||
</div>
|
||||
<div className="x-pinpad__keys">
|
||||
{KEYS.map(k => k === null
|
||||
? <span key="blank" aria-hidden="true" />
|
||||
: (
|
||||
<button
|
||||
key={k}
|
||||
type="button"
|
||||
className={cx('x-pinpad__key', k === 'Backspace' && 'x-pinpad__key--backspace')}
|
||||
onClick={() => press(k)}
|
||||
disabled={disabled || busy}
|
||||
aria-label={k === 'Backspace' ? backspaceLabel : undefined}
|
||||
>
|
||||
{k === 'Backspace'
|
||||
? (
|
||||
<svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
|
||||
<path d="M21 5H9l-6 7 6 7h12a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1z" /><path d="M17 9l-6 6M11 9l6 6" />
|
||||
</svg>
|
||||
)
|
||||
: k}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { cx } from '../internal/cx.js'
|
||||
import { ModalFrame } from '../internal/ModalFrame.jsx'
|
||||
|
||||
/**
|
||||
* A panel that slides in from the bottom (phones: action sheets, pickers) or the
|
||||
* right (desktop: detail and edit panels). Same props and behaviour as Dialog.
|
||||
* side: 'bottom' | 'right'
|
||||
*/
|
||||
export function Sheet({ side = 'bottom', className, ...props }) {
|
||||
return (
|
||||
<ModalFrame
|
||||
{...props}
|
||||
overlayClass={`x-overlay--${side}`}
|
||||
panelClass={cx('x-sheet', `x-sheet--${side}`, className)}
|
||||
bodyClass="x-sheet__body"
|
||||
grip={side === 'bottom'}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { cx } from '../internal/cx.js'
|
||||
|
||||
/**
|
||||
* Loading indicator. With a `label` (default "Loading") it is announced to screen
|
||||
* readers; pass label={null} when the surrounding element already says it (a busy button).
|
||||
* size: 'sm' (16px) | 'md' (24px) | 'lg' (40px)
|
||||
*/
|
||||
export function Spinner({ size = 'md', label = 'Loading', className, ...rest }) {
|
||||
return (
|
||||
<span
|
||||
className={cx('x-spinner', `x-spinner--${size}`, className)}
|
||||
role={label ? 'status' : undefined}
|
||||
aria-hidden={label ? undefined : true}
|
||||
{...rest}
|
||||
>
|
||||
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
|
||||
<circle cx="12" cy="12" r="9" stroke="currentColor" strokeOpacity="0.25" strokeWidth="3" />
|
||||
<path d="M21 12a9 9 0 0 0-9-9" stroke="currentColor" strokeWidth="3" strokeLinecap="round" />
|
||||
</svg>
|
||||
{label && <span className="x-visually-hidden">{label}</span>}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { useId } from 'react'
|
||||
import { cx } from '../internal/cx.js'
|
||||
|
||||
/**
|
||||
* On/off toggle for settings that take effect immediately.
|
||||
* <Switch checked={on} onChange={setOn} label="Print kitchen tickets" description="..." />
|
||||
* onChange receives the new boolean. Without `label`, pass aria-label.
|
||||
* The whole row (label + description) is clickable.
|
||||
*/
|
||||
export function Switch({ checked, onChange, label, description, disabled = false, id, className, ...rest }) {
|
||||
const auto = useId()
|
||||
const switchId = id || auto
|
||||
const descId = `${switchId}-desc`
|
||||
|
||||
const control = (
|
||||
<button
|
||||
id={switchId}
|
||||
type="button"
|
||||
role="switch"
|
||||
aria-checked={!!checked}
|
||||
aria-describedby={description ? descId : undefined}
|
||||
disabled={disabled}
|
||||
className={cx('x-switch', checked && 'x-switch--on')}
|
||||
onClick={() => onChange?.(!checked)}
|
||||
{...rest}
|
||||
>
|
||||
<span className="x-switch__thumb" />
|
||||
</button>
|
||||
)
|
||||
|
||||
if (!label && !description) return <span className={className}>{control}</span>
|
||||
return (
|
||||
<div className={cx('x-switch-row', disabled && 'x-switch-row--disabled', className)}>
|
||||
<div className="x-switch-row__text">
|
||||
{label && <label className="x-switch-row__label" htmlFor={switchId}>{label}</label>}
|
||||
{description && <div id={descId} className="x-switch-row__description">{description}</div>}
|
||||
</div>
|
||||
{control}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { cx } from '../internal/cx.js'
|
||||
import { Portal } from '../internal/Portal.jsx'
|
||||
import { ToastContext } from './toastContext.js'
|
||||
|
||||
let nextId = 1
|
||||
|
||||
/**
|
||||
* Wrap the app once: <ToastProvider><App /></ToastProvider>
|
||||
* Then anywhere: const toast = useToast()
|
||||
* toast.success('Saved')
|
||||
* toast.show({ tone: 'danger', title: 'Printer offline', description: 'Bar printer', duration: 0 })
|
||||
*
|
||||
* tone: 'neutral' | 'success' | 'warning' | 'danger' | 'info'. duration in ms (0 = stays until closed).
|
||||
* Danger toasts are announced assertively (role="alert"), the rest politely.
|
||||
* The timer pauses while the pointer is over a toast.
|
||||
* placement: 'top-right' | 'top-center' | 'bottom-center'. closeLabel: the × text (translate it).
|
||||
*/
|
||||
export function ToastProvider({ children, placement = 'top-right', max = 4, closeLabel = 'Dismiss' }) {
|
||||
const [toasts, setToasts] = useState([])
|
||||
|
||||
const dismiss = useCallback(id => setToasts(list => list.filter(t => t.id !== id)), [])
|
||||
const show = useCallback(opts => {
|
||||
const t = typeof opts === 'string' ? { title: opts } : opts
|
||||
const id = t.id ?? nextId++
|
||||
const toast = { tone: 'neutral', duration: t.tone === 'danger' ? 8000 : 4000, ...t, id }
|
||||
setToasts(list => [...list.filter(x => x.id !== id), toast].slice(-max))
|
||||
return id
|
||||
}, [max])
|
||||
|
||||
const api = useMemo(() => {
|
||||
const tone = name => (title, opts = {}) => show({ ...opts, title, tone: name })
|
||||
return { show, dismiss, success: tone('success'), error: tone('danger'), warning: tone('warning'), info: tone('info') }
|
||||
}, [show, dismiss])
|
||||
|
||||
return (
|
||||
<ToastContext.Provider value={api}>
|
||||
{children}
|
||||
<Portal>
|
||||
<div className={cx('x-toasts', `x-toasts--${placement}`)} role="region" aria-label="Notifications">
|
||||
{toasts.map(t => <ToastItem key={t.id} toast={t} onDismiss={dismiss} closeLabel={closeLabel} />)}
|
||||
</div>
|
||||
</Portal>
|
||||
</ToastContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
function ToastItem({ toast, onDismiss, closeLabel }) {
|
||||
const { id, tone, title, description, duration, action } = toast
|
||||
const [paused, setPaused] = useState(false)
|
||||
const remaining = useRef(duration)
|
||||
const started = useRef(0)
|
||||
|
||||
useEffect(() => {
|
||||
if (!duration || paused) return
|
||||
started.current = Date.now()
|
||||
const timer = setTimeout(() => onDismiss(id), remaining.current)
|
||||
return () => {
|
||||
clearTimeout(timer)
|
||||
remaining.current -= Date.now() - started.current
|
||||
}
|
||||
}, [paused, duration, id, onDismiss])
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cx('x-toast', `x-toast--${tone}`)}
|
||||
role={tone === 'danger' ? 'alert' : 'status'}
|
||||
onMouseEnter={() => setPaused(true)}
|
||||
onMouseLeave={() => setPaused(false)}
|
||||
>
|
||||
<span className="x-toast__bar" aria-hidden="true" />
|
||||
<div className="x-toast__text">
|
||||
{title && <div className="x-toast__title">{title}</div>}
|
||||
{description && <div className="x-toast__description">{description}</div>}
|
||||
</div>
|
||||
{action && (
|
||||
<button type="button" className="x-toast__action" onClick={() => { action.onClick?.(); onDismiss(id) }}>
|
||||
{action.label}
|
||||
</button>
|
||||
)}
|
||||
<button type="button" className="x-toast__close" aria-label={closeLabel} title={closeLabel} onClick={() => onDismiss(id)}>
|
||||
<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" aria-hidden="true">
|
||||
<path d="M6 6l12 12M18 6L6 18" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// PIN entry rules, kept free of React so they can be unit-tested (tests/pin.test.mjs).
|
||||
|
||||
/** Normalise a key or keypad press into an action, or null if it isn't one. */
|
||||
export function pinAction(key) {
|
||||
if (/^[0-9]$/.test(key)) return { type: 'digit', digit: key }
|
||||
if (key === 'Backspace' || key === 'Delete') return { type: 'backspace' }
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Next PIN value. Digits are ignored once `length` is reached; backspace on an
|
||||
* empty PIN is a no-op; 'clear' empties it.
|
||||
* @returns {string}
|
||||
*/
|
||||
export function nextPin(value, action, length) {
|
||||
switch (action?.type) {
|
||||
case 'digit': return value.length >= length ? value : value + action.digit
|
||||
case 'backspace': return value.slice(0, -1)
|
||||
case 'clear': return ''
|
||||
default: return value
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { createContext, useContext } from 'react'
|
||||
|
||||
export const ToastContext = createContext(null)
|
||||
|
||||
/** toast.success('Saved'), toast.error(title, { description }), toast.show({...}), toast.dismiss(id). See ToastProvider. */
|
||||
export function useToast() {
|
||||
const ctx = useContext(ToastContext)
|
||||
if (!ctx) throw new Error('useToast() needs a <ToastProvider> above it')
|
||||
return ctx
|
||||
}
|
||||
@@ -1,3 +1,23 @@
|
||||
// @xenia/ui — Design tokens (CSS variables), the Tailwind preset and base components (plan step 2.3).
|
||||
// Imported from source by Vite (no build step). Filled in by its plan step.
|
||||
export {}
|
||||
// @xenia/ui — design tokens and base components shared by the manager, the terminal
|
||||
// and the waiter app (APPS_PLATFORM §9, plan step 2.3). Imported from source by Vite.
|
||||
//
|
||||
// Styles are separate so an app chooses what to load:
|
||||
// import '@xenia/ui/tokens.css' CSS variables only (the waiter today)
|
||||
// import '@xenia/ui/styles.css' tokens + the components' styles (.x-* classes)
|
||||
// Tailwind apps also add the preset: import xenia from '@xenia/ui/tailwind-preset'.
|
||||
//
|
||||
// Components ship English default labels (Close, Loading, Delete…); pass translated
|
||||
// ones as props until @xenia/i18n exists (2.4).
|
||||
|
||||
export { Button, IconButton } from './components/Button.jsx'
|
||||
export { Dialog } from './components/Dialog.jsx'
|
||||
export { Sheet } from './components/Sheet.jsx'
|
||||
export { ToastProvider } from './components/Toast.jsx'
|
||||
export { useToast } from './components/toastContext.js'
|
||||
export { PinPad } from './components/PinPad.jsx'
|
||||
export { InfoTip } from './components/InfoTip.jsx'
|
||||
export { EmptyState } from './components/EmptyState.jsx'
|
||||
export { Spinner } from './components/Spinner.jsx'
|
||||
export { Field, Input, Textarea, Select } from './components/Field.jsx'
|
||||
export { Switch } from './components/Switch.jsx'
|
||||
export { cx } from './internal/cx.js'
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import { useId, useRef } from 'react'
|
||||
import { cx } from './cx.js'
|
||||
import { Portal } from './Portal.jsx'
|
||||
import { useModal } from './useModal.js'
|
||||
import { IconButton } from '../components/Button.jsx'
|
||||
|
||||
const CloseIcon = () => (
|
||||
<svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" aria-hidden="true">
|
||||
<path d="M6 6l12 12M18 6L6 18" />
|
||||
</svg>
|
||||
)
|
||||
|
||||
/** The shared body of Dialog and Sheet: backdrop, panel, header with ×, body, footer. */
|
||||
export function ModalFrame({
|
||||
open, onClose, title, description, children, footer,
|
||||
dismissible = true, closeLabel = 'Close', initialFocus,
|
||||
overlayClass, panelClass, grip = false, bodyClass,
|
||||
}) {
|
||||
const panel = useRef(null)
|
||||
const titleId = useId()
|
||||
const descId = useId()
|
||||
useModal(open, panel, { onClose, dismissible, initialFocus })
|
||||
if (!open) return null
|
||||
|
||||
const showClose = dismissible && !!onClose
|
||||
return (
|
||||
<Portal>
|
||||
<div
|
||||
className={cx('x-overlay', overlayClass)}
|
||||
onMouseDown={e => { if (e.target === e.currentTarget && dismissible) onClose?.() }}
|
||||
>
|
||||
<div
|
||||
ref={panel}
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby={title ? titleId : undefined}
|
||||
aria-describedby={description ? descId : undefined}
|
||||
tabIndex={-1}
|
||||
className={panelClass}
|
||||
>
|
||||
{grip && <div className="x-sheet__grip" aria-hidden="true" />}
|
||||
{(title || description || showClose) && (
|
||||
<div className="x-modal__header">
|
||||
<div className="x-modal__titles">
|
||||
{title && <h2 id={titleId} className="x-modal__title">{title}</h2>}
|
||||
{description && <p id={descId} className="x-modal__description">{description}</p>}
|
||||
</div>
|
||||
{showClose && (
|
||||
<IconButton label={closeLabel} size="sm" className="x-modal__close" onClick={onClose} data-x-autofocus-skip="">
|
||||
<CloseIcon />
|
||||
</IconButton>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{children != null && <div className={cx('x-modal__body', bodyClass)}>{children}</div>}
|
||||
{footer && <div className="x-modal__footer">{footer}</div>}
|
||||
</div>
|
||||
</div>
|
||||
</Portal>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { createPortal } from 'react-dom'
|
||||
|
||||
/** Render children into document.body (dialogs, sheets, toasts, popovers). */
|
||||
export function Portal({ children }) {
|
||||
if (typeof document === 'undefined') return null
|
||||
return createPortal(children, document.body)
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
/** Join class names, skipping falsy values: cx('a', cond && 'b') */
|
||||
export function cx(...parts) {
|
||||
return parts.filter(Boolean).join(' ')
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import { useEffect, useLayoutEffect, useRef } from 'react'
|
||||
|
||||
// Shared by Dialog and Sheet: Escape closes (the topmost one only), focus moves in
|
||||
// and is trapped while open, focus returns on close, and the page doesn't scroll.
|
||||
|
||||
const stack = [] // open modals, innermost last
|
||||
let scrollLocks = 0
|
||||
let savedOverflow = ''
|
||||
|
||||
const FOCUSABLE = [
|
||||
'a[href]', 'button:not([disabled])', 'input:not([disabled]):not([type="hidden"])',
|
||||
'select:not([disabled])', 'textarea:not([disabled])', '[tabindex]:not([tabindex="-1"])',
|
||||
'[contenteditable="true"]',
|
||||
].join(',')
|
||||
|
||||
export function focusables(root) {
|
||||
return [...root.querySelectorAll(FOCUSABLE)].filter(el => el.getClientRects().length > 0)
|
||||
}
|
||||
|
||||
/** Is this modal the innermost open one? (Toasts and popovers use it to stay out of the way.) */
|
||||
export function isTopmost(token) {
|
||||
return stack[stack.length - 1] === token
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {boolean} open
|
||||
* @param {{ current: HTMLElement|null }} panelRef the dialog/sheet panel
|
||||
* @param {{ onClose?: () => void, dismissible?: boolean, initialFocus?: { current: HTMLElement|null } }} opts
|
||||
*/
|
||||
export function useModal(open, panelRef, { onClose, dismissible = true, initialFocus } = {}) {
|
||||
const latest = useRef({ onClose, dismissible })
|
||||
useLayoutEffect(() => { latest.current = { onClose, dismissible } })
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return
|
||||
const token = {}
|
||||
stack.push(token)
|
||||
const previous = document.activeElement
|
||||
|
||||
if (scrollLocks++ === 0) {
|
||||
savedOverflow = document.body.style.overflow
|
||||
document.body.style.overflow = 'hidden'
|
||||
}
|
||||
|
||||
const panel = panelRef.current
|
||||
const target = initialFocus?.current || (panel && focusables(panel).find(el => !el.hasAttribute('data-x-autofocus-skip'))) || panel
|
||||
target?.focus({ preventScroll: true })
|
||||
|
||||
const onKey = e => {
|
||||
if (!isTopmost(token)) return
|
||||
if (e.key === 'Escape') {
|
||||
if (latest.current.dismissible && latest.current.onClose) {
|
||||
e.stopPropagation()
|
||||
latest.current.onClose()
|
||||
}
|
||||
return
|
||||
}
|
||||
const root = panelRef.current
|
||||
if (e.key !== 'Tab' || !root) return
|
||||
const items = focusables(root)
|
||||
if (!items.length) { e.preventDefault(); root.focus(); return }
|
||||
const first = items[0]
|
||||
const last = items[items.length - 1]
|
||||
const inside = root.contains(document.activeElement)
|
||||
if (e.shiftKey && (document.activeElement === first || !inside)) {
|
||||
e.preventDefault(); last.focus()
|
||||
} else if (!e.shiftKey && (document.activeElement === last || !inside)) {
|
||||
e.preventDefault(); first.focus()
|
||||
}
|
||||
}
|
||||
document.addEventListener('keydown', onKey)
|
||||
|
||||
return () => {
|
||||
document.removeEventListener('keydown', onKey)
|
||||
stack.splice(stack.indexOf(token), 1)
|
||||
if (--scrollLocks === 0) document.body.style.overflow = savedOverflow
|
||||
if (previous && typeof previous.focus === 'function' && document.contains(previous)) {
|
||||
previous.focus({ preventScroll: true })
|
||||
}
|
||||
}
|
||||
}, [open]) // eslint-disable-line react-hooks/exhaustive-deps
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
/* Tokens + component styles. Import once at the app root: import '@xenia/ui/styles.css' */
|
||||
@import './tokens.css';
|
||||
@import './components.css';
|
||||
@@ -0,0 +1,374 @@
|
||||
/*
|
||||
* @xenia/ui design tokens (APPS_PLATFORM §9, plan step 2.3).
|
||||
*
|
||||
* Every token is prefixed --x- so it never collides with an app's own variables
|
||||
* (the waiter already uses --bg, --text, --accent…). This file only declares custom
|
||||
* properties: importing it changes nothing on screen until something uses them.
|
||||
*
|
||||
* Colours come in two forms:
|
||||
* --x-<name>-rgb space-separated channels, e.g. "15 118 110" (Tailwind preset: alpha support)
|
||||
* --x-<name> ready to use, e.g. color: var(--x-ink)
|
||||
*
|
||||
* Theme, set on <html> (or any container; portals render in <body>, so prefer <html>):
|
||||
* data-theme="light" (default) | "dark" | "system" (follows the OS)
|
||||
* data-venue-theme="teal" (default) | "amber" | "blue" | "violet" | "rose" (accent colour only)
|
||||
*/
|
||||
|
||||
/* ── Light (default) ─────────────────────────────────────────────────────── */
|
||||
:root {
|
||||
--x-canvas-rgb: 248 250 252;
|
||||
--x-surface-rgb: 255 255 255;
|
||||
--x-surface-2-rgb: 241 245 249;
|
||||
--x-surface-3-rgb: 226 232 240;
|
||||
--x-line-rgb: 226 232 240;
|
||||
--x-line-strong-rgb: 203 213 225;
|
||||
--x-ink-rgb: 15 23 42;
|
||||
--x-ink-2-rgb: 71 85 105;
|
||||
--x-ink-3-rgb: 100 116 139;
|
||||
--x-success-rgb: 21 128 61;
|
||||
--x-success-fg-rgb: 255 255 255;
|
||||
--x-success-soft-rgb: 220 252 231;
|
||||
--x-success-ink-rgb: 21 128 61;
|
||||
--x-warning-rgb: 180 83 9;
|
||||
--x-warning-fg-rgb: 255 255 255;
|
||||
--x-warning-soft-rgb: 254 243 199;
|
||||
--x-warning-ink-rgb: 146 64 14;
|
||||
--x-danger-rgb: 220 38 38;
|
||||
--x-danger-fg-rgb: 255 255 255;
|
||||
--x-danger-soft-rgb: 254 226 226;
|
||||
--x-danger-ink-rgb: 185 28 28;
|
||||
--x-info-rgb: 37 99 235;
|
||||
--x-info-fg-rgb: 255 255 255;
|
||||
--x-info-soft-rgb: 219 234 254;
|
||||
--x-info-ink-rgb: 29 78 216;
|
||||
--x-scrim-rgb: 15 23 42;
|
||||
--x-accent-rgb: 15 118 110;
|
||||
--x-accent-strong-rgb: 17 94 89;
|
||||
--x-accent-fg-rgb: 255 255 255;
|
||||
--x-accent-soft-rgb: 204 251 241;
|
||||
--x-accent-ink-rgb: 17 94 89;
|
||||
}
|
||||
|
||||
/* ── Dark ────────────────────────────────────────────────────────────────── */
|
||||
[data-theme="dark"] {
|
||||
--x-canvas-rgb: 13 21 32;
|
||||
--x-surface-rgb: 26 37 53;
|
||||
--x-surface-2-rgb: 36 48 68;
|
||||
--x-surface-3-rgb: 46 61 84;
|
||||
--x-line-rgb: 37 50 69;
|
||||
--x-line-strong-rgb: 58 77 104;
|
||||
--x-ink-rgb: 237 242 247;
|
||||
--x-ink-2-rgb: 148 163 184;
|
||||
--x-ink-3-rgb: 122 143 166;
|
||||
--x-success-rgb: 34 197 94;
|
||||
--x-success-fg-rgb: 5 46 22;
|
||||
--x-success-soft-rgb: 20 83 45;
|
||||
--x-success-ink-rgb: 134 239 172;
|
||||
--x-warning-rgb: 245 158 11;
|
||||
--x-warning-fg-rgb: 28 16 0;
|
||||
--x-warning-soft-rgb: 107 58 0;
|
||||
--x-warning-ink-rgb: 253 230 138;
|
||||
--x-danger-rgb: 248 113 113;
|
||||
--x-danger-fg-rgb: 69 10 10;
|
||||
--x-danger-soft-rgb: 90 20 20;
|
||||
--x-danger-ink-rgb: 254 202 202;
|
||||
--x-info-rgb: 96 165 250;
|
||||
--x-info-fg-rgb: 23 37 84;
|
||||
--x-info-soft-rgb: 30 58 138;
|
||||
--x-info-ink-rgb: 191 219 254;
|
||||
--x-scrim-rgb: 0 0 0;
|
||||
--x-accent-rgb: 45 212 191;
|
||||
--x-accent-strong-rgb: 94 234 212;
|
||||
--x-accent-fg-rgb: 4 47 46;
|
||||
--x-accent-soft-rgb: 19 78 74;
|
||||
--x-accent-ink-rgb: 153 246 228;
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
[data-theme="system"] {
|
||||
--x-canvas-rgb: 13 21 32;
|
||||
--x-surface-rgb: 26 37 53;
|
||||
--x-surface-2-rgb: 36 48 68;
|
||||
--x-surface-3-rgb: 46 61 84;
|
||||
--x-line-rgb: 37 50 69;
|
||||
--x-line-strong-rgb: 58 77 104;
|
||||
--x-ink-rgb: 237 242 247;
|
||||
--x-ink-2-rgb: 148 163 184;
|
||||
--x-ink-3-rgb: 122 143 166;
|
||||
--x-success-rgb: 34 197 94;
|
||||
--x-success-fg-rgb: 5 46 22;
|
||||
--x-success-soft-rgb: 20 83 45;
|
||||
--x-success-ink-rgb: 134 239 172;
|
||||
--x-warning-rgb: 245 158 11;
|
||||
--x-warning-fg-rgb: 28 16 0;
|
||||
--x-warning-soft-rgb: 107 58 0;
|
||||
--x-warning-ink-rgb: 253 230 138;
|
||||
--x-danger-rgb: 248 113 113;
|
||||
--x-danger-fg-rgb: 69 10 10;
|
||||
--x-danger-soft-rgb: 90 20 20;
|
||||
--x-danger-ink-rgb: 254 202 202;
|
||||
--x-info-rgb: 96 165 250;
|
||||
--x-info-fg-rgb: 23 37 84;
|
||||
--x-info-soft-rgb: 30 58 138;
|
||||
--x-info-ink-rgb: 191 219 254;
|
||||
--x-scrim-rgb: 0 0 0;
|
||||
--x-accent-rgb: 45 212 191;
|
||||
--x-accent-strong-rgb: 94 234 212;
|
||||
--x-accent-fg-rgb: 4 47 46;
|
||||
--x-accent-soft-rgb: 19 78 74;
|
||||
--x-accent-ink-rgb: 153 246 228;
|
||||
}
|
||||
}
|
||||
|
||||
/* ── Venue themes (accent only) ──────────────────────────────────────────── */
|
||||
[data-venue-theme="teal"] {
|
||||
--x-accent-rgb: 15 118 110;
|
||||
--x-accent-strong-rgb: 17 94 89;
|
||||
--x-accent-fg-rgb: 255 255 255;
|
||||
--x-accent-soft-rgb: 204 251 241;
|
||||
--x-accent-ink-rgb: 17 94 89;
|
||||
}
|
||||
[data-theme="dark"][data-venue-theme="teal"],
|
||||
[data-theme="dark"] [data-venue-theme="teal"] {
|
||||
--x-accent-rgb: 45 212 191;
|
||||
--x-accent-strong-rgb: 94 234 212;
|
||||
--x-accent-fg-rgb: 4 47 46;
|
||||
--x-accent-soft-rgb: 19 78 74;
|
||||
--x-accent-ink-rgb: 153 246 228;
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
[data-theme="system"][data-venue-theme="teal"],
|
||||
[data-theme="system"] [data-venue-theme="teal"] {
|
||||
--x-accent-rgb: 45 212 191;
|
||||
--x-accent-strong-rgb: 94 234 212;
|
||||
--x-accent-fg-rgb: 4 47 46;
|
||||
--x-accent-soft-rgb: 19 78 74;
|
||||
--x-accent-ink-rgb: 153 246 228;
|
||||
}
|
||||
}
|
||||
[data-venue-theme="amber"] {
|
||||
--x-accent-rgb: 180 83 9;
|
||||
--x-accent-strong-rgb: 146 64 14;
|
||||
--x-accent-fg-rgb: 255 255 255;
|
||||
--x-accent-soft-rgb: 254 243 199;
|
||||
--x-accent-ink-rgb: 146 64 14;
|
||||
}
|
||||
[data-theme="dark"][data-venue-theme="amber"],
|
||||
[data-theme="dark"] [data-venue-theme="amber"] {
|
||||
--x-accent-rgb: 245 158 11;
|
||||
--x-accent-strong-rgb: 251 191 36;
|
||||
--x-accent-fg-rgb: 28 16 0;
|
||||
--x-accent-soft-rgb: 107 58 0;
|
||||
--x-accent-ink-rgb: 253 230 138;
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
[data-theme="system"][data-venue-theme="amber"],
|
||||
[data-theme="system"] [data-venue-theme="amber"] {
|
||||
--x-accent-rgb: 245 158 11;
|
||||
--x-accent-strong-rgb: 251 191 36;
|
||||
--x-accent-fg-rgb: 28 16 0;
|
||||
--x-accent-soft-rgb: 107 58 0;
|
||||
--x-accent-ink-rgb: 253 230 138;
|
||||
}
|
||||
}
|
||||
[data-venue-theme="blue"] {
|
||||
--x-accent-rgb: 37 99 235;
|
||||
--x-accent-strong-rgb: 29 78 216;
|
||||
--x-accent-fg-rgb: 255 255 255;
|
||||
--x-accent-soft-rgb: 219 234 254;
|
||||
--x-accent-ink-rgb: 29 78 216;
|
||||
}
|
||||
[data-theme="dark"][data-venue-theme="blue"],
|
||||
[data-theme="dark"] [data-venue-theme="blue"] {
|
||||
--x-accent-rgb: 96 165 250;
|
||||
--x-accent-strong-rgb: 147 197 253;
|
||||
--x-accent-fg-rgb: 23 37 84;
|
||||
--x-accent-soft-rgb: 30 58 138;
|
||||
--x-accent-ink-rgb: 191 219 254;
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
[data-theme="system"][data-venue-theme="blue"],
|
||||
[data-theme="system"] [data-venue-theme="blue"] {
|
||||
--x-accent-rgb: 96 165 250;
|
||||
--x-accent-strong-rgb: 147 197 253;
|
||||
--x-accent-fg-rgb: 23 37 84;
|
||||
--x-accent-soft-rgb: 30 58 138;
|
||||
--x-accent-ink-rgb: 191 219 254;
|
||||
}
|
||||
}
|
||||
[data-venue-theme="violet"] {
|
||||
--x-accent-rgb: 124 58 237;
|
||||
--x-accent-strong-rgb: 109 40 217;
|
||||
--x-accent-fg-rgb: 255 255 255;
|
||||
--x-accent-soft-rgb: 237 233 254;
|
||||
--x-accent-ink-rgb: 91 33 182;
|
||||
}
|
||||
[data-theme="dark"][data-venue-theme="violet"],
|
||||
[data-theme="dark"] [data-venue-theme="violet"] {
|
||||
--x-accent-rgb: 167 139 250;
|
||||
--x-accent-strong-rgb: 196 181 253;
|
||||
--x-accent-fg-rgb: 46 16 101;
|
||||
--x-accent-soft-rgb: 76 29 149;
|
||||
--x-accent-ink-rgb: 221 214 254;
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
[data-theme="system"][data-venue-theme="violet"],
|
||||
[data-theme="system"] [data-venue-theme="violet"] {
|
||||
--x-accent-rgb: 167 139 250;
|
||||
--x-accent-strong-rgb: 196 181 253;
|
||||
--x-accent-fg-rgb: 46 16 101;
|
||||
--x-accent-soft-rgb: 76 29 149;
|
||||
--x-accent-ink-rgb: 221 214 254;
|
||||
}
|
||||
}
|
||||
[data-venue-theme="rose"] {
|
||||
--x-accent-rgb: 225 29 72;
|
||||
--x-accent-strong-rgb: 190 18 60;
|
||||
--x-accent-fg-rgb: 255 255 255;
|
||||
--x-accent-soft-rgb: 255 228 230;
|
||||
--x-accent-ink-rgb: 159 18 57;
|
||||
}
|
||||
[data-theme="dark"][data-venue-theme="rose"],
|
||||
[data-theme="dark"] [data-venue-theme="rose"] {
|
||||
--x-accent-rgb: 251 113 133;
|
||||
--x-accent-strong-rgb: 253 164 175;
|
||||
--x-accent-fg-rgb: 76 5 25;
|
||||
--x-accent-soft-rgb: 136 19 55;
|
||||
--x-accent-ink-rgb: 254 205 211;
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
[data-theme="system"][data-venue-theme="rose"],
|
||||
[data-theme="system"] [data-venue-theme="rose"] {
|
||||
--x-accent-rgb: 251 113 133;
|
||||
--x-accent-strong-rgb: 253 164 175;
|
||||
--x-accent-fg-rgb: 76 5 25;
|
||||
--x-accent-soft-rgb: 136 19 55;
|
||||
--x-accent-ink-rgb: 254 205 211;
|
||||
}
|
||||
}
|
||||
|
||||
/* ── Ready-to-use colours ────────────────────────────────────────────────────
|
||||
* Redeclared wherever the channels can change, so a nested data-theme /
|
||||
* data-venue-theme container gets its own values (custom properties are
|
||||
* resolved where they are declared, then inherited). */
|
||||
:root,
|
||||
[data-theme],
|
||||
[data-venue-theme] {
|
||||
--x-canvas: rgb(var(--x-canvas-rgb));
|
||||
--x-surface: rgb(var(--x-surface-rgb));
|
||||
--x-surface-2: rgb(var(--x-surface-2-rgb));
|
||||
--x-surface-3: rgb(var(--x-surface-3-rgb));
|
||||
--x-line: rgb(var(--x-line-rgb));
|
||||
--x-line-strong: rgb(var(--x-line-strong-rgb));
|
||||
--x-ink: rgb(var(--x-ink-rgb));
|
||||
--x-ink-2: rgb(var(--x-ink-2-rgb));
|
||||
--x-ink-3: rgb(var(--x-ink-3-rgb));
|
||||
--x-success: rgb(var(--x-success-rgb));
|
||||
--x-success-fg: rgb(var(--x-success-fg-rgb));
|
||||
--x-success-soft: rgb(var(--x-success-soft-rgb));
|
||||
--x-success-ink: rgb(var(--x-success-ink-rgb));
|
||||
--x-warning: rgb(var(--x-warning-rgb));
|
||||
--x-warning-fg: rgb(var(--x-warning-fg-rgb));
|
||||
--x-warning-soft: rgb(var(--x-warning-soft-rgb));
|
||||
--x-warning-ink: rgb(var(--x-warning-ink-rgb));
|
||||
--x-danger: rgb(var(--x-danger-rgb));
|
||||
--x-danger-fg: rgb(var(--x-danger-fg-rgb));
|
||||
--x-danger-soft: rgb(var(--x-danger-soft-rgb));
|
||||
--x-danger-ink: rgb(var(--x-danger-ink-rgb));
|
||||
--x-info: rgb(var(--x-info-rgb));
|
||||
--x-info-fg: rgb(var(--x-info-fg-rgb));
|
||||
--x-info-soft: rgb(var(--x-info-soft-rgb));
|
||||
--x-info-ink: rgb(var(--x-info-ink-rgb));
|
||||
--x-scrim: rgb(var(--x-scrim-rgb));
|
||||
--x-accent: rgb(var(--x-accent-rgb));
|
||||
--x-accent-strong: rgb(var(--x-accent-strong-rgb));
|
||||
--x-accent-fg: rgb(var(--x-accent-fg-rgb));
|
||||
--x-accent-soft: rgb(var(--x-accent-soft-rgb));
|
||||
--x-accent-ink: rgb(var(--x-accent-ink-rgb));
|
||||
--x-focus-ring: 0 0 0 3px rgb(var(--x-accent-rgb) / 0.35);
|
||||
}
|
||||
|
||||
/* For native controls (select popups, scrollbars) inside @xenia/ui components only.
|
||||
* Deliberately NOT set on <html>: that would restyle an app's own controls. */
|
||||
:root { --x-color-scheme: light; }
|
||||
[data-theme="dark"] { --x-color-scheme: dark; }
|
||||
@media (prefers-color-scheme: dark) {
|
||||
[data-theme="system"] { --x-color-scheme: dark; }
|
||||
}
|
||||
|
||||
/* ── Everything that doesn't depend on the theme ─────────────────────────── */
|
||||
:root {
|
||||
/* Type */
|
||||
--x-font-sans: "Google Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
|
||||
--x-font-mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Consolas, monospace;
|
||||
--x-text-caption: 12px; --x-leading-caption: 16px;
|
||||
--x-text-label: 13px; --x-leading-label: 18px;
|
||||
--x-text-body: 14px; --x-leading-body: 20px;
|
||||
--x-text-body-lg: 16px; --x-leading-body-lg: 24px;
|
||||
--x-text-title: 18px; --x-leading-title: 26px;
|
||||
--x-text-heading: 22px; --x-leading-heading: 30px;
|
||||
--x-text-display: 28px; --x-leading-display: 36px;
|
||||
--x-weight-regular: 400;
|
||||
--x-weight-medium: 500;
|
||||
--x-weight-semibold: 600;
|
||||
--x-weight-bold: 700;
|
||||
|
||||
/* Spacing: the same 4 px steps as Tailwind's default scale (p-1 = 4px … p-16 = 64px) */
|
||||
--x-space-0-5: 2px;
|
||||
--x-space-1: 4px;
|
||||
--x-space-1-5: 6px;
|
||||
--x-space-2: 8px;
|
||||
--x-space-2-5: 10px;
|
||||
--x-space-3: 12px;
|
||||
--x-space-4: 16px;
|
||||
--x-space-5: 20px;
|
||||
--x-space-6: 24px;
|
||||
--x-space-8: 32px;
|
||||
--x-space-10: 40px;
|
||||
--x-space-12: 48px;
|
||||
--x-space-16: 64px;
|
||||
|
||||
/* Radius */
|
||||
--x-radius-sm: 8px; /* chips, small controls */
|
||||
--x-radius-control: 12px; /* buttons, inputs (the manager's rounded-xl) */
|
||||
--x-radius-card: 16px; /* cards, popovers (rounded-2xl) */
|
||||
--x-radius-dialog: 20px; /* dialogs, sheets */
|
||||
--x-radius-full: 9999px;
|
||||
|
||||
/* Control heights: 44 px is the minimum touch target */
|
||||
--x-control-sm: 36px;
|
||||
--x-control-md: 44px;
|
||||
--x-control-lg: 52px;
|
||||
|
||||
/* Elevation */
|
||||
--x-shadow-raised: 0 1px 2px rgb(15 23 42 / 0.06), 0 1px 3px rgb(15 23 42 / 0.08);
|
||||
--x-shadow-popover: 0 8px 24px rgb(15 23 42 / 0.12), 0 2px 6px rgb(15 23 42 / 0.08);
|
||||
--x-shadow-overlay: 0 24px 48px rgb(15 23 42 / 0.18), 0 8px 16px rgb(15 23 42 / 0.10);
|
||||
|
||||
/* Motion */
|
||||
--x-duration-fast: 120ms;
|
||||
--x-duration-base: 180ms;
|
||||
--x-ease: cubic-bezier(0.2, 0.8, 0.2, 1);
|
||||
|
||||
/* Stacking */
|
||||
--x-z-overlay: 1000;
|
||||
--x-z-toast: 1100;
|
||||
--x-z-popover: 1200;
|
||||
}
|
||||
[data-theme="dark"] {
|
||||
--x-shadow-raised: 0 1px 2px rgb(0 0 0 / 0.30), 0 1px 3px rgb(0 0 0 / 0.30);
|
||||
--x-shadow-popover: 0 8px 24px rgb(0 0 0 / 0.45), 0 2px 6px rgb(0 0 0 / 0.30);
|
||||
--x-shadow-overlay: 0 24px 48px rgb(0 0 0 / 0.55), 0 8px 16px rgb(0 0 0 / 0.35);
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
[data-theme="system"] {
|
||||
--x-shadow-raised: 0 1px 2px rgb(0 0 0 / 0.30), 0 1px 3px rgb(0 0 0 / 0.30);
|
||||
--x-shadow-popover: 0 8px 24px rgb(0 0 0 / 0.45), 0 2px 6px rgb(0 0 0 / 0.30);
|
||||
--x-shadow-overlay: 0 24px 48px rgb(0 0 0 / 0.55), 0 8px 16px rgb(0 0 0 / 0.35);
|
||||
}
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
:root {
|
||||
--x-duration-fast: 0ms;
|
||||
--x-duration-base: 0ms;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user