71 lines
2.8 KiB
Text
71 lines
2.8 KiB
Text
import { Theme } from "../theme.slint";
|
|
import { Motion } from "../motion.slint";
|
|
import { Icon } from "icon.slint";
|
|
import { StateLayer } from "state-layer.slint";
|
|
|
|
// Emphasis, from the main action of a screen (filled) down to the least (text).
|
|
// `danger`: filled red (the error colour; its deep container in dark mode, where the error
|
|
// colour itself is pale), for an action that destroys data.
|
|
export enum ButtonKind { filled, tonal, outlined, text, danger }
|
|
|
|
// A labelled button with an optional leading icon.
|
|
export component Button inherits StateLayer {
|
|
in property <string> text;
|
|
// Glyph from `Icons`; empty for none.
|
|
in property <string> icon;
|
|
in property <ButtonKind> kind: ButtonKind.filled;
|
|
|
|
property <bool> contained: root.kind == ButtonKind.filled || root.kind == ButtonKind.tonal || root.kind == ButtonKind.danger;
|
|
property <color> content: !root.enabled ? Theme.on-surface.with-alpha(Theme.disabled-content)
|
|
: root.kind == ButtonKind.filled ? Theme.on-primary
|
|
: root.kind == ButtonKind.danger ? (Theme.dark ? Theme.on-error-container : Theme.on-error)
|
|
: root.kind == ButtonKind.tonal ? Theme.on-secondary-container
|
|
: Theme.primary;
|
|
|
|
height: 40px;
|
|
border-radius: Theme.corner-full(self.height);
|
|
background: !root.contained ? transparent
|
|
: !root.enabled ? Theme.on-surface.with-alpha(Theme.disabled-container)
|
|
: root.kind == ButtonKind.filled ? Theme.primary
|
|
: root.kind == ButtonKind.danger ? (Theme.dark ? Theme.error-container : Theme.error)
|
|
: Theme.secondary-container;
|
|
border-width: root.kind == ButtonKind.outlined ? Theme.hairline : 0;
|
|
border-color: root.enabled ? Theme.outline : Theme.on-surface.with-alpha(Theme.disabled-container);
|
|
tint: root.content;
|
|
animate background, border-color {
|
|
duration: Motion.time(Motion.short4);
|
|
easing: Motion.standard;
|
|
}
|
|
|
|
accessible-role: button;
|
|
accessible-label: root.text;
|
|
accessible-enabled: root.enabled;
|
|
accessible-action-default => {
|
|
self.activate();
|
|
}
|
|
|
|
HorizontalLayout {
|
|
padding-left: root.kind == ButtonKind.text ? Theme.space-3 : root.icon != "" ? Theme.space-4 : Theme.space-6;
|
|
padding-right: root.kind == ButtonKind.text ? (root.icon != "" ? Theme.space-4 : Theme.space-3) : Theme.space-6;
|
|
spacing: Theme.space-2;
|
|
|
|
if root.icon != "": VerticalLayout {
|
|
alignment: center;
|
|
|
|
Icon {
|
|
glyph: root.icon;
|
|
size: 18px;
|
|
color: root.content;
|
|
}
|
|
}
|
|
|
|
Text {
|
|
text: root.text;
|
|
color: root.content;
|
|
font-size: Theme.label-large.size;
|
|
font-weight: Theme.label-large.weight;
|
|
vertical-alignment: center;
|
|
overflow: elide;
|
|
}
|
|
}
|
|
}
|