Files
2026-10-10 14:54:39 +02:00

36 lines
1.3 KiB
Swift

import SwiftUI
/// A framed segment button: hairline frame, radius 2; while on, an amber fill with ink text.
public struct SegmentButton: View {
var label: String
var isOn: Bool
var action: () -> Void
@State private var isHovered = false
public init(_ label: String, isOn: Bool, action: @escaping () -> Void) {
self.label = label
self.isOn = isOn
self.action = action
}
public var body: some View {
Button(action: action) {
Text(label)
.typeRole(isOn ? Typography.segmentOn : Typography.segment)
.foregroundStyle(isOn ? Palette.ink : isHovered ? Palette.text1 : Palette.text3)
.padding(.horizontal, 12)
.padding(.vertical, 5)
.background(isOn ? Palette.amber : isHovered ? Palette.hover : .clear)
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.pointerHand()
.fixedSize()
.clipShape(RoundedRectangle(cornerRadius: Metrics.radiusSmall))
.overlay(RoundedRectangle(cornerRadius: Metrics.radiusSmall).strokeBorder(Palette.raised, lineWidth: Metrics.hairline))
.accessibilityAddTraits(isOn ? .isSelected : [])
.onHover { isHovered = $0 }
.animation(Metrics.smallControlTransition, value: isHovered)
}
}