Repository Public License
1import SwiftUI23/// The living catalogue of the design system: every token, theme, glyph and component, with a theme picker.4/// It is the screen used for previews and (through `LunarGalleryContent`) for the reference renders.5public struct LunarGallery: View {6 @State private var familyID: String7 @State private var appearance: LunarAppearance89 public init(initialFamily: LunarThemeFamily = .default, appearance: LunarAppearance = .system) {10 self._familyID = State(initialValue: initialFamily.id)11 self._appearance = State(initialValue: appearance)12 }1314 public var body: some View {15 GeometryReader { proxy in16 let layout: LunarGalleryContent.Layout = proxy.size.width >= 900 ? .wide : .compact17 ZStack {18 LunarWindowBackground()19 ScrollView {20 VStack(alignment: .leading, spacing: LunarSpacing.lg) {21 picker22 LunarGalleryContent(layout: layout)23 }24 .padding(layout == .wide ? LunarSpacing.xl : LunarSpacing.md)25 }26 }27 }28 .lunarTheme(LunarThemes.family(id: familyID), appearance: appearance)29 }3031 private var picker: some View {32 VStack(alignment: .leading, spacing: LunarSpacing.sm) {33 LunarSegmentedControl("Appearance", selection: $appearance, segments: [34 LunarSegment("System", value: .system), LunarSegment("Dark", value: .dark),35 LunarSegment("Light", value: .light),36 ])37 .frame(maxWidth: 360)38 ScrollView(.horizontal, showsIndicators: false) {39 HStack(spacing: LunarSpacing.xs) {40 ForEach(LunarThemes.all) { family in41 LunarChip(family.name, isSelected: family.id == familyID) { familyID = family.id }42 }43 }44 .padding(.vertical, 2)45 }46 }47 }48}4950/// The catalogue itself, without scrolling or theme picker, in the theme of the environment. It has no lazy or51/// platform-backed container, so it can be rendered offscreen with `ImageRenderer`.52public struct LunarGalleryContent: View {53 public enum Layout: Sendable { case wide, compact }5455 @Environment(\.lunarTheme) private var theme56 private let layout: Layout5758 @State private var chipOn = true59 @State private var toggleOn = true60 @State private var toggleOff = false61 @State private var segment = 162 @State private var sliderValue = 0.6263 @State private var fieldText = ""64 @State private var searchText = "orixlab.dev/navigator"65 @State private var selectedTab = 16667 public init(layout: Layout = .wide) { self.layout = layout }6869 public var body: some View {70 VStack(alignment: .leading, spacing: LunarSpacing.xl) {71 header72 columns(tokens, themesAndGlyphs)73 columns(componentsLeading, componentsTrailing)74 }75 }7677 @ViewBuilder private func columns(_ leading: some View, _ trailing: some View) -> some View {78 if layout == .wide {79 HStack(alignment: .top, spacing: LunarSpacing.lg) {80 leading.frame(maxWidth: .infinity, alignment: .topLeading)81 trailing.frame(maxWidth: .infinity, alignment: .topLeading)82 }83 } else {84 VStack(alignment: .leading, spacing: LunarSpacing.lg) { leading; trailing }85 }86 }8788 // MARK: Header8990 private var header: some View {91 HStack(spacing: LunarSpacing.md) {92 LunarMarkView(size: 72)93 VStack(alignment: .leading, spacing: LunarSpacing.unit) {94 Text("Lunar Glass").lunarFont(.display).foregroundStyle(theme.textPrimary)95 Text("ORIX Navigator design system · \(theme.name) · \(theme.variant.rawValue) · tokens \(LunarDesign.tokenVersion)")96 .lunarFont(.callout).foregroundStyle(theme.textSecondary)97 }98 Spacer(minLength: 0)99 }100 }101102 // MARK: Tokens103104 private var tokens: some View {105 VStack(alignment: .leading, spacing: LunarSpacing.lg) {106 GalleryGroup("Core palette") {107 grid(LunarPalette.all.map { ($0.name, $0.color) }, columns: layout == .wide ? 4 : 2) { item in108 GallerySwatch(name: item.0, color: item.1)109 }110 }111 GalleryGroup("Semantic roles") {112 grid(roles, columns: layout == .wide ? 4 : 2) { item in GallerySwatch(name: item.0, color: item.1) }113 }114 GalleryGroup("Workspace tints") {115 grid(LunarTint.allCases, columns: 5) { tint in116 VStack(spacing: LunarSpacing.xs) {117 LunarPlanet(tint: tint, size: 34, isActive: tint == .lunarBlue, hasRing: tint == .solar)118 .frame(height: 48)119 Text(tint.displayName).lunarFont(.caption).foregroundStyle(theme.textSecondary)120 .lineLimit(1).minimumScaleFactor(0.7)121 }122 .frame(maxWidth: .infinity)123 }124 }125 GalleryGroup("Spacing · 4-point grid") {126 HStack(alignment: .bottom, spacing: LunarSpacing.md) {127 ForEach(LunarSpacing.scale, id: \.self) { value in128 VStack(spacing: LunarSpacing.xs) {129 RoundedRectangle(cornerRadius: 3, style: .continuous).fill(theme.accent)130 .frame(width: value, height: value)131 Text("\(Int(value))").lunarFont(.caption).lunarTabularDigits()132 .foregroundStyle(theme.textSecondary)133 }134 }135 Spacer(minLength: 0)136 }137 }138 GalleryGroup("Radii") {139 HStack(alignment: .bottom, spacing: LunarSpacing.sm) {140 ForEach(LunarRadius.scale, id: \.self) { radius in141 VStack(spacing: LunarSpacing.xs) {142 LunarShape.rounded(radius).fill(theme.elevatedSurface)143 .frame(width: 72, height: 72).lunarHairline(.rounded(radius))144 Text("\(Int(radius))").lunarFont(.caption).lunarTabularDigits()145 .foregroundStyle(theme.textSecondary)146 }147 }148 VStack(spacing: LunarSpacing.xs) {149 LunarShape.capsule.fill(theme.elevatedSurface)150 .frame(width: 96, height: 44).lunarHairline(.capsule)151 Text("capsule").lunarFont(.caption).foregroundStyle(theme.textSecondary)152 }153 .frame(height: 72 + 24, alignment: .bottom)154 Spacer(minLength: 0)155 }156 }157 GalleryGroup("Type scale · SF Pro, Dynamic Type") {158 VStack(alignment: .leading, spacing: LunarSpacing.xs) {159 ForEach(LunarTextStyle.allCases, id: \.self) { style in160 HStack(alignment: .firstTextBaseline, spacing: LunarSpacing.sm) {161 Text(style.rawValue).lunarFont(.caption).foregroundStyle(theme.textTertiary)162 .frame(width: 112, alignment: .leading)163 Text(style == .mono ? "let orbit = 0123456789" : (style == .overline ? "OVERLINE 0123456789" : "Navigate by moonlight 0123456789"))164 .lunarFont(style).lunarTabularDigits()165 .foregroundStyle(theme.textPrimary).lineLimit(1)166 }167 }168 }169 }170 }171 }172173 private var roles: [(String, LunarRGBA)] {174 [175 ("Window", theme.windowBackground), ("Chrome", theme.chromeSurface),176 ("Elevated", theme.elevatedSurface), ("Sunken", theme.sunkenSurface),177 ("Text primary", theme.textPrimary), ("Text secondary", theme.textSecondary),178 ("Text tertiary", theme.textTertiary), ("Hairline", theme.hairline),179 ("Accent", theme.accent), ("Accent secondary", theme.accentSecondary),180 ("On accent", theme.onAccent), ("Selection", theme.selection),181 ("Success", theme.success), ("Warning", theme.warning),182 ("Danger", theme.danger), ("Focus ring", theme.focusRing),183 ]184 }185186 // MARK: Themes and glyphs187188 private var themesAndGlyphs: some View {189 VStack(alignment: .leading, spacing: LunarSpacing.lg) {190 GalleryGroup("Themes · 12 families, dark and light") {191 grid(LunarThemes.all, columns: layout == .wide ? 3 : 2) { family in192 GalleryThemeCard(family: family, isCurrent: family.id == theme.familyID)193 }194 }195 GalleryGroup("Mark") {196 HStack(spacing: LunarSpacing.lg) {197 LunarMarkView(size: 120)198 LunarMarkView(size: 56)199 LunarMarkView(size: 28, showsGlow: false)200 LunarMarkShape().fill(theme.textPrimary).frame(width: 56, height: 56)201 LunarMarkShape().fill(theme.textPrimary).frame(width: 20, height: 20)202 Spacer(minLength: 0)203 }204 }205 GalleryGroup("Module glyphs · 24 pt and 16 pt") {206 grid(LunarGlyph.allCases, columns: layout == .wide ? 5 : 4) { glyph in207 VStack(spacing: LunarSpacing.xs) {208 HStack(alignment: .center, spacing: LunarSpacing.sm) {209 LunarGlyphView(glyph, size: 24).foregroundStyle(theme.textPrimary)210 LunarGlyphView(glyph, size: 16).foregroundStyle(theme.accent)211 }212 .frame(height: 32)213 Text(glyph.displayName).lunarFont(.caption).foregroundStyle(theme.textSecondary)214 }215 .frame(maxWidth: .infinity)216 .padding(.vertical, LunarSpacing.xs)217 }218 }219 GalleryGroup("Backdrop · starfield and orbital rings") {220 ZStack {221 LunarShape.sm.fill(theme.windowGradient)222 LunarStarfield(density: 2.4).clipShape(LunarShape.sm)223 LunarOrbitRings(count: 3).frame(width: 190, height: 190)224 LunarPlanet(tint: .spectralViolet, size: 16, isActive: true).offset(x: 95, y: 0)225 LunarPlanet(tint: .auroraMint, size: 12).offset(x: -52, y: -42)226 LunarPlanet(tint: .solar, size: 14, hasRing: true).offset(x: -18, y: 61)227 LunarMarkView(size: 54)228 }229 .frame(height: 220)230 .lunarHairline(.sm)231 }232 }233 }234235 // MARK: Components236237 private var componentsLeading: some View {238 VStack(alignment: .leading, spacing: LunarSpacing.lg) {239 GalleryGroup("Capsule bar and search field") {240 VStack(spacing: LunarSpacing.md) {241 LunarCapsuleBar {242 LunarIconButton(systemName: "chevron.left", label: "Back") {}243 LunarIconButton(systemName: "chevron.right", label: "Forward") {}.disabled(true)244 LunarSearchField(text: $searchText, prompt: "Search or enter an address",245 leading: .symbol("lock.fill")) {246 LunarIconButton(glyph: .reader, label: "Reader", diameter: 28) {}247 }248 LunarIconButton(glyph: .shield, label: "Shield", isActive: true) {}249 LunarIconButton(glyph: .orbit, label: "Orbit") {}250 }251 LunarTextField("Workspace name", text: $fieldText, icon: .glyph(.orbit))252 }253 }254 GalleryGroup("Buttons") {255 VStack(alignment: .leading, spacing: LunarSpacing.sm) {256 HStack(spacing: LunarSpacing.sm) {257 Button("Continue") {}.buttonStyle(.lunar(.primary))258 Button("Not now") {}.buttonStyle(.lunar(.secondary))259 Button("Clear history") {}.buttonStyle(.lunar(.destructive))260 }261 HStack(spacing: LunarSpacing.sm) {262 Button("Compact") {}.buttonStyle(.lunar(.primary, size: .compact))263 Button("Compact") {}.buttonStyle(.lunar(.secondary, size: .compact))264 Button("Disabled") {}.buttonStyle(.lunar(.primary, size: .compact)).disabled(true)265 }266 HStack(spacing: LunarSpacing.sm) {267 LunarIconButton(glyph: .command, label: "Command") {}268 LunarIconButton(glyph: .split, label: "Split", isActive: true) {}269 LunarIconButton(glyph: .agent, label: "Agent", style: .glass) {}270 LunarIconButton(glyph: .ghost, label: "Ghost", style: .glass, isActive: true) {}271 LunarIconButton(systemName: "plus", label: "New tab", style: .accent) {}272 }273 }274 }275 GalleryGroup("Chips, segmented control, slider, toggles") {276 VStack(alignment: .leading, spacing: LunarSpacing.sm) {277 HStack(spacing: LunarSpacing.xs) {278 LunarChip("Private", icon: .glyph(.ghost), isOn: $chipOn)279 LunarChip("Reader", icon: .glyph(.reader), isSelected: false) {}280 LunarChip("Focus", icon: .glyph(.focus), isSelected: false) {}281 }282 LunarSegmentedControl("View", selection: $segment, segments: [283 LunarSegment("Tabs", value: 0), LunarSegment("Orbit", value: 1, icon: .glyph(.orbit)),284 LunarSegment("Memory", value: 2, icon: .glyph(.memory)),285 ])286 LunarSlider("Page zoom", value: $sliderValue)287 Toggle("Block trackers", isOn: $toggleOn).toggleStyle(.lunar)288 Toggle("Send usage data", isOn: $toggleOff).toggleStyle(.lunar)289 }290 }291 GalleryGroup("Tab chips") {292 VStack(alignment: .leading, spacing: LunarSpacing.sm) {293 HStack(spacing: LunarSpacing.unit) {294 LunarTabChip(title: "Mail", tint: .rose, isPinned: true, onSelect: {})295 LunarTabChip(title: "ORIX Lab", tint: .lunarBlue, isSelected: selectedTab == 1,296 onSelect: { selectedTab = 1 }, onClose: {})297 LunarTabChip(title: "Night sounds", tint: .auroraMint, isSelected: selectedTab == 2,298 audio: .playing, onSelect: { selectedTab = 2 }, onClose: {})299 }300 VStack(spacing: 2) {301 LunarTabChip(title: "Orbital mechanics", tint: .spectralViolet, isSelected: true,302 layout: .vertical, onSelect: {}, onClose: {})303 LunarTabChip(title: "Loading a long page title that truncates", tint: .ocean,304 isLoading: true, layout: .vertical, onSelect: {}, onClose: {})305 LunarTabChip(title: "Podcast", tint: .ember, isPinned: true, audio: .muted,306 layout: .vertical, onSelect: {})307 }308 }309 }310 GalleryGroup("Satellites and shortcuts") {311 VStack(alignment: .leading, spacing: LunarSpacing.sm) {312 HStack(spacing: LunarSpacing.xs) {313 LunarSatelliteChip("Research", tint: .spectralViolet, isActive: true, count: 8) {}314 LunarSatelliteChip("Travel", tint: .solar, count: 3) {}315 LunarSatelliteChip("Studio", tint: .auroraMint, count: 12) {}316 }317 HStack(spacing: LunarSpacing.md) {318 LunarShortcut("⌘K")319 LunarShortcut("⌘⇧O")320 LunarShortcut(["⌥", "Space"])321 LunarLabel("Reader", icon: .glyph(.reader), help: "Read this page without distractions")322 .foregroundStyle(theme.textSecondary)323 }324 }325 }326 }327 }328329 private var componentsTrailing: some View {330 VStack(alignment: .leading, spacing: LunarSpacing.lg) {331 GalleryGroup("Rows, section header, card") {332 VStack(alignment: .leading, spacing: LunarSpacing.xs) {333 LunarSectionHeader("Library", actionTitle: "Edit") {}334 LunarListRow("Reading list", subtitle: "12 pages saved", icon: .glyph(.reader),335 isSelected: true, action: {}) { LunarBadge("12", status: .accent) }336 LunarListRow("Archive", icon: .glyph(.archive), action: {}) { LunarShortcut("⌘⇧A") }337 LunarListRow("Time travel", subtitle: "History as a timeline", icon: .glyph(.time), action: {})338 LunarHairline().padding(.vertical, LunarSpacing.unit)339 LunarCard {340 VStack(alignment: .leading, spacing: LunarSpacing.xs) {341 HStack {342 Text("Shield report").lunarFont(.headline).foregroundStyle(theme.textPrimary)343 Spacer()344 LunarBadge("Protected", status: .success)345 }346 Text("148 trackers and 12 fingerprinting attempts were blocked this week.")347 .lunarFont(.callout).lunarTabularDigits().foregroundStyle(theme.textSecondary)348 LunarProgressBar(value: 0.74, label: "Weekly protection")349 }350 }351 }352 }353 GalleryGroup("Badges and progress") {354 VStack(alignment: .leading, spacing: LunarSpacing.sm) {355 HStack(spacing: LunarSpacing.xs) {356 LunarBadge("Neutral")357 LunarBadge("12", status: .accent)358 LunarBadge("Secure", status: .success, icon: .symbol("lock.fill"))359 LunarBadge("Tracker", status: .warning)360 LunarBadge("Blocked", status: .danger)361 }362 LunarProgressBar(value: 0.62, label: "Download")363 LunarProgressBar(value: nil, label: "Loading")364 HStack(spacing: LunarSpacing.md) {365 LunarProgressRing(value: 0.7)366 LunarProgressRing(value: nil)367 LunarProgressRing(value: 0.35, size: 44)368 }369 }370 }371 GalleryGroup("Banner and toast") {372 VStack(alignment: .leading, spacing: LunarSpacing.sm) {373 LunarBanner(.warning, title: "This connection is not private",374 message: "The site's certificate expired yesterday.", actionTitle: "Details",375 action: {}, onDismiss: {})376 LunarBanner(.accent, title: "Agent finished summarising 4 tabs")377 HStack(spacing: LunarSpacing.sm) {378 LunarToast("Link copied", status: .success)379 LunarToast("Download failed", status: .danger)380 }381 }382 }383 GalleryGroup("Sheet header, empty and error states") {384 VStack(spacing: LunarSpacing.xs) {385 LunarSheetHeader("New satellite", subtitle: "Group pages around a topic", icon: .glyph(.orbit),386 onClose: {})387 LunarHairline()388 HStack(alignment: .top, spacing: 0) {389 LunarEmptyState(icon: .glyph(.memory), title: "No memories yet",390 message: "Pages you choose to keep will gather here.",391 actionTitle: "Keep this page") {}392 LunarErrorState(title: "The page did not load",393 message: "The server took too long to answer.", retryTitle: "Try again") {}394 }395 }396 }397 }398 }399400 // MARK: Layout helper401402 /// A plain (non-lazy) grid: lazy containers do not render offscreen.403 private func grid<Item, Cell: View>(_ items: [Item], columns: Int,404 @ViewBuilder cell: @escaping (Item) -> Cell) -> some View {405 let rows = stride(from: 0, to: items.count, by: columns).map { Array(items[$0..<min($0 + columns, items.count)]) }406 return VStack(spacing: LunarSpacing.sm) {407 ForEach(Array(rows.enumerated()), id: \.offset) { _, row in408 HStack(alignment: .top, spacing: LunarSpacing.sm) {409 ForEach(Array(row.enumerated()), id: \.offset) { _, item in410 cell(item).frame(maxWidth: .infinity)411 }412 ForEach(0..<(columns - row.count), id: \.self) { _ in Color.clear.frame(maxWidth: .infinity, maxHeight: 1) }413 }414 }415 }416 }417}418419private struct GalleryGroup<Content: View>: View {420 @Environment(\.lunarTheme) private var theme421 private let title: String422 private let content: Content423424 init(_ title: String, @ViewBuilder content: () -> Content) {425 self.title = title426 self.content = content()427 }428429 var body: some View {430 VStack(alignment: .leading, spacing: LunarSpacing.sm) {431 LunarSectionHeader(title)432 content433 .frame(maxWidth: .infinity, alignment: .leading)434 .padding(LunarSpacing.md)435 .lunarGlass(.md, style: .chrome, elevation: .raised)436 }437 }438}439440private struct GallerySwatch: View {441 @Environment(\.lunarTheme) private var theme442 let name: String443 let color: LunarRGBA444445 var body: some View {446 VStack(alignment: .leading, spacing: LunarSpacing.unit + 2) {447 LunarShape.xs.fill(color)448 .frame(height: 44)449 .lunarHairline(.xs)450 Text(name).lunarFont(.caption).foregroundStyle(theme.textPrimary).lineLimit(1).minimumScaleFactor(0.8)451 Text(color.hexString).font(.system(.caption2, design: .monospaced)).foregroundStyle(theme.textSecondary)452 }453 .accessibilityElement(children: .combine)454 }455}456457/// A miniature of a family: both renditions side by side, each with a chrome capsule, text lines and accents.458private struct GalleryThemeCard: View {459 @Environment(\.lunarTheme) private var theme460 let family: LunarThemeFamily461 let isCurrent: Bool462463 var body: some View {464 VStack(alignment: .leading, spacing: LunarSpacing.unit + 2) {465 HStack(spacing: 0) {466 half(family.dark)467 half(family.light)468 }469 .frame(height: 76)470 .clipShape(LunarShape.xs)471 .overlay { LunarShape.xs.strokeBorder(isCurrent ? theme.accent : theme.hairline, lineWidth: isCurrent ? 2 : 1) }472 Text(family.name).lunarFont(.caption).foregroundStyle(theme.textPrimary)473 Text(family.id).font(.system(.caption2, design: .monospaced)).foregroundStyle(theme.textSecondary)474 }475 .accessibilityElement(children: .combine)476 .accessibilityAddTraits(isCurrent ? .isSelected : [])477 }478479 private func half(_ variant: LunarTheme) -> some View {480 ZStack {481 Rectangle().fill(variant.windowGradient)482 VStack(alignment: .leading, spacing: 6) {483 Capsule().fill(variant.chromeSurface)484 .overlay { Capsule().strokeBorder(variant.hairlineStrong, lineWidth: 1) }485 .overlay(alignment: .leading) {486 Circle().fill(variant.accent).frame(width: 7, height: 7).padding(.leading, 6)487 }488 .frame(height: 16)489 Capsule().fill(variant.textPrimary).frame(width: 44, height: 4)490 Capsule().fill(variant.textSecondary).frame(width: 30, height: 4)491 HStack(spacing: 4) {492 Circle().fill(variant.accent).frame(width: 10, height: 10)493 Circle().fill(variant.accentSecondary).frame(width: 10, height: 10)494 RoundedRectangle(cornerRadius: 3).fill(variant.elevatedSurface)495 .overlay { RoundedRectangle(cornerRadius: 3).strokeBorder(variant.hairline, lineWidth: 1) }496 .frame(width: 18, height: 10)497 }498 }499 .padding(8)500 }501 }502}503504#Preview("Gallery · Lunar") {505 LunarGallery()506 .frame(minWidth: 1100, minHeight: 800)507}508509#Preview("Gallery · Solar light") {510 LunarGallery(initialFamily: LunarThemes.solar, appearance: .light)511 .frame(minWidth: 1100, minHeight: 800)512}513