Add link hover state and tooltip

This commit is contained in:
Shadowfacts 2020-07-15 22:52:15 -04:00
parent ab34d537d8
commit 80fcfd3b91
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 14 additions and 3 deletions

View File

@ -11,6 +11,7 @@ import GeminiFormat
struct RenderingBlockView: View {
let block: RenderingBlock
let changeURL: ((URL) -> Void)?
@State var hovering = false
init(block: RenderingBlock, changeURL: ((URL) -> Void)? = nil) {
self.block = block
@ -43,15 +44,25 @@ struct RenderingBlockView: View {
private func link(_ url: URL, text: String?) -> some View {
let text = text ?? url.absoluteString
return Button {
let button: some View = Button {
self.changeURL?(url)
} label: {
Text(verbatim: text)
.font(.documentBody)
.foregroundColor(.blue)
.foregroundColor(hovering ? .blue : Color.blue.opacity(0.8))
.underline()
.frame(maxWidth: .infinity, alignment: .leading)
}.buttonStyle(LinkButtonStyle())
}
.buttonStyle(LinkButtonStyle())
.onHover { hovering in
self.hovering = hovering
}
if #available(macOS 10.16, iOS 14.0, *) {
return AnyView(button.help(url.absoluteString))
} else {
return AnyView(button)
}
}
private func preformatted(_ text: String) -> some View {