Files
qbz/crates/qbz-slint/ui/primitives/QbzPrimaryButton.slint
T
vicrodh 24f64e687e feat(a11y): active-row shape cue + tokenized drop target in Sidebar
The active playlist/folder row and a hover row both paint surface-hover,
so the only active signal was a subtle text-color shift. Add a 3px accent
left-edge bar (non-layout overlay, no reflow) as a redundant WCAG 1.4.1
shape cue. Move the hardcoded green drop-target fill/border (#22c55e26 /
#22c55e66) to Theme.success-bg / success-border so the affordance is
themed across all 33 palettes.

cc
2026-06-20 15:50:10 -06:00

76 lines
2.5 KiB
Plaintext

// Full-width accent button primitive.
import { Theme } from "../foundation/semantic-colors.slint";
import { Radius } from "../foundation/radius.slint";
import { Typography } from "../foundation/typography.slint";
export component QbzPrimaryButton inherits Rectangle {
in property <string> label;
in property <bool> enabled: true;
// Destructive variant (e.g. the Delete confirm) — a red fill instead of the
// accent. Additive; existing callers default to the accent primary.
in property <bool> destructive: false;
callback clicked();
height: 48px;
border-radius: Radius.sm;
opacity: root.enabled ? 1.0 : 0.5;
background: root.destructive
? (ta.has-hover && root.enabled ? Theme.danger-hover : Theme.danger)
: (ta.has-hover && root.enabled ? Theme.accent-hover : Theme.accent);
animate background { duration: 150ms; }
// A padded layout drives the preferred-width (label + 20px each side) so the
// button auto-sizes as a footer chip inside an `alignment: end` row, while
// still stretching full-width when the parent layout stretches it (login).
HorizontalLayout {
alignment: center;
padding-left: 20px;
padding-right: 20px;
Text {
text: root.label;
color: Theme.accent-text;
font-size: Typography.button;
font-weight: Typography.semibold;
horizontal-alignment: center;
vertical-alignment: center;
}
}
ta := TouchArea {
enabled: root.enabled;
mouse-cursor: root.enabled ? pointer : default;
clicked => {
root.clicked();
}
}
// Keyboard activation: Enter/Space fire the same click. The TouchArea above
// stays the pointer source; this only adds key activation + focusability.
fs := FocusScope {
enabled: root.enabled;
key-pressed(event) => {
if (event.text == Key.Return || event.text == " ") {
root.clicked();
return accept;
}
return reject;
}
}
// Non-layout focus ring — a transparent-bordered overlay shown only on
// keyboard focus, so it never reflows the button (universal a11y, neutral
// at rest in all themes).
Rectangle {
x: 0;
y: 0;
width: parent.width;
height: parent.height;
background: transparent;
border-width: 2px;
border-color: fs.has-focus ? Theme.focus-ring : transparent;
border-radius: parent.border-radius;
}
}