From 0b60e2d087e6a9277684cf1db478de56dd390e4d Mon Sep 17 00:00:00 2001 From: Ethan Dickson Date: Tue, 18 Feb 2025 16:52:48 +1100 Subject: [PATCH] chore: make cli-auth link visually responsive --- .../Coder Desktop/Views/LoginForm.swift | 4 +- .../Coder Desktop/Views/ResponsiveLink.swift | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 Coder Desktop/Coder Desktop/Views/ResponsiveLink.swift diff --git a/Coder Desktop/Coder Desktop/Views/LoginForm.swift b/Coder Desktop/Coder Desktop/Views/LoginForm.swift index 8943b50..d501437 100644 --- a/Coder Desktop/Coder Desktop/Views/LoginForm.swift +++ b/Coder Desktop/Coder Desktop/Views/LoginForm.swift @@ -128,9 +128,7 @@ struct LoginForm: View { Text("Generate a session token at ") .font(.subheadline) .foregroundColor(.secondary) - Link(cliAuthURL.absoluteString, destination: cliAuthURL) - .font(.subheadline) - .foregroundColor(.blue) + ResponsiveLink(title: cliAuthURL.absoluteString, destination: cliAuthURL) } } }.formStyle(.grouped).scrollDisabled(true).padding(.horizontal) diff --git a/Coder Desktop/Coder Desktop/Views/ResponsiveLink.swift b/Coder Desktop/Coder Desktop/Views/ResponsiveLink.swift new file mode 100644 index 0000000..fd37881 --- /dev/null +++ b/Coder Desktop/Coder Desktop/Views/ResponsiveLink.swift @@ -0,0 +1,39 @@ +import SwiftUI + +struct ResponsiveLink: View { + let title: String + let destination: URL + + @State private var isHovered = false + @State private var isPressed = false + @Environment(\.openURL) private var openURL + + var body: some View { + Text(title) + .font(.subheadline) + .foregroundColor(isPressed ? .red : .blue) + .underline(isHovered, color: isPressed ? .red : .blue) + .onHover { hovering in + isHovered = hovering + if hovering { + NSCursor.pointingHand.push() + } else { + NSCursor.pop() + } + } + .simultaneousGesture( + DragGesture(minimumDistance: 0) + .onChanged { _ in + withAnimation(.easeInOut(duration: 0.1)) { + isPressed = true + } + } + .onEnded { _ in + withAnimation(.easeInOut(duration: 0.1)) { + isPressed = false + } + openURL(destination) + } + ) + } +}