Skip to content

Instantly share code, notes, and snippets.

View o-nnerb's full-sized avatar

Brenno de Moura o-nnerb

View GitHub Profile
@o-nnerb
o-nnerb / DesignSystem.ColorScale.swift
Created June 24, 2021 02:12
The ColorScale provider that describes the color intensity
public struct ColorScale<Color: ColorType>: ColorProvider {
public var lighttest: Color {
transformHandler("lighttest")
}
public var light: Color {
transformHandler("light")
}
@o-nnerb
o-nnerb / DesignSystem.ColorVariant.swift
Last active July 1, 2021 22:46
ColorVariant is a provider that implements intermediate properties
public struct ColorVariant<Provider: ColorProvider>: ColorProvider {
public typealias Color = Provider.Color
public var xs: Provider {
transformHandler("xs")
}
public var md: Provider {
transformHandler("md")
}
@o-nnerb
o-nnerb / DesignSystem.ImageSpace.swift
Last active July 1, 2021 22:46
The ImageSpace defines all the categories for a family of icons
public struct ImageSpace<Provider: ImageProvider>: ImageProvider {
public typealias Image = Provider.Image
public var acessibility: AcessibilityCategory<Provider> {
AcessibilityCategory {
transformHandler("accessibility.\($0)")
}
}
}
@o-nnerb
o-nnerb / DesignSystem.ContentView.swift
Created June 24, 2021 02:31
Example of properties linked to Color and Font
import SwiftUI
struct ContentView: View {
var body: some View {
Text("Hello World!")
.foregroundColor(.ds.primary.medium)
.font(.arial.medium.xxxl)
.lineSpacing(.medium)
}
@o-nnerb
o-nnerb / DesignSystem.UIColor+ColorType.swift
Created June 24, 2021 22:42
Implementation of ColorType protocol in UIColor
extension UIColor: ColorType {
public static var ds: DSColors<UIColor> {
DSColors { literal in
UIColor(
name: literal,
in: .module,
compatibleWith: nil
)
}
@o-nnerb
o-nnerb / DesignSystem.DSColors.swift
Last active July 1, 2021 22:46
Implementation of DSColors with distinct properties
public struct DSColors<Color: ColorType>: ColorProvider {
public var primary: ColorScale<Color> {
ColorScale {
transformHandler("primary.\(%0)")
}
}
public var complementary: ColorStyle<Color> {
ColorStyle {
@o-nnerb
o-nnerb / DesignSystem.Shadow.swift
Created June 24, 2021 22:49
Implementation of a token for shadow with internal methods
public enum Shadow {
case level1
case level2
case level3
}
internal extension Shadow {
var x: CGFloat { ... }
@o-nnerb
o-nnerb / DesignSystem.Object+Shadow.swift
Created June 24, 2021 22:53
Adaptation of Shadow token to support UIKit and SwiftUI
// UIKit
extension CALayer {
public func setShadow(_ level: Shadow) {
shadowRadius = level.radius
shadowOpacity = level.opacity
shadowColor = level.uiColor.cgFloat
shadowOffset = .init(
width: level.x,
@o-nnerb
o-nnerb / DesignSystem.Spacing.swift
Created June 24, 2021 22:54
Spacing contains a generic Number type
public struct Spacing<Number: Numeric> {
public var small: Number {
32
}
public var medium: Number {
64
}
@o-nnerb
o-nnerb / DesignSystem.Double+Spacing.swift
Created June 24, 2021 22:56
Double supporting Spacing
extension Double {
public static var spacing: Spacing<Self> {
Spacing()
}
}