Skip to content

Commit

Permalink
⚡️ :: darModeColor func , init
Browse files Browse the repository at this point in the history
  • Loading branch information
HongSJae committed Jul 24, 2023
1 parent 3f3a63c commit 9f2f184
Showing 1 changed file with 9 additions and 23 deletions.
32 changes: 9 additions & 23 deletions xquare-design-system-iOS/Sources/Color/Color+init.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,15 @@ public enum ColorType: String {
case netural = "Netural"
case neutralVariant = "Neutral Variant"
}

public enum ColorState {
case base
case on
case container
case onContainer

func colorState(_ type: ColorType) -> String {
switch self {
case .base:
return type.rawValue
case .on:
return "on \(type.rawValue)"
case .container:
return "\(type.rawValue) Container"
case .onContainer:
return "On \(type.rawValue) Container"
}
}
}

extension Color {
init(type: ColorType, _ state: ColorState) {
self.init(state.colorState(type), bundle: Bundle.module)
init(type: ColorType, _ palette: Int) {
self.init("\(type.rawValue) \(palette)", bundle: Bundle.module)
}

public func darkModeColor(_ dark: Color) -> Color {
let color = UIColor { (UITraitCollection: UITraitCollection) -> UIColor in
return UITraitCollection.userInterfaceStyle == .dark ? UIColor(dark) : UIColor(self)
}
return Color(uiColor: color)
}
}

0 comments on commit 9f2f184

Please sign in to comment.