Skip to content

An awesome Swift CSS DSL library using result builders.

License

Notifications You must be signed in to change notification settings

BinaryBirds/swift-css

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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