Skip to content

Commit fa36c6d

Browse files
authored
Merge pull request #95 from basemate/make_buttons_disableable
Make buttons disableable
2 parents 24ba6fb + 9c6c634 commit fa36c6d

File tree

3 files changed

+100
-1
lines changed

3 files changed

+100
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
module Matestack::Ui::Core::Button
22
class Button < Matestack::Ui::Core::Component::Static
33

4+
def setup
5+
@tag_attributes.merge!({
6+
"disabled": options[:disabled] ||= nil
7+
})
8+
end
9+
410
end
511
end

docs/components/button.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,69 @@
11
# matestack core component: Button
22

33
Show [specs](../../spec/usage/components/button_spec.rb)
4+
5+
The HTML `<button>` tag implemented in Ruby.
6+
7+
## Parameters
8+
9+
This component can take 4 optional configuration params and optional content.
10+
11+
#### # id (optional)
12+
Expects a string with all ids the button should have.
13+
14+
#### # class (optional)
15+
Expects a string with all classes the button should have.
16+
17+
#### # text (optional)
18+
Expects a string with the text that should go inside the `<button>` tag.
19+
20+
#### # disabled (optional)
21+
Expects a boolean to specify a disabled `<button>` tag.
22+
23+
## Example 1
24+
25+
Specifying the button text directly
26+
27+
```ruby
28+
button text: 'Click me'
29+
```
30+
31+
returns
32+
33+
```html
34+
<button>Click me</button>
35+
```
36+
37+
## Example 2
38+
39+
Rendering a content block inside the `<button>` tag:
40+
41+
```ruby
42+
button id: 'foo', class: 'bar' do
43+
plain "Click me"
44+
end
45+
```
46+
47+
returns
48+
49+
```html
50+
<button id="foo" class="bar">Click me</button>
51+
```
52+
53+
## Example 3
54+
55+
By passing a boolean via `disabled: true`, you define disabled buttons. Passing nothing or explicitly defining `disabled: false` return the same result:
56+
57+
```ruby
58+
button disabled: true, text: 'You can not click me'
59+
button disabled: false, text: 'You can click me'
60+
button text: 'You can click me too'
61+
```
62+
63+
returns
64+
65+
```html
66+
<button disabled="disabled">You can not click me</button>
67+
<button>You can click me</button>
68+
<button>You can click me too</button>
69+
```

spec/usage/components/button_spec.rb

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,34 @@ def response
4141
<button>Click me too, m8</button>
4242
<button>I am prefered</button>
4343
HTML
44-
# <!-- <button id='my-button-id-1' class='my-button-class'>Click me, m8</button> -->
44+
45+
expect(stripped(static_output)).to include(stripped(expected_static_output))
46+
end
47+
48+
it 'Example 2: disabled buttons' do
49+
50+
class ExamplePage < Matestack::Ui::Page
51+
52+
def response
53+
components {
54+
# three possible ways of (not) using disabled buttons
55+
button disabled: true, text: 'You can not click me'
56+
button disabled: false, text: 'You can click me'
57+
button text: 'You can click me too'
58+
}
59+
end
60+
61+
end
62+
63+
visit "/example"
64+
65+
static_output = page.html
66+
67+
expected_static_output = <<~HTML
68+
<button disabled="disabled">You can not click me</button>
69+
<button>You can click me</button>
70+
<button>You can click me too</button>
71+
HTML
4572

4673
expect(stripped(static_output)).to include(stripped(expected_static_output))
4774
end

0 commit comments

Comments
 (0)