#if os(macOS) import RastrilloApple import SwiftUI /// The Mac's window (B, mockup `mac-main-b`): the sky, a floating glass /// sidebar with the apps, and Ask in the middle as a sheet. The sidebar /// toggle sits in Ask's bar. public struct MacMainView: View { let me: Me? let home: HomeData? let ask: AskModel? let transport: NativeTransport? let actions: BaseActions @Binding var sidebarShown: Bool @Environment(\.colorScheme) private var scheme public init(me: Me?, home: HomeData?, ask: AskModel?, transport: NativeTransport?, actions: BaseActions, sidebarShown: Binding) { self.me = me; self.home = home; self.ask = ask; self.transport = transport; self.actions = actions; _sidebarShown = sidebarShown } public var body: some View { ZStack { Sky() HStack(spacing: 10) { if sidebarShown { MacSidebar(me: me, home: home, waiting: ask?.waitingJobs ?? 0, transport: transport, actions: actions) .frame(width: 236) .transition(.move(edge: .leading).combined(with: .opacity)) } pane } .padding(10) } .animation(.easeOut(duration: 0.2), value: sidebarShown) } private var pane: some View { let p = Palette(scheme) return VStack(spacing: 0) { HStack(spacing: 10) { if !sidebarShown { Color.clear.frame(width: 64, height: 1) } // the window's buttons HStack(spacing: 9) { BaseMark(size: 16) Text(BaseText.text("native.sidebar.ask")).font(BaseFont.heading(17, .semibold, relativeTo: .headline)) } .accessibilityElement(children: .combine) .accessibilityAddTraits(.isHeader) Spacer() Button { sidebarShown.toggle() } label: { Image(systemName: "sidebar.left").font(.system(size: 14, weight: .medium)) .frame(width: 32, height: 32) .background(p[.chip], in: Circle()) .overlay { Circle().strokeBorder(p[.chipEdge], lineWidth: 1) } .contentShape(Circle()) } .buttonStyle(.plain) .help(Text(BaseText.text(sidebarShown ? "native.sidebar.toggle_a11y" : "native.sidebar.toggle_a11y.show"))) .accessibilityLabel(Text(BaseText.text(sidebarShown ? "native.sidebar.toggle_a11y" : "native.sidebar.toggle_a11y.show"))) .keyboardShortcut("s", modifiers: [.command, .control]) } .padding(.leading, 20).padding(.trailing, 12) .frame(height: 52) .overlay(alignment: .bottom) { Rectangle().fill(p[.rule]).frame(height: 1).padding(.horizontal, 12) } if let ask { AskView(model: ask, layout: .window, timeZone: me?.base.timeZone, actions: AskActions(setUp: actions.setUpAsk, setUpOnWeb: actions.setUpAskOnWeb)) .frame(maxWidth: 760) .frame(maxWidth: .infinity) } else { Spacer() } } .foregroundStyle(p[.frost]) .glassSheet(cornerRadius: 18) } } /// The floating sidebar: Ask Base (with its badge), Getting started while /// a step is open, the apps, the team's Store and People, and the person /// and team at its foot with the account's menu. struct MacSidebar: View { let me: Me? let home: HomeData? let waiting: Int let transport: NativeTransport? let actions: BaseActions @State private var switching = false @State private var confirmingSignOut = false @Environment(\.colorScheme) private var scheme var body: some View { let p = Palette(scheme) VStack(alignment: .leading, spacing: 0) { Color.clear.frame(height: 34) // the window's buttons sit here ScrollView { VStack(alignment: .leading, spacing: 2) { askRow(p) if let home, home.stepsOpen { steps(home, p) } if let home, !home.launchable.isEmpty { heading(BaseText.text("native.sidebar.apps"), p) ForEach(home.launchable) { app in appRow(app, p) } } if let home, !home.own.isEmpty { heading(BaseText.format("native.sidebar.team", ["team": me?.base.name ?? ""]), p) ForEach(home.own.filter { $0.id != "settings" }) { app in appRow(app, p) } } } .padding(.horizontal, 10) } .scrollIndicators(.never) foot(p) } .foregroundStyle(p[.frost]) .glass(cornerRadius: 18) .accountChoices(actions: actions, switching: $switching, confirmingSignOut: $confirmingSignOut) } private func askRow(_ p: Palette) -> some View { HStack(spacing: 10) { BaseMark(size: 16).frame(width: 22, height: 22) Text(BaseText.text("native.sidebar.ask")).font(BaseFont.body(14, .semibold)) Spacer(minLength: 4) if waiting > 0 { Text(verbatim: "\(waiting)") .font(BaseFont.body(11.5, .bold, relativeTo: .caption)) .foregroundStyle(p[.onSignal]) .padding(.horizontal, 6).frame(minWidth: 20, minHeight: 20) .background(p[.stAsk], in: Capsule()) .accessibilityLabel(Text(BaseText.plural("native.sidebar.ask.badge_a11y", waiting))) } } .padding(.horizontal, 10).frame(minHeight: 32) .background(p[.hover], in: RoundedRectangle(cornerRadius: 9, style: .continuous)) .overlay { RoundedRectangle(cornerRadius: 9, style: .continuous).strokeBorder(p[.accentEdge], lineWidth: 1) } .accessibilityElement(children: .combine) .accessibilityAddTraits(.isSelected) } private func steps(_ home: HomeData, _ p: Palette) -> some View { VStack(alignment: .leading, spacing: 5) { Text(BaseText.text("native.sidebar.steps")).font(BaseFont.body(13, .semibold)).padding(.bottom, 1) .accessibilityAddTraits(.isHeader) ForEach(home.steps, id: \.self) { step in HStack(spacing: 8) { StepDot(done: step.done) Text(verbatim: step.label).font(BaseFont.body(13)).foregroundStyle(step.done ? p[.haze] : p[.frost]) } .accessibilityElement(children: .combine) .accessibilityAddTraits(step.done ? .isSelected : []) } } .padding(.vertical, 10).padding(.horizontal, 12) .frame(maxWidth: .infinity, alignment: .leading) .background(p[.chip], in: RoundedRectangle(cornerRadius: 12, style: .continuous)) .overlay { RoundedRectangle(cornerRadius: 12, style: .continuous).strokeBorder(p[.chipEdge], lineWidth: 1) } .padding(.top, 6).padding(.horizontal, 2) } private func heading(_ text: String, _ p: Palette) -> some View { Text(verbatim: text).font(BaseFont.body(11.5, .semibold, relativeTo: .caption)).foregroundStyle(p[.haze]) .padding(.top, 14).padding(.bottom, 4).padding(.horizontal, 10) .accessibilityAddTraits(.isHeader) } private func appRow(_ app: HomeData.App, _ p: Palette) -> some View { Button { actions.open(app) } label: { HStack(spacing: 10) { AppIcon(app, size: 22, transport: transport) Text(verbatim: app.name).font(BaseFont.body(14)) Spacer(minLength: 0) } .padding(.horizontal, 10).frame(minHeight: 32) .contentShape(Rectangle()) } .buttonStyle(SidebarRowStyle()) } private func foot(_ p: Palette) -> some View { Menu { AccountMenuItems(actions: actions, switching: $switching, confirmingSignOut: $confirmingSignOut) } label: { HStack(spacing: 10) { Avatar(me?.member.initials ?? "", size: 30) VStack(alignment: .leading, spacing: 0) { Text(verbatim: me?.member.name ?? "").font(BaseFont.body(13.5, .medium)) Text(verbatim: me?.base.name ?? "").font(BaseFont.body(12, relativeTo: .caption)).foregroundStyle(p[.haze]) } Spacer(minLength: 0) } .contentShape(Rectangle()) } .menuStyle(.button) .buttonStyle(.plain) .menuIndicator(.hidden) .padding(.top, 10).padding(.leading, 8).padding(.horizontal, 10).padding(.bottom, 10) .overlay(alignment: .top) { Rectangle().fill(p[.rule]).frame(height: 1).padding(.horizontal, 10) } } } /// A sidebar row: the hover's tint while pressed or pointed at. struct SidebarRowStyle: ButtonStyle { @State private var hovering = false @Environment(\.colorScheme) private var scheme func makeBody(configuration: Configuration) -> some View { configuration.label .foregroundStyle(Palette(scheme)[.frost]) .background((configuration.isPressed || hovering) ? Palette(scheme)[.hover] : .clear, in: RoundedRectangle(cornerRadius: 9, style: .continuous)) .onHover { hovering = $0 } } } #endif