baoagency / polaris_view_components

ViewComponents for Polaris Design System
https://polarisviewcomponents.org
MIT License
380 stars 53 forks source link

How to add logic the button click callback? #410

Closed mikemikehe closed 5 months ago

mikemikehe commented 6 months ago

Hi friends here. I am exploring this components/polaris/resource_item_component.rb and I found that it already has callbacks defined in some stimulus controller callback. see below

https://github.com/baoagency/polaris_view_components/blob/main/app/components/polaris/resource_item_component.rb#L90

 prepend_option(args[:data], :action, "click->polaris-resource-item#open")

I am wondering how I can add customized logic for my usage? It seems polaris-resource-item is with the gem and apply to all usage of resource_item_component.

thanks /

kirillplatonov commented 6 months ago

You can pass your custom action via data attributes:

<%= polaris_card(sectioned: false) do %>
  <%= polaris_resource_list do %>
    <%= polaris_resource_item(data: {action: "click->custom-controller#action"}) do %>
      <p>Content</p>
    <% end %>
  <% end %>
<% end %>