Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NSColor extension for light and dark versions #6

Open
pcolton opened this issue Aug 28, 2020 · 1 comment
Open

NSColor extension for light and dark versions #6

pcolton opened this issue Aug 28, 2020 · 1 comment

Comments

@pcolton
Copy link

pcolton commented Aug 28, 2020

I used the tool to generate this set of light and dark mode equivalents for when running SwiftUI on macOS since when not using Catalyst, these colors aren't [as of macOS 11 beta 5] available.

extension NSColor {
    static var label: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0)
        } else {
            return labelDark
        }
    }
    static var secondaryLabel: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 0.23529411764705882, green: 0.23529411764705882, blue: 0.2627450980392157, alpha: 0.6)
        } else {
            return secondaryLabelDark
        }
    }
    static var tertiaryLabel: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 0.23529411764705882, green: 0.23529411764705882, blue: 0.2627450980392157, alpha: 0.3)
        } else {
            return tertiaryLabelDark
        }
    }
    static var quaternaryLabel: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 0.23529411764705882, green: 0.23529411764705882, blue: 0.2627450980392157, alpha: 0.18)
        } else {
            return quaternaryLabelDark
        }
    }
    static var systemFill: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 0.47058823529411764, green: 0.47058823529411764, blue: 0.5019607843137255, alpha: 0.2)
        } else {
            return systemFillDark
        }
    }
    static var secondarySystemFill: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 0.47058823529411764, green: 0.47058823529411764, blue: 0.5019607843137255, alpha: 0.16)
        } else {
            return secondarySystemFillDark
        }
    }
    static var tertiarySystemFill: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 0.4627450980392157, green: 0.4627450980392157, blue: 0.5019607843137255, alpha: 0.12)
        } else {
            return tertiarySystemFillDark
        }
    }
    static var quaternarySystemFill: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 0.4549019607843137, green: 0.4549019607843137, blue: 0.5019607843137255, alpha: 0.08)
        } else {
            return quaternarySystemFillDark
        }
    }
    static var placeholderText: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 0.23529411764705882, green: 0.23529411764705882, blue: 0.2627450980392157, alpha: 0.3)
        } else {
            return placeholderTextDark
        }
    }
    static var systemBackground: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
        } else {
            return systemBackgroundDark
        }
    }
    static var secondarySystemBackground: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 0.9490196078431372, green: 0.9490196078431372, blue: 0.9686274509803922, alpha: 1.0)
        } else {
            return secondarySystemBackgroundDark
        }
    }
    static var tertiarySystemBackground: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
        } else {
            return tertiarySystemBackgroundDark
        }
    }
    static var systemGroupedBackground: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 0.9490196078431372, green: 0.9490196078431372, blue: 0.9686274509803922, alpha: 1.0)
        } else {
            return systemGroupedBackgroundDark
        }
    }
    static var secondarySystemGroupedBackground: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
        } else {
            return secondarySystemGroupedBackgroundDark
        }
    }
    static var tertiarySystemGroupedBackground: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 0.9490196078431372, green: 0.9490196078431372, blue: 0.9686274509803922, alpha: 1.0)
        } else {
            return tertiarySystemGroupedBackgroundDark
        }
    }
    static var separator: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 0.23529411764705882, green: 0.23529411764705882, blue: 0.2627450980392157, alpha: 0.29)
        } else {
            return separatorDark
        }
    }
    static var opaqueSeparator: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 0.7764705882352941, green: 0.7764705882352941, blue: 0.7843137254901961, alpha: 1.0)
        } else {
            return opaqueSeparatorDark
        }
    }
    static var link: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 0.0, green: 0.47843137254901963, blue: 1.0, alpha: 1.0)
        } else {
            return linkDark
        }
    }
    static var darkText: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0)
        } else {
            return darkTextDark
        }
    }
    static var lightText: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.6)
        } else {
            return lightTextDark
        }
    }
    static var systemBlue: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 0.0, green: 0.47843137254901963, blue: 1.0, alpha: 1.0)
        } else {
            return systemBlueDark
        }
    }
    static var systemGreen: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 0.20392156862745098, green: 0.7803921568627451, blue: 0.34901960784313724, alpha: 1.0)
        } else {
            return systemGreenDark
        }
    }
    static var systemIndigo: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 0.34509803921568627, green: 0.33725490196078434, blue: 0.8392156862745098, alpha: 1.0)
        } else {
            return systemIndigoDark
        }
    }
    static var systemOrange: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 1.0, green: 0.5843137254901961, blue: 0.0, alpha: 1.0)
        } else {
            return systemOrangeDark
        }
    }
    static var systemPink: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 1.0, green: 0.17647058823529413, blue: 0.3333333333333333, alpha: 1.0)
        } else {
            return systemPinkDark
        }
    }
    static var systemPurple: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 0.6862745098039216, green: 0.3215686274509804, blue: 0.8705882352941177, alpha: 1.0)
        } else {
            return systemPurpleDark
        }
    }
    static var systemRed: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 1.0, green: 0.23137254901960785, blue: 0.18823529411764706, alpha: 1.0)
        } else {
            return systemRedDark
        }
    }
    static var systemTeal: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 0.35294117647058826, green: 0.7843137254901961, blue: 0.9803921568627451, alpha: 1.0)
        } else {
            return systemTealDark
        }
    }
    static var systemYellow: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 1.0, green: 0.8, blue: 0.0, alpha: 1.0)
        } else {
            return systemYellowDark
        }
    }
    static var systemGray: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 0.5568627450980392, green: 0.5568627450980392, blue: 0.5764705882352941, alpha: 1.0)
        } else {
            return systemGrayDark
        }
    }
    static var systemGray2: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 0.6823529411764706, green: 0.6823529411764706, blue: 0.6980392156862745, alpha: 1.0)
        } else {
            return systemGray2Dark
        }
    }
    static var systemGray3: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 0.7803921568627451, green: 0.7803921568627451, blue: 0.8, alpha: 1.0)
        } else {
            return systemGray3Dark
        }
    }
    static var systemGray4: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 0.8196078431372549, green: 0.8196078431372549, blue: 0.8392156862745098, alpha: 1.0)
        } else {
            return systemGray4Dark
        }
    }
    static var systemGray5: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 0.8980392156862745, green: 0.8980392156862745, blue: 0.9176470588235294, alpha: 1.0)
        } else {
            return systemGray5Dark
        }
    }
    static var systemGray6: NSColor {
        if NSAppearance.current.name == .aqua {
            return NSColor(red: 0.9490196078431372, green: 0.9490196078431372, blue: 0.9686274509803922, alpha: 1.0)
        } else {
            return systemGray6Dark
        }
    }
}

// Dark mode colors
extension NSColor {
    static var labelDark: NSColor {
        NSColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
    }
    static var secondaryLabelDark: NSColor {
        NSColor(red: 0.9215686274509803, green: 0.9215686274509803, blue: 0.9607843137254902, alpha: 0.6)
    }
    static var tertiaryLabelDark: NSColor {
        NSColor(red: 0.9215686274509803, green: 0.9215686274509803, blue: 0.9607843137254902, alpha: 0.3)
    }
    static var quaternaryLabelDark: NSColor {
        NSColor(red: 0.9215686274509803, green: 0.9215686274509803, blue: 0.9607843137254902, alpha: 0.18)
    }
    static var systemFillDark: NSColor {
        NSColor(red: 0.47058823529411764, green: 0.47058823529411764, blue: 0.5019607843137255, alpha: 0.36)
    }
    static var secondarySystemFillDark: NSColor {
        NSColor(red: 0.47058823529411764, green: 0.47058823529411764, blue: 0.5019607843137255, alpha: 0.32)
    }
    static var tertiarySystemFillDark: NSColor {
        NSColor(red: 0.4627450980392157, green: 0.4627450980392157, blue: 0.5019607843137255, alpha: 0.24)
    }
    static var quaternarySystemFillDark: NSColor {
        NSColor(red: 0.4627450980392157, green: 0.4627450980392157, blue: 0.5019607843137255, alpha: 0.18)
    }
    static var placeholderTextDark: NSColor {
        NSColor(red: 0.9215686274509803, green: 0.9215686274509803, blue: 0.9607843137254902, alpha: 0.3)
    }
    static var systemBackgroundDark: NSColor {
        NSColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0)
    }
    static var secondarySystemBackgroundDark: NSColor {
        NSColor(red: 0.10980392156862745, green: 0.10980392156862745, blue: 0.11764705882352941, alpha: 1.0)
    }
    static var tertiarySystemBackgroundDark: NSColor {
        NSColor(red: 0.17254901960784313, green: 0.17254901960784313, blue: 0.1803921568627451, alpha: 1.0)
    }
    static var systemGroupedBackgroundDark: NSColor {
        NSColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0)
    }
    static var secondarySystemGroupedBackgroundDark: NSColor {
        NSColor(red: 0.10980392156862745, green: 0.10980392156862745, blue: 0.11764705882352941, alpha: 1.0)
    }
    static var tertiarySystemGroupedBackgroundDark: NSColor {
        NSColor(red: 0.17254901960784313, green: 0.17254901960784313, blue: 0.1803921568627451, alpha: 1.0)
    }
    static var separatorDark: NSColor {
        NSColor(red: 0.32941176470588235, green: 0.32941176470588235, blue: 0.34509803921568627, alpha: 0.6)
    }
    static var opaqueSeparatorDark: NSColor {
        NSColor(red: 0.2196078431372549, green: 0.2196078431372549, blue: 0.22745098039215686, alpha: 1.0)
    }
    static var linkDark: NSColor {
        NSColor(red: 0.03529411764705882, green: 0.5176470588235295, blue: 1.0, alpha: 1.0)
    }
    static var darkTextDark: NSColor {
        NSColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0)
    }
    static var lightTextDark: NSColor {
        NSColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.6)
    }
    static var systemBlueDark: NSColor {
        NSColor(red: 0.0392156862745098, green: 0.5176470588235295, blue: 1.0, alpha: 1.0)
    }
    static var systemGreenDark: NSColor {
        NSColor(red: 0.18823529411764706, green: 0.8196078431372549, blue: 0.34509803921568627, alpha: 1.0)
    }
    static var systemIndigoDark: NSColor {
        NSColor(red: 0.3686274509803922, green: 0.3607843137254902, blue: 0.9019607843137255, alpha: 1.0)
    }
    static var systemOrangeDark: NSColor {
        NSColor(red: 1.0, green: 0.6235294117647059, blue: 0.0392156862745098, alpha: 1.0)
    }
    static var systemPinkDark: NSColor {
        NSColor(red: 1.0, green: 0.21568627450980393, blue: 0.37254901960784315, alpha: 1.0)
    }
    static var systemPurpleDark: NSColor {
        NSColor(red: 0.7490196078431373, green: 0.35294117647058826, blue: 0.9490196078431372, alpha: 1.0)
    }
    static var systemRedDark: NSColor {
        NSColor(red: 1.0, green: 0.27058823529411763, blue: 0.22745098039215686, alpha: 1.0)
    }
    static var systemTealDark: NSColor {
        NSColor(red: 0.39215686274509803, green: 0.8235294117647058, blue: 1.0, alpha: 1.0)
    }
    static var systemYellowDark: NSColor {
        NSColor(red: 1.0, green: 0.8392156862745098, blue: 0.0392156862745098, alpha: 1.0)
    }
    static var systemGrayDark: NSColor {
        NSColor(red: 0.5568627450980392, green: 0.5568627450980392, blue: 0.5764705882352941, alpha: 1.0)
    }
    static var systemGray2Dark: NSColor {
        NSColor(red: 0.38823529411764707, green: 0.38823529411764707, blue: 0.4, alpha: 1.0)
    }
    static var systemGray3Dark: NSColor {
        NSColor(red: 0.2823529411764706, green: 0.2823529411764706, blue: 0.2901960784313726, alpha: 1.0)
    }
    static var systemGray4Dark: NSColor {
        NSColor(red: 0.22745098039215686, green: 0.22745098039215686, blue: 0.23529411764705882, alpha: 1.0)
    }
    static var systemGray5Dark: NSColor {
        NSColor(red: 0.17254901960784313, green: 0.17254901960784313, blue: 0.1803921568627451, alpha: 1.0)
    }
    static var systemGray6Dark: NSColor {
        NSColor(red: 0.10980392156862745, green: 0.10980392156862745, blue: 0.11764705882352941, alpha: 1.0)
   }
}
@noahsark769
Copy link
Owner

Cool! I'd be happy to accept a pull request for this. I believe it would involve basically throwing this code in ColorCompatibility.swift under an #if os(macOS) correct? I believe we could add mac as a supported platform to the podfile as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants