ajaishankar / stimulus-reactive

Reactivity for the Stimulus you already have
MIT License
26 stars 1 forks source link

Feature request: stimulus-helper package, a package for rendering stimulus attributes easily #3

Open tacman opened 2 months ago

tacman commented 2 months ago

This is really a request for a new package, but I wasn't sure how to contact you directly.

I'd like to be able to use the twig helpers for stimulus in javascript

For example,

import {stimulus_controller, stimulus_target, stimulus_action} from 'stimulus-helper';

let str = stimulus_controller('my-controller',  {myValue: 'scalar-value'});
console.assert(str == 'data-controller="my-controller" data-my-controller-my-value-value="scalar-value"');

All of the tests can be found (in PHP) at https://github.com/symfony/ux/blob/2.x/src/StimulusBundle/tests/Twig/StimulusTwigExtensionTest.php

The PHP code is at https://github.com/symfony/ux/blob/2.x/src/StimulusBundle/src/Dto/StimulusAttributes.php

I posted a job on fiverr requesting this, but this seems like a nice fit with your existing packages (this, stimulus-typescript, the 10 people on earth that use zod with stimulus). Even if you're not a PHP developer, the code is pretty straightforward.

In particular, this could be called from twigjs (https://github.com/twigjs/twig.js/issues/878) but also from anywhere that's rendering html within javascript.

I don't have a huge budget (it's a personal/volunteer project), but I can contribute something financially. I can be reached at tacman@gmail.com to discuss this.

Thanks again for this bundle!

tacman commented 2 months ago

I'm really hoping you'll be able to do this. But if not, can you give me some guidance as to how to do this?

ajaishankar commented 2 months ago

I think you should be able to extend with a custom stimulus_controller function

https://github.com/twigjs/twig.js/wiki/Extending-twig.js#functions

tacman commented 2 months ago

Indeed, that's my plan. A library that exports those 3 functions, then map those by extending twig.

I already do that with another library, it works fine. Do you do freelance work? Because you know stimulus and javascript so well, I'm confident you'd be able to knock it out.