Skip to content

Commit f3076be

Browse files
Merge pull request #237 from marcoroth/develop
add kbd matestack core component
2 parents 7c31ffe + 19a9f88 commit f3076be

File tree

5 files changed

+85
-0
lines changed

5 files changed

+85
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
%kbd{@tag_attributes}
2+
- if options[:text].blank? && block_given?
3+
= yield
4+
- else
5+
= 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::Kbd
2+
class Kbd < Matestack::Ui::Core::Component::Static
3+
end
4+
end

docs/components/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ You can build your [own components](/docs/extend/custom_components.md) as well,
4040
- [noscript](/docs/components/noscript.md)
4141
- [sup](/docs/components/sup.md)
4242
- [sub](/docs/components/sub.md)
43+
- [kbd](/docs/components/kbd.md)
4344

4445
## Dynamic Core Components
4546

docs/components/kbd.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# matestack core component: kbd
2+
3+
Show [specs](/spec/usage/components/kbd_spec.rb)
4+
5+
The HTML kbd tag implemented in ruby.
6+
7+
## Parameters
8+
9+
This component can take 2 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 kbd should have.
13+
14+
#### # class (optional)
15+
Expects a string with all classes the kbd should have.
16+
17+
## Example 1: Yield a given block
18+
19+
```ruby
20+
kbd id: 'foo', class: 'bar' do
21+
plain 'Keyboard input' # optional content
22+
end
23+
```
24+
25+
returns
26+
27+
```html
28+
<kbd id="foo" class="bar">
29+
Keyboard input
30+
</kbd>
31+
```
32+
33+
## Example 2: Render `options[:text]` param
34+
35+
```ruby
36+
kbd id: 'foo', class: 'bar', text: 'Keyboard input'
37+
```
38+
39+
returns
40+
41+
```html
42+
<kbd id="foo" class="bar">
43+
Keyboard input
44+
</kbd>

spec/usage/components/kbd_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 'kbd Component', type: :feature, js: true do
5+
it 'Renders a simple and enhanced kbd tag on a page' do
6+
class ExamplePage < Matestack::Ui::Page
7+
def response
8+
components {
9+
# simple kbd
10+
kbd text: 'Simple Keyboard Input'
11+
12+
# enhanced kbd
13+
kbd id: 'my-id', class: 'my-class' do
14+
plain 'Enhanced Keyboard Input'
15+
end
16+
}
17+
end
18+
end
19+
20+
visit '/example'
21+
22+
static_output = page.html
23+
24+
expected_static_output = <<~HTML
25+
<kbd>Simple Keyboard Input</kbd>
26+
<kbd id="my-id" class="my-class">Enhanced Keyboard Input</kbd>
27+
HTML
28+
29+
expect(stripped(static_output)).to include(stripped(expected_static_output))
30+
end
31+
end

0 commit comments

Comments
 (0)