Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 18 additions & 23 deletions Sources/Kaset/Views/AccountRowView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import SwiftUI

/// A single account row component displaying account info.
///
/// Shows the account avatar, name, handle, type badge, and selection state.
/// Shows the account avatar, name, handle, account type, and selection state.
struct AccountRowView: View {
let account: UserAccount
let isSelected: Bool
Expand Down Expand Up @@ -41,23 +41,24 @@ struct AccountRowView: View {

Spacer()

// Type badge
self.typeBadge
// Account type
self.typeLabel

// Selection checkmark
if self.isSelected {
Image(systemName: "checkmark")
.font(.system(size: 12, weight: .semibold))
.foregroundStyle(.blue)
.foregroundStyle(Color.accentColor)
.accessibilityLabel(String(localized: "Selected"))
}
}
.padding(.horizontal, 12)
.padding(.vertical, 10)
.background(self.rowBackground)
.contentShape(Rectangle())
.contentShape(.rect(cornerRadius: 10))
}
.buttonStyle(.plain)
.animation(.easeInOut(duration: 0.14), value: self.isHovering)
.onHover { hovering in
self.isHovering = hovering
}
Expand Down Expand Up @@ -97,36 +98,30 @@ struct AccountRowView: View {
}
}

// MARK: - Type Badge
// MARK: - Type Label

