import SwiftUI /// A key hint: 12pt mono 600, amber glyph, 1pt border, radius 2. Use it for every shortcut shown in the UI. public struct Keycap: View { public enum Style { /// Amber glyph, raised border. case normal /// On an amber fill (primary button): ink glyph, ink border. case onAmber /// On an amber-deep fill (destructive button): light glyph, light border. case onDeep } var keys: String var style: Style var role: TypeRole public init(_ keys: String, style: Style = .normal, small: Bool = false) { self.keys = keys self.style = style role = small ? Typography.keycapSmall : Typography.keycap } public var body: some View { Text(keys) .typeRole(role) .foregroundStyle(glyph) .padding(.horizontal, 6) .padding(.vertical, 4) .overlay(RoundedRectangle(cornerRadius: Metrics.radiusSmall).strokeBorder(border, lineWidth: Metrics.hairline)) .fixedSize() } private var glyph: Color { switch style { case .normal: Palette.amber case .onAmber: Palette.ink case .onDeep: Palette.onDeep } } private var border: Color { switch style { case .normal: Palette.raised case .onAmber: Palette.inkKeycapBorder case .onDeep: Palette.onDeep.opacity(0.4) } } } /// The `esc` (or `↵`) chip at the right of an overlay header or footer: mono 11, text-4, hairline border. public struct EscChip: View { var label: String public init(_ label: String = "esc") { self.label = label } public var body: some View { Text(label) .typeRole(Typography.chip) .foregroundStyle(Palette.text4) .padding(.horizontal, 6) .padding(.vertical, 4) .overlay(RoundedRectangle(cornerRadius: Metrics.radiusSmall).strokeBorder(Palette.raised, lineWidth: Metrics.hairline)) .fixedSize() } }