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

d8abe7e · Jul 30, 2023

History

28 Commits
Jul 30, 2023
Dec 27, 2021
Jul 11, 2021
Feb 17, 2022
Jul 11, 2021
Jul 11, 2021
Nov 21, 2021

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