sliemeobn / elementary

A modern and efficient HTML rendering library - inspired by SwiftUI, built for the web.
https://swiftpackageindex.com/sliemeobn/elementary
Apache License 2.0
63 stars 4 forks source link

Initialize HTML elements with array of attributes #22

Closed lovetodream closed 2 weeks ago

lovetodream commented 2 weeks ago

This allows to create custom HTML components and forward attributes from those to the underlying tag.

Example:

struct Title<Title: HTML>: HTML {
    var attributes: [HTMLAttribute<HTMLTag.h2>]
    var title: () -> Title

    init(attributes: HTMLAttribute<HTMLTag.h2>..., @HTMLBuilder title: @escaping () -> Title) {
        self.attributes = attributes + [.class("mt-14 text-base/7 font-semibold text-zinc-950 sm:text-sm/6 dark:text-white")]
        self.title = title
    }

    var content: some HTML {
        h2(attributes) {
            title()
        }
    }
}

Let me know if I should add tests for this.

lovetodream commented 2 weeks ago

Example CI is failing due to changes in the Hummingbird release candidate