Skip to content

Commit

Permalink
Merge pull request #423 from adevinta/feature/button_add_info_intent
Browse files Browse the repository at this point in the history
[Button#1377] Added info intent
  • Loading branch information
LouisBorleeAdevinta authored Sep 7, 2023
2 parents 9088d17 + 3109f8a commit bca0e83
Show file tree
Hide file tree
Showing 11 changed files with 152 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/Sources/Components/Button/Enum/ButtonIntent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import Foundation
@frozen
public enum ButtonIntent: CaseIterable {
case accent
case basic
case alert
case basic
case danger
case info
case main
case neutral
case success
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ struct ButtonVariantGetContrastUseCase: ButtonGetVariantUseCaseable {
borderColor: borderColor,
pressedBorderColor: pressedBorderColor
)
case .info:
return .init(
foregroundColor: colors.feedback.info,
backgroundColor: backgroundColor,
pressedBackgroundColor: colors.states.infoContainerPressed,
borderColor: borderColor,
pressedBorderColor: pressedBorderColor
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,28 @@ final class ButtonVariantGetContrastUseCaseTests: ButtonVariantUseCaseTests {
].map(\.color))
}

func test_info_colors() throws {
// Given
let sut = self.sut()

// When
let colors = sut.execute(intent: .info, colors: self.theme.colors, dims: self.theme.dims)

// Then
XCTAssertEqual(
[colors.foregroundColor,
colors.backgroundColor,
colors.pressedBackgroundColor,
colors.borderColor,
colors.pressedBorderColor].map(\.color),
[self.theme.colors.feedback.info,
self.theme.colors.base.surface,
self.theme.colors.states.infoContainerPressed,
ColorTokenDefault.clear,
ColorTokenDefault.clear
].map(\.color))
}

// MARK: - Helper Functions
func sut() -> ButtonVariantGetContrastUseCase {
return ButtonVariantGetContrastUseCase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ struct ButtonGetVariantFilledUseCase: ButtonGetVariantUseCaseable {
borderColor: borderColor,
pressedBorderColor: pressedBorderColor
)
case .info:
return .init(
foregroundColor: colors.feedback.onInfo,
backgroundColor: colors.feedback.info,
pressedBackgroundColor: colors.states.infoPressed,
borderColor: borderColor,
pressedBorderColor: pressedBorderColor
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,28 @@ final class ButtonGetVariantFilledUseCaseTests: ButtonVariantUseCaseTests {
].map(\.color))
}

func test_info_colors() throws {
// Given
let sut = self.sut()

// When
let colors = sut.execute(intent: .info, colors: self.theme.colors, dims: self.theme.dims)

// Then
XCTAssertEqual(
[colors.foregroundColor,
colors.backgroundColor,
colors.pressedBackgroundColor,
colors.borderColor,
colors.pressedBorderColor].map(\.color),
[self.theme.colors.feedback.onInfo,
self.theme.colors.feedback.info,
self.theme.colors.states.infoPressed,
ColorTokenDefault.clear,
ColorTokenDefault.clear
].map(\.color))
}

// MARK: - Helper Functions
func sut() -> ButtonGetVariantFilledUseCase {
return ButtonGetVariantFilledUseCase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ struct ButtonGetVariantGhostUseCase: ButtonGetVariantUseCaseable {
borderColor: borderColor,
pressedBorderColor: pressedBorderColor
)
case .info:
return .init(
foregroundColor: colors.feedback.info,
backgroundColor: ColorTokenDefault.clear,
pressedBackgroundColor: colors.feedback.info.opacity(dim5),
borderColor: borderColor,
pressedBorderColor: pressedBorderColor
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,28 @@ final class ButtonGetVariantGhostUseCaseTests: ButtonVariantUseCaseTests {
].map(\.color))
}

func test_info_colors() throws {
// Given
let sut = self.sut()

// When
let colors = sut.execute(intent: .info, colors: self.theme.colors, dims: self.theme.dims)

// Then
XCTAssertEqual(
[colors.foregroundColor,
colors.backgroundColor,
colors.pressedBackgroundColor,
colors.borderColor,
colors.pressedBorderColor].map(\.color),
[self.theme.colors.feedback.info,
ColorTokenDefault.clear,
self.theme.colors.feedback.info.opacity(self.theme.dims.dim5),
ColorTokenDefault.clear,
ColorTokenDefault.clear
].map(\.color))
}

// MARK: - Helper Functions
func sut() -> ButtonGetVariantGhostUseCase {
return ButtonGetVariantGhostUseCase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ struct ButtonGetVariantOutlinedUseCase: ButtonGetVariantUseCaseable {
borderColor: colors.base.surface,
pressedBorderColor: colors.base.surface
)
case .info:
return .init(
foregroundColor: colors.feedback.info,
backgroundColor: backgroundColor,
pressedBackgroundColor: colors.feedback.info.opacity(dim5),
borderColor: colors.feedback.info,
pressedBorderColor: colors.feedback.info
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,28 @@ final class ButtonGetVariantOutlinedUseCaseTests: ButtonVariantUseCaseTests {
].map(\.color))
}

func test_info_colors() throws {
// Given
let sut = self.sut()

// When
let colors = sut.execute(intent: .info, colors: self.theme.colors, dims: self.theme.dims)

// Then
XCTAssertEqual(
[colors.foregroundColor,
colors.backgroundColor,
colors.pressedBackgroundColor,
colors.borderColor,
colors.pressedBorderColor].map(\.color),
[self.theme.colors.feedback.info,
self.theme.colors.base.surface,
self.theme.colors.feedback.info.opacity(self.theme.dims.dim5),
self.theme.colors.feedback.info,
self.theme.colors.feedback.info
].map(\.color))
}

// MARK: - Helper Functions
func sut() -> ButtonGetVariantOutlinedUseCase {
return ButtonGetVariantOutlinedUseCase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ struct ButtonGetVariantTintedUseCase: ButtonGetVariantUseCaseable {
borderColor: borderColor,
pressedBorderColor: pressedBorderColor
)
case .info:
return .init(
foregroundColor: colors.feedback.onInfoContainer,
backgroundColor: colors.feedback.infoContainer,
pressedBackgroundColor: colors.states.infoContainerPressed,
borderColor: borderColor,
pressedBorderColor: pressedBorderColor
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,28 @@ final class ButtonGetVariantTintedUseCaseTests: ButtonVariantUseCaseTests {
].map(\.color))
}

func test_info_colors() throws {
// Given
let sut = self.sut()

// When
let colors = sut.execute(intent: .info, colors: self.theme.colors, dims: self.theme.dims)

// Then
XCTAssertEqual(
[colors.foregroundColor,
colors.backgroundColor,
colors.pressedBackgroundColor,
colors.borderColor,
colors.pressedBorderColor].map(\.color),
[self.theme.colors.feedback.onInfoContainer,
self.theme.colors.feedback.infoContainer,
self.theme.colors.states.infoContainerPressed,
ColorTokenDefault.clear,
ColorTokenDefault.clear
].map(\.color))
}

// MARK: - Helper Functions
func sut() -> ButtonGetVariantTintedUseCase {
return ButtonGetVariantTintedUseCase()
Expand Down

0 comments on commit bca0e83

Please sign in to comment.