Files
Pulse/Sources/PulseUI/Views/SelectableButton.swift
T
Alex Grebenyuk 245898eff7 Squash
2023-04-09 08:34:41 -04:00

28 lines
726 B
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// The MIT License (MIT)
//
// Copyright (c) 20202023 Alexander Grebenyuk (github.com/kean).
#if os(macOS)
import SwiftUI
struct SelectableButton: View {
let image: Image
@Binding var isSelected: Bool
@State private var isHovering = false
var body: some View {
Button(action: { isSelected.toggle() }) {
image
.foregroundColor(isSelected ? .white : .secondary)
.padding(2)
.padding(.horizontal, 2)
.onHover { isHovering = $0 }
.background(isSelected ? Color.blue.opacity(0.8) : (isHovering ? Color.blue.opacity(0.25) : nil))
.cornerRadius(4)
}.buttonStyle(.plain)
}
}
#endif