Replace the hardcoded variant hex with the themed families: error -> danger/danger-bg/danger-border, success -> success(+bg/border), warning(default) -> warning(+bg/border). The "info" variant has no dedicated token, so it maps to Theme.accent with the same 10% bg / 30% border alphas the literals used -- a small hue shift in some themes (behavior change, not a pure 1:1), but accent is the themed informational color. The per-variant glyph already provides the non-color cue (WCAG 1.4.1). cc
75 lines
3.0 KiB
Plaintext
75 lines
3.0 KiB
Plaintext
// 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 <string> title: "";
|
|
in property <string> body: "";
|
|
in property <string> variant: "warning"; // info | warning | error | success
|
|
|
|
// Themed via the semantic families. error→danger, success→success,
|
|
// warning(default)→warning. "info" has no dedicated token, so it maps to
|
|
// the themed informational color (accent) with the same 10% bg / 30% border
|
|
// alphas the literals used. The per-variant glyph already carries the
|
|
// non-color cue (WCAG 1.4.1); this only makes the tone themeable.
|
|
property <color> tone: root.variant == "error" ? Theme.danger
|
|
: (root.variant == "info" ? Theme.accent
|
|
: (root.variant == "success" ? Theme.success : Theme.warning));
|
|
property <color> bg: root.variant == "error" ? Theme.danger-bg
|
|
: (root.variant == "info" ? Theme.accent.with-alpha(0.10)
|
|
: (root.variant == "success" ? Theme.success-bg : Theme.warning-bg));
|
|
property <color> brd: root.variant == "error" ? Theme.danger-border
|
|
: (root.variant == "info" ? Theme.accent.with-alpha(0.30)
|
|
: (root.variant == "success" ? Theme.success-border : Theme.warning-border));
|
|
property <image> glyph: root.variant == "error"
|
|
? @image-url("../assets/icons/circle-alert.svg")
|
|
: (root.variant == "info"
|
|
? @image-url("../assets/icons/info.svg")
|
|
: (root.variant == "success"
|
|
? @image-url("../assets/icons/circle-check-big.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;
|
|
}
|
|
}
|
|
}
|
|
}
|