From 5e57db7a0ccd677521e632d613f9011cacc56793 Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Mon, 15 Jun 2026 20:09:35 -0600 Subject: [PATCH] feat(slint): CommandBlock + WarningBanner primitives (HiFi wizard Slice 4) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CommandBlock: surface-elevated copy-paste card (Radius.sm, no pills) with an optional caption, a monospace wrapping command body and a copy button that flips to a green check for 2s (Timer). Read-only — the copy() callback is wired to the clipboard by the consumer; nothing is executed. WarningBanner: info/warning/error variants (tone drives icon + 10%/30% alpha bg/border, matching the existing inline banners). Adds lucide copy.svg. cc --- crates/qbz-slint/ui/assets/icons/copy.svg | 1 + .../ui/primitives/CommandBlock.slint | 96 +++++++++++++++++++ .../ui/primitives/WarningBanner.slint | 64 +++++++++++++ 3 files changed, 161 insertions(+) create mode 100644 crates/qbz-slint/ui/assets/icons/copy.svg create mode 100644 crates/qbz-slint/ui/primitives/CommandBlock.slint create mode 100644 crates/qbz-slint/ui/primitives/WarningBanner.slint diff --git a/crates/qbz-slint/ui/assets/icons/copy.svg b/crates/qbz-slint/ui/assets/icons/copy.svg new file mode 100644 index 000000000..4fb0db9f4 --- /dev/null +++ b/crates/qbz-slint/ui/assets/icons/copy.svg @@ -0,0 +1 @@ + diff --git a/crates/qbz-slint/ui/primitives/CommandBlock.slint b/crates/qbz-slint/ui/primitives/CommandBlock.slint new file mode 100644 index 000000000..846cda014 --- /dev/null +++ b/crates/qbz-slint/ui/primitives/CommandBlock.slint @@ -0,0 +1,96 @@ +// CommandBlock — a copy-paste shell command / config snippet (HiFi wizard). +// +// Surface-elevated card (Radius.sm, no pills) with an optional caption, a +// monospace command body that wraps, and a copy button that flips to a green +// check for 2s. READ-ONLY: the `copy()` callback is wired by the consumer to +// the clipboard (crate::share::copy_to_clipboard); nothing is ever executed. +// +// The height is content-sized (col.preferred-height) so a multi-line command +// grows the block; callers place it in a VerticalLayout and never set a fixed +// height. + +import { Theme } from "../foundation/semantic-colors.slint"; +import { Typography } from "../foundation/typography.slint"; +import { Radius } from "../foundation/radius.slint"; +import { QbzIcon } from "QbzIcon.slint"; + +export component CommandBlock inherits Rectangle { + in property command; + // Optional caption rendered above the command (e.g. what it does). + in property caption: ""; + callback copy(); + + property just-copied: false; + + border-radius: Radius.sm; + background: Theme.surface-elevated; + border-width: 1px; + border-color: Theme.border-subtle; + height: col.preferred-height; + + col := VerticalLayout { + padding: 12px; + spacing: 8px; + + if root.caption != "": Text { + text: root.caption; + color: Theme.text-secondary; + font-size: Typography.legal; + font-weight: Typography.medium; + wrap: word-wrap; + } + + HorizontalLayout { + spacing: 10px; + // Monospace command body — wraps, takes the remaining width. + Text { + text: root.command; + color: Theme.text-primary; + font-size: Typography.legal; + font-family: "monospace"; + wrap: word-wrap; + horizontal-stretch: 1; + } + // Copy button — fixed 30x30, pinned to the top of the row. + VerticalLayout { + alignment: start; + copy-btn := Rectangle { + width: 30px; + height: 30px; + border-radius: Radius.sm; + border-width: 1px; + border-color: Theme.border-subtle; + background: copy-ta.has-hover ? Theme.surface-hover : Theme.surface-card; + QbzIcon { + width: 15px; + height: 15px; + source: root.just-copied + ? @image-url("../assets/icons/check.svg") + : @image-url("../assets/icons/copy.svg"); + tint: root.just-copied + ? #3fae6a + : (copy-ta.has-hover ? Theme.text-primary : Theme.text-muted); + } + copy-ta := TouchArea { + mouse-cursor: pointer; + clicked => { + root.copy(); + root.just-copied = true; + reset-timer.running = true; + } + } + } + } + } + } + + // Resets the "copied" check after 2s. + reset-timer := Timer { + interval: 2s; + running: false; + triggered => { + root.just-copied = false; + self.running = false; + } + } +} diff --git a/crates/qbz-slint/ui/primitives/WarningBanner.slint b/crates/qbz-slint/ui/primitives/WarningBanner.slint new file mode 100644 index 000000000..c314f957e --- /dev/null +++ b/crates/qbz-slint/ui/primitives/WarningBanner.slint @@ -0,0 +1,64 @@ +// WarningBanner — a colored info / warning / error notice (HiFi wizard). +// +// variant ∈ {"info","warning","error"}; the tone drives the icon, the 10% +// alpha background and the 30% alpha border (matching the existing inline +// banners in PlaylistImportModal). Title + body both wrap; either can be "". + +import { Theme } from "../foundation/semantic-colors.slint"; +import { Typography } from "../foundation/typography.slint"; +import { QbzIcon } from "QbzIcon.slint"; + +export component WarningBanner inherits Rectangle { + in property title: ""; + in property body: ""; + in property variant: "warning"; + + property tone: root.variant == "error" ? #ef4444 + : (root.variant == "info" ? #3b82f6 : #eab308); + property bg: root.variant == "error" ? #ef44441a + : (root.variant == "info" ? #3b82f61a : #eab3081a); + property brd: root.variant == "error" ? #ef44444d + : (root.variant == "info" ? #3b82f64d : #eab3084d); + property glyph: root.variant == "error" + ? @image-url("../assets/icons/circle-alert.svg") + : (root.variant == "info" + ? @image-url("../assets/icons/info.svg") + : @image-url("../assets/icons/triangle-alert.svg")); + + border-radius: 8px; + background: root.bg; + border-width: 1px; + border-color: root.brd; + height: row.preferred-height; + + row := HorizontalLayout { + padding: 12px; + spacing: 10px; + VerticalLayout { + alignment: start; + QbzIcon { + source: root.glyph; + width: 16px; + height: 16px; + tint: root.tone; + } + } + VerticalLayout { + spacing: 3px; + horizontal-stretch: 1; + if root.title != "": Text { + text: root.title; + color: root.tone; + font-size: Typography.legal; + font-weight: Typography.semibold; + wrap: word-wrap; + } + if root.body != "": Text { + text: root.body; + color: Theme.text-secondary; + font-size: Typography.legal; + wrap: word-wrap; + } + } + } +}