Jotley / app / macOS / Views / SettingsView+Sidebar.swift
| 1 | import SwiftUI |
| 2 | import AppKit |
| 3 | |
| 4 | extension SettingsView { |
| 5 | var visibleSections: [SettingsSection] { SettingsSection.allCases } |
| 6 | @ViewBuilder func sectionHeader(for section: SettingsSection) -> some View { |
| 7 | if section == .obsidian { Text("Integrations").font(.caption).foregroundColor(.secondary).padding(.horizontal, 20).padding(.top, 20).padding(.bottom, 8) } |
| 8 | } |
| 9 | |
| 10 | func sectionButton(for section: SettingsSection) -> some View { |
| 11 | let isSelected = selectedSection == section |
| 12 | |
| 13 | return Button(action: { |
| 14 | selectedSection = section |
| 15 | }) { |
| 16 | HStack(spacing: 12) { |
| 17 | if section == .obsidian { |
| 18 | Image("obsidian-icon") |
| 19 | .resizable() |
| 20 | .scaledToFit() |
| 21 | .frame(width: 16, height: 16) |
| 22 | .opacity(isSelected ? 1.0 : 0.9) |
| 23 | } else { |
| 24 | Image(systemName: section.icon) |
| 25 | .font(.system(size: 16)) |
| 26 | .foregroundColor(isSelected ? .themePrimaryAccent : .themeTextSecondary) |
| 27 | .frame(width: 16) |
| 28 | } |
| 29 | |
| 30 | Text(section.rawValue) |
| 31 | .font(.system(size: 14)) |
| 32 | .foregroundColor(isSelected ? .themeTextPrimary : .themeTextSecondary) |
| 33 | |
| 34 | Spacer() |
| 35 | } |
| 36 | .frame(maxWidth: .infinity, alignment: .leading) |
| 37 | .padding(.horizontal, 20) |
| 38 | .padding(.vertical, 8) |
| 39 | .background( |
| 40 | isSelected ? |
| 41 | Color.themeSelectionBackground : Color.clear |
| 42 | ) |
| 43 | .cornerRadius(6) |
| 44 | .contentShape(Rectangle()) |
| 45 | } |
| 46 | .buttonStyle(.plain) |
| 47 | .padding(.horizontal, 8) |
| 48 | .accessibilityIdentifier("settings\(section.rawValue.replacingOccurrences(of: " ", with: ""))Section") |
| 49 | } |
| 50 | |
| 51 | var sidebarView: some View { |
| 52 | VStack(alignment: .leading, spacing: 0) { |
| 53 | HStack { |
| 54 | Text("Settings") |
| 55 | .font(.title2) |
| 56 | .fontWeight(.semibold) |
| 57 | .foregroundColor(.primary) |
| 58 | Spacer() |
| 59 | Button(action: { dismiss() }) { |
| 60 | Image(systemName: "xmark") |
| 61 | .foregroundColor(.secondary) |
| 62 | .font(.system(size: 14, weight: .medium)) |
| 63 | } |
| 64 | .buttonStyle(JotleyGlassButtonStyle(circular: true)) |
| 65 | .accessibilityIdentifier("settingsCloseButton") |
| 66 | } |
| 67 | .padding(.horizontal, 20) |
| 68 | .padding(.top, 28) |
| 69 | .padding(.bottom, 20) |
| 70 | |
| 71 | ScrollView { |
| 72 | VStack(alignment: .leading, spacing: 2) { |
| 73 | ForEach(visibleSections, id: \.self) { section in |
| 74 | sectionHeader(for: section) |
| 75 | sectionButton(for: section) |
| 76 | } |
| 77 | } |
| 78 | .padding(.bottom, 12) |
| 79 | } |
| 80 | .frame(maxHeight: .infinity) |
| 81 | |
| 82 | |
| 83 | } |
| 84 | .frame(width: 210) |
| 85 | .frame(maxHeight: .infinity, alignment: .top) |
| 86 | .background(Color(NSColor.controlBackgroundColor)) |
| 87 | } |
| 88 | } |