This repository has been archived on 2026-11-02. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files

64 lines
2.1 KiB
QML

import QtQuick
import QtQuick.Effects
import "."
Rectangle {
id: button
// "primary" | "secondary" | "accent" | "destructive" | "success" | "warning" | "info"
property string variant: "primary"
property string text: ""
signal clicked()
// primary and accent are the same color (Theme.colors.primary === .accent);
// kept as separate variant names for call-site clarity.
readonly property bool filled: variant === "primary" || variant === "accent"
readonly property color tint: variant === "accent" ? Theme.colors.accent
: variant === "destructive" ? Theme.colors.alert
: variant === "success" ? Theme.colors.success
: variant === "warning" ? Theme.colors.warning
: variant === "info" ? Theme.colors.info
: Theme.colors.primary
implicitWidth: label.implicitWidth + Theme.geometry.padding * 2
implicitHeight: label.implicitHeight + Theme.geometry.padding
radius: Theme.geometry.radiusSmall
color: filled
? (mouseArea.pressed ? Qt.darker(tint, 1.1) : tint)
: (mouseArea.containsMouse ? Qt.alpha(tint, 0.22) : Qt.alpha(tint, 0.15))
border.width: filled ? 0 : 1
border.color: Qt.alpha(tint, 0.3)
layer.enabled: filled
layer.effect: MultiEffect {
shadowEnabled: true
shadowColor: button.tint
shadowOpacity: Theme.elevation.medium.opacity
shadowBlur: Theme.elevation.medium.blur
shadowVerticalOffset: 2
}
Behavior on color { ColorAnimation { duration: Theme.animation.durationFast } }
Behavior on scale { SpringAnimation { spring: Theme.motion.springSnappy.spring; damping: Theme.motion.springSnappy.damping } }
scale: mouseArea.pressed ? 0.97 : 1.0
Text {
id: label
anchors.centerIn: parent
text: button.text
font.family: Theme.font.family
font.pixelSize: 13
font.bold: true
color: button.filled ? Theme.colors.background : button.tint
}
MouseArea {
id: mouseArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: button.clicked()
}
}