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

Initialize HTML elements with array of attributes #22

Merged
merged 3 commits into from
Aug 28, 2024

Conversation

lovetodream
Copy link
Contributor

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
Copy link
Contributor Author

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

Copy link
Owner

@sliemeobn sliemeobn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey, thanks for this, I was going to add the same thing today ; )

please add a test or two just to have it covered - nothing fancy

also, I am in the process of fixing the hummingbird example right now.

Sources/Elementary/Core/Html+Attributes.swift Outdated Show resolved Hide resolved
Sources/Elementary/Core/Html+Attributes.swift Outdated Show resolved Hide resolved
Sources/Elementary/Core/Html+Attributes.swift Show resolved Hide resolved
Copy link
Owner

@sliemeobn sliemeobn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice one, thanks!

lgtm

@sliemeobn sliemeobn merged commit 04bd2fc into sliemeobn:main Aug 28, 2024
2 checks passed
@lovetodream lovetodream deleted the attribute-array-init branch August 28, 2024 09:07
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

Successfully merging this pull request may close these issues.

2 participants