SidebarNavItemView.swift 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import SwiftUI
  2. struct SidebarNavItemView: View {
  3. let item: SidebarNavItem
  4. let isSelected: Bool
  5. let action: () -> Void
  6. var body: some View {
  7. Button(action: action) {
  8. SidebarItemRow(
  9. title: item.title,
  10. subtitle: item.subtitle,
  11. isSelected: isSelected
  12. ) {
  13. ModernSidebarIconView(kind: item.iconKind)
  14. }
  15. }
  16. .buttonStyle(AppPlainButtonStyle())
  17. }
  18. }
  19. struct SidebarQuickAccessItemView: View {
  20. let isSelected: Bool
  21. let action: () -> Void
  22. var body: some View {
  23. Button(action: action) {
  24. SidebarItemRow(
  25. title: "Open Reddit",
  26. subtitle: "Browse Reddit in-app",
  27. isSelected: isSelected,
  28. showsChevron: true
  29. ) {
  30. ModernRedditIconView()
  31. }
  32. }
  33. .buttonStyle(AppPlainButtonStyle())
  34. }
  35. }
  36. private struct SidebarItemRow<Icon: View>: View {
  37. let title: String
  38. let subtitle: String
  39. var isSelected: Bool = false
  40. var showsChevron: Bool = false
  41. @ViewBuilder let icon: () -> Icon
  42. var body: some View {
  43. HStack(alignment: .center, spacing: AppTheme.sidebarRowSpacing) {
  44. icon()
  45. .frame(width: AppTheme.iconContainerSize, height: AppTheme.iconContainerSize)
  46. VStack(alignment: .leading, spacing: 1) {
  47. Text(title)
  48. .font(.system(size: 12, weight: .semibold))
  49. .foregroundStyle(AppTheme.textPrimary)
  50. if !subtitle.isEmpty {
  51. Text(subtitle)
  52. .font(.system(size: 10))
  53. .foregroundStyle(AppTheme.textSecondary)
  54. }
  55. }
  56. .padding(.leading, 2)
  57. Spacer(minLength: 0)
  58. if showsChevron {
  59. Image(systemName: "chevron.right")
  60. .font(.system(size: 10, weight: .semibold))
  61. .foregroundStyle(AppTheme.textSecondary)
  62. }
  63. }
  64. .padding(.horizontal, AppTheme.sidebarRowPaddingH)
  65. .padding(.vertical, AppTheme.sidebarRowPaddingV)
  66. .contentShape(RoundedRectangle(cornerRadius: AppTheme.cornerRadiusSmall))
  67. .sidebarRowHover(isSelected: isSelected)
  68. }
  69. }
  70. struct SidebarSectionHeader: View {
  71. let title: String
  72. var body: some View {
  73. Text(title)
  74. .font(.system(size: 10, weight: .bold))
  75. .foregroundStyle(AppTheme.textTertiary)
  76. .tracking(1.0)
  77. .frame(maxWidth: .infinity, alignment: .leading)
  78. .padding(.horizontal, AppTheme.sidebarRowPaddingH)
  79. .padding(.top, 5)
  80. .padding(.bottom, 4)
  81. }
  82. }