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 {
|
extension _Button: ViewDeferredToRenderer where Label == Text {
|
||||||
public var deferredBody: AnyView {
|
public var deferredBody: AnyView {
|
||||||
let attributes: [String: String]
|
let listeners: [String: Listener] = [
|
||||||
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() },
|
|
||||||
"pointerdown": { _ in isPressed = true },
|
"pointerdown": { _ in isPressed = true },
|
||||||
"pointerup": { _ in isPressed = false },
|
"pointerup": { _ in
|
||||||
]) {
|
isPressed = false
|
||||||
buttonStyle.makeBody(
|
action()
|
||||||
configuration: _ButtonStyleConfigurationProxy(
|
},
|
||||||
label: AnyView(label),
|
]
|
||||||
isPressed: isPressed
|
if buttonStyle.type == DefaultButtonStyle.self {
|
||||||
).subject
|
return AnyView(DynamicHTML(
|
||||||
)
|
"button",
|
||||||
.colorScheme(.light)
|
["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 }
|
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 tag: String
|
||||||
public let attributes: [String: String]
|
public let attributes: [String: String]
|
||||||
public let listeners: [String: Listener]
|
public let listeners: [String: Listener]
|
||||||
let content: Content
|
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(
|
public init(
|
||||||
_ tag: String,
|
_ tag: String,
|
||||||
_ attributes: [String: String] = [:],
|
_ attributes: [String: String] = [:],
|
||||||
|
@ -41,12 +64,11 @@ public struct DynamicHTML<Content>: View, AnyDynamicHTML where Content: View {
|
||||||
self.attributes = attributes
|
self.attributes = attributes
|
||||||
self.listeners = listeners
|
self.listeners = listeners
|
||||||
self.content = content()
|
self.content = content()
|
||||||
|
innerHTML = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
public var innerHTML: String? { nil }
|
public var children: [AnyView] {
|
||||||
|
[AnyView(content)]
|
||||||
public var body: Never {
|
|
||||||
neverBody("HTML")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,9 +81,3 @@ extension DynamicHTML where Content == EmptyView {
|
||||||
self = DynamicHTML(tag, attributes, listeners: listeners) { 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 tag: String
|
||||||
public let attributes: [String: String]
|
public let attributes: [String: String]
|
||||||
let content: Content
|
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(
|
public init(
|
||||||
_ tag: String,
|
_ tag: String,
|
||||||
_ attributes: [String: String] = [:],
|
_ attributes: [String: String] = [:],
|
||||||
|
@ -47,12 +68,11 @@ public struct HTML<Content>: View, AnyHTML where Content: View {
|
||||||
self.tag = tag
|
self.tag = tag
|
||||||
self.attributes = attributes
|
self.attributes = attributes
|
||||||
self.content = content()
|
self.content = content()
|
||||||
|
innerHTML = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
public var innerHTML: String? { nil }
|
public var children: [AnyView] {
|
||||||
|
[AnyView(content)]
|
||||||
public var body: Never {
|
|
||||||
neverBody("HTML")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,12 +85,6 @@ extension HTML where Content == EmptyView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension HTML: ParentView {
|
|
||||||
public var children: [AnyView] {
|
|
||||||
[AnyView(content)]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public protocol StylesConvertible {
|
public protocol StylesConvertible {
|
||||||
var styles: [String: String] { get }
|
var styles: [String: String] { get }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue