udpate text chip colors

This commit is contained in:
Satindar Dhillon 2022-04-07 13:30:18 -07:00
parent 287da3d939
commit 9fb0e11124
2 changed files with 12 additions and 8 deletions

View file

@ -45,8 +45,7 @@ public extension Color {
}
private func toHex() -> String? {
let uic = UIColor(self)
guard let components = uic.cgColor.components, components.count >= 3 else {
guard let components = UIColor(self).cgColor.components, components.count >= 3 else {
return nil
}
let red = Float(components[0])
@ -60,4 +59,13 @@ public extension Color {
lroundf(blue * 255)
)
}
var isDark: Bool {
guard let components = UIColor(self).cgColor.components, components.count >= 3 else {
return false
}
let lum = 0.2126 * Float(components[0]) + 0.7152 * Float(components[1]) + 0.0722 * Float(components[2])
return lum < 0.50
}
}

View file

@ -24,13 +24,9 @@ public struct TextChip: View {
.padding(.horizontal, 10)
.padding(.vertical, 5)
.font(.appFootnote)
.foregroundColor(color)
.foregroundColor(color.isDark ? .white : .black)
.lineLimit(1)
.background(color.opacity(0.1))
.background(color)
.cornerRadius(cornerRadius)
.overlay(
RoundedRectangle(cornerRadius: cornerRadius)
.stroke(color.opacity(0.3), lineWidth: 1)
)
}
}