Skip to content
Discussion options

You must be logged in to vote

On the first point, you would need to implement the component interface to remove the need for Render(). It is a bit more code but should have the desired effect.

type button struct {
    class string
    attrs templ.Attributes
}

func Button() *button {
    return &button {
        class: "some_button_classes",
        attrs: templ.Attributes{},
    }
}

func (b *button) XL() *button {
    b.class += " xl" // just an example
    return b
}

func (b *button) Set(k string, v interface{}) *button {
    b.attrs[k] = v
    return b
}

templ (b *button) renderButton() {
    <button { b.attrs... } class={b.class}>{children...}</button>
}

func (b *button) Render(ctx context.Context, w io.Writer…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@tim-rus
Comment options

Answer selected by tim-rus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants