Skip to content

Commit

Permalink
Remove isTrailingIconSeparated parameter replaceable by a call site…
Browse files Browse the repository at this point in the history
… icon content
  • Loading branch information
PavelHolec committed Nov 21, 2023
1 parent 9b806bd commit 8c4f62b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 37 deletions.
12 changes: 2 additions & 10 deletions Sources/Orbit/Components/Button.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public struct Button<LeadingIcon: View, TrailingIcon: View>: View, PotentiallyEm

private let label: String
private let type: ButtonType
private let isTrailingIconSeparated: Bool
private let action: () -> Void
@ViewBuilder private let leadingIcon: LeadingIcon
@ViewBuilder private let trailingIcon: TrailingIcon
Expand All @@ -21,7 +20,7 @@ public struct Button<LeadingIcon: View, TrailingIcon: View>: View, PotentiallyEm
} else {
button
.buttonStyle(
OrbitButtonStyle(type: type, isTrailingIconSeparated: isTrailingIconSeparated) {
OrbitButtonStyle(type: type) {
leadingIcon
} trailingIcon: {
trailingIcon
Expand Down Expand Up @@ -59,14 +58,9 @@ public extension Button {
icon: Icon.Symbol? = nil,
disclosureIcon: Icon.Symbol? = nil,
type: ButtonType = .primary,
isTrailingIconSeparated: Bool = false,
action: @escaping () -> Void
) where LeadingIcon == Icon, TrailingIcon == Icon {
self.init(
label,
type: type,
isTrailingIconSeparated: isTrailingIconSeparated
) {
self.init(label, type: type) {
action()
} icon: {
Icon(icon)
Expand All @@ -84,14 +78,12 @@ public extension Button {
init(
_ label: String = "",
type: ButtonType = .primary,
isTrailingIconSeparated: Bool = false,
action: @escaping () -> Void,
@ViewBuilder icon: () -> LeadingIcon,
@ViewBuilder disclosureIcon: () -> TrailingIcon = { EmptyView() }
) {
self.label = label
self.type = type
self.isTrailingIconSeparated = isTrailingIconSeparated
self.action = action
self.leadingIcon = icon()
self.trailingIcon = disclosureIcon()
Expand Down
4 changes: 0 additions & 4 deletions Sources/Orbit/Support/ButtonStyles/OrbitButtonStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public struct OrbitButtonStyle<LeadingIcon: View, TrailingIcon: View>: Primitive
@Environment(\.textColor) private var textColor

private var type: ButtonType
private var isTrailingIconSeparated: Bool
@ViewBuilder private let icon: LeadingIcon
@ViewBuilder private let disclosureIcon: TrailingIcon

Expand All @@ -20,7 +19,6 @@ public struct OrbitButtonStyle<LeadingIcon: View, TrailingIcon: View>: Primitive
configuration: configuration,
horizontalPadding: padding,
verticalPadding: padding,
isTrailingIconSeparated: isTrailingIconSeparated,
hapticFeedback: hapticFeedback
) {
icon
Expand Down Expand Up @@ -106,12 +104,10 @@ public struct OrbitButtonStyle<LeadingIcon: View, TrailingIcon: View>: Primitive
/// Create button style for Orbit ``Button`` component.
public init(
type: ButtonType = .primary,
isTrailingIconSeparated: Bool = false,
@ViewBuilder icon: () -> LeadingIcon = { EmptyView() },
@ViewBuilder trailingIcon: () -> TrailingIcon = { EmptyView() }
) {
self.type = type
self.isTrailingIconSeparated = isTrailingIconSeparated
self.icon = icon()
self.disclosureIcon = trailingIcon()
}
Expand Down
27 changes: 4 additions & 23 deletions Sources/Orbit/Support/Components/OrbitCustomButtonContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ struct OrbitCustomButtonContent<LeadingIcon: View, TrailingIcon: View>: View {
var verticalBackgroundPadding: CGFloat = 0
var cornerRadius: CGFloat = BorderRadius.default
var spacing: CGFloat = .xxSmall
var isTrailingIconSeparated = false
var hapticFeedback: HapticsProvider.HapticFeedbackType = .light()
@ViewBuilder let icon: LeadingIcon
@ViewBuilder let disclosureIcon: TrailingIcon
Expand All @@ -31,24 +30,16 @@ struct OrbitCustomButtonContent<LeadingIcon: View, TrailingIcon: View>: View {
// Maintain height to allow button with no content
TextStrut()

if shouldExpand {
Spacer(minLength: 0)
}

HStack(spacing: spacing) {
icon
label
.padding(.horizontal, horizontalLabelPadding)
.layoutPriority(1)
disclosureIcon
.frame(maxWidth: disclosureIconMaxWidth, alignment: .trailing)
}

if shouldExpand {
Spacer(minLength: 0)
.fixedSize(horizontal: idealSize.horizontal == true, vertical: false)
}
.frame(maxWidth: idealSize.horizontal == true ? nil : .infinity)
}
.frame(maxWidth: idealSize.horizontal == true ? nil : .infinity)
.padding(.horizontal, horizontalPadding)
.padding(.vertical, verticalPadding)
.padding(.horizontal, horizontalBackgroundPadding)
Expand Down Expand Up @@ -91,16 +82,6 @@ struct OrbitCustomButtonContent<LeadingIcon: View, TrailingIcon: View>: View {
backgroundShape?.inactiveView
}
}

var shouldExpand: Bool {
idealSize.horizontal != true && isTrailingIconSeparated == false
}

var disclosureIconMaxWidth: CGFloat? {
idealSize.horizontal != true && isTrailingIconSeparated
? .infinity
: nil
}
}

// MARK: Previews
Expand Down Expand Up @@ -159,12 +140,12 @@ struct OrbitCustomButtonContentPreviews: PreviewProvider {
horizontalBackgroundPadding: .small,
verticalBackgroundPadding: .xSmall,
cornerRadius: BorderRadius.default,
spacing: .medium,
isTrailingIconSeparated: true
spacing: .xSmall
) {
Icon(.grid)
} disclosureIcon: {
Icon(.chevronForward)
.frame(maxWidth: .infinity, alignment: .trailing)
}
.textColor(.blueDark)
.backgroundStyle(.orangeLight, active: .greenLight)
Expand Down

0 comments on commit 8c4f62b

Please sign in to comment.