wrabit / django-cotton

Enabling Modern UI Composition in Django
https://django-cotton.com
MIT License
482 stars 19 forks source link

Support kebab-style attributes #205

Closed aaronbrethorst closed 3 days ago

aaronbrethorst commented 4 days ago

I am building a form component library with Cotton and Tailwind. All of my Tailwind UI components look like this:

<c-vars type="text" name label class />

<div class="gap-x-0.5">
    {% if label %}
        <c-forms.label for="{{id}}">{{label}}</c-forms.label>
    {% endif %}

    <div>
        <input
            type="{{type}}"
            name="{{name}}"
            id="{% if id %}{{id}}{% else %}{{name}}{% endif %}"
            class="block w-full rounded-md border-0 py-1 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-blue-600 sm:text-sm sm:leading-6 {{class}}"
            {{attrs}}>
        <c-forms.hint-text hint="{{hint}}" />
    </div>
</div>

I want to be able to add classes to the outer wrapper <div> like this:

<c-forms.text-field wrapper-class="mb-4" />

and consume that value like this:

<c-vars type="text" name label class wrapper_class />

<div class="gap-x-0.5 {{wrapper_class}}">

but this doesn't seem to be possible today.

Workaround:

Use snake case or pascal case.

wrabit commented 4 days ago

Hi @aaronbrethorst, if you use kebab case in the cvars instead, it should work, because we're looking for matches of the same attribute in the parent view on the component.

<c-vars ... wrapper-class />