Textley / app · textley.ai / Sources / Textley / TextleyGlass.swift
| 1 | import AppKit |
| 2 | import SwiftUI |
| 3 | |
| 4 | enum TextleyTheme { |
| 5 | static let accent = Color(nsColor: NSColor(name: nil) { appearance in |
| 6 | if appearance.bestMatch(from: [.aqua, .darkAqua]) == .darkAqua { |
| 7 | return NSColor(srgbRed: 198 / 255, green: 178 / 255, blue: 250 / 255, alpha: 1) |
| 8 | } |
| 9 | return NSColor(srgbRed: 101 / 255, green: 69 / 255, blue: 168 / 255, alpha: 1) |
| 10 | }) |
| 11 | } |
| 12 | |
| 13 | struct TextleyGlassGroup<Content: View>: View { |
| 14 | let spacing: CGFloat |
| 15 | @ViewBuilder let content: () -> Content |
| 16 | |
| 17 | var body: some View { |
| 18 | if #available(macOS 26, *) { |
| 19 | GlassEffectContainer(spacing: spacing, content: content) |
| 20 | } else { |
| 21 | content() |
| 22 | } |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | extension View { |
| 27 | @ViewBuilder |
| 28 | func textleyGlassButton(prominent: Bool = false) -> some View { |
| 29 | if #available(macOS 26, *) { |
| 30 | if prominent { |
| 31 | buttonStyle(.glassProminent) |
| 32 | } else { |
| 33 | buttonStyle(.glass).tint(nil) |
| 34 | } |
| 35 | } else if prominent { |
| 36 | buttonStyle(.borderedProminent) |
| 37 | } else { |
| 38 | buttonStyle(.bordered) |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | @ViewBuilder |
| 43 | func textleyGlassSurface<S: Shape>(_ shape: S, tint: Color? = nil, interactive: Bool = false) -> some View { |
| 44 | if #available(macOS 26, *) { |
| 45 | glassEffect(.regular.tint(tint).interactive(interactive), in: shape) |
| 46 | } else { |
| 47 | background { |
| 48 | shape |
| 49 | .fill(.regularMaterial) |
| 50 | .overlay { shape.fill(tint ?? .clear) } |
| 51 | .overlay { shape.stroke(Color.primary.opacity(0.12), lineWidth: 1) } |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | } |