Skip to content

Commit

Permalink
[Button] Button refactoring
Browse files Browse the repository at this point in the history
- Remove protocol into internal struct
- Rename ForX parameters into UseCases
- Rename IntentColor to Intent
  • Loading branch information
robergro committed Jul 7, 2023
1 parent 202c336 commit 3ec26ea
Show file tree
Hide file tree
Showing 54 changed files with 639 additions and 491 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// ButtonIntentColor.swift
// ButtonIntent.swift
// Spark
//
// Created by janniklas.freundt.ext on 02.05.23.
Expand All @@ -10,7 +10,7 @@ import Foundation

/// A button intent is used to apply a color scheme to a button.
@frozen
public enum ButtonIntentColor: CaseIterable {
public enum ButtonIntent: CaseIterable {
/// Intent used for warning-feedback.
case alert

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// ButtonBorder.swift
// SparkCore
//
// Created by robin.lemaire on 23/06/2023.
// Copyright © 2023 Adevinta. All rights reserved.
//

import Foundation
@testable import SparkCore

extension ButtonBorder {

// MARK: - Properties

static func mocked(
width: CGFloat = 2,
radius: CGFloat = 8
) -> Self {
return .init(
width: width,
radius: radius
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@

import Foundation

// sourcery: AutoMockable
protocol ButtonBorder {
var width: CGFloat { get }
var radius: CGFloat { get }
}

struct ButtonBorderDefault: ButtonBorder {
struct ButtonBorder: Equatable {

// MARK: - Properties

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// ButtonColors.swift
// Spark
//
// Created by janniklas.freundt.ext on 02.05.23.
// Copyright © 2023 Adevinta. All rights reserved.
//

@testable import SparkCore

extension ButtonColors {

// MARK: - Properties

static func mocked(
foregroundColor: any ColorToken = ColorTokenGeneratedMock.random(),
backgroundColor: any ColorToken = ColorTokenGeneratedMock.random(),
pressedBackgroundColor: any ColorToken = ColorTokenGeneratedMock.random(),
borderColor: any ColorToken = ColorTokenGeneratedMock.random(),
pressedBorderColor: any ColorToken = ColorTokenGeneratedMock.random()
) -> Self {
return .init(
foregroundColor: foregroundColor,
backgroundColor: backgroundColor,
pressedBackgroundColor: pressedBackgroundColor,
borderColor: borderColor,
pressedBorderColor: pressedBorderColor
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// ButtonColors.swift
// Spark
//
// Created by janniklas.freundt.ext on 02.05.23.
// Copyright © 2023 Adevinta. All rights reserved.
//

/// All Button Colors from a theme, variant and intents
struct ButtonColors {

// MARK: - Properties

let foregroundColor: any ColorToken
let backgroundColor: any ColorToken
let pressedBackgroundColor: any ColorToken
let borderColor: any ColorToken
let pressedBorderColor: any ColorToken
}

// MARK: Hashable & Equatable

extension ButtonColors: Hashable, Equatable {

func hash(into hasher: inout Hasher) {
hasher.combine(self.foregroundColor)
hasher.combine(self.backgroundColor)
hasher.combine(self.pressedBackgroundColor)
hasher.combine(self.borderColor)
hasher.combine(self.pressedBorderColor)
}

static func == (lhs: ButtonColors, rhs: ButtonColors) -> Bool {
return lhs.hashValue == rhs.hashValue
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// ButtonContent.swift
// SparkCore
//
// Created by robin.lemaire on 27/06/2023.
// Copyright © 2023 Adevinta. All rights reserved.
//

@testable import SparkCore

extension ButtonContent {

// MARK: - Properties

static func mocked(
shouldShowIconImage: Bool = true ,
isIconImageOnRight: Bool = false,
iconImage: ImageEither? = .left(IconographyTests.shared.arrow),
shouldShowText: Bool = true
) -> Self {
return .init(
shouldShowIconImage: shouldShowIconImage,
isIconImageOnRight: isIconImageOnRight,
iconImage: iconImage,
shouldShowText: shouldShowText
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// ButtonContent.swift
// SparkCore
//
// Created by robin.lemaire on 27/06/2023.
// Copyright © 2023 Adevinta. All rights reserved.
//

struct ButtonContent: Equatable {

// MARK: - Properties

let shouldShowIconImage: Bool
let isIconImageOnRight: Bool
let iconImage: ImageEither?

let shouldShowText: Bool
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// ButtonCurrentColors.swift
// SparkCore
//
// Created by robin.lemaire on 27/06/2023.
// Copyright © 2023 Adevinta. All rights reserved.
//

@testable import SparkCore

extension ButtonCurrentColors {

// MARK: - Properties

static func mocked(
foregroundColor: any ColorToken = ColorTokenGeneratedMock.random(),
backgroundColor: any ColorToken = ColorTokenGeneratedMock.random(),
borderColor: any ColorToken = ColorTokenGeneratedMock.random()
) -> Self {
return .init(
foregroundColor: foregroundColor,
backgroundColor: backgroundColor,
borderColor: borderColor
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// ButtonCurrentColors.swift
// SparkCore
//
// Created by robin.lemaire on 27/06/2023.
// Copyright © 2023 Adevinta. All rights reserved.
//

/// Current Button Colors properties from a button colors and state
struct ButtonCurrentColors {

// MARK: - Properties

let foregroundColor: any ColorToken
let backgroundColor: any ColorToken
let borderColor: any ColorToken
}

// MARK: Hashable & Equatable

extension ButtonCurrentColors: Hashable, Equatable {

func hash(into hasher: inout Hasher) {
hasher.combine(self.foregroundColor)
hasher.combine(self.backgroundColor)
hasher.combine(self.borderColor)
}

static func == (lhs: ButtonCurrentColors, rhs: ButtonCurrentColors) -> Bool {
return lhs.hashValue == rhs.hashValue
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// ButtonSizes.swift
// SparkCore
//
// Created by robin.lemaire on 30/06/2023.
// Copyright © 2023 Adevinta. All rights reserved.
//

import Foundation
@testable import SparkCore

extension ButtonSizes {

// MARK: - Properties

static func mocked(
height: CGFloat = 30,
iconSize: CGFloat = 20
) -> Self {
return .init(
height: height,
iconSize: iconSize
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@

import Foundation

// sourcery: AutoMockable
protocol ButtonSizes {
var height: CGFloat { get }
var iconSize: CGFloat { get }
}

struct ButtonSizesDefault: ButtonSizes {
struct ButtonSizes: Equatable {

// MARK: - Properties

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// ButtonSpacings.swift
// SparkCore
//
// Created by robin.lemaire on 23/06/2023.
// Copyright © 2023 Adevinta. All rights reserved.
//

import Foundation
@testable import SparkCore

extension ButtonSpacings {

// MARK: - Properties

static func mocked(
verticalSpacing: CGFloat = 10,
horizontalSpacing: CGFloat = 11,
horizontalPadding: CGFloat = 12
) -> Self {
return .init(
verticalSpacing: verticalSpacing,
horizontalSpacing: horizontalSpacing,
horizontalPadding: horizontalPadding
)
}
}
Loading

0 comments on commit 3ec26ea

Please sign in to comment.