private var typeBadge: some View {
private var typeLabel: some View {
Text(self.account.typeLabel)
.font(.caption2)
.fontWeight(.medium)
.foregroundStyle(self.account.isPrimary ? .blue : .orange)
.padding(.horizontal, 8)
.padding(.vertical, 3)
.background {
Capsule()
.fill(self.account.isPrimary ? Color.blue.opacity(0.15) : Color.orange.opacity(0.15))
.overlay {
Capsule()
.strokeBorder(Color.white.opacity(0.12), lineWidth: 1)
}
}
.foregroundStyle(.tertiary)
.fixedSize()
}

// MARK: - Background

@ViewBuilder
private var rowBackground: some View {
if self.isSelected || self.isHovering {
RoundedRectangle(cornerRadius: 10)
.fill(Color.white.opacity(self.isSelected ? 0.16 : 0.08))
if self.isSelected {
RoundedRectangle(cornerRadius: 10, style: .continuous)
.fill(Color.accentColor.opacity(self.isHovering ? 0.12 : 0.08))
.overlay {
RoundedRectangle(cornerRadius: 10)
.strokeBorder(Color.white.opacity(self.isSelected ? 0.22 : 0.14), lineWidth: 1)
RoundedRectangle(cornerRadius: 10, style: .continuous)
.strokeBorder(Color.accentColor.opacity(0.18), lineWidth: 0.5)
}
} else if self.isHovering {
RoundedRectangle(cornerRadius: 10, style: .continuous)
.fill(Color.primary.opacity(0.05))
} else {
Color.clear
}
Expand Down
92 changes: 72 additions & 20 deletions Sources/Kaset/Views/AccountSwitcherPopover.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,28 @@ struct AccountSwitcherPopover: View {
@Environment(AuthService.self) private var authService
@Environment(\.dismiss) private var dismiss

@State private var isGuestModeHovering = false
@State private var isSignOutHovering = false

/// Namespace for glass effect morphing.
@Namespace private var popoverNamespace

var body: some View {
CompatGlassContainer(spacing: 8) {
VStack(spacing: 8) {
// Header
VStack(spacing: 4) {
self.headerView

self.accountsListView
self.guestModeRow

Divider()
.opacity(0.3)
.opacity(0.18)
.padding(.horizontal, 12)
.padding(.top, 2)

// Accounts list
self.accountsListView
self.signOutButton
}
.padding(10)
.frame(minWidth: 280)
.padding(8)
.frame(minWidth: 288)
.compatGlass(interactive: true, in: .rect(cornerRadius: 14))
.compatGlassID("accountSwitcherPopover", in: self.popoverNamespace)
}
Expand All @@ -47,7 +49,7 @@ struct AccountSwitcherPopover: View {
private var headerView: some View {
HStack {
Text(String(localized: "Switch Account"))
.font(.headline)
.font(.subheadline.weight(.semibold))
.foregroundStyle(.primary)

Spacer()
Expand All @@ -57,8 +59,9 @@ struct AccountSwitcherPopover: View {
.controlSize(.small)
}
}
.padding(.horizontal, 14)
.padding(.vertical, 10)
.padding(.horizontal, 12)
.padding(.top, 8)
.padding(.bottom, 4)
.accessibilityIdentifier(AccessibilityID.AccountSwitcher.header)
}

Expand Down Expand Up @@ -93,16 +96,20 @@ struct AccountSwitcherPopover: View {
if self.authService.isGuestModeEnabled {
Image(systemName: "checkmark")
.font(.system(size: 12, weight: .semibold))
.foregroundStyle(.blue)
.foregroundStyle(Color.accentColor)
.accessibilityLabel(String(localized: "Selected"))
}
}
.padding(.horizontal, 12)
.padding(.vertical, 10)
.padding(.vertical, 9)
.background(self.guestRowBackground)
.contentShape(Rectangle())
.contentShape(.rect(cornerRadius: 10))
}
.buttonStyle(.plain)
.animation(.easeInOut(duration: 0.14), value: self.isGuestModeHovering)
.onHover { hovering in
self.isGuestModeHovering = hovering
}
.accessibilityIdentifier(AccessibilityID.AccountSwitcher.guestModeRow)
.accessibilityLabel(String(localized: "Guest Mode, browse without personalization"))
.accessibilityAddTraits(self.authService.isGuestModeEnabled ? [.isButton, .isSelected] : .isButton)
Expand All @@ -111,12 +118,15 @@ struct AccountSwitcherPopover: View {
@ViewBuilder
private var guestRowBackground: some View {
if self.authService.isGuestModeEnabled {
RoundedRectangle(cornerRadius: 10)
.fill(Color.white.opacity(0.16))
RoundedRectangle(cornerRadius: 10, style: .continuous)
.fill(Color.accentColor.opacity(self.isGuestModeHovering ? 0.12 : 0.08))
.overlay {
RoundedRectangle(cornerRadius: 10)
.strokeBorder(Color.white.opacity(0.22), lineWidth: 1)
RoundedRectangle(cornerRadius: 10, style: .continuous)
.strokeBorder(Color.accentColor.opacity(0.18), lineWidth: 0.5)
}
} else if self.isGuestModeHovering {
RoundedRectangle(cornerRadius: 10, style: .continuous)
.fill(Color.primary.opacity(0.05))
} else {
Color.clear
}
Expand All @@ -131,7 +141,8 @@ struct AccountSwitcherPopover: View {
VStack(spacing: 0) {
AccountRowView(
account: account,
isSelected: account == self.accountService.currentAccount,
isSelected: !self.authService.isGuestModeEnabled
&& account == self.accountService.currentAccount,
onSelect: {
Task {
let wasGuestMode = self.authService.isGuestModeEnabled
Expand All @@ -158,11 +169,51 @@ struct AccountSwitcherPopover: View {
}
}
}
.padding(.vertical, 6)
.padding(.vertical, 2)
}
.frame(maxHeight: 300)
.accessibilityIdentifier(AccessibilityID.AccountSwitcher.accountsList)
}

private var signOutButton: some View {
Button(role: .destructive) {
Task {
await self.accountService.prepareForSignOut()
await self.authService.signOut()
self.dismiss()
}
} label: {
HStack(spacing: 10) {
Image(systemName: "rectangle.portrait.and.arrow.right")
.font(.system(size: 14, weight: .medium))
.frame(width: 18)
Text(String(localized: "Sign Out"))
.font(.callout)
Spacer()
}
.padding(.horizontal, 12)
.padding(.vertical, 9)
.contentShape(.rect(cornerRadius: 8))
}
.buttonStyle(.plain)
.foregroundStyle(self.isSignOutHovering ? Color.red : Color.secondary)
.background(self.signOutBackground)
.animation(.easeInOut(duration: 0.14), value: self.isSignOutHovering)
.onHover { hovering in
self.isSignOutHovering = hovering
}
.accessibilityIdentifier(AccessibilityID.AccountSwitcher.signOutButton)
}

@ViewBuilder
private var signOutBackground: some View {
if self.isSignOutHovering {
RoundedRectangle(cornerRadius: 8, style: .continuous)
.fill(Color.red.opacity(0.10))
} else {
Color.clear
}
}
}

// MARK: - AccessibilityID.AccountSwitcher
Expand All @@ -173,6 +224,7 @@ extension AccessibilityID {
static let header = "accountSwitcher.header"
static let accountsList = "accountSwitcher.accountsList"
static let guestModeRow = "accountSwitcher.guestMode"
static let signOutButton = "accountSwitcher.signOut"

static func accountRow(index: Int) -> String {
"accountSwitcher.account.\(index)"
Expand Down
1 change: 1 addition & 0 deletions Tests/KasetUITests/KasetUITestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ enum TestAccessibilityID {
static let header = "accountSwitcher.header"
static let accountsList = "accountSwitcher.accountsList"
static let guestModeRow = "accountSwitcher.guestMode"
static let signOutButton = "accountSwitcher.signOut"

static func accountRow(index: Int) -> String {
"accountSwitcher.account.\(index)"
Expand Down
Loading