pr suggestions and updated tests
This commit is contained in:
@@ -12,6 +12,7 @@ struct ToolbarButton: View {
|
||||
enum Role {
|
||||
case cancel
|
||||
case done
|
||||
case save
|
||||
|
||||
var title: String {
|
||||
switch self {
|
||||
@@ -19,15 +20,29 @@ struct ToolbarButton: View {
|
||||
L10n.actionCancel
|
||||
case .done:
|
||||
L10n.actionDone
|
||||
case .save:
|
||||
L10n.actionSave
|
||||
}
|
||||
}
|
||||
|
||||
var icon: CompoundIcon {
|
||||
@ViewBuilder
|
||||
var icon: some View {
|
||||
switch self {
|
||||
case .cancel:
|
||||
CompoundIcon(\.close)
|
||||
case .done:
|
||||
.foregroundStyle(.compound.iconPrimary)
|
||||
case .done, .save:
|
||||
CompoundIcon(\.check)
|
||||
.foregroundStyle(.compound.iconOnSolidPrimary)
|
||||
}
|
||||
}
|
||||
|
||||
var tint: Color {
|
||||
switch self {
|
||||
case .cancel:
|
||||
.compound.bgCanvasDefault
|
||||
case .done, .save:
|
||||
.compound.bgAccentRest
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,8 +56,40 @@ struct ToolbarButton: View {
|
||||
role.icon
|
||||
.accessibilityLabel(role.title)
|
||||
}
|
||||
.tint(role.tint)
|
||||
.buttonStyleGlassProminent()
|
||||
} else {
|
||||
Button(role.title, action: action)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 26, *)
|
||||
private extension View {
|
||||
@ViewBuilder
|
||||
func buttonStyleGlassProminent() -> some View {
|
||||
// `.glassProminent` breaks our preview tests so we need to disable it when running tests.
|
||||
// https://github.com/pointfreeco/swift-snapshot-testing/issues/1029#issuecomment-3366942138
|
||||
if ProcessInfo.isRunningTests {
|
||||
self
|
||||
} else {
|
||||
buttonStyle(.glassProminent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ToolbarButton_Previews: PreviewProvider, TestablePreview {
|
||||
static var previews: some View {
|
||||
NavigationStack {
|
||||
Color.clear
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .confirmationAction) {
|
||||
ToolbarButton(role: .done) { }
|
||||
}
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
ToolbarButton(role: .cancel) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user