Add link hover state and tooltip
This commit is contained in:
parent
ab34d537d8
commit
80fcfd3b91
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue