Skip to content

Commit 89e7d75

Browse files
Merge pull request #318 from basemate/add_dialog_component
Add dialog component, add missing line in core component generator
2 parents 585a9b4 + 547ee34 commit 89e7d75

File tree

6 files changed

+95
-0
lines changed

6 files changed

+95
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
%dialog{@tag_attributes}
2+
- if options[:text].blank? && block_given?
3+
= yield
4+
- else
5+
= options[:text]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Matestack::Ui::Core::Dialog
2+
class Dialog < Matestack::Ui::Core::Component::Static
3+
def setup
4+
@tag_attributes.merge!({
5+
"open": options[:open] ||= nil
6+
})
7+
end
8+
end
9+
end

docs/components/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ You can build your [own components](/docs/extend/README.md) as well, both static
2525
- [dl](/docs/components/dl.md)
2626
- dd
2727
- dt
28+
- [dialog](/docs/components/dialog.md)
2829
- [div](/docs/components/div.md)
2930
- [em](/docs/components/em.md)
3031
- [fieldset](/docs/components/fieldset.md)

docs/components/dialog.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# matestack core component: Dialog
2+
3+
Show [specs](/spec/usage/components/dialog_spec.rb)
4+
5+
The HTML `<dialog>` tag implemented in Ruby.
6+
7+
## Parameters
8+
9+
This component can take 3 optional configuration params and either yield content or display what gets passed to the `text` configuration param.
10+
11+
#### # id (optional)
12+
Expects a string with all ids the `<dialog>` should have.
13+
14+
#### # class (optional)
15+
Expects a string with all classes the `<dialog>` should have.
16+
17+
#### # open (optional)
18+
Expects a boolean. If set to true, the `<dialog>` will be visible.
19+
20+
## Example 1: Yield a given block
21+
22+
```ruby
23+
dialog id: 'foo', class: 'bar' do
24+
plain 'Dialog example 1' # optional content
25+
end
26+
```
27+
28+
returns
29+
30+
```html
31+
<dialog id="foo" class="bar">
32+
Dialog example 1
33+
</dialog>
34+
```
35+
36+
## Example 2: Render `options[:text]` param
37+
38+
```ruby
39+
dialog id: 'foo', class: 'bar', text: 'Dialog example 2', open: true
40+
```
41+
42+
returns
43+
44+
```html
45+
<dialog id="foo" class="bar" open="open">
46+
Dialog example 2
47+
</dialog>
48+
```

lib/generators/matestack/core/component/templates/docs/components/%file_name%.md.tt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ returns
4242
<<%= file_name.underscore %> id="foo" class="bar">
4343
<%= file_name.camelcase %> example 2
4444
</<%= file_name.underscore %>>
45+
```

spec/usage/components/dialog_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
require_relative '../../support/utils'
2+
include Utils
3+
4+
describe 'Dialog component', type: :feature, js: true do
5+
it 'Renders a simple and enhanced dialog tag on a page' do
6+
class ExamplePage < Matestack::Ui::Page
7+
def response
8+
components {
9+
# Simple dialog
10+
dialog text: 'Simple dialog tag'
11+
12+
# Enhanced dialog
13+
dialog id: 'my-id', class: 'my-class', open: true do
14+
plain 'Enhanced dialog tag'
15+
end
16+
}
17+
end
18+
end
19+
20+
visit '/example'
21+
22+
static_output = page.html
23+
24+
expected_static_output = <<~HTML
25+
<dialog>Simple dialog tag</dialog>
26+
<dialog id="my-id" open="open" class="my-class">Enhanced dialog tag</dialog>
27+
HTML
28+
29+
expect(stripped(static_output)).to include(stripped(expected_static_output))
30+
end
31+
end

0 commit comments

Comments
 (0)