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

Add support For HTML data attributes on components #631

Open
guspower opened this issue Sep 30, 2024 · 2 comments
Open

Add support For HTML data attributes on components #631

guspower opened this issue Sep 30, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@guspower
Copy link

What are you building with SQLPage ?

A link sharing tool

What is your problem ? A description of the problem, not the solution you are proposing.

I am using htmx to add interactivity to some of the components.

What are you currently doing ? Since your solution is not implemented in SQLPage currently, what are you doing instead ?

I copy the component source into my configuration/templates directory and modify it to support attributes. On sqlpage release I have to update the templates.

Describe the solution you'd like

I would like the sqlpage mainline components to support user-provided html attributes.

Describe alternatives you've considered

Decorating attributes onto DOM elements using javascript and css selectors. It's unpleasant.

Additional context

Here is an example of the datagrid component (datagrid.handlebars):

<div class="card my-2 {{class}}" {{#if id}}id="{{id}}"{{/if}}{{#each attribute}} {{{this}}}{{/each}}>
   ...
    <div class="card-body">
        <div class="datagrid">
            {{#each_row}}
                <div class="datagrid-item {{title}}"{{#each attribute}} {{{this}}}{{/each}}>
                    ...
                    </div>
                </div>
            {{/each_row}}
        </div>
    </div>
</div>

and in use:

SELECT 'datagrid'             AS component
;

SELECT 'Edit Link' AS title
    , 'edit' AS icon
    , 'hx-get="/component/dropdown.sql?_sqlpage_embed&link=' || $link || '"' AS attribute
    , 'hx-target=".datagrid-item.' || $linkl || '"' AS attribute
    , 'hx-swap="outerHTML"' AS attribute
    , 'hx-trigger="click once"' AS attribute
;

There is probably a nicer way to express this - maybe with name/value json pairs - but this was a quick solution that works.

@guspower guspower added the enhancement New feature or request label Sep 30, 2024
@francesco-cattoglio
Copy link

Just my 2 cents: I have been using SQLPage on a personal project (TY by the way, this project is awesome) and I wanted to add a little feature (auto-submission of form when a drop-down menu was changed). A quick and easy way to achieve that was using htmx, so I did something similar to @guspower and added some fields to my custom form component.

In my opinion this kind of integration works great and fits the SQLPage philosophy: I can add some htmx attributes to components to get tiny, self contained actions and that do not "pollute" the page. Better yet, htmx works very well with the pre-rendered nature of this project.

I think it would be really nice if we were able to get something like this proposal. Also, there is a discussion on the same topic here: #628

@ToniJ123
Copy link

Could we have more integrated co-work with htmx with SQLpage somehow, maybe some examples and guides or pre-selected features integrated? Or is this area which everybody can, or have to, go find out and explore within themselfs? It would be awesome to have co-operation with something like htmx if it's very suitable for ideology of SQLpage 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants