Skip to content

Commit e9c9a5d

Browse files
committed
Made the tests and documents far easier to understand for the onclick function
1 parent b7a2077 commit e9c9a5d

File tree

2 files changed

+8
-20
lines changed

2 files changed

+8
-20
lines changed

docs/components/onclick.md

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,20 @@
1-
# matestack core component: Action
1+
# matestack core component: Onclick
22

33
Show [specs](../../spec/usage/components/onclick_spec.rb)
44

5-
The `onclick` component renders a div that runs a function on click. This is a nice component for use cases where you would like to wrap multiple components into one click function. The function called by the onclick component requires two fields. These two fields are `emit` and `data`. These two fields are then emitted as a event in javascript when the component is clicked
5+
The `onclick` component renders a div that runs a function when the user clicks on it. This is a simple component that can be used to wrap components with a onclick function that will emit a event. The event that must be emitted onclick can defined by passing a hash into the `onclick` component that has the key `emit`. See example below for more details.
66

77
```ruby
88
class Pages::MyPage::Home < Matestack::Ui::Page
99
def response
1010
components{
11-
onclick run_this_function do
11+
onclick(emit: "abc") do
1212
plain "Hello world"
1313
end
1414
}
15-
end
16-
17-
def run_this_function
18-
return {
19-
emit: "abc",
20-
data: {
21-
id: 1,
22-
name: "John",
23-
detail: "Clicked the button"
24-
}
25-
}
15+
async rerender_on: "abc" do
16+
plain "Render this text when the 'abc' event is emitted"
17+
end
2618
end
2719
end
2820
```

spec/usage/components/onclick_spec.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require_relative "../../support/utils"
22
include Utils
33

4-
describe "Nav Component", type: :feature, js: true do
4+
describe "Onclick Component", type: :feature, js: true do
55

66
it "Example 1" do
77
class ExamplePage < Matestack::Ui::Page
@@ -22,10 +22,7 @@ def response
2222

2323
def click_function
2424
return {
25-
emit: 'show_message',
26-
data: {
27-
message: "This is a cool message"
28-
}
25+
emit: 'show_message'
2926
}
3027
end
3128
end
@@ -46,5 +43,4 @@ def click_function
4643
<div>Click me!</div>
4744
HTML
4845
end
49-
5046
end

0 commit comments

Comments
 (0)