feat: Removes reset button style bc it wasn't working as expected
This commit is contained in:
@@ -20,8 +20,6 @@ public struct InfoButton: View {
|
||||
|
||||
public struct ResetButton: View {
|
||||
|
||||
@Environment(\.resetButtonStyle) private var resetButtonStyle
|
||||
|
||||
let action: () -> Void
|
||||
|
||||
public init(action: @escaping () -> Void) {
|
||||
@@ -29,7 +27,16 @@ public struct ResetButton: View {
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
Button("Reset") { action() }
|
||||
.buttonStyle(resetButtonStyle)
|
||||
Button("Reset", role: .destructive) {
|
||||
action()
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
VStack {
|
||||
InfoButton { }
|
||||
ResetButton { }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,14 +3,10 @@ import SwiftUI
|
||||
/// A name space for info button styles.
|
||||
public enum InfoButtonType { }
|
||||
|
||||
/// A name space for info button styles.
|
||||
public enum ResetButtonType { }
|
||||
|
||||
|
||||
public struct AnyButtonStyle<ButtonType>: ButtonStyle {
|
||||
public struct AnyButtonStyle<ButtonType>: PrimitiveButtonStyle {
|
||||
private let _makeBody: (Configuration) -> AnyView
|
||||
|
||||
public init<S: ButtonStyle>(_ style: S) {
|
||||
public init<S: PrimitiveButtonStyle>(_ style: S) {
|
||||
self._makeBody = { configuration in
|
||||
AnyView(style.makeBody(configuration: configuration))
|
||||
}
|
||||
@@ -22,7 +18,7 @@ public struct AnyButtonStyle<ButtonType>: ButtonStyle {
|
||||
}
|
||||
|
||||
|
||||
public struct DefaultInfoButtonStyle: ButtonStyle {
|
||||
public struct DefaultInfoButtonStyle: PrimitiveButtonStyle {
|
||||
public func makeBody(configuration: Configuration) -> some View {
|
||||
configuration.label
|
||||
.buttonStyle(.plain)
|
||||
@@ -37,54 +33,33 @@ extension AnyButtonStyle where ButtonType == InfoButtonType {
|
||||
}
|
||||
}
|
||||
|
||||
public struct DefaultResetButtonStyle: ButtonStyle {
|
||||
public struct DefaultResetButtonStyle: PrimitiveButtonStyle {
|
||||
public func makeBody(configuration: Configuration) -> some View {
|
||||
configuration.label
|
||||
.buttonStyle(.borderedProminent)
|
||||
}
|
||||
}
|
||||
|
||||
extension AnyButtonStyle where ButtonType == ResetButtonType {
|
||||
public static var `default`: Self {
|
||||
.init(DefaultResetButtonStyle())
|
||||
}
|
||||
}
|
||||
|
||||
private struct InfoButtonStyleKey: EnvironmentKey {
|
||||
static var defaultValue = AnyButtonStyle<InfoButtonType>.default
|
||||
}
|
||||
|
||||
private struct ResetButtonStyleKey: EnvironmentKey {
|
||||
static var defaultValue = AnyButtonStyle<ResetButtonType>.default
|
||||
}
|
||||
|
||||
extension EnvironmentValues {
|
||||
public var infoButtonStyle: AnyButtonStyle<InfoButtonType> {
|
||||
get { self[InfoButtonStyleKey.self] }
|
||||
set { self[InfoButtonStyleKey.self] = newValue }
|
||||
}
|
||||
|
||||
public var resetButtonStyle: AnyButtonStyle<ResetButtonType> {
|
||||
get { self[ResetButtonStyleKey.self] }
|
||||
set { self[ResetButtonStyleKey.self] = newValue }
|
||||
}
|
||||
}
|
||||
|
||||
extension View {
|
||||
|
||||
public func infoButtonStyle(_ style: AnyButtonStyle<InfoButtonType>) -> some View {
|
||||
environment(\.infoButtonStyle, AnyButtonStyle(style))
|
||||
environment(\.infoButtonStyle, style)
|
||||
}
|
||||
|
||||
public func infoButtonStyle<S: ButtonStyle>(_ style: S) -> some View {
|
||||
public func infoButtonStyle<S: PrimitiveButtonStyle>(_ style: S) -> some View {
|
||||
infoButtonStyle(AnyButtonStyle(style))
|
||||
}
|
||||
|
||||
public func resetButtonStyle(_ style: AnyButtonStyle<ResetButtonType>) -> some View {
|
||||
environment(\.resetButtonStyle, AnyButtonStyle(style))
|
||||
}
|
||||
|
||||
public func resetButtonStyle<S: ButtonStyle>(_ style: S) -> some View {
|
||||
resetButtonStyle(AnyButtonStyle(style))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user