From b77bb8bb4051a1f7a6355d7f8ee177bdd7a2204f Mon Sep 17 00:00:00 2001 From: bonamin Date: Fri, 20 Nov 2026 14:48:50 +0200 Subject: [PATCH] feat(ui): IconButton tones, Switch info slot, wide right sheet, PrintArea / PrintSheet - IconButton tone=danger|warning|info|success|special|accent: a pastel button (soft background, ink icon) for row actions that stand apart. - Switch info: an element (InfoTip) right after the label instead of after the switch. - Sheet size=wide: a 600 px drawer. - PrintArea: content rendered into , hidden on screen, the only thing printed while mounted; PrintSheet: cards to cut out (dashed cut lines, never split across pages). Co-Authored-By: Claude Opus 5.5 --- packages/ui/src/components.css | 32 ++++++++++++++++++++++++ packages/ui/src/components/Button.jsx | 11 +++++--- packages/ui/src/components/PrintArea.jsx | 27 ++++++++++++++++++++ packages/ui/src/components/Sheet.jsx | 4 +-- packages/ui/src/components/Switch.jsx | 10 ++++++-- packages/ui/src/index.js | 1 + 6 files changed, 78 insertions(+), 7 deletions(-) create mode 100644 packages/ui/src/components/PrintArea.jsx diff --git a/packages/ui/src/components.css b/packages/ui/src/components.css index c0ee0f8..367e6ff 100644 --- a/packages/ui/src/components.css +++ b/packages/ui/src/components.css @@ -52,6 +52,15 @@ .x-btn--danger:hover:not(:disabled) { background: rgb(var(--x-danger-rgb) / 0.88); } .x-btn--icon { padding: 0; width: var(--x-control-md); } +/* a pastel tone on a button (IconButton tone=…): soft background, ink icon */ +.x-btn--tone { background: rgb(var(--x-tone-soft)); color: rgb(var(--x-tone-ink)); } +.x-btn--tone:hover:not(:disabled) { background: rgb(var(--x-tone) / 0.24); color: rgb(var(--x-tone-ink)); } +.x-btn--tone-danger { --x-tone: var(--x-danger-rgb); --x-tone-soft: var(--x-danger-soft-rgb); --x-tone-ink: var(--x-danger-ink-rgb); } +.x-btn--tone-warning { --x-tone: var(--x-warning-rgb); --x-tone-soft: var(--x-warning-soft-rgb); --x-tone-ink: var(--x-warning-ink-rgb); } +.x-btn--tone-info { --x-tone: var(--x-info-rgb); --x-tone-soft: var(--x-info-soft-rgb); --x-tone-ink: var(--x-info-ink-rgb); } +.x-btn--tone-success { --x-tone: var(--x-success-rgb); --x-tone-soft: var(--x-success-soft-rgb); --x-tone-ink: var(--x-success-ink-rgb); } +.x-btn--tone-special { --x-tone: var(--x-special-rgb); --x-tone-soft: var(--x-special-soft-rgb); --x-tone-ink: var(--x-special-ink-rgb); } +.x-btn--tone-accent { --x-tone: var(--x-accent-rgb); --x-tone-soft: var(--x-accent-soft-rgb); --x-tone-ink: var(--x-accent-ink-rgb); } .x-btn--icon.x-btn--sm { width: var(--x-control-sm); } .x-btn--icon.x-btn--lg { width: var(--x-control-lg); } @@ -91,6 +100,9 @@ } .x-sheet--right { width: min(480px, 100vw); height: 100%; +} +.x-sheet--right.x-sheet--wide { width: min(600px, 100vw); } +.x-sheet--right { border-radius: var(--x-radius-dialog) 0 0 var(--x-radius-dialog); animation: x-slide-left var(--x-duration-base) var(--x-ease); } @@ -313,6 +325,8 @@ .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__head { display: flex; align-items: center; gap: var(--x-space-1-5); } +.x-switch-row__head .x-switch-row__label { display: inline; } .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; } @@ -498,3 +512,21 @@ .x-tabs__badge { min-width: 18px; padding: 0 var(--x-space-1-5); box-sizing: border-box; border-radius: var(--x-radius-full); background: var(--x-surface-2); color: var(--x-ink-2); font-size: var(--x-text-caption); font-weight: var(--x-weight-bold); text-align: center; font-variant-numeric: tabular-nums; } .x-tabs__badge--warn { background: var(--x-danger-soft); color: var(--x-danger-ink); } .x-tabs__end { flex-shrink: 0; display: flex; align-items: center; gap: var(--x-space-2); } + +/* ── Print (PrintArea / PrintSheet, 2026-11-20) ───────────────────────────── + * A mounted .x-print-area is the only thing printed; on screen it is hidden. */ +.x-print-area { display: none; } +@media print { + @page { margin: 10mm; } + body:has(> .x-print-area) > :not(.x-print-area) { display: none !important; } + .x-print-area { display: block; color: #000; background: #fff; } +} +.x-print-sheet { + display: grid; grid-template-columns: repeat(var(--x-print-columns, 3), 1fr); + border-top: 1px dashed #888; border-left: 1px dashed #888; +} +.x-print-sheet > * { + break-inside: avoid; page-break-inside: avoid; + border-right: 1px dashed #888; border-bottom: 1px dashed #888; + padding: 6mm 4mm; display: grid; justify-items: center; align-content: start; gap: 2mm; text-align: center; +} diff --git a/packages/ui/src/components/Button.jsx b/packages/ui/src/components/Button.jsx index d46ed91..5f69fa1 100644 --- a/packages/ui/src/components/Button.jsx +++ b/packages/ui/src/components/Button.jsx @@ -27,9 +27,14 @@ export function Button({ ) } -/** A square button with only an icon. `label` is required: it becomes aria-label and the tooltip. */ +/** + * A square button with only an icon. `label` is required: it becomes aria-label and the tooltip. + * tone: 'danger' | 'warning' | 'info' | 'success' | 'special' | 'accent' — a pastel button in that + * colour (soft background, ink icon), for row actions that should stand apart (delete red, block + * orange, zones blue: DESIGN.md §3). + */ export function IconButton({ - label, variant = 'ghost', size = 'md', type = 'button', className, children, ref, ...rest + label, variant = 'ghost', size = 'md', tone, type = 'button', className, children, ref, ...rest }) { return ( + * + * Mount one at a time (the page's own print content). + */ +export function PrintArea({ className, children, ...rest }) { + return ( + +
{children}
+
+ ) +} + +/** + * Cards to cut out: a grid of equal cells with dashed cut lines between them, never split across + * pages. columns: cells per row on an A4 page (default 3). + */ +export function PrintSheet({ columns = 3, className, children, ...rest }) { + return
{children}
+} diff --git a/packages/ui/src/components/Sheet.jsx b/packages/ui/src/components/Sheet.jsx index 9a1bf32..cecbeab 100644 --- a/packages/ui/src/components/Sheet.jsx +++ b/packages/ui/src/components/Sheet.jsx @@ -6,12 +6,12 @@ import { ModalFrame } from '../internal/ModalFrame.jsx' * right (desktop: detail and edit panels). Same props and behaviour as Dialog. * side: 'bottom' | 'right' */ -export function Sheet({ side = 'bottom', className, ...props }) { +export function Sheet({ side = 'bottom', size, className, ...props }) { return ( diff --git a/packages/ui/src/components/Switch.jsx b/packages/ui/src/components/Switch.jsx index f49dc62..824aacd 100644 --- a/packages/ui/src/components/Switch.jsx +++ b/packages/ui/src/components/Switch.jsx @@ -6,8 +6,9 @@ import { cx } from '../internal/cx.js' * * onChange receives the new boolean. Without `label`, pass aria-label. * The whole row (label + description) is clickable. + * info: an element right after the label (an ), not after the switch. */ -export function Switch({ checked, onChange, label, description, disabled = false, id, className, ...rest }) { +export function Switch({ checked, onChange, label, description, info, disabled = false, id, className, ...rest }) { const auto = useId() const switchId = id || auto const descId = `${switchId}-desc` @@ -32,7 +33,12 @@ export function Switch({ checked, onChange, label, description, disabled = false return (
- {label && } + {label && ( + + + {info} + + )} {description &&
{description}
}
{control} diff --git a/packages/ui/src/index.js b/packages/ui/src/index.js index 795dd9b..1334175 100644 --- a/packages/ui/src/index.js +++ b/packages/ui/src/index.js @@ -12,6 +12,7 @@ export { Button, IconButton } from './components/Button.jsx' export { Dialog } from './components/Dialog.jsx' export { Sheet } from './components/Sheet.jsx' +export { PrintArea, PrintSheet } from './components/PrintArea.jsx' export { ToastProvider } from './components/Toast.jsx' export { useToast } from './components/toastContext.js' export { PinPad } from './components/PinPad.jsx'