Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ DerivedData/
.swiftpm/
*Generated/
Package.resolved
.swiftlint/
.swiftlint/

# SwiftLint Remote Config Cache
.swiftlint/RemoteConfigCache
1 change: 1 addition & 0 deletions Sources/Core/Enum/Public/ButtonIntent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ public enum ButtonIntent: CaseIterable {
case success
case support
case surface
case surfaceInverse
}
16 changes: 16 additions & 0 deletions Sources/Core/Extension/ControlStateText+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// ControlStateText+Extension.swift
// SparkComponentButton
//
// Created by robin.lemaire on 18/09/2025.
// Copyright © 2025 Leboncoin. All rights reserved.
//

@_spi(SI_SPI) import SparkCommon

extension ControlStateText {

var isText: Bool {
self.text != nil || self.attributedText != nil
}
}
8 changes: 5 additions & 3 deletions Sources/Core/UseCase/GetBorder/ButtonGetBorderUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import SparkTheming
// sourcery: AutoMockable, AutoMockTest
protocol ButtonGetBorderUseCaseable {
// sourcery: border = "Identical"
func execute(shape: ButtonShape,
border: any Border,
variant: ButtonVariant) -> ButtonBorder
func execute(
shape: ButtonShape,
border: any Border,
variant: ButtonVariant
) -> ButtonBorder
}

