Skip to content

Components composition and attributes #755

Answered by JuroOravec
vb8448 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @vb8448, your approach is fine! But if it doesn't feel right, you can use the spread operator (...dict) to do the following :)

@register("button")
class Button(Component):
    def get_context_data(
            self,
            value: Optional[str] = None,
            html_type: Optional[str] = None,
            klass: Optional[str] = None,
            **kwargs
    ) -> dict:
        icon_attrs = {k[2:]: kwargs.pop(k) for k in list(kwargs.keys()) if k.startswith("i_")}

        return {
            "icon_attrs": icon_attrs,
            "base_attrs": {
                "html_type": html_type or self.html_type,
                "class": self.html_class,
            },
        }

    # lang…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@vb8448
Comment options

Answer selected by vb8448
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
Converted from issue

This discussion was converted from issue #754 on November 14, 2024 22:50.