Skip to content

Commit e15c49a

Browse files
committed
Details and Summary
Added Components / Docs / tests for Details and Summary html tags
1 parent 4dad570 commit e15c49a

File tree

6 files changed

+105
-5
lines changed

6 files changed

+105
-5
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
%details{@tag_attributes}
2+
- if block_given?
3+
= yield
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Matestack::Ui::Core::Details
2+
class Details < Matestack::Ui::Core::Component::Static
3+
end
4+
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
%summary{@tag_attributes}
2+
- if options[:text].blank?
3+
- if block_given?
4+
= yield
5+
- else
6+
= options[:text]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Matestack::Ui::Core::Summary
2+
class Summary < Matestack::Ui::Core::Component::Static
3+
end
4+
end

docs/components/details.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# matestack core component: Details
2+
3+
Show [specs](../../spec/usage/components/details_summary_spec.rb)
4+
5+
Use details to implement `<details>` and `<summary>` tags.
6+
7+
8+
## Parameters
9+
10+
`<details>` and `<summary>` can take two optional configuration params and optional content.
11+
12+
13+
### Optional configuration
14+
15+
#### id (optional)
16+
17+
Expects a string with all ids the details tag should have.
18+
19+
#### class (optional)
20+
21+
Expects a string with all classes the details tag should have.
22+
23+
24+
## Example 1
25+
26+
```ruby
27+
details id: 'foo', class: 'bar' do
28+
summary text: 'Greetings'
29+
plain "Hello World!" # optional content
30+
end
31+
```
32+
33+
```html
34+
<details id="foo" class="bar">
35+
<summary>Greetings</summary>
36+
Hello World!
37+
</details>
38+
```
39+
40+
## Example 2
41+
42+
```ruby
43+
details id: 'foo', class: 'bar' do
44+
summary id: 'baz', text: 'Greetings'
45+
pg text: 'Hello World!'
46+
end
47+
```
48+
49+
```html
50+
<details id="foo" class="bar">
51+
<summary id="baz">Greetings</summary>
52+
<p>Hello World!</p>
53+
</details>
54+
```
55+
56+
## Example 3 (Without Summary)
57+
58+
```ruby
59+
details id: 'foo' do
60+
plan "Hello World!"
61+
end
62+
```
63+
64+
```html
65+
<details id="foo">
66+
Hello World!
67+
</details>
68+
```

spec/usage/components/details_summary_spec.rb

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
describe 'Details Element with summary', type: :feature, js: true do
55
it 'Example 1' do
6-
class ExamplePage < Page::Cell::Page
6+
class ExamplePage < Matestack::Ui::Page
77
def response
88
components {
99
# basic
@@ -12,6 +12,11 @@ def response
1212
pg text: 'World!'
1313
end
1414

15+
# without summary
16+
17+
details id: 'foo' do
18+
plain "Hello World!"
19+
end
1520
# enhanced
1621
details id: 'detail_id', class: 'detail_class' do
1722
summary id: 'summary_id', class: 'summary_class', text: 'Hello'
@@ -25,10 +30,20 @@ def response
2530
static_output = page.html
2631

2732
expected_static_output = <<~HTML
28-
<details class="detail_class" id="detail_id">
29-
<summary id="summary_id" class="summary_class">Hello</summary>
30-
<p>World!</p>
31-
</details>
33+
34+
<details>
35+
<summary>Hello</summary>
36+
<p>World!</p>
37+
</details>
38+
39+
<details id="foo">
40+
Hello World!
41+
</details>
42+
43+
<details id="detail_id" class="detail_class">
44+
<summary id="summary_id" class="summary_class">Hello</summary>
45+
<p>World!</p>
46+
</details>
3247
HTML
3348

3449
expect(stripped(static_output)).to include(stripped(expected_static_output))

0 commit comments

Comments
 (0)