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 {
|
public struct ResetButton: View {
|
||||||
|
|
||||||
@Environment(\.resetButtonStyle) private var resetButtonStyle
|
|
||||||
|
|
||||||
let action: () -> Void
|
let action: () -> Void
|
||||||
|
|
||||||
public init(action: @escaping () -> Void) {
|
public init(action: @escaping () -> Void) {
|
||||||
@@ -29,7 +27,16 @@ public struct ResetButton: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public var body: some View {
|
public var body: some View {
|
||||||
Button("Reset") { action() }
|
Button("Reset", role: .destructive) {
|
||||||
.buttonStyle(resetButtonStyle)
|
action()
|
||||||
|
}
|
||||||
|
.buttonStyle(.borderedProminent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#Preview {
|
||||||
|
VStack {
|
||||||
|
InfoButton { }
|
||||||
|
ResetButton { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,14 +3,10 @@ import SwiftUI
|
|||||||
/// A name space for info button styles.
|
/// A name space for info button styles.
|
||||||
public enum InfoButtonType { }
|
public enum InfoButtonType { }
|
||||||
|
|
||||||
/// A name space for info button styles.
|
public struct AnyButtonStyle<ButtonType>: PrimitiveButtonStyle {
|
||||||
public enum ResetButtonType { }
|
|
||||||
|
|
||||||
|
|
||||||
public struct AnyButtonStyle<ButtonType>: ButtonStyle {
|
|
||||||
private let _makeBody: (Configuration) -> AnyView
|
private let _makeBody: (Configuration) -> AnyView
|
||||||
|
|
||||||
public init<S: ButtonStyle>(_ style: S) {
|
public init<S: PrimitiveButtonStyle>(_ style: S) {
|
||||||
self._makeBody = { configuration in
|
self._makeBody = { configuration in
|
||||||
AnyView(style.makeBody(configuration: configuration))
|
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 {
|
public func makeBody(configuration: Configuration) -> some View {
|
||||||
configuration.label
|
configuration.label
|
||||||
.buttonStyle(.plain)
|
.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 {
|
public func makeBody(configuration: Configuration) -> some View {
|
||||||
configuration.label
|
configuration.label
|
||||||
.buttonStyle(.borderedProminent)
|
.buttonStyle(.borderedProminent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension AnyButtonStyle where ButtonType == ResetButtonType {
|
|
||||||
public static var `default`: Self {
|
|
||||||
.init(DefaultResetButtonStyle())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private struct InfoButtonStyleKey: EnvironmentKey {
|
private struct InfoButtonStyleKey: EnvironmentKey {
|
||||||
static var defaultValue = AnyButtonStyle<InfoButtonType>.default
|
static var defaultValue = AnyButtonStyle<InfoButtonType>.default
|
||||||
}
|
}
|
||||||
|
|
||||||
private struct ResetButtonStyleKey: EnvironmentKey {
|
|
||||||
static var defaultValue = AnyButtonStyle<ResetButtonType>.default
|
|
||||||
}
|
|
||||||
|
|
||||||
extension EnvironmentValues {
|
extension EnvironmentValues {
|
||||||
public var infoButtonStyle: AnyButtonStyle<InfoButtonType> {
|
public var infoButtonStyle: AnyButtonStyle<InfoButtonType> {
|
||||||
get { self[InfoButtonStyleKey.self] }
|
get { self[InfoButtonStyleKey.self] }
|
||||||
set { self[InfoButtonStyleKey.self] = newValue }
|
set { self[InfoButtonStyleKey.self] = newValue }
|
||||||
}
|
}
|
||||||
|
|
||||||
public var resetButtonStyle: AnyButtonStyle<ResetButtonType> {
|
|
||||||
get { self[ResetButtonStyleKey.self] }
|
|
||||||
set { self[ResetButtonStyleKey.self] = newValue }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension View {
|
extension View {
|
||||||
|
|
||||||
public func infoButtonStyle(_ style: AnyButtonStyle<InfoButtonType>) -> some 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))
|
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