restores Helder in all its glory
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import SwiftUI
|
||||
|
||||
/// The stepped on/off blink of the caret, terminal cursor and wordmark period: no fade.
|
||||
struct BlinkModifier: ViewModifier {
|
||||
var isActive: Bool
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
if isActive {
|
||||
TimelineView(.periodic(from: .now, by: Metrics.blinkInterval / 2)) { context in
|
||||
content.opacity(Self.isOn(at: context.date) ? 1 : 0)
|
||||
}
|
||||
} else {
|
||||
content
|
||||
}
|
||||
}
|
||||
|
||||
/// On for the first half of each 1.1s cycle, off for the second.
|
||||
static func isOn(at date: Date) -> Bool {
|
||||
let half = Metrics.blinkInterval / 2
|
||||
return Int(date.timeIntervalSinceReferenceDate / half).isMultiple(of: 2)
|
||||
}
|
||||
}
|
||||
|
||||
extension View {
|
||||
/// Blinks the view with the design's stepped 1.1s cycle.
|
||||
public func blinking(_ isActive: Bool = true) -> some View {
|
||||
modifier(BlinkModifier(isActive: isActive))
|
||||
}
|
||||
}
|
||||
|
||||
/// `Helder` with the blinking amber period.
|
||||
public struct Wordmark: View {
|
||||
var role: TypeRole
|
||||
|
||||
public init(role: TypeRole = Typography.wordmark) {
|
||||
self.role = role
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
HStack(alignment: .firstTextBaseline, spacing: 0) {
|
||||
Text("Helder").foregroundStyle(Palette.text1)
|
||||
Text(".").foregroundStyle(Palette.amber).blinking()
|
||||
}
|
||||
.typeRole(role)
|
||||
.fixedSize()
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
import SwiftUI
|
||||
|
||||
/// The context-menu surface: 320pt, `panel`, hairline border, radius 4, menu shadow, 8pt vertical padding.
|
||||
/// Fill it with a `ContextMenuHeader`, then `ContextMenuRow`s and `ContextMenuSeparator`s.
|
||||
public struct ContextMenuPanel<Content: View>: View {
|
||||
var content: Content
|
||||
|
||||
public init(@ViewBuilder content: () -> Content) {
|
||||
self.content = content()
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
VStack(alignment: .leading, spacing: 0) { content }
|
||||
.padding(.vertical, 8)
|
||||
.frame(width: Metrics.contextMenuWidth, alignment: .leading)
|
||||
.background(Palette.panel, in: RoundedRectangle(cornerRadius: Metrics.radiusMedium))
|
||||
.overlay(RoundedRectangle(cornerRadius: Metrics.radiusMedium).strokeBorder(Palette.raised, lineWidth: Metrics.hairline))
|
||||
.shadow(color: Palette.menuShadow, radius: Metrics.menuShadowRadius / 2, y: Metrics.menuShadowY)
|
||||
}
|
||||
}
|
||||
|
||||
/// The path line at the top of a context menu: mono 11, text-4, hairline below.
|
||||
public struct ContextMenuHeader: View {
|
||||
var text: String
|
||||
|
||||
public init(_ text: String) {
|
||||
self.text = text
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
Text(text)
|
||||
.typeRole(Typography.meta)
|
||||
.foregroundStyle(Palette.text4)
|
||||
.lineLimit(1)
|
||||
.truncationMode(.middle)
|
||||
.padding(.horizontal, 14)
|
||||
.padding(.bottom, 8)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.hairline(.bottom)
|
||||
.padding(.bottom, 8)
|
||||
}
|
||||
}
|
||||
|
||||
/// One 30pt menu item. Highlighted: `raised` fill, 2pt amber left rule, text-1 500 label, amber icon.
|
||||
/// A tinted icon keeps its tint when highlighted; destructive items stay amber-deep in every state.
|
||||
public struct ContextMenuRow: View {
|
||||
var label: String
|
||||
var systemImage: String?
|
||||
var iconTint: Color?
|
||||
var shortcut: String?
|
||||
var isHighlighted: Bool
|
||||
var isDestructive: Bool
|
||||
|
||||
public init(_ label: String, systemImage: String? = nil, iconTint: Color? = nil, shortcut: String? = nil,
|
||||
isHighlighted: Bool, isDestructive: Bool = false) {
|
||||
self.label = label
|
||||
self.systemImage = systemImage
|
||||
self.iconTint = iconTint
|
||||
self.shortcut = shortcut
|
||||
self.isHighlighted = isHighlighted
|
||||
self.isDestructive = isDestructive
|
||||
}
|
||||
|
||||
/// Pass as `systemImage` for the pass-on spark, which has no SF Symbol.
|
||||
nonisolated public static let spark = "helder.spark"
|
||||
|
||||
public var body: some View {
|
||||
HStack(spacing: 10) {
|
||||
if systemImage == Self.spark {
|
||||
SparkGlyph()
|
||||
.stroke(iconColor, style: StrokeStyle(lineWidth: 1.1 * 13 / 16, lineJoin: .round))
|
||||
.frame(width: 13, height: 13)
|
||||
.frame(width: 15)
|
||||
} else if let systemImage {
|
||||
Image(systemName: systemImage)
|
||||
.font(.system(size: 12, weight: .light))
|
||||
.foregroundStyle(iconColor)
|
||||
.frame(width: 15)
|
||||
}
|
||||
Text(label).typeRole(isHighlighted ? Typography.menuItemHighlighted : Typography.menuItem)
|
||||
.foregroundStyle(labelColor)
|
||||
Spacer(minLength: 8)
|
||||
if let shortcut {
|
||||
Text(shortcut).typeRole(Typography.chip).foregroundStyle(Palette.text4)
|
||||
}
|
||||
}
|
||||
.padding(.leading, 16)
|
||||
.padding(.trailing, 14)
|
||||
.frame(height: Metrics.contextMenuItem)
|
||||
.background(isHighlighted ? Palette.raised : .clear)
|
||||
.overlay(alignment: .leading) {
|
||||
Rectangle().fill(isHighlighted ? Palette.amber : .clear).frame(width: Metrics.accentRule)
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
|
||||
private var labelColor: Color {
|
||||
if isDestructive { return Palette.removedText }
|
||||
return isHighlighted ? Palette.text1 : Palette.text3
|
||||
}
|
||||
|
||||
private var iconColor: Color {
|
||||
if isDestructive { return Palette.removedText }
|
||||
if let iconTint { return iconTint }
|
||||
return isHighlighted ? Palette.amber : Palette.text4
|
||||
}
|
||||
}
|
||||
|
||||
/// The 1pt rule between menu groups, with 6pt above and below.
|
||||
public struct ContextMenuSeparator: View {
|
||||
public init() {}
|
||||
|
||||
public var body: some View {
|
||||
Hairline().padding(.vertical, 6)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import SwiftUI
|
||||
|
||||
/// The 1pt `raised` divider. Use it for every border between panels, rows and bars.
|
||||
public struct Hairline: View {
|
||||
var axis: Axis
|
||||
|
||||
/// `.horizontal` draws a line across (a row divider); `.vertical` draws a column divider.
|
||||
public init(_ axis: Axis = .horizontal) {
|
||||
self.axis = axis
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
Rectangle()
|
||||
.fill(Palette.raised)
|
||||
.frame(width: axis == .vertical ? Metrics.hairline : nil,
|
||||
height: axis == .horizontal ? Metrics.hairline : nil)
|
||||
}
|
||||
}
|
||||
|
||||
extension View {
|
||||
/// Draws a hairline along one edge without changing the layout.
|
||||
public func hairline(_ edge: Edge) -> some View {
|
||||
overlay(alignment: edge.alignment) {
|
||||
Hairline(edge == .top || edge == .bottom ? .horizontal : .vertical)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Edge {
|
||||
fileprivate var alignment: Alignment {
|
||||
switch self {
|
||||
case .top: .top
|
||||
case .bottom: .bottom
|
||||
case .leading: .leading
|
||||
case .trailing: .trailing
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
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 active toolbar toggle: the border turns amber.
|
||||
case active
|
||||
/// On a toggle that is off by meaning: glyph and border step back to text-4.
|
||||
case muted
|
||||
/// 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 init(_ keys: String, highlighted: Bool) {
|
||||
self.init(keys, style: highlighted ? .active : .normal)
|
||||
}
|
||||
|
||||
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, .active: Palette.amber
|
||||
case .muted: Palette.text4
|
||||
case .onAmber: Palette.ink
|
||||
case .onDeep: Palette.onDeep
|
||||
}
|
||||
}
|
||||
|
||||
private var border: Color {
|
||||
switch style {
|
||||
case .normal, .muted: Palette.raised
|
||||
case .active: Palette.amberKeycapBorder
|
||||
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()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
import SwiftUI
|
||||
|
||||
/// The frame every overlay sits in: a flat ink scrim (no blur) and a `panel` card with a hairline border,
|
||||
/// radius 8 and the overlay shadow. `.inset` fills the window minus 34pt; `.sized` centres a fixed-width card
|
||||
/// at the top. A click on the scrim calls `onDismiss`.
|
||||
public struct OverlayShell<Content: View>: View {
|
||||
public enum Placement {
|
||||
/// Search, Diff: the whole window minus the 34pt inset.
|
||||
case inset
|
||||
/// A card of this width, top-aligned inside the inset.
|
||||
case sized(width: CGFloat)
|
||||
}
|
||||
|
||||
var placement: Placement
|
||||
var onDismiss: () -> Void
|
||||
var content: Content
|
||||
|
||||
public init(_ placement: Placement = .inset, onDismiss: @escaping () -> Void, @ViewBuilder content: () -> Content) {
|
||||
self.placement = placement
|
||||
self.onDismiss = onDismiss
|
||||
self.content = content()
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
ZStack(alignment: .top) {
|
||||
Palette.scrim
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture(perform: onDismiss)
|
||||
card
|
||||
.padding(Metrics.overlayInset)
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var card: some View {
|
||||
switch placement {
|
||||
case .inset:
|
||||
OverlayCard { content }
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
case let .sized(width):
|
||||
OverlayCard { content }
|
||||
.frame(width: width)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The overlay card alone, for surfaces that place themselves (the launcher, the pass-on prompt).
|
||||
public struct OverlayCard<Content: View>: View {
|
||||
var content: Content
|
||||
|
||||
public init(@ViewBuilder content: () -> Content) {
|
||||
self.content = content()
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
content
|
||||
.background(Palette.panel)
|
||||
.clipShape(RoundedRectangle(cornerRadius: Metrics.radiusOverlay))
|
||||
.overlay(RoundedRectangle(cornerRadius: Metrics.radiusOverlay).strokeBorder(Palette.raised, lineWidth: Metrics.hairline))
|
||||
.shadow(color: Palette.overlayShadow, radius: Metrics.overlayShadowRadius / 2, y: Metrics.overlayShadowY)
|
||||
}
|
||||
}
|
||||
|
||||
/// An overlay's header row: glyph (amber by default), mono 700 14 title, an optional mono detail right after it,
|
||||
/// optional trailing content, then the `esc` chip unless `showsEscChip` is false.
|
||||
public struct OverlayHeader<Trailing: View>: View {
|
||||
var systemImage: String
|
||||
var title: String
|
||||
var detail: String?
|
||||
var iconColor: Color
|
||||
var showsEscChip: Bool
|
||||
var height: CGFloat
|
||||
var trailing: Trailing
|
||||
|
||||
public init(systemImage: String, title: String, detail: String? = nil, iconColor: Color = Palette.amber,
|
||||
showsEscChip: Bool = true, height: CGFloat = 50, @ViewBuilder trailing: () -> Trailing) {
|
||||
self.systemImage = systemImage
|
||||
self.title = title
|
||||
self.detail = detail
|
||||
self.iconColor = iconColor
|
||||
self.showsEscChip = showsEscChip
|
||||
self.height = height
|
||||
self.trailing = trailing()
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
HStack(spacing: 12) {
|
||||
Image(systemName: systemImage).font(.system(size: 14, weight: .light)).foregroundStyle(iconColor)
|
||||
Text(title).typeRole(Typography.dialogTitle).foregroundStyle(Palette.text1)
|
||||
if let detail {
|
||||
Text(detail).typeRole(Typography.path).foregroundStyle(Palette.text4).lineLimit(1)
|
||||
}
|
||||
Spacer(minLength: 12)
|
||||
trailing
|
||||
if showsEscChip { EscChip() }
|
||||
}
|
||||
.padding(.horizontal, 18)
|
||||
.frame(height: height)
|
||||
.hairline(.bottom)
|
||||
}
|
||||
}
|
||||
|
||||
extension OverlayHeader where Trailing == EmptyView {
|
||||
public init(systemImage: String, title: String, detail: String? = nil, iconColor: Color = Palette.amber,
|
||||
showsEscChip: Bool = true, height: CGFloat = 50) {
|
||||
self.init(systemImage: systemImage, title: title, detail: detail, iconColor: iconColor,
|
||||
showsEscChip: showsEscChip, height: height) { EmptyView() }
|
||||
}
|
||||
}
|
||||
|
||||
/// An overlay footer (38pt): mono 11 key hints with amber glyphs. Build the hints with `OverlayFooter.hint`.
|
||||
public struct OverlayFooter<Trailing: View>: View {
|
||||
var hints: Text
|
||||
var trailing: Trailing
|
||||
|
||||
public init(_ hints: Text, @ViewBuilder trailing: () -> Trailing) {
|
||||
self.hints = hints
|
||||
self.trailing = trailing()
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
HStack(spacing: 14) {
|
||||
hints.typeRole(Typography.chip)
|
||||
Spacer(minLength: 0)
|
||||
trailing
|
||||
}
|
||||
.padding(.horizontal, 18)
|
||||
.frame(height: 38)
|
||||
.hairline(.top)
|
||||
}
|
||||
}
|
||||
|
||||
extension OverlayFooter where Trailing == EmptyView {
|
||||
public init(_ hints: Text) {
|
||||
self.init(hints) { EmptyView() }
|
||||
}
|
||||
|
||||
/// "⌘↑↓ navigate · ↵ open": pass pairs of (keys, action).
|
||||
public static func hint(_ pairs: [(keys: String, action: String)]) -> Text {
|
||||
pairs.enumerated().reduce(Text("")) { text, item in
|
||||
let (index, pair) = item
|
||||
let separator = index == 0 ? Text("") : Text(" · ").foregroundColor(Palette.text4)
|
||||
return text + separator + Text(pair.keys).foregroundColor(Palette.amber) + Text(" " + pair.action).foregroundColor(Palette.text4)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import SwiftUI
|
||||
|
||||
/// The 10pt uppercase mono label over a panel or section, with an optional amber count.
|
||||
public struct PanelLabel: View {
|
||||
var title: String
|
||||
var count: Int?
|
||||
|
||||
public init(_ title: String, count: Int? = nil) {
|
||||
self.title = title
|
||||
self.count = count
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
HStack {
|
||||
Text(title).typeRole(Typography.panelLabel).foregroundStyle(Palette.text4)
|
||||
Spacer()
|
||||
if let count {
|
||||
Text("\(count)").typeRole(Typography.panelLabel).foregroundStyle(Palette.amber)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A column's header bar: the panel label left, optional trailing content, hairline below.
|
||||
/// Use it at the top of Explorer, Source Control groups and code panels.
|
||||
public struct PanelHeader<Trailing: View>: View {
|
||||
var title: String
|
||||
var height: CGFloat
|
||||
var trailing: Trailing
|
||||
|
||||
public init(_ title: String, height: CGFloat = Metrics.panelHeader, @ViewBuilder trailing: () -> Trailing) {
|
||||
self.title = title
|
||||
self.height = height
|
||||
self.trailing = trailing()
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
HStack(spacing: 8) {
|
||||
Text(title).typeRole(Typography.panelLabel).foregroundStyle(Palette.text4)
|
||||
Spacer(minLength: 8)
|
||||
trailing
|
||||
}
|
||||
.padding(.horizontal, 12)
|
||||
.frame(height: height)
|
||||
.hairline(.bottom)
|
||||
}
|
||||
}
|
||||
|
||||
extension PanelHeader where Trailing == EmptyView {
|
||||
public init(_ title: String, height: CGFloat = Metrics.panelHeader) {
|
||||
self.init(title, height: height) { EmptyView() }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
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)
|
||||
.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)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import SwiftUI
|
||||
|
||||
/// Row states shared by every list (git rows, tree rows, launcher, search hits): hover is one fill step,
|
||||
/// selected is `raised` with the 2pt amber rule on the left. Nothing lifts, scales or fades.
|
||||
struct SelectableRowModifier: ViewModifier {
|
||||
var isSelected: Bool
|
||||
var isHovered: Bool
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
content
|
||||
.background(isSelected ? Palette.raised : isHovered ? Palette.hover : .clear)
|
||||
.overlay(alignment: .leading) {
|
||||
Rectangle().fill(isSelected ? Palette.amber : .clear).frame(width: Metrics.accentRule)
|
||||
}
|
||||
.animation(Metrics.colorTransition, value: isHovered)
|
||||
}
|
||||
}
|
||||
|
||||
extension View {
|
||||
/// Applies the selected and hover fills plus the amber selection rule.
|
||||
public func selectableRow(isSelected: Bool, isHovered: Bool = false) -> some View {
|
||||
modifier(SelectableRowModifier(isSelected: isSelected, isHovered: isHovered))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
import AppKit
|
||||
import SwiftUI
|
||||
|
||||
/// A 1pt hairline divider that resizes what is next to it. The pointer target reaches 3pt past the line
|
||||
/// on both sides; hover and drag turn the line amber. `onDrag` receives the movement since the last call.
|
||||
public struct Splitter: View {
|
||||
var axis: Axis
|
||||
var onDrag: (Double) -> Void
|
||||
var onEnd: () -> Void
|
||||
@State private var isHovered = false
|
||||
@State private var isDragging = false
|
||||
@State private var last: CGFloat = 0
|
||||
|
||||
/// `.vertical` is a column divider dragged left and right; `.horizontal` a row divider dragged up and down.
|
||||
public init(_ axis: Axis = .vertical, onDrag: @escaping (Double) -> Void, onEnd: @escaping () -> Void = {}) {
|
||||
self.axis = axis
|
||||
self.onDrag = onDrag
|
||||
self.onEnd = onEnd
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
Rectangle()
|
||||
.fill(isHovered || isDragging ? Palette.amber : Palette.raised)
|
||||
.frame(width: axis == .vertical ? Metrics.hairline : nil, height: axis == .horizontal ? Metrics.hairline : nil)
|
||||
.overlay {
|
||||
Color.clear
|
||||
.frame(width: axis == .vertical ? Metrics.splitterHitArea : nil,
|
||||
height: axis == .horizontal ? Metrics.splitterHitArea : nil)
|
||||
.contentShape(Rectangle())
|
||||
.onHover(perform: hover)
|
||||
.gesture(drag)
|
||||
}
|
||||
.zIndex(5)
|
||||
.animation(Metrics.smallControlTransition, value: isHovered || isDragging)
|
||||
}
|
||||
|
||||
private var drag: some Gesture {
|
||||
DragGesture(minimumDistance: 0, coordinateSpace: .global)
|
||||
.onChanged { value in
|
||||
let position = axis == .vertical ? value.translation.width : value.translation.height
|
||||
if !isDragging {
|
||||
isDragging = true
|
||||
last = 0
|
||||
}
|
||||
onDrag(Double(position - last))
|
||||
last = position
|
||||
}
|
||||
.onEnded { _ in
|
||||
isDragging = false
|
||||
last = 0
|
||||
if !isHovered { NSCursor.pop() }
|
||||
onEnd()
|
||||
}
|
||||
}
|
||||
|
||||
private func hover(_ inside: Bool) {
|
||||
guard inside != isHovered else { return }
|
||||
isHovered = inside
|
||||
if isDragging { return }
|
||||
if inside {
|
||||
(axis == .vertical ? NSCursor.resizeLeftRight : NSCursor.resizeUpDown).push()
|
||||
} else {
|
||||
NSCursor.pop()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import SwiftUI
|
||||
|
||||
/// A title-bar toggle: Sans 12 label plus keycap. Off has no fill; on gets the amber tint and an amber keycap border;
|
||||
/// `muted` is for a toggle that is off by meaning (hidden files), where label and keycap step back to text-4.
|
||||
public struct ToolbarToggle: View {
|
||||
var label: String
|
||||
var keys: String
|
||||
var isOn: Bool
|
||||
var isMuted: Bool
|
||||
var action: () -> Void
|
||||
@State private var isHovered = false
|
||||
|
||||
public init(_ label: String, keys: String, isOn: Bool, muted: Bool = false, action: @escaping () -> Void) {
|
||||
self.label = label
|
||||
self.keys = keys
|
||||
self.isOn = isOn
|
||||
isMuted = muted
|
||||
self.action = action
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
Button(action: action) {
|
||||
HStack(spacing: 8) {
|
||||
Text(label).typeRole(isOn ? Typography.toolbarLabelOn : Typography.toolbarLabel)
|
||||
Keycap(keys, style: isOn ? .active : isMuted ? .muted : .normal)
|
||||
}
|
||||
.foregroundStyle(labelColor)
|
||||
.padding(Metrics.toolbarPadding)
|
||||
.background(fill, in: RoundedRectangle(cornerRadius: Metrics.radiusSmall))
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.onHover { isHovered = $0 }
|
||||
.animation(Metrics.smallControlTransition, value: isHovered)
|
||||
.animation(Metrics.smallControlTransition, value: isOn)
|
||||
}
|
||||
|
||||
private var labelColor: Color {
|
||||
if isOn { return Palette.text1 }
|
||||
if isMuted { return isHovered ? Palette.text3 : Palette.text4 }
|
||||
return isHovered ? Palette.text1 : Palette.text3
|
||||
}
|
||||
|
||||
private var fill: Color {
|
||||
if isOn { return Palette.amberTint }
|
||||
return isHovered && !isMuted ? Palette.hover : .clear
|
||||
}
|
||||
}
|
||||
|
||||
/// The icon-only title-bar control (the `?`): a 26pt square with a hairline border.
|
||||
public struct ToolbarIconButton: View {
|
||||
var glyph: String
|
||||
var action: () -> Void
|
||||
@State private var isHovered = false
|
||||
|
||||
public init(_ glyph: String, action: @escaping () -> Void) {
|
||||
self.glyph = glyph
|
||||
self.action = action
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
Button(action: action) {
|
||||
Text(glyph)
|
||||
.typeRole(Typography.keycap)
|
||||
.foregroundStyle(isHovered ? Palette.text1 : Palette.text4)
|
||||
.frame(width: Metrics.toolbarIconButton, height: Metrics.toolbarIconButton)
|
||||
.background(isHovered ? Palette.hover : .clear, in: RoundedRectangle(cornerRadius: Metrics.radiusSmall))
|
||||
.overlay(RoundedRectangle(cornerRadius: Metrics.radiusSmall).strokeBorder(Palette.raised, lineWidth: Metrics.hairline))
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.onHover { isHovered = $0 }
|
||||
.animation(Metrics.smallControlTransition, value: isHovered)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
import SwiftUI
|
||||
|
||||
/// The design's tooltip: `raised` surface, text-5 border, radius 2, Sans 12/1.5, no arrow, no shadow.
|
||||
/// Name the current state in amber with `Tooltip.stated`, then say what a click does.
|
||||
public struct Tooltip: View {
|
||||
var text: Text
|
||||
|
||||
public init(_ text: Text) {
|
||||
self.text = text
|
||||
}
|
||||
|
||||
public init(_ string: String) {
|
||||
text = Text(string)
|
||||
}
|
||||
|
||||
/// "Lead: *state* — rest", with the state word in amber.
|
||||
public static func stated(_ lead: String, _ state: String, _ rest: String) -> Text {
|
||||
Text(lead).foregroundColor(Palette.text2) + Text(state).foregroundColor(Palette.amber) + Text(rest).foregroundColor(Palette.text2)
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
text
|
||||
.typeRole(Typography.tooltip)
|
||||
.foregroundStyle(Palette.text2)
|
||||
.multilineTextAlignment(.leading)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.padding(.horizontal, 10)
|
||||
.padding(.vertical, 8)
|
||||
.frame(maxWidth: Metrics.tooltipMaxWidth, alignment: .leading)
|
||||
.fixedSize()
|
||||
.background(Palette.raised, in: RoundedRectangle(cornerRadius: Metrics.radiusSmall))
|
||||
.overlay(RoundedRectangle(cornerRadius: Metrics.radiusSmall).strokeBorder(Palette.tooltipBorder, lineWidth: Metrics.hairline))
|
||||
}
|
||||
}
|
||||
|
||||
struct TooltipModifier: ViewModifier {
|
||||
var text: Text
|
||||
var edge: HorizontalAlignment
|
||||
@State private var isShown = false
|
||||
@State private var pending: Task<Void, Never>?
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
content
|
||||
.onHover { inside in
|
||||
pending?.cancel()
|
||||
if inside {
|
||||
pending = Task { @MainActor in
|
||||
try? await Task.sleep(for: Metrics.tooltipDelay)
|
||||
if !Task.isCancelled { isShown = true }
|
||||
}
|
||||
} else {
|
||||
isShown = false
|
||||
}
|
||||
}
|
||||
.simultaneousGesture(TapGesture().onEnded { pending?.cancel(); isShown = false })
|
||||
.overlay(alignment: Alignment(horizontal: edge, vertical: .bottom)) {
|
||||
if isShown {
|
||||
Tooltip(text)
|
||||
.alignmentGuide(.bottom) { $0[.top] - 8 }
|
||||
.allowsHitTesting(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension View {
|
||||
/// Shows a design tooltip 350ms after the pointer rests on the view, 8pt below it.
|
||||
/// The host must sit above its neighbours (`zIndex`) so the tip is not drawn under them.
|
||||
public func tip(_ text: Text, edge: HorizontalAlignment = .leading) -> some View {
|
||||
modifier(TooltipModifier(text: text, edge: edge))
|
||||
}
|
||||
|
||||
public func tip(_ string: String, edge: HorizontalAlignment = .leading) -> some View {
|
||||
tip(Text(string), edge: edge)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import HelderCore
|
||||
import SwiftUI
|
||||
|
||||
/// The per-extension chip: a fixed 28pt wide, mono 600 10 in ink on the badge fill, radius 2.
|
||||
/// The fixed width keeps the file names beside it in one column.
|
||||
public struct TypeBadge: View {
|
||||
var badge: FileBadge
|
||||
|
||||
public init(path: String) {
|
||||
badge = FileType.badge(for: path)
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
Text(badge.text)
|
||||
.typeRole(TypeRole(.monoSemiBold, 10))
|
||||
.foregroundStyle(Palette.badgeText)
|
||||
.lineLimit(1)
|
||||
.frame(width: 28, height: 16)
|
||||
.background(Palette.badge(badge.tint), in: RoundedRectangle(cornerRadius: Metrics.radiusSmall))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user