import SwiftUI /// The frame every overlay sits in. `.sized` puts a top-aligned `panel` card on a flat ink scrim, and a click /// on the scrim calls `onDismiss`; `.fullScreen` fills the window edge to edge on the slate page, like the Git view. public struct OverlayShell: View { public enum Placement { /// Search: the whole window, title bar and status bar included, with no scrim to click. case fullScreen /// 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, onDismiss: @escaping () -> Void, @ViewBuilder content: () -> Content) { self.placement = placement self.onDismiss = onDismiss self.content = content() } public var body: some View { switch placement { case .fullScreen: content .frame(maxWidth: .infinity, maxHeight: .infinity) .background(Palette.editor) .contentShape(Rectangle()) case let .sized(width): ZStack(alignment: .top) { Palette.scrim .contentShape(Rectangle()) .onTapGesture(perform: onDismiss) OverlayCard { content } .frame(width: width) .padding(Metrics.overlayInset) } } } } /// The overlay card alone, for surfaces that place themselves (the launcher, the pass-on prompt). public struct OverlayCard: 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: 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: 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) } } }