struct ButtonGetBorderUseCase: ButtonGetBorderUseCaseable {
Expand Down
8 changes: 5 additions & 3 deletions Sources/Core/UseCase/GetColors/ButtonGetColorsUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import SparkTheming
// sourcery: AutoMockable, AutoMockTest
protocol ButtonGetColorsUseCaseable {
// sourcery: theme = "Identical"
func execute(theme: any Theme,
intent: ButtonIntent,
variant: ButtonVariant) -> ButtonColors
func execute(
theme: any Theme,
intent: ButtonIntent,
variant: ButtonVariant
) -> ButtonColors
}

struct ButtonGetColorsUseCase: ButtonGetColorsUseCaseable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

// sourcery: AutoMockable, AutoMockTest
protocol ButtonGetCurrentColorsUseCaseable {
func execute(colors: ButtonColors,
isPressed: Bool) -> ButtonCurrentColors
func execute(
colors: ButtonColors,
isPressed: Bool
) -> ButtonCurrentColors
}

struct ButtonGetCurrentColorsUseCase: ButtonGetCurrentColorsUseCaseable {
Expand Down
6 changes: 4 additions & 2 deletions Sources/Core/UseCase/GetSizes/ButtonGetSizesUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import Foundation

// sourcery: AutoMockable, AutoMockTest
protocol ButtonGetSizesUseCaseable {
func execute(size: ButtonSize,
type: ButtonType) -> ButtonSizes
func execute(
size: ButtonSize,
type: ButtonType
) -> ButtonSizes
}

struct ButtonGetSizesUseCase: ButtonGetSizesUseCaseable {
Expand Down
6 changes: 4 additions & 2 deletions Sources/Core/UseCase/GetState/ButtonGetStateUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import SparkTheming
// sourcery: AutoMockable, AutoMockTest
protocol ButtonGetStateUseCaseable {
// sourcery: dims = "Identical"
func execute(isEnabled: Bool,
dims: any Dims) -> ButtonState
func execute(
isEnabled: Bool,
dims: any Dims
) -> ButtonState
}

struct ButtonGetStateUseCase: ButtonGetStateUseCaseable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,65 +24,73 @@ struct ButtonVariantGetContrastUseCase: ButtonGetVariantUseCaseable {
switch intent {
case .accent:
return .init(
foregroundColor: colors.accent.accent,
foregroundColor: colors.accent.onAccentContainer,
backgroundColor: backgroundColor,
pressedBackgroundColor: colors.states.accentContainerPressed,
borderColor: borderColor,
pressedBorderColor: pressedBorderColor
)
case .alert:
return .init(
foregroundColor: colors.feedback.onAlertContainer,
backgroundColor: backgroundColor,
pressedBackgroundColor: colors.states.alertContainerPressed,
borderColor: borderColor,
pressedBorderColor: pressedBorderColor
)
case .basic:
return .init(
foregroundColor: colors.basic.basic,
foregroundColor: colors.basic.onBasicContainer,
backgroundColor: backgroundColor,
pressedBackgroundColor: colors.states.basicContainerPressed,
borderColor: borderColor,
pressedBorderColor: pressedBorderColor
)
case .main:
case .danger:
return .init(
foregroundColor: colors.main.main,
foregroundColor: colors.feedback.onErrorContainer,
backgroundColor: backgroundColor,
pressedBackgroundColor: colors.states.mainContainerPressed,
pressedBackgroundColor: colors.states.errorContainerPressed,
borderColor: borderColor,
pressedBorderColor: pressedBorderColor
)
case .support:
case .info:
return .init(
foregroundColor: colors.support.support,
foregroundColor: colors.feedback.onInfoContainer,
backgroundColor: backgroundColor,
pressedBackgroundColor: colors.states.supportContainerPressed,
pressedBackgroundColor: colors.states.infoContainerPressed,
borderColor: borderColor,
pressedBorderColor: pressedBorderColor
)
case .neutral:
case .main:
return .init(
foregroundColor: colors.feedback.neutral,
foregroundColor: colors.main.onMainContainer,
backgroundColor: backgroundColor,
pressedBackgroundColor: colors.states.neutralContainerPressed,
pressedBackgroundColor: colors.states.mainContainerPressed,
borderColor: borderColor,
pressedBorderColor: pressedBorderColor
)
case .alert:
case .neutral:
return .init(
foregroundColor: colors.feedback.alert,
foregroundColor: colors.feedback.onNeutralContainer,
backgroundColor: backgroundColor,
pressedBackgroundColor: colors.states.alertContainerPressed,
pressedBackgroundColor: colors.states.neutralContainerPressed,
borderColor: borderColor,
pressedBorderColor: pressedBorderColor
)
case .success:
return .init(
foregroundColor: colors.feedback.success,
foregroundColor: colors.feedback.onSuccessContainer,
backgroundColor: backgroundColor,
pressedBackgroundColor: colors.states.successContainerPressed,
borderColor: borderColor,
pressedBorderColor: pressedBorderColor
)
case .danger:
case .support:
return .init(
foregroundColor: colors.feedback.error,
foregroundColor: colors.support.onSupportContainer,
backgroundColor: backgroundColor,
pressedBackgroundColor: colors.states.errorContainerPressed,
pressedBackgroundColor: colors.states.supportContainerPressed,
borderColor: borderColor,
pressedBorderColor: pressedBorderColor
)
Expand All @@ -94,11 +102,11 @@ struct ButtonVariantGetContrastUseCase: ButtonGetVariantUseCaseable {
borderColor: borderColor,
pressedBorderColor: pressedBorderColor
)
case .info:
case .surfaceInverse:
return .init(
foregroundColor: colors.feedback.info,
backgroundColor: backgroundColor,
pressedBackgroundColor: colors.states.infoContainerPressed,
foregroundColor: colors.base.onSurfaceInverse,
backgroundColor: colors.base.surfaceInverse,
pressedBackgroundColor: colors.states.surfaceInversePressed,
borderColor: borderColor,
pressedBorderColor: pressedBorderColor
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ struct ButtonGetVariantFilledUseCase: ButtonGetVariantUseCaseable {
borderColor: borderColor,
pressedBorderColor: pressedBorderColor
)
case .alert:
return .init(
foregroundColor: colors.feedback.onAlert,
backgroundColor: colors.feedback.alert,
pressedBackgroundColor: colors.states.alertPressed,
borderColor: borderColor,
pressedBorderColor: pressedBorderColor
)
case .basic:
return .init(
foregroundColor: colors.basic.onBasic,
Expand All @@ -37,35 +45,35 @@ struct ButtonGetVariantFilledUseCase: ButtonGetVariantUseCaseable {
borderColor: borderColor,
pressedBorderColor: pressedBorderColor
)
case .main:
case .danger:
return .init(
foregroundColor: colors.main.onMain,
backgroundColor: colors.main.main,
pressedBackgroundColor: colors.states.mainPressed,
foregroundColor: colors.feedback.onError,
backgroundColor: colors.feedback.error,
pressedBackgroundColor: colors.states.errorPressed,
borderColor: borderColor,
pressedBorderColor: pressedBorderColor
)
case .support:
case .info:
return .init(
foregroundColor: colors.support.onSupport,
backgroundColor: colors.support.support,
pressedBackgroundColor: colors.states.supportPressed,
foregroundColor: colors.feedback.onInfo,
backgroundColor: colors.feedback.info,
pressedBackgroundColor: colors.states.infoPressed,
borderColor: borderColor,
pressedBorderColor: pressedBorderColor
)
case .neutral:
case .main:
return .init(
foregroundColor: colors.feedback.onNeutral,
backgroundColor: colors.feedback.neutral,
pressedBackgroundColor: colors.states.neutralPressed,
foregroundColor: colors.main.onMain,
backgroundColor: colors.main.main,
pressedBackgroundColor: colors.states.mainPressed,
borderColor: borderColor,
pressedBorderColor: pressedBorderColor
)
case .alert:
case .neutral:
return .init(
foregroundColor: colors.feedback.onAlert,
backgroundColor: colors.feedback.alert,
pressedBackgroundColor: colors.states.alertPressed,
foregroundColor: colors.feedback.onNeutral,
backgroundColor: colors.feedback.neutral,
pressedBackgroundColor: colors.states.neutralPressed,
borderColor: borderColor,
pressedBorderColor: pressedBorderColor
)
Expand All @@ -77,11 +85,11 @@ struct ButtonGetVariantFilledUseCase: ButtonGetVariantUseCaseable {
borderColor: borderColor,
pressedBorderColor: pressedBorderColor
)
case .danger:
case .support:
return .init(
foregroundColor: colors.feedback.onError,
backgroundColor: colors.feedback.error,
pressedBackgroundColor: colors.states.errorPressed,
foregroundColor: colors.support.onSupport,
backgroundColor: colors.support.support,
pressedBackgroundColor: colors.states.supportPressed,
borderColor: borderColor,
pressedBorderColor: pressedBorderColor
)
Expand All @@ -93,11 +101,11 @@ struct ButtonGetVariantFilledUseCase: ButtonGetVariantUseCaseable {
borderColor: borderColor,
pressedBorderColor: pressedBorderColor
)
case .info:
case .surfaceInverse:
return .init(
foregroundColor: colors.feedback.onInfo,
backgroundColor: colors.feedback.info,
pressedBackgroundColor: colors.states.infoPressed,
foregroundColor: colors.base.onSurfaceInverse,
backgroundColor: colors.base.surfaceInverse,
pressedBackgroundColor: colors.states.surfaceInversePressed,
borderColor: borderColor,
pressedBorderColor: pressedBorderColor
)
Expand Down
Loading