Skip to content

Commit

Permalink
Merge pull request #27 from adevinta/theme
Browse files Browse the repository at this point in the history
Added theme protocols, default structures and spark implementation (Colors, Typography, Border and Layout)
  • Loading branch information
LouisBorleeAdevinta authored Mar 9, 2023
2 parents b649765 + a596770 commit f3cbf8a
Show file tree
Hide file tree
Showing 60 changed files with 1,864 additions and 200 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,6 @@ out

#snapshots
spark-ios-snapshots

#plists
*.plist
8 changes: 8 additions & 0 deletions Spark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ targetTemplates:
PRODUCT_NAME: Spark
info:
path: spark/Sources/Info.plist
properties:
UIAppFonts:
- "NunitoSans-Bold.ttf"
- "NunitoSans-Regular.ttf"
sources:
- path: spark/Sources
excludes:
Expand All @@ -24,6 +28,8 @@ targetTemplates:
testTargets:
- name: SparkTests
gatherCoverageData: true
dependencies:
- target: SparkCore

SparkTestsTemplate:
type: bundle.unit-test
Expand Down Expand Up @@ -57,6 +63,8 @@ targetTemplates:
info:
path: spark/Demo/Info.plist
properties:
UILaunchScreen: []

UIApplicationSceneManifest:
UIApplicationSupportsMultipleScenes: false
UISceneConfigurations: {}
Expand Down
29 changes: 0 additions & 29 deletions core/Demo/Info.plist

This file was deleted.

22 changes: 0 additions & 22 deletions core/Info.plist

This file was deleted.

44 changes: 44 additions & 0 deletions core/Sources/Extension/Bundle+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// Bundle+Extension.swift
// Spark
//
// Created by robin.lemaire on 02/03/2023.
//

import Foundation
import UIKit

public extension Bundle {

// MARK: - Constants

private enum Constants {
static let fontExtensions = ["ttf", "otf"]
}

// MARK: - Fonts

func registerAllFonts() {
// Get all custom fonts on bundle
let fontURLs = Constants.fontExtensions.compactMap { fontExtension in
self.urls(forResourcesWithExtension: fontExtension, subdirectory: nil)
}
.flatMap {
$0
}
.map {
$0 as CFURL
}

// Try to register all customs fonts
fontURLs.forEach {
guard let fontDataProvider = CGDataProvider(url: $0),
let font = CGFont(fontDataProvider) else {
return
}

var error: Unmanaged<CFError>?
CTFontManagerRegisterGraphicsFont(font, &error)
}
}
}
22 changes: 0 additions & 22 deletions core/Sources/Info.plist

This file was deleted.

11 changes: 11 additions & 0 deletions core/Sources/Theming/Configuration.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// Configuration.swift
// Spark
//
// Created by robin.lemaire on 02/03/2023.
//

public protocol Configuration {

static func load()
}
39 changes: 39 additions & 0 deletions core/Sources/Theming/Content/Border/Border.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// Border.swift
// SparkCore
//
// Created by robin.lemaire on 28/02/2023.
//

import Foundation

public protocol Border {
var width: BorderWidth { get }
var radius: BorderRadius { get }
}

// MARK: - Width

public protocol BorderWidth {
var none: CGFloat { get }
var small: CGFloat { get }
var medium: CGFloat { get }
}

public extension BorderWidth {
var none: CGFloat { 0 }
}

// MARK: - Radius

public protocol BorderRadius {
var none: CGFloat { get }
var small: CGFloat { get }
var medium: CGFloat { get }
var large: CGFloat { get }
var xLarge: CGFloat { get }
}

public extension BorderRadius {
var none: CGFloat { 0 }
}
65 changes: 65 additions & 0 deletions core/Sources/Theming/Content/Border/BorderDefault.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// BorderDefault.swift
// SparkCore
//
// Created by robin.lemaire on 28/02/2023.
//

import Foundation

public struct BorderDefault: Border {

// MARK: - Properties

public let width: BorderWidth
public let radius: BorderRadius

// MARK: - Initialization

public init(width: BorderWidth, radius: BorderRadius) {
self.width = width
self.radius = radius
}
}

// MARK: - Width

public struct BorderWidthDefault: BorderWidth {

// MARK: - Properties

public let small: CGFloat
public let medium: CGFloat

// MARK: - Initialization

public init(small: CGFloat,
medium: CGFloat) {
self.small = small
self.medium = medium
}
}

// MARK: - Radius

public struct BorderRadiusDefault: BorderRadius {

// MARK: - Properties

public let small: CGFloat
public let medium: CGFloat
public let large: CGFloat
public let xLarge: CGFloat

// MARK: - Initialization

public init(small: CGFloat,
medium: CGFloat,
large: CGFloat,
xLarge: CGFloat) {
self.small = small
self.medium = medium
self.large = large
self.xLarge = xLarge
}
}
52 changes: 52 additions & 0 deletions core/Sources/Theming/Content/Colors/Colors.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// Colors.swift
// SparkCore
//
// Created by louis.borlee on 23/02/2023.
//

import UIKit
import SwiftUI

public protocol Colors {
var primary: ColorToken { get }
var primaryVariant: ColorToken { get }

var secondary: ColorToken { get }
var secondaryVariant: ColorToken { get }

var background: ColorToken { get }

var surface: ColorToken { get }
var surfaceInverse: ColorToken { get }

var success: ColorToken { get }
var alert: ColorToken { get }
var error: ColorToken { get }
var info: ColorToken { get }
var neutral: ColorToken { get }

var primaryContainer: ColorToken { get }
var secondaryContainer: ColorToken { get }
var successContainer: ColorToken { get }
var alertContainer: ColorToken { get }
var errorContainer: ColorToken { get }
var infoContainer: ColorToken { get }
var neutralContainer: ColorToken { get }
}

// MARK: - Token

public protocol ColorToken {
var enabled: ColorTokenValue { get }
var pressed: ColorTokenValue { get }
var disabled: ColorTokenValue { get }
var on: ColorTokenValue { get }
}

// MARK: - Value

public protocol ColorTokenValue {
var uiColor: UIColor { get }
var swiftUIcolor: Color { get }
}
Loading

0 comments on commit f3cbf8a

Please sign in to comment.