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

[LiveComponent] Add 'live_action' twig function #1946

Merged
merged 1 commit into from
Jul 31, 2024

Conversation

pierredup
Copy link
Contributor

@pierredup pierredup commented Jun 29, 2024

Q A
Bug fix? no
New feature? yes
Issues N/A
License MIT

Adds a new live_action twig function.

This helps with creating the proper attributes to call a live action. I can never remember the syntax and need to look up the docs every time to add a live action. This will make the process much easier.

Example Usage:

- <button data-action="live#action" data-live-action-param="save">Save</button>
+ <button {{ live_action('save') }}>Save</button>

Additional Parameters:

<button
-  data-action="live#action"
-  data-live-action-param="addItem"
-  data-live-id-param="{{ item.id }}"
-  data-live-item-name-param="CustomItem"
+  {{ live_action('addItem', {'id': item.id, 'itemName': 'CustomItem'}) }}
>Add Item</button>

Adding Modifiers:

<button
-  data-action="live#action:prevent"
-  data-live-action-param="debounce(300)|save"
+  {{ live_action('save', {}, {'debounce': 300, 'prevent': true}) }}
 >Save</button>

TODO:

  • Add CHANGELOG entry
  • Update docs

@smnandre
Copy link
Member

Hi @pierredup !

I like the idea very much (in term of DX), but internally i think we should leverage the StimulusAttribute already present in the Stimulus-Bundle ... https://symfony.com/bundles/StimulusBundle/current/index.html#stimulus-action

... what do you thinkl ?

@smnandre
Copy link
Member

Depending on your answer on the previous question, this comment could be useless ;)

We'd need to specify the trigger, as even if an action is often trigger by the "default event" on the DOM element it's registerered on, but this can be more specific / diverse

Examples here: https://stimulus.hotwired.dev/reference/actions#keyboardevent-filter

@pierredup pierredup changed the title Add 'live_action' twig function [LiveComponent] Add 'live_action' twig function Jun 30, 2024
@pierredup
Copy link
Contributor Author

internally i think we should leverage the StimulusAttribute already present in the Stimulus-Bundle

I did initially start to go down this route, but then noticed the StimulusBundle is not a direct dependency of the LiveComponent, so didn't want to use classes that's not guaranteed to be available. Will then just add the StimulusBundle as a dependency to LiveComponent

We'd need to specify the trigger, as even if an action is often trigger by the "default event" on the DOM element it's registerered on, but this can be more specific / diverse

Cool, yeah that makes sense, will add it to the function

Copy link
Member

@kbond kbond left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this - you're totally right, the syntax is hard to remember!

@carsonbot carsonbot added Status: Reviewed Has been reviewed by a maintainer and removed Status: Needs Review Needs to be reviewed labels Jul 6, 2024
@kbond kbond added Status: Needs Review Needs to be reviewed Status: Needs Work Additional work is needed and removed Status: Reviewed Has been reviewed by a maintainer Status: Needs Review Needs to be reviewed labels Jul 8, 2024
@carsonbot carsonbot added Status: Needs Review Needs to be reviewed and removed Status: Needs Work Additional work is needed labels Jul 31, 2024
@pierredup pierredup force-pushed the live-action-twig-function branch 2 times, most recently from e5e715d to 2417af1 Compare July 31, 2024 10:27
@pierredup pierredup requested review from smnandre and kbond July 31, 2024 10:28
Copy link
Member

@smnandre smnandre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @pierredup !

Just two last tiny details and good!

@carsonbot carsonbot added Status: Reviewed Has been reviewed by a maintainer and removed Status: Needs Review Needs to be reviewed labels Jul 31, 2024
@kbond kbond force-pushed the live-action-twig-function branch from 2c7e330 to b35807b Compare July 31, 2024 13:33
@kbond
Copy link
Member

kbond commented Jul 31, 2024

Thanks for your work on this new feature!

@kbond kbond merged commit f4dfe0e into symfony:2.x Jul 31, 2024
6 checks passed
@pierredup pierredup deleted the live-action-twig-function branch July 31, 2024 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX Feature New Feature LiveComponent Status: Reviewed Has been reviewed by a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants