Skip to content

Commit

Permalink
feat(Feedback): LATCH-1676 Allowing 3 buttons at the same time: prima…
Browse files Browse the repository at this point in the history
…ry, secondary and link

* feat(Feedback): LATCH-1676 Allowing 3 buttons at the same time: primary, secondary and link

---------

Co-authored-by: salavert <salavert@users.noreply.github.com>
  • Loading branch information
salavert and salavert committed Jun 18, 2024
1 parent af95c6e commit 7a260f5
Show file tree
Hide file tree
Showing 12 changed files with 238 additions and 116 deletions.
8 changes: 4 additions & 4 deletions Sources/MisticaSwiftUI/Components/Callout/Callout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public extension Callout {
// MARK: Modifiers

public extension Callout {
func assetAccessibilityLabel(_ assetAccessibilityLaber: String?) -> Callout {
func assetAccessibilityLabel(_ assetAccessibilityLabel: String?) -> Callout {
var callout = self
callout.assetAccessibilityLabel = assetAccessibilityLabel
return callout
Expand All @@ -293,7 +293,7 @@ public extension Callout {
return callout
}

func dismissButtonAccessibilityLabel(_ dismissButtonAccessibilityLaber: String?) -> Callout {
func dismissButtonAccessibilityLabel(_ dismissButtonAccessibilityLabel: String?) -> Callout {
var callout = self
callout.dismissButtonAccessibilityLabel = dismissButtonAccessibilityLabel
return callout
Expand All @@ -305,7 +305,7 @@ public extension Callout {
return callout
}

func titleAccessibilityLabel(_ titleAccessibilityLaber: String?) -> Callout {
func titleAccessibilityLabel(_ titleAccessibilityLabel: String?) -> Callout {
var callout = self
callout.titleAccessibilityLabel = titleAccessibilityLabel
return callout
Expand All @@ -317,7 +317,7 @@ public extension Callout {
return callout
}

func descriptionAccessibilityLabel(_ descriptionAccessibilityLaber: String?) -> Callout {
func descriptionAccessibilityLabel(_ descriptionAccessibilityLabel: String?) -> Callout {
var callout = self
callout.descriptionAccessibilityLabel = descriptionAccessibilityLabel
return callout
Expand Down
148 changes: 124 additions & 24 deletions Sources/MisticaSwiftUI/Components/Feedback/Feedback.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@ private enum Constants {
}
}

public struct Feedback<ContentView: View, PrimaryButton: View, SecondaryButton: View>: View {
public struct Feedback<
ContentView: View,
PrimaryButton: View,
SecondaryButton: View,
LinkButton: View
>: View {
private let style: FeedbackStyle
private let title: String
private let message: String
private let primaryButton: PrimaryButton
private let secondaryButton: SecondaryButton
private let secondaryButtonStyle: MisticaButtonStyle
private let linkButton: LinkButton
private let contentView: ContentView

private var titleAccessibilityLabel: String?
Expand All @@ -46,15 +51,15 @@ public struct Feedback<ContentView: View, PrimaryButton: View, SecondaryButton:
contentView: ContentView,
primaryButton: PrimaryButton,
secondaryButton: SecondaryButton,
secondaryButtonStyle: MisticaButtonStyle
linkButton: LinkButton
) {
self.style = style
self.title = title
self.message = message
self.contentView = contentView
self.primaryButton = primaryButton
self.secondaryButton = secondaryButton
self.secondaryButtonStyle = secondaryButtonStyle
self.linkButton = linkButton
}

public var body: some View {
Expand Down Expand Up @@ -103,7 +108,8 @@ public struct Feedback<ContentView: View, PrimaryButton: View, SecondaryButton:

VStack {
primaryButton.buttonStyle(style.primaryButtonStyle)
secondaryButton.buttonStyle(secondaryButtonStyle)
secondaryButton.buttonStyle(style.secondaryButtonStyle)
linkButton.buttonStyle(style.linkButtonStyle)
}
.padding(Constants.spacing)
.background(misticaColorView(footerBackgroundColor))
Expand Down Expand Up @@ -224,7 +230,8 @@ public extension Feedback {
message: String,
@ViewBuilder contentView: () -> ContentView,
@ViewBuilder primaryButton: () -> PrimaryButton,
@ViewBuilder secondaryButton: () -> SecondaryButton
@ViewBuilder secondaryButton: () -> SecondaryButton,
@ViewBuilder linkButton: () -> LinkButton
) {
self.init(
style: style,
Expand All @@ -233,7 +240,7 @@ public extension Feedback {
contentView: contentView(),
primaryButton: primaryButton(),
secondaryButton: secondaryButton(),
secondaryButtonStyle: style.secondaryButtonStyle
linkButton: linkButton()
)
}

Expand All @@ -243,25 +250,64 @@ public extension Feedback {
message: String,
@ViewBuilder contentView: () -> ContentView,
@ViewBuilder primaryButton: () -> PrimaryButton,
@ViewBuilder linkButton: () -> SecondaryButton
) {
@ViewBuilder secondaryButton: () -> SecondaryButton
) where LinkButton == EmptyView {
self.init(
style: style,
title: title,
message: message,
contentView: contentView(),
primaryButton: primaryButton(),
secondaryButton: linkButton(),
secondaryButtonStyle: style.linkButtonStyle
secondaryButton: secondaryButton(),
linkButton: EmptyView()
)
}

init(
style: FeedbackStyle,
title: String,
message: String,
@ViewBuilder contentView: () -> ContentView,
@ViewBuilder primaryButton: () -> PrimaryButton,
@ViewBuilder secondaryButton: () -> SecondaryButton
@ViewBuilder linkButton: () -> LinkButton
) where SecondaryButton == EmptyView {
self.init(
style: style,
title: title,
message: message,
contentView: contentView(),
primaryButton: primaryButton(),
secondaryButton: EmptyView(),
linkButton: linkButton()
)
}

init(
style: FeedbackStyle,
title: String,
message: String,
@ViewBuilder contentView: () -> ContentView,
@ViewBuilder secondaryButton: () -> SecondaryButton,
@ViewBuilder linkButton: () -> LinkButton
) where PrimaryButton == EmptyView {
self.init(
style: style,
title: title,
message: message,
contentView: contentView(),
primaryButton: EmptyView(),
secondaryButton: secondaryButton(),
linkButton: linkButton()
)
}

init(
style: FeedbackStyle,
title: String,
message: String,
@ViewBuilder primaryButton: () -> PrimaryButton,
@ViewBuilder secondaryButton: () -> SecondaryButton,
@ViewBuilder linkButton: () -> LinkButton
) where ContentView == EmptyView {
self.init(
style: style,
Expand All @@ -270,7 +316,7 @@ public extension Feedback {
contentView: EmptyView(),
primaryButton: primaryButton(),
secondaryButton: secondaryButton(),
secondaryButtonStyle: style.secondaryButtonStyle
linkButton: linkButton()
)
}

Expand All @@ -279,34 +325,52 @@ public extension Feedback {
title: String,
message: String,
@ViewBuilder primaryButton: () -> PrimaryButton,
@ViewBuilder linkButton: () -> SecondaryButton
) where ContentView == EmptyView {
@ViewBuilder secondaryButton: () -> SecondaryButton
) where ContentView == EmptyView, LinkButton == EmptyView {
self.init(
style: style,
title: title,
message: message,
contentView: EmptyView(),
primaryButton: primaryButton(),
secondaryButton: linkButton(),
secondaryButtonStyle: style.linkButtonStyle
secondaryButton: secondaryButton(),
linkButton: EmptyView()
)
}

init(
style: FeedbackStyle,
title: String,
message: String,
@ViewBuilder contentView: () -> ContentView,
@ViewBuilder primaryButton: () -> PrimaryButton
) where SecondaryButton == EmptyView {
@ViewBuilder primaryButton: () -> PrimaryButton,
@ViewBuilder linkButton: () -> LinkButton
) where ContentView == EmptyView, SecondaryButton == EmptyView {
self.init(
style: style,
title: title,
message: message,
contentView: contentView(),
contentView: EmptyView(),
primaryButton: primaryButton(),
secondaryButton: EmptyView(),
secondaryButtonStyle: style.secondaryButtonStyle
linkButton: linkButton()
)
}

init(
style: FeedbackStyle,
title: String,
message: String,
@ViewBuilder secondaryButton: () -> SecondaryButton,
@ViewBuilder linkButton: () -> LinkButton
) where ContentView == EmptyView, PrimaryButton == EmptyView {
self.init(
style: style,
title: title,
message: message,
contentView: EmptyView(),
primaryButton: EmptyView(),
secondaryButton: secondaryButton(),
linkButton: linkButton()
)
}

Expand All @@ -315,15 +379,49 @@ public extension Feedback {
title: String,
message: String,
@ViewBuilder primaryButton: () -> PrimaryButton
) where SecondaryButton == EmptyView, ContentView == EmptyView {
) where ContentView == EmptyView, SecondaryButton == EmptyView, LinkButton == EmptyView {
self.init(
style: style,
title: title,
message: message,
contentView: EmptyView(),
primaryButton: primaryButton(),
secondaryButton: EmptyView(),
secondaryButtonStyle: style.secondaryButtonStyle
linkButton: EmptyView()
)
}

init(
style: FeedbackStyle,
title: String,
message: String,
@ViewBuilder secondaryButton: () -> SecondaryButton
) where ContentView == EmptyView, PrimaryButton == EmptyView, LinkButton == EmptyView {
self.init(
style: style,
title: title,
message: message,
contentView: EmptyView(),
primaryButton: EmptyView(),
secondaryButton: secondaryButton(),
linkButton: EmptyView()
)
}

init(
style: FeedbackStyle,
title: String,
message: String,
@ViewBuilder linkButton: () -> LinkButton
) where ContentView == EmptyView, PrimaryButton == EmptyView, SecondaryButton == EmptyView {
self.init(
style: style,
title: title,
message: message,
contentView: EmptyView(),
primaryButton: EmptyView(),
secondaryButton: EmptyView(),
linkButton: linkButton()
)
}
}
Expand Down Expand Up @@ -447,6 +545,8 @@ private extension View {
Button("Primary") {}
} secondaryButton: {
Button("Secondary") {}
} linkButton: {
Button("Link") {}
}
.titleAccessibilityLabel("Title Label")
.titleAccessibilityIdentifier("Title identifier")
Expand Down
Loading

0 comments on commit 7a260f5

Please sign in to comment.