SPB Git

Repository Public

StudioLayout.swift 3.9 KB 83 lines swift

1// Author: Simon-Pierre Boucher — contact@spboucher.ai2// File: Packages/LocalChatUI/Sources/Features/Knowledge/StudioLayout.swift3// Description: Adaptive master-detail container for the studios: side by side on wide windows, list then pushed detail on narrow ones.4import SwiftUI56/// Master-detail that does not depend on the surrounding navigation container (works inside split views, stacks and tabs).7struct StudioSplit<Master: View, Detail: View>: View {8    let showsDetail: Bool9    let backTitle: String10    let onBack: () -> Void11    @ViewBuilder var master: Master12    @ViewBuilder var detail: Detail1314    var body: some View {15        GeometryReader { geo in16            if geo.size.width >= 760 {17                HStack(spacing: 0) {18                    master.frame(width: min(330, max(270, geo.size.width * 0.3)))19                    Rectangle().fill(DS.C.border).frame(width: 1)20                    detail.frame(maxWidth: .infinity, maxHeight: .infinity)21                }22            } else if showsDetail {23                VStack(spacing: 0) {24                    HStack {25                        Button(action: onBack) { Label(backTitle, systemImage: "chevron.left").font(DS.F.callout.weight(.medium)) }26                            .buttonStyle(.plain).foregroundStyle(DS.C.accent).accessibilityLabel("Back to \(backTitle)")27                        Spacer()28                    }29                    .padding(.horizontal, DS.S.lg).padding(.vertical, DS.S.sm)30                    Rectangle().fill(DS.C.border).frame(height: 1)31                    detail.frame(maxWidth: .infinity, maxHeight: .infinity)32                }33                .transition(.move(edge: .trailing))34            } else {35                master.frame(maxWidth: .infinity, maxHeight: .infinity)36            }37        }38        .animation(DS.M.smooth, value: showsDetail)39        .screenBackground()40    }41}4243/// Segmented tab strip used inside the studios.44struct StudioTabs<Tab: Hashable & Identifiable>: View {45    let tabs: [Tab]; let title: (Tab) -> String; let symbol: (Tab) -> String46    @Binding var selection: Tab47    var body: some View {48        ScrollView(.horizontal, showsIndicators: false) {49            HStack(spacing: 6) {50                ForEach(tabs) { tab in51                    Button { withAnimation(DS.M.snappy) { selection = tab } } label: {52                        Label(title(tab), systemImage: symbol(tab)).font(.system(size: 12.5, weight: .medium))53                            .padding(.horizontal, 11).padding(.vertical, 6)54                            .foregroundStyle(selection == tab ? Color.white : DS.C.text2)55                            .background { if selection == tab { Capsule().fill(DS.G.accent) } else { Capsule().fill(DS.C.surface2) } }56                    }57                    .buttonStyle(.plain).accessibilityAddTraits(selection == tab ? .isSelected : [])58                }59            }60        }61    }62}6364let studioSymbols = ["books.vertical", "doc.text", "folder", "graduationcap", "briefcase", "hammer", "sparkle", "brain", "terminal", "globe", "chart.bar", "leaf", "heart", "building.columns", "wrench.and.screwdriver", "magnifyingglass"]6566struct SymbolPicker: View {67    @Binding var symbol: String68    var body: some View {69        ScrollView(.horizontal, showsIndicators: false) {70            HStack(spacing: 6) {71                ForEach(studioSymbols, id: \.self) { s in72                    Button { symbol = s } label: {73                        Image(systemName: s).font(.system(size: 14)).frame(width: 32, height: 32)74                            .foregroundStyle(symbol == s ? Color.white : DS.C.text2)75                            .background(symbol == s ? AnyShapeStyle(DS.G.accent) : AnyShapeStyle(DS.C.surface2), in: RoundedRectangle(cornerRadius: 8, style: .continuous))76                    }77                    .buttonStyle(.plain).accessibilityLabel("Symbol \(s)")78                }79            }80        }81    }82}83
Files main
Menu

Theme