restores Helder in all its glory
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
import SwiftUI
|
||||
|
||||
/// The one primary action on a surface: amber fill, ink Sans 500 12 label, radius 2, padding 6×10.
|
||||
/// `destructive` switches to amber-deep with a light label (Delete, Discard).
|
||||
public struct PrimaryButtonStyle: ButtonStyle {
|
||||
var destructive: Bool
|
||||
|
||||
public init(destructive: Bool = false) {
|
||||
self.destructive = destructive
|
||||
}
|
||||
|
||||
public func makeBody(configuration: Configuration) -> some View {
|
||||
configuration.label
|
||||
.typeRole(Typography.button)
|
||||
.foregroundStyle(destructive ? Palette.onDeep : Palette.ink)
|
||||
.padding(.horizontal, 10)
|
||||
.padding(.vertical, 6)
|
||||
.background(destructive ? Palette.amberDeep : Palette.amber, in: RoundedRectangle(cornerRadius: Metrics.radiusSmall))
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
}
|
||||
|
||||
/// A secondary action beside a primary one (Cancel): hairline border, text-3 label, hover fill.
|
||||
public struct SecondaryButtonStyle: ButtonStyle {
|
||||
public init() {}
|
||||
|
||||
public func makeBody(configuration: Configuration) -> some View {
|
||||
SecondaryButtonBody(configuration: configuration)
|
||||
}
|
||||
}
|
||||
|
||||
private struct SecondaryButtonBody: View {
|
||||
let configuration: ButtonStyleConfiguration
|
||||
@State private var isHovered = false
|
||||
|
||||
var body: some View {
|
||||
configuration.label
|
||||
.typeRole(Typography.button)
|
||||
.foregroundStyle(isHovered || configuration.isPressed ? Palette.text1 : Palette.text3)
|
||||
.padding(.horizontal, 10)
|
||||
.padding(.vertical, 6)
|
||||
.background(isHovered || configuration.isPressed ? Palette.hover : .clear, in: RoundedRectangle(cornerRadius: Metrics.radiusSmall))
|
||||
.overlay(RoundedRectangle(cornerRadius: Metrics.radiusSmall).strokeBorder(Palette.raised, lineWidth: Metrics.hairline))
|
||||
.contentShape(Rectangle())
|
||||
.onHover { isHovered = $0 }
|
||||
.animation(Metrics.smallControlTransition, value: isHovered)
|
||||
}
|
||||
}
|
||||
|
||||
extension ButtonStyle where Self == PrimaryButtonStyle {
|
||||
public static var primary: PrimaryButtonStyle { PrimaryButtonStyle() }
|
||||
public static var destructive: PrimaryButtonStyle { PrimaryButtonStyle(destructive: true) }
|
||||
}
|
||||
|
||||
extension ButtonStyle where Self == SecondaryButtonStyle {
|
||||
public static var secondary: SecondaryButtonStyle { SecondaryButtonStyle() }
|
||||
}
|
||||
|
||||
/// The focus treatment used everywhere: a 2pt amber border plus a 2pt 22% amber ring outside it.
|
||||
struct FocusRingModifier: ViewModifier {
|
||||
var isFocused: Bool
|
||||
var cornerRadius: CGFloat
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
content
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: cornerRadius)
|
||||
.strokeBorder(isFocused ? Palette.amber : Palette.raised, lineWidth: isFocused ? Metrics.accentRule : Metrics.hairline)
|
||||
)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: cornerRadius + Metrics.focusRingWidth)
|
||||
.fill(isFocused ? Palette.focusRing : .clear)
|
||||
.padding(-Metrics.focusRingWidth)
|
||||
)
|
||||
.animation(Metrics.smallControlTransition, value: isFocused)
|
||||
}
|
||||
}
|
||||
|
||||
extension View {
|
||||
/// Draws the field border: a hairline at rest, the amber border and ring when focused. Never remove it.
|
||||
public func focusRing(_ isFocused: Bool, cornerRadius: CGFloat = Metrics.radiusSmall) -> some View {
|
||||
modifier(FocusRingModifier(isFocused: isFocused, cornerRadius: cornerRadius))
|
||||
}
|
||||
|
||||
/// Disabled is 40% opacity and nothing else: no recolouring.
|
||||
public func disabledLook(_ isDisabled: Bool) -> some View {
|
||||
opacity(isDisabled ? 0.4 : 1).allowsHitTesting(!isDisabled)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user