import SwiftUI #if os(macOS) import AppKit #else import UIKit #endif // Graphley's own controls (design/DESIGN.md, section 2). The window, sidebar container, toolbar, // menus, sheets and confirmation dialogs stay native; everything inside the content uses these. // MARK: Buttons public struct TideButtonStyle: ButtonStyle { public enum Kind { case primary, secondary, quiet, destructive, quietDestructive } public enum Size { case small, regular, large } let kind: Kind, size: Size public init(_ kind: Kind = .secondary, size: Size = .regular) { self.kind = kind; self.size = size } public func makeBody(configuration c: Configuration) -> some View { Styled(configuration: c, kind: kind, size: size) } struct Styled: View { let configuration: Configuration, kind: Kind, size: Size @Environment(\.isEnabled) private var enabled @State private var hover = false var body: some View { let pressed = configuration.isPressed configuration.label .font(Tide.sans(fontSize, .semibold)) .labelStyle(TideLabelStyle()) .lineLimit(1) .padding(.horizontal, size == .small ? 10 : size == .large ? 18 : 14) .frame(minHeight: height) .foregroundStyle(fg(pressed)) .background(bg(pressed), in: RoundedRectangle(cornerRadius: 8)) .overlay(RoundedRectangle(cornerRadius: 8).strokeBorder(border(pressed), lineWidth: 1)) .contentShape(RoundedRectangle(cornerRadius: 8)) .onHover { hover = $0 } .animation(.easeOut(duration: 0.15), value: hover) .animation(.easeOut(duration: 0.1), value: pressed) } var fontSize: CGFloat { Tide.phone ? 16 : size == .small ? 12 : size == .large ? 14 : 13 } var height: CGFloat { Tide.phone ? 44 : size == .small ? 24 : size == .large ? 36 : 30 } func fg(_ pressed: Bool) -> Color { guard enabled else { return Tide.muted } switch kind { case .primary: return Tide.accentInk case .secondary: return Tide.ink case .quiet: return Tide.accent case .destructive: return Tide.onDown case .quietDestructive: return Tide.downText } } func bg(_ pressed: Bool) -> Color { switch kind { case .primary: return !enabled ? Tide.sunk : pressed ? Tide.fillPressed : hover ? Tide.fillHover : Tide.fill case .secondary: return !enabled ? Tide.surface : pressed ? Tide.sunk : hover ? Tide.surface2 : Tide.surface case .quiet: return !enabled ? .clear : pressed ? Tide.accentTint2 : hover ? Tide.accentTint : .clear case .destructive: return !enabled ? Tide.sunk : pressed ? Tide.downPressed : hover ? Tide.downHover : Tide.down case .quietDestructive: return !enabled ? .clear : (pressed || hover) ? Tide.down.opacity(0.12) : .clear } } func border(_ pressed: Bool) -> Color { switch kind { case .secondary: return !enabled ? Tide.line : (pressed || hover) ? Tide.accent : Tide.line2 case .quietDestructive: return pressed ? Tide.down : .clear default: return .clear } } } } /// Icon, 6 pt gap, title. Keeps SF Symbols at 13 pt next to button text. struct TideLabelStyle: LabelStyle { func makeBody(configuration: Configuration) -> some View { HStack(spacing: 6) { configuration.icon.font(.system(size: 12, weight: .semibold)); configuration.title } } } public extension ButtonStyle where Self == TideButtonStyle { static var tidePrimary: TideButtonStyle { TideButtonStyle(.primary) } static var tideSecondary: TideButtonStyle { TideButtonStyle(.secondary) } static var tideQuiet: TideButtonStyle { TideButtonStyle(.quiet) } static func tide(_ kind: TideButtonStyle.Kind, size: TideButtonStyle.Size = .regular) -> TideButtonStyle { TideButtonStyle(kind, size: size) } } /// 28×28 glyph button for toolbars and rows. Always give it `.help` and an accessibility label. public struct IconButtonStyle: ButtonStyle { public init() {} public func makeBody(configuration c: Configuration) -> some View { Styled(configuration: c) } struct Styled: View { let configuration: Configuration @Environment(\.isEnabled) private var enabled @State private var hover = false var body: some View { configuration.label .labelStyle(.iconOnly) .font(.system(size: 14, weight: .medium)) .foregroundStyle(!enabled ? Tide.line2 : hover ? Tide.ink : Tide.muted) .frame(width: Tide.phone ? 44 : 28, height: Tide.phone ? 44 : 28) .background(configuration.isPressed ? Tide.sunk : hover && enabled ? Tide.surface2 : .clear, in: RoundedRectangle(cornerRadius: 7)) .contentShape(RoundedRectangle(cornerRadius: 7)) .onHover { hover = $0 } .animation(.easeOut(duration: 0.15), value: hover) } } } public extension ButtonStyle where Self == IconButtonStyle { static var tideIcon: IconButtonStyle { IconButtonStyle() } } /// Copies `text`, then shows "Copied" for 1.5 seconds. public struct CopyButton: View { let text: String, label: String @State private var copied = false public init(_ text: String, label: String = "Copy") { self.text = text; self.label = label } public var body: some View { Button { Clipboard.copy(text) copied = true AccessibilityNotification.Announcement("Copied").post() Task { try? await Task.sleep(for: .seconds(1.5)); copied = false } } label: { ZStack { Label(label, systemImage: "doc.on.doc").opacity(copied ? 0 : 1) Label("Copied", systemImage: "checkmark").foregroundStyle(Tide.up).opacity(copied ? 1 : 0) } } .buttonStyle(.tide(.secondary, size: .small)) .help("Copy to the clipboard") } } public enum Clipboard { public static func copy(_ text: String) { #if os(macOS) NSPasteboard.general.clearContents(); NSPasteboard.general.setString(text, forType: .string) #else UIPasteboard.general.string = text #endif } } // MARK: Toggle /// 32×18 switch in Tide colors (Mac). The iPhone keeps the native switch with the accent tint. public struct TideToggleStyle: ToggleStyle { public init() {} public func makeBody(configuration c: Configuration) -> some View { HStack(alignment: .firstTextBaseline) { c.label Spacer(minLength: 12) Switch(isOn: c.$isOn) } .contentShape(Rectangle()) .onTapGesture { Switch.flip(c.$isOn) } } struct Switch: View { @Binding var isOn: Bool @Environment(\.isEnabled) private var enabled @Environment(\.accessibilityReduceMotion) private var reduceMotion static func flip(_ binding: Binding) { binding.wrappedValue.toggle() } var body: some View { ZStack(alignment: isOn ? .trailing : .leading) { Capsule().fill(isOn ? Tide.fill : Tide.control).frame(width: 32, height: 18) Circle().fill(Tide.knob).frame(width: 14, height: 14).padding(2).shadow(color: .black.opacity(0.18), radius: 0.5, y: 1) } .opacity(enabled ? 1 : 0.45) .animation(reduceMotion ? nil : .spring(duration: 0.18), value: isOn) .alignmentGuide(.firstTextBaseline) { $0[VerticalAlignment.center] + 4 } .accessibilityHidden(true) } } } /// Settings row: title, description, switch on the trailing edge. The whole row toggles. public struct ToggleRow: View { let title: String, detail: String @Binding var isOn: Bool public init(_ title: String, detail: String, isOn: Binding) { self.title = title; self.detail = detail; _isOn = isOn } public var body: some View { #if os(macOS) Toggle(isOn: $isOn) { RowText(title: title, detail: detail) } .toggleStyle(TideToggleStyle()) .accessibilityElement(children: .ignore) .accessibilityLabel(title).accessibilityHint(detail) .accessibilityValue(isOn ? "On" : "Off") .accessibilityAddTraits(.isButton) .accessibilityAction { isOn.toggle() } #else Toggle(isOn: $isOn) { RowText(title: title, detail: detail) }.tint(Tide.accent) #endif } } struct RowText: View { let title: String, detail: String var body: some View { VStack(alignment: .leading, spacing: 3) { Text(title).font(Tide.rowTitle).foregroundStyle(Tide.ink) if !detail.isEmpty { Text(detail).font(Tide.secondary).foregroundStyle(Tide.muted).frame(maxWidth: 440, alignment: .leading) .fixedSize(horizontal: false, vertical: true) } } } } // MARK: Text field public struct TideField: View { let label: String, placeholder: String, help: String?, error: String?, monospaced: Bool @Binding var text: String @FocusState private var focused: Bool @State private var hover = false public init(_ label: String, text: Binding, placeholder: String = "", help: String? = nil, error: String? = nil, monospaced: Bool = false) { self.label = label; _text = text; self.placeholder = placeholder; self.help = help; self.error = error; self.monospaced = monospaced } public var body: some View { VStack(alignment: .leading, spacing: 6) { Text(label).font(Tide.fieldLabel).foregroundStyle(Tide.ink) TextField(label, text: $text, prompt: Text(placeholder).foregroundStyle(Tide.muted)) .textFieldStyle(.plain) .labelsHidden() .font(monospaced ? Tide.figure(13) : Tide.sans(13)) .autocorrectionDisabled() .focused($focused) .padding(.horizontal, 10) .frame(height: Tide.phone ? 44 : 30) .background(Tide.ground, in: RoundedRectangle(cornerRadius: 8)) .overlay(RoundedRectangle(cornerRadius: 8).strokeBorder(borderColor, lineWidth: focused || error != nil ? 2 : 1)) .onHover { hover = $0 } .focusEffectDisabled() if let error { Label(error, systemImage: "exclamationmark.circle.fill").font(Tide.caption).foregroundStyle(Tide.downText) .fixedSize(horizontal: false, vertical: true) } else if let help { Text(help).font(Tide.caption).foregroundStyle(Tide.muted).fixedSize(horizontal: false, vertical: true) } } } var borderColor: Color { error != nil ? Tide.down : focused ? Tide.accent : hover ? Tide.muted : Tide.control } } // MARK: Range selector /// Pill segmented control for 7 / 30 / 90 days. Replaces the stock segmented picker. public struct RangeSelector: View { @Binding var selection: Int let options: [Int] @Namespace private var ns @Environment(\.accessibilityReduceMotion) private var reduceMotion public init(selection: Binding, options: [Int] = [7, 30, 90]) { _selection = selection; self.options = options } public var body: some View { HStack(spacing: 2) { ForEach(options, id: \.self) { n in Segment(title: "\(n) days", selected: selection == n, ns: ns) { withAnimation(reduceMotion ? nil : .spring(duration: 0.18)) { selection = n } } } } .padding(3) .frame(height: Tide.phone ? nil : 30) .background(Tide.sunk, in: Capsule()) .overlay(Capsule().strokeBorder(Tide.line)) .accessibilityRepresentation { Picker("Date range", selection: $selection) { ForEach(options, id: \.self) { Text("Last \($0) days").tag($0) } } } } struct Segment: View { let title: String, selected: Bool, ns: Namespace.ID, action: () -> Void @State private var hover = false @State private var pressed = false var body: some View { Button(action: action) { // Touch sizes on iPhone and iPad, pointer sizes on the Mac. Text(title).font(Tide.sans(Tide.phone ? 14 : 12.5, .medium)) .foregroundStyle(selected || hover ? Tide.ink : Tide.phone ? Tide.muted : Tide.pillText) .padding(.horizontal, Tide.phone ? 14 : 11).frame(height: Tide.phone ? 34 : 24) .background { if selected { Capsule().fill(Tide.pillSelected).shadow(color: Color(light: 0x0E2830, dark: 0x000000).opacity(0.18), radius: 1, y: 1) .matchedGeometryEffect(id: "range", in: ns) } else if hover && !Tide.phone { Capsule().fill(Tide.surface2) } } .animation(.easeOut(duration: 0.15), value: hover) .contentShape(Capsule()) } .buttonStyle(.plain) .onHover { hover = $0 } } } } // MARK: Refresh pill /// What the top bar's status says. Checked in this order: refreshing, failed, stale, fresh, then /// `dataThrough` (numbers in the store but no refresh recorded) and `never` (an empty store). public enum RefreshPillStatus: Equatable { case never, dataThrough(String), fresh(String), stale(String), refreshing, failed(Int) } /// "● Updated 9:01 PM ┊ ↻" in one capsule built like RangeSelector: 30 pt tall, 3 pt inset, /// `sunk` fill and a `line` border. The refresh circle shares its centre with the rounded end. public struct RefreshPill: View { let status: RefreshPillStatus let refresh: () -> Void let openSources: () -> Void /// The label shown when the refresh started, so the pill never shrinks mid-refresh. @State private var heldLabel = "" public init(status: RefreshPillStatus, refresh: @escaping () -> Void, openSources: @escaping () -> Void) { self.status = status; self.refresh = refresh; self.openSources = openSources } public var body: some View { HStack(spacing: 0) { statusSegment Rectangle().fill(Tide.line2).frame(width: 1, height: 14) RefreshCircle(turning: status == .refreshing, action: refresh) } .padding(.leading, 3) .frame(height: 30) .background(Tide.sunk, in: Capsule()) .overlay(Capsule().strokeBorder(Tide.line)) .fixedSize() .accessibilityElement(children: .contain) .accessibilityLabel("Refresh status") .onChange(of: status) { old, new in if new == .refreshing { heldLabel = Self.label(old) } if old == .refreshing { announce(new) } } } @ViewBuilder var statusSegment: some View { if case .failed = status { Button(action: openSources) { statusContent.modifier(SegmentHover()) } .buttonStyle(.plain) .help("Open Sources & keys") .accessibilityLabel(Self.label(status)) .accessibilityHint("Opens Sources and keys") } else { statusContent .accessibilityElement(children: .ignore) .accessibilityLabel(spoken) .help(tooltip) } } var statusContent: some View { HStack(spacing: 6) { Circle().fill(dot).frame(width: 6, height: 6).accessibilityHidden(true) ZStack(alignment: .leading) { // The label from before the refresh holds the width, so the pill never shrinks mid-refresh. Text(heldLabel).hidden() Text(Self.label(status)).foregroundStyle(isFailed ? Tide.downText : Tide.pillText) .contentTransition(.opacity) } .font(Tide.sans(12.5)).monospacedDigit().lineLimit(1) .animation(.easeOut(duration: 0.15), value: status) } .padding(.leading, 11).padding(.trailing, 10) .frame(height: 24) .contentShape(Capsule()) } var isFailed: Bool { if case .failed = status { true } else { false } } var dot: Color { switch status { case .fresh: Tide.up case .stale: Tide.attention case .failed: Tide.down case .never, .dataThrough: Tide.muted case .refreshing: Tide.line2 } } static func label(_ status: RefreshPillStatus) -> String { switch status { case .never: "Not refreshed yet" case .dataThrough(let day): "Data through \(day)" case .fresh(let when), .stale(let when): "Updated \(when)" case .refreshing: "Refreshing…" case .failed(let n): n == 1 ? "1 source needs attention" : "\(n) sources need attention" } } var spoken: String { switch status { case .fresh(let when): "Updated at \(when)" case .stale(let when): "Updated \(when). Numbers may be out of date." case .refreshing: "Refreshing" default: Self.label(status) } } var tooltip: String { switch status { case .stale: "These numbers may be out of date. Refresh now with ⌘R." case .never, .dataThrough: "Refresh now with ⌘R." default: "Graphley refreshes on its own every day." } } func announce(_ status: RefreshPillStatus) { let text = isFailed ? Self.label(status) : "Numbers updated" AccessibilityNotification.Announcement(text).post() } } /// The 24 pt refresh circle at the pill's right end. The arrow turns while refreshing and /// finishes its turn before it rests, so it never snaps. struct RefreshCircle: View { let turning: Bool, action: () -> Void @State private var hover = false @State private var startedAt: Date? @Environment(\.accessibilityReduceMotion) private var reduceMotion static let period = 0.9 var body: some View { Button(action: action) { TimelineView(.animation(paused: startedAt == nil)) { context in Image(systemName: "arrow.clockwise") .font(.system(size: 12, weight: .medium)) .foregroundStyle(turning ? Tide.accent : hover ? Tide.ink : Tide.pillText) // The symbol's ink sits 1 pt low in its frame (measured); lift it so it centres on the pill's end. .offset(y: -1) .frame(width: 24, height: 24) .rotationEffect(.degrees(angle(at: context.date))) } .background(Circle().fill(hover && !turning ? Tide.surface2 : .clear)) .frame(width: 30, height: 30) .contentShape(Rectangle()) } .buttonStyle(PressFill()) .disabled(turning) .onHover { hover = $0 } .animation(.easeOut(duration: 0.15), value: hover) .help("Refresh now (⌘R)") .accessibilityLabel(turning ? "Refreshing" : "Refresh now") .onChange(of: turning, initial: true) { _, now in if now && !reduceMotion && startedAt == nil { startedAt = .now } if !now, let start = startedAt { // Finish the current revolution, then rest at 0°. let elapsed = Date.now.timeIntervalSince(start) let left = Self.period - elapsed.truncatingRemainder(dividingBy: Self.period) Task { try? await Task.sleep(for: .seconds(left)); if !turning { startedAt = nil } } } } } func angle(at date: Date) -> Double { guard let start = startedAt else { return 0 } return date.timeIntervalSince(start) / Self.period * 360 } } /// Pressed state for the refresh circle: a `line` fill on the 24 pt circle. struct PressFill: ButtonStyle { func makeBody(configuration c: Configuration) -> some View { c.label.background(Circle().fill(c.isPressed ? Tide.line : .clear).frame(width: 24, height: 24)) } } /// Hover fill for the failed status segment. struct SegmentHover: ViewModifier { @State private var hover = false func body(content: Content) -> some View { content.background(Capsule().fill(hover ? Tide.surface2 : .clear)) .onHover { hover = $0 } .animation(.easeOut(duration: 0.15), value: hover) } } // MARK: Pill public struct StatusPill: View { public enum Kind { case ok, attention, error, info, neutral } let text: String, kind: Kind public init(_ text: String, _ kind: Kind) { self.text = text; self.kind = kind } public var body: some View { let (bg, fg) = colors HStack(spacing: 6) { Circle().fill(fg).frame(width: 6, height: 6); Text(text).font(Tide.sans(11.5, .semibold)) } .foregroundStyle(fg) .padding(.horizontal, 8).frame(height: 20) .background(bg, in: Capsule()) .accessibilityElement(children: .ignore).accessibilityLabel(text) } var colors: (Color, Color) { switch kind { case .ok: (Color(light: 0xDAE8E2, dark: 0x1E423F), Color(light: 0x276E51, dark: 0x5CC594)) case .attention: (Color(light: 0xF1EADE, dark: 0x373C34), Color(light: 0x755B36, dark: 0xE3A45A)) case .error: (Color(light: 0xEDE2DE, dark: 0x373739), Color(light: 0x984A38, dark: 0xE58A72)) case .info: (Color(light: 0xD8E6E9, dark: 0x1F3F4A), Color(light: 0x1D6E8A, dark: 0x5DB6D2)) case .neutral: (Color(light: 0xE0E7E6, dark: 0x263C41), Color(light: 0x4A6566, dark: 0x88A2A2)) } } } // MARK: Card, heading, code, disclosure, empty state public struct TideCard: View { let title: String?, subtitle: String?, icon: String?, padding: CGFloat let accessory: Accessory let content: Content public init(_ title: String? = nil, subtitle: String? = nil, icon: String? = nil, padding: CGFloat = 16, @ViewBuilder accessory: () -> Accessory, @ViewBuilder content: () -> Content) { self.title = title; self.subtitle = subtitle; self.icon = icon; self.padding = padding; self.accessory = accessory(); self.content = content() } public var body: some View { VStack(alignment: .leading, spacing: 12) { if title != nil || subtitle != nil { HStack(alignment: .top, spacing: 10) { if let icon { Image(systemName: icon).font(.system(size: 14, weight: .medium)).foregroundStyle(Tide.accent) .frame(width: 28, height: 28).background(Tide.sunk, in: RoundedRectangle(cornerRadius: 7)) } VStack(alignment: .leading, spacing: 3) { if let title { Text(title).font(Tide.cardTitle).foregroundStyle(Tide.ink) } if let subtitle { Text(subtitle).font(Tide.secondary).foregroundStyle(Tide.muted).fixedSize(horizontal: false, vertical: true) } } .padding(.top, icon == nil ? 0 : 5) Spacer(minLength: 8) accessory.padding(.top, icon == nil ? 0 : 4) } } content } .padding(padding) .frame(maxWidth: .infinity, alignment: .leading) .background(Tide.surface, in: RoundedRectangle(cornerRadius: Tide.phone ? 16 : 12)) .overlay(RoundedRectangle(cornerRadius: Tide.phone ? 16 : 12).strokeBorder(Tide.line)) } } public extension TideCard where Accessory == EmptyView { init(_ title: String? = nil, subtitle: String? = nil, icon: String? = nil, padding: CGFloat = 16, @ViewBuilder content: () -> Content) { self.init(title, subtitle: subtitle, icon: icon, padding: padding, accessory: { EmptyView() }, content: content) } } /// Divider between rows inside a card. public struct RowDivider: View { public init() {} public var body: some View { Rectangle().fill(Tide.line).frame(height: 1) } } public struct ScreenHeading: View { let title: String, subtitle: String? let link: (title: String, url: URL)? let trailing: Trailing let footnote: Footnote public init(_ title: String, subtitle: String? = nil, link: (title: String, url: URL)? = nil, @ViewBuilder trailing: () -> Trailing, @ViewBuilder footnote: () -> Footnote) { self.title = title; self.subtitle = subtitle; self.link = link; self.trailing = trailing(); self.footnote = footnote() } public var body: some View { HStack(alignment: .bottom, spacing: 12) { VStack(alignment: .leading, spacing: 4) { Text(title).font(Tide.screenTitle).tracking(-0.3).foregroundStyle(Tide.ink).accessibilityAddTraits(.isHeader) if subtitle != nil || link != nil { subtitleText.fixedSize(horizontal: false, vertical: true) } footnote.padding(.top, 4) } Spacer(minLength: 0) trailing } .frame(maxWidth: .infinity, alignment: .leading) .padding(.bottom, 6) } /// The subtitle, with an optional link at its end ("… · protomota.com ↗"). var subtitleText: some View { // En spaces around "·" so the separator doesn't read as a word space. let sep = "\u{2002}·\u{2002}" var text = AttributedString((subtitle ?? "").replacingOccurrences(of: " · ", with: sep)) text.foregroundColor = Tide.muted if let link { if subtitle != nil { var dot = AttributedString(sep); dot.foregroundColor = Tide.muted; text += dot } var l = AttributedString("\(link.title) ↗") l.link = link.url l.foregroundColor = Tide.accent l.font = Tide.sans(Tide.phone ? 14 : 12.5, .medium) text += l } return Text(text).font(Tide.secondary).tint(Tide.accent) .help(link.map { "Open \($0.title)" } ?? "") } } public extension ScreenHeading where Footnote == EmptyView { init(_ title: String, subtitle: String? = nil, link: (title: String, url: URL)? = nil, @ViewBuilder trailing: () -> Trailing) { self.init(title, subtitle: subtitle, link: link, trailing: trailing) { EmptyView() } } } public extension ScreenHeading where Trailing == EmptyView, Footnote == EmptyView { init(_ title: String, subtitle: String? = nil, link: (title: String, url: URL)? = nil) { self.init(title, subtitle: subtitle, link: link) { EmptyView() } footnote: { EmptyView() } } } /// Selectable command or prompt with a Copy button in its corner. public struct CopyBlock: View { let text: String, wraps: Bool @Environment(\.colorScheme) private var scheme public init(_ text: String, wraps: Bool = false) { self.text = text; self.wraps = wraps } public var body: some View { HStack(alignment: .top, spacing: 10) { Group { if wraps { Text(text).fixedSize(horizontal: false, vertical: true).frame(maxWidth: .infinity, alignment: .leading) } else { ScrollView(.horizontal, showsIndicators: false) { Text(text).fixedSize() } } } .font(Tide.code).foregroundStyle(Tide.ink).textSelection(.enabled) .padding(.top, 3) CopyButton(text) } .padding(.vertical, 10).padding(.horizontal, 12) .background(scheme == .dark ? Tide.sunk : Tide.ground, in: RoundedRectangle(cornerRadius: 8)) .overlay(RoundedRectangle(cornerRadius: 8).strokeBorder(Tide.line)) } } /// "› Or let your agent do it": a quiet disclosure with a rotating chevron. public struct TideDisclosure: View { let title: String @Binding var isOpen: Bool let content: Content public init(_ title: String, isOpen: Binding, @ViewBuilder content: () -> Content) { self.title = title; _isOpen = isOpen; self.content = content() } public var body: some View { VStack(alignment: .leading, spacing: 10) { Button { withAnimation(.easeOut(duration: 0.2)) { isOpen.toggle() } } label: { HStack(spacing: 6) { Image(systemName: "chevron.right").font(.system(size: 10, weight: .bold)).rotationEffect(.degrees(isOpen ? 90 : 0)) Text(title).font(Tide.sans(13, .medium)) } .foregroundStyle(Tide.accent).contentShape(Rectangle()) } .buttonStyle(.plain) .accessibilityValue(isOpen ? "Expanded" : "Collapsed") if isOpen { content.transition(.opacity) } } } } public struct EmptyState: View { let title: String?, message: String let actions: Actions public init(_ title: String? = nil, message: String, @ViewBuilder actions: () -> Actions) { self.title = title; self.message = message; self.actions = actions() } public var body: some View { HStack(alignment: .top, spacing: 14) { // Titled empty states carry the brand mark, so a first launch looks like Graphley, not a blank form. if title != nil { TideMark(size: 40) } VStack(alignment: .leading, spacing: 6) { if let title { Text(title).font(Tide.cardTitle).foregroundStyle(Tide.ink) } Text(message).font(Tide.secondary).foregroundStyle(Tide.ink2).frame(maxWidth: 460, alignment: .leading).fixedSize(horizontal: false, vertical: true) HStack(spacing: 8) { actions }.padding(.top, 6) } } .padding(title == nil ? 0 : 4) .frame(maxWidth: .infinity, alignment: .leading) } } public extension EmptyState where Actions == EmptyView { init(_ title: String? = nil, message: String) { self.init(title, message: message) { EmptyView() } } } /// A small button that copies a ready-made prompt for the user's agent. public struct PromptChip: View { let prompt: String @State private var copied = false public init(_ prompt: String) { self.prompt = prompt } public var body: some View { Button { Clipboard.copy(prompt); copied = true Task { try? await Task.sleep(for: .seconds(1.5)); copied = false } } label: { Label(copied ? "Copied" : "“\(prompt)”", systemImage: copied ? "checkmark" : "doc.on.doc") .lineLimit(1).truncationMode(.tail) } .buttonStyle(.tide(.secondary, size: .small)) .help("Copy this prompt for your agent") } } /// "Try: “…” Copy": a quiet, wrapping prompt line for under a screen's subtitle. public struct PromptLine: View { let prompt: String @State private var copied = false @State private var hover = false public init(_ prompt: String) { self.prompt = prompt } public var body: some View { HStack(alignment: .firstTextBaseline, spacing: 10) { Text("Try: “\(prompt)”").foregroundStyle(Tide.muted) .font(Tide.secondary).textSelection(.enabled) .fixedSize(horizontal: false, vertical: true) Button { Clipboard.copy(prompt); copied = true AccessibilityNotification.Announcement("Copied").post() Task { try? await Task.sleep(for: .seconds(1.5)); copied = false } } label: { // Everything sits on the prompt's text baseline, so "Copy" lines up with "Try". ZStack(alignment: Alignment(horizontal: .leading, vertical: .firstTextBaseline)) { HStack(alignment: .firstTextBaseline, spacing: 4) { Image(systemName: "checkmark").font(.system(size: 10, weight: .bold)); Text("Copied") }.hidden() if copied { HStack(alignment: .firstTextBaseline, spacing: 4) { Image(systemName: "checkmark").font(.system(size: 10, weight: .bold)); Text("Copied") } .foregroundStyle(Tide.up) } else { HStack(alignment: .firstTextBaseline, spacing: 4) { Image(systemName: "doc.on.doc").font(.system(size: 10, weight: .semibold)); Text("Copy").underline(hover) } .foregroundStyle(hover ? Tide.accentStrong : Tide.accent) } } .font(Tide.sans(12.5, .semibold)) .contentShape(Rectangle()) } .buttonStyle(.plain) .onHover { hover = $0 } .help("Copy this prompt for your agent") .accessibilityLabel("Copy prompt") } .frame(maxWidth: 640, alignment: .leading) } }