SPB Git

Repository Public

Theme.swift 5.5 KB 146 lines swift

1import AppKit2import SwiftUI34/// Mac-side names of the design tokens. Since 3.0 every value comes from AURA UI (`Shared/Aura/AuraTokens.swift`);5/// this enum only keeps the names the Mac views have always used.6enum Theme {7    static let radiusS = Aura.Radius.s, radiusM = Aura.Radius.m, radiusL = Aura.Radius.l, radiusXL = Aura.Radius.xl89    static let accent = Aura.Palette.accent10    static let electricBlue = Aura.Palette.electricBlue11    static let cyan = Aura.Palette.cyan12    static let violet = Aura.Palette.violet13    static let brandGradient = Aura.gradient14    static let privateTint = Aura.Palette.violet1516    /// Palette used for workspaces, tab groups and profiles.17    static let palette = Aura.Palette.identity18    static func color(_ index: Int) -> Color { Aura.Palette.identity(index) }19    static func adaptive(light: NSColor, dark: NSColor) -> Color { Aura.Palette.adaptive(light: light, dark: dark) }2021    static let chrome = Aura.Palette.chrome22    static let surface = Aura.Palette.surface23    static let field = Aura.Palette.field24    static let hairline = Aura.Palette.hairline25    static let hover = Aura.Palette.hover26    static let selected = Aura.Palette.selected2728    /// The standard panel animation. New code names a motion token instead (`AuraMotion.animation(.standard)`).29    @MainActor static func animation(_ reduceMotion: Bool) -> Animation? { AuraMotion.animation(.standard, policy: MotionPolicy(reduceMotion: reduceMotion)) }30}3132struct VisualEffect: NSViewRepresentable {33    var material: NSVisualEffectView.Material = .sidebar34    var blending: NSVisualEffectView.BlendingMode = .behindWindow3536    func makeNSView(context: Context) -> NSVisualEffectView {37        let view = NSVisualEffectView()38        view.state = .followsWindowActiveState39        return view40    }4142    func updateNSView(_ view: NSVisualEffectView, context: Context) {43        view.material = material44        view.blendingMode = blending45    }46}4748/// The standard toolbar button is the AURA icon button.49typealias IconButton = AuraIconButton5051/// Full-area message used for empty, error, offline and crash states.52struct StateView: View {53    let symbol: String54    let title: String55    var message: String = ""56    var tint: Color = .secondary57    var actionTitle: String?58    var action: (() -> Void)?59    var compact = false6061    var body: some View {62        VStack(spacing: compact ? 8 : 14) {63            Image(systemName: symbol)64                .font(.system(size: compact ? 26 : 44, weight: .light))65                .foregroundStyle(tint)66                .accessibilityHidden(true)67            Text(title).font(compact ? .headline : .title2.weight(.semibold)).multilineTextAlignment(.center)68            if !message.isEmpty {69                Text(message).font(compact ? .callout : .body).foregroundStyle(.secondary)70                    .multilineTextAlignment(.center).frame(maxWidth: 460).fixedSize(horizontal: false, vertical: true)71            }72            if let actionTitle, let action {73                Button(actionTitle, action: action).controlSize(compact ? .regular : .large).buttonStyle(.borderedProminent).padding(.top, 4)74            }75        }76        .padding(compact ? 16 : 32)77        .frame(maxWidth: .infinity, maxHeight: .infinity)78        .accessibilityElement(children: .combine)79    }80}8182struct Favicon: View {83    let image: NSImage?84    let fallback: String85    var size: CGFloat = 168687    var body: some View {88        Group {89            if let image {90                Image(nsImage: image).resizable().interpolation(.high)91            } else {92                RoundedRectangle(cornerRadius: size * 0.25, style: .continuous).fill(Color.secondary.opacity(0.22))93                    .overlay(Text(String(fallback.prefix(1)).uppercased()).font(.system(size: size * 0.6, weight: .semibold)).foregroundStyle(.secondary))94            }95        }96        .frame(width: size, height: size)97        .clipShape(RoundedRectangle(cornerRadius: size * 0.22, style: .continuous))98        .accessibilityHidden(true)99    }100}101102/// A row that highlights on hover and when selected — used in the sidebar, palette and suggestion lists.103struct HoverRow<Content: View>: View {104    var isSelected = false105    var radius: CGFloat = Theme.radiusS106    @ViewBuilder var content: () -> Content107    @State private var hovering = false108109    var body: some View {110        content()111            .frame(maxWidth: .infinity, alignment: .leading)112            .background(RoundedRectangle(cornerRadius: radius, style: .continuous)113                .fill(isSelected ? Theme.selected : (hovering ? Theme.hover : .clear))114                .shadow(color: .black.opacity(isSelected ? 0.08 : 0), radius: 1.5, y: 0.5))115            .contentShape(Rectangle())116            .onHover { hovering = $0 }117    }118}119120struct SectionLabel: View {121    let text: String122    var body: some View {123        AuraSectionHeader(text: text)124    }125}126127extension View {128    /// Card surface used by panels and popovers.129    func cardSurface(radius: CGFloat = Theme.radiusL) -> some View {130        background(RoundedRectangle(cornerRadius: radius, style: .continuous).fill(Theme.surface))131            .overlay(RoundedRectangle(cornerRadius: radius, style: .continuous).strokeBorder(Theme.hairline))132    }133}134135extension Date {136    var relativeShort: String {137        let formatter = RelativeDateTimeFormatter()138        formatter.unitsStyle = .abbreviated139        return formatter.localizedString(for: self, relativeTo: Date())140    }141}142143func formattedBytes(_ count: Int64) -> String {144    ByteCountFormatter.string(fromByteCount: max(count, 0), countStyle: .file)145}146
Files main
Menu

Theme