Skip to content

Commit 3147cbc

Browse files
authored
Update README.md
1 parent e1a7a8c commit 3147cbc

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,23 @@ class ButtonComponent < Vident::ViewComponent::Base
7676

7777
# Configure Stimulus integration
7878
stimulus do
79-
actions [:click, :handle_click]
80-
# Static values
81-
values loading_duration: 1000
79+
# Setup actions, including with proc to evaluate on instance
80+
actions [:click, :handle_click],
81+
-> { [stimulus_scoped_event(:my_custom_event), :handle_this] if should_handle_this? }
8282
# Map the clicked_count prop as a Stimulus value
8383
values_from_props :clicked_count
8484
# Dynamic values using procs (evaluated in component context)
85-
values item_count: -> { @items.count }
86-
values api_url: -> { Rails.application.routes.url_helpers.api_items_path }
85+
values item_count: -> { @items.count },
86+
api_url: -> { Rails.application.routes.url_helpers.api_items_path },
87+
loading_duration: 1000 # or set static values
8788
# Static and dynamic classes
88-
classes loading: "opacity-50 cursor-wait"
89-
classes size: -> { @items.count > 10 ? "large" : "small" }
89+
classes loading: "opacity-50 cursor-wait",
90+
size: -> { @items.count > 10 ? "large" : "small" }
9091
end
9192

9293
def call
9394
root_element do |component|
95+
# Wire up targets etc
9496
component.tag(:span, stimulus_target: :status) do
9597
@text
9698
end
@@ -99,13 +101,15 @@ class ButtonComponent < Vident::ViewComponent::Base
99101

100102
private
101103

104+
# Configure your components root HTML element
102105
def root_element_attributes
103106
{
104107
element_tag: @url ? :a : :button,
105108
html_options: { href: @url }.compact
106109
}
107110
end
108111

112+
# optionally add logic to determine initial classes
109113
def element_classes
110114
base_classes = "btn"
111115
case @style

0 commit comments

Comments
 (0)