Add links for email, phone and domain
This commit is contained in:
@ -1,5 +1,8 @@
|
||||
import SwiftUI
|
||||
import SFSafeSymbols
|
||||
import PhoneNumberKit
|
||||
|
||||
private let emailPattern = #"^\S+@\S+\.\S+$"#
|
||||
|
||||
struct TopView: View {
|
||||
|
||||
@ -8,6 +11,21 @@ struct TopView: View {
|
||||
let style: HeaderStyle
|
||||
|
||||
let accent: Color
|
||||
|
||||
private let phoneNumberKit = PhoneNumberKit()
|
||||
|
||||
var isValidEmail: Bool {
|
||||
info.email.range(of: emailPattern, options: .regularExpression) != nil
|
||||
}
|
||||
|
||||
var isValidPhoneNumber: Bool {
|
||||
do {
|
||||
_ = try phoneNumberKit.parse(info.phone)
|
||||
return true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
GeometryReader { geo in
|
||||
@ -34,18 +52,26 @@ struct TopView: View {
|
||||
shadow: style.imageShadowSize,
|
||||
lineWidth: style.imageBorderWidth)
|
||||
VStack(alignment: .trailing) {
|
||||
LeftImageLabel(info.web, systemSymbol: .globe)
|
||||
.frame(maxHeight: style.iconHeight)
|
||||
LeftImageLabel(systemSymbol: .globe) {
|
||||
Link(info.web, destination: URL(string: "https://" + info.web)!)
|
||||
}
|
||||
.frame(maxHeight: style.iconHeight)
|
||||
Spacer()
|
||||
LeftImageLabel(info.email, systemSymbol: .envelope)
|
||||
.frame(maxHeight: style.iconHeight)
|
||||
LeftImageLabel(systemSymbol: .envelope) {
|
||||
Link(info.email, destination: URL(string: "mailto:" + info.email)!)
|
||||
.disabled(!isValidEmail)
|
||||
}
|
||||
.frame(maxHeight: style.iconHeight)
|
||||
Spacer()
|
||||
LeftImageLabel(info.phone, systemSymbol: .phone)
|
||||
.frame(maxHeight: style.iconHeight)
|
||||
LeftImageLabel(systemSymbol: .phone) {
|
||||
Link(info.phone, destination: URL(string: "tel:" + info.phone)!)
|
||||
.disabled(!isValidPhoneNumber)
|
||||
}
|
||||
.frame(maxHeight: style.iconHeight)
|
||||
Spacer()
|
||||
HStack(spacing: 0) {
|
||||
Spacer()
|
||||
Text(info.github)
|
||||
Link(info.github, destination: URL(string: "https://" + info.github)!)
|
||||
Image("Github")
|
||||
.resizable()
|
||||
.aspectRatio(1.0, contentMode: .fit)
|
||||
@ -55,6 +81,7 @@ struct TopView: View {
|
||||
}
|
||||
.font(.subheadline)
|
||||
.frame(width: sideWidth)
|
||||
.foregroundStyle(.primary)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user