Fix Button on Safari
This commit is contained in:
parent
365e0c7be9
commit
94510a0c9e
|
@ -19,25 +19,34 @@ import TokamakCore
|
|||
|
||||
extension _Button: ViewDeferredToRenderer where Label == Text {
|
||||
public var deferredBody: AnyView {
|
||||
let attributes: [String: String]
|
||||
if buttonStyle.type == DefaultButtonStyle.self {
|
||||
attributes = ["class": "_tokamak-buttonstyle-default"]
|
||||
} else {
|
||||
attributes = ["class": "_tokamak-buttonstyle-reset"]
|
||||
}
|
||||
|
||||
return AnyView(DynamicHTML("button", attributes, listeners: [
|
||||
"click": { _ in action() },
|
||||
let listeners: [String: Listener] = [
|
||||
"pointerdown": { _ in isPressed = true },
|
||||
"pointerup": { _ in isPressed = false },
|
||||
]) {
|
||||
buttonStyle.makeBody(
|
||||
configuration: _ButtonStyleConfigurationProxy(
|
||||
label: AnyView(label),
|
||||
isPressed: isPressed
|
||||
).subject
|
||||
)
|
||||
.colorScheme(.light)
|
||||
})
|
||||
"pointerup": { _ in
|
||||
isPressed = false
|
||||
action()
|
||||
},
|
||||
]
|
||||
if buttonStyle.type == DefaultButtonStyle.self {
|
||||
return AnyView(DynamicHTML(
|
||||
"button",
|
||||
["class": "_tokamak-buttonstyle-default"],
|
||||
listeners: listeners,
|
||||
content: label.innerHTML ?? ""
|
||||
))
|
||||
} else {
|
||||
return AnyView(DynamicHTML(
|
||||
"button",
|
||||
["class": "_tokamak-buttonstyle-reset"],
|
||||
listeners: listeners
|
||||
) {
|
||||
buttonStyle.makeBody(
|
||||
configuration: _ButtonStyleConfigurationProxy(
|
||||
label: AnyView(label),
|
||||
isPressed: isPressed
|
||||
).subject
|
||||
)
|
||||
.colorScheme(.light)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,12 +25,35 @@ protocol AnyDynamicHTML: AnyHTML {
|
|||
var listeners: [String: Listener] { get }
|
||||
}
|
||||
|
||||
public struct DynamicHTML<Content>: View, AnyDynamicHTML where Content: View {
|
||||
public struct DynamicHTML<Content>: View, AnyDynamicHTML {
|
||||
public let tag: String
|
||||
public let attributes: [String: String]
|
||||
public let listeners: [String: Listener]
|
||||
let content: Content
|
||||
|
||||
public var innerHTML: String?
|
||||
|
||||
public var body: Never {
|
||||
neverBody("HTML")
|
||||
}
|
||||
}
|
||||
|
||||
extension DynamicHTML where Content: StringProtocol {
|
||||
public init(
|
||||
_ tag: String,
|
||||
_ attributes: [String: String] = [:],
|
||||
listeners: [String: Listener] = [:],
|
||||
content: Content
|
||||
) {
|
||||
self.tag = tag
|
||||
self.attributes = attributes
|
||||
self.listeners = listeners
|
||||
self.content = content
|
||||
innerHTML = String(content)
|
||||
}
|
||||
}
|
||||
|
||||
extension DynamicHTML: ParentView where Content: View {
|
||||
public init(
|
||||
_ tag: String,
|
||||
_ attributes: [String: String] = [:],
|
||||
|
@ -41,12 +64,11 @@ public struct DynamicHTML<Content>: View, AnyDynamicHTML where Content: View {
|
|||
self.attributes = attributes
|
||||
self.listeners = listeners
|
||||
self.content = content()
|
||||
innerHTML = nil
|
||||
}
|
||||
|
||||
public var innerHTML: String? { nil }
|
||||
|
||||
public var body: Never {
|
||||
neverBody("HTML")
|
||||
public var children: [AnyView] {
|
||||
[AnyView(content)]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,9 +81,3 @@ extension DynamicHTML where Content == EmptyView {
|
|||
self = DynamicHTML(tag, attributes, listeners: listeners) { EmptyView() }
|
||||
}
|
||||
}
|
||||
|
||||
extension DynamicHTML: ParentView {
|
||||
public var children: [AnyView] {
|
||||
[AnyView(content)]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,11 +34,32 @@ extension AnyHTML {
|
|||
}
|
||||
}
|
||||
|
||||
public struct HTML<Content>: View, AnyHTML where Content: View {
|
||||
public struct HTML<Content>: View, AnyHTML {
|
||||
public let tag: String
|
||||
public let attributes: [String: String]
|
||||
let content: Content
|
||||
|
||||
public let innerHTML: String?
|
||||
|
||||
public var body: Never {
|
||||
neverBody("HTML")
|
||||
}
|
||||
}
|
||||
|
||||
extension HTML where Content: StringProtocol {
|
||||
public init(
|
||||
_ tag: String,
|
||||
_ attributes: [String: String] = [:],
|
||||
content: Content
|
||||
) {
|
||||
self.tag = tag
|
||||
self.attributes = attributes
|
||||
self.content = content
|
||||
innerHTML = String(content)
|
||||
}
|
||||
}
|
||||
|
||||
extension HTML: ParentView where Content: View {
|
||||
public init(
|
||||
_ tag: String,
|
||||
_ attributes: [String: String] = [:],
|
||||
|
@ -47,12 +68,11 @@ public struct HTML<Content>: View, AnyHTML where Content: View {
|
|||
self.tag = tag
|
||||
self.attributes = attributes
|
||||
self.content = content()
|
||||
innerHTML = nil
|
||||
}
|
||||
|
||||
public var innerHTML: String? { nil }
|
||||
|
||||
public var body: Never {
|
||||
neverBody("HTML")
|
||||
public var children: [AnyView] {
|
||||
[AnyView(content)]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,12 +85,6 @@ extension HTML where Content == EmptyView {
|
|||
}
|
||||
}
|
||||
|
||||
extension HTML: ParentView {
|
||||
public var children: [AnyView] {
|
||||
[AnyView(content)]
|
||||
}
|
||||
}
|
||||
|
||||
public protocol StylesConvertible {
|
||||
var styles: [String: String] { get }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue