/swift-css

An awesome Swift CSS DSL library using result builders.

Primary LanguageSwiftMIT LicenseMIT

SwiftCss

An awesome Swift CSS DSL library using result builders.

let css = Stylesheet {            
    Media {
        All {
            Background("#222")
        }
        Root {
            Color(.blue)
        }
        Element(.div) {
            BackgroundColor(.red)
            Color(.white)
            TextAlign(.left)
        }
        .pseudo(.nthChild(2))
    }
    Media("only screen and (max-width: 600px)") {
        Id("custom-identifier") {
            Background("#222")
            Color(.cyan)
        }
        Class("custom-class") {
            Background("#333")
            Color(.aliceBlue)
        }
        Selector("ul > li > a") {
            Background("black")
            Color(.red)
                .important()
        }
        .pseudo(.hover)
    }
}
    
print(StylesheetRenderer(minify: false, indent: 4).render(css))

Install

You can simply use SwiftCss as a dependency via the Swift Package Manager:

.package(url: "https://github.com/binarybirds/swift-css", from: "1.0.0"),

Add the SwiftCss product from the swift-css package as a dependency to your target:

.product(name: "SwiftCss", package: "swift-css"),

Import the framework:

import SwiftCss

That's it.

Credits & references