Skip to content

Commit 862e690

Browse files
authored
Add instructions how to add new colors
1 parent e9be7ac commit 862e690

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,54 @@ public static let systemPink = Color.dynamicColor(
7474
)
7575
```
7676

77+
## How to add a new color
78+
79+
1. Add the color to the `BaseColor` enum.
80+
```swift
81+
/// A color that represents the system-provided systemPink color.
82+
public static let systemPink = Color.dynamicColor(
83+
light: .init(red: 1.00, green: 0.18, blue: 0.33, alpha: 1.00),
84+
dark: .init(red: 1.00, green: 0.18, blue: 0.33, alpha: 1.00)
85+
)
86+
```
87+
2. Add the color to the `Color` extension.
88+
- Use the native `Color`,`NSColor`,`UIColor.colorName` where possible.
89+
- Add #if os(iOS) / #if os(macOS) where needed.
90+
- Example (works on almost all versions):
91+
```swift
92+
/// A color that represents the system-provided pink color.
93+
public static var systemPink: Color {
94+
#if os(iOS) || os(tvOS)
95+
Color(UIColor.systemPink)
96+
#elseif os(macOS)
97+
Color(NSColor.systemPink)
98+
#else
99+
BaseColor.systemPink
100+
#endif
101+
}
102+
```
103+
- Example 2 (works from a specific iOS/macOS version):
104+
```swift
105+
/// A color that represents the system-provided cyan color.
106+
public static var systemCyan: Color {
107+
#if os(iOS) || os(tvOS)
108+
if #available(iOS 15.0, *) {
109+
Color(UIColor.systemCyan)
110+
} else {
111+
BaseColor.systemCyan
112+
}
113+
#elseif os(macOS)
114+
if #available(macOS 12.0, *) {
115+
Color(NSColor.systemCyan)
116+
} else {
117+
BaseColor.systemCyan
118+
}
119+
#else
120+
BaseColor.systemCyan
121+
#endif
122+
}
123+
```
124+
77125
## Contact
78126

79127
We can get in touch via [Mastodon](https://mastodon.social/@0xWDG), [Twitter/X](https://twitter.com/0xWDG), [Discord](https://discordapp.com/users/918438083861573692), [Email](mailto:[email protected]), [Website](https://wesleydegroot.nl).

0 commit comments

Comments
 (0)