-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
102 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
module Bulmacomp | ||
# Make an HTML [turbo Frame](https://turbo.hotwired.dev/handbook/frames) structure. | ||
# | ||
# @example empty turbo frame, on default when the compoent is have't yield content, is added a lod icon | ||
# = render Layout::TurboFrameComponent.new | ||
# | ||
# <turbo-frame> | ||
# <span class="icon"><i class="fas fa-sync fa-spin fa-2x"></i></span> | ||
# </turbo-frame> | ||
# | ||
# @example with id and src (to load remote content) | ||
# = render Layout::TurboFrameComponent.new(id: 'nav1', src: books_path ) | ||
# | ||
# <turbo-frame id='nav1' src='/books'> | ||
# <span class="icon"><i class="fas fa-sync fa-spin fa-2x"></i></span> | ||
# </turbo-frame> | ||
# | ||
# @example with no icon | ||
# = render Layout::TurboFrameComponent.new(icon: nil, id: 'nav1', src: books_path ) | ||
# | ||
# <turbo-frame id='nav1' src='/books'></turbo-frame> | ||
# | ||
# @example with yield content | ||
# = render Layout::TurboFrameComponent.new do | ||
# some text | ||
# | ||
# <turbo-frame>some text</turbo-frame> | ||
class TurboFrameComponent < ViewComponent::Base | ||
# @param [Hash] opts | ||
# options to generate content | ||
# @param [String] icon | ||
# text to add whe yield content is empty | ||
# default: [default_icon] | ||
# @option opts [String] :* | ||
# each other key going as tag option | ||
# @yield [optional] turbo frame content | ||
def initialize(icon: default_icon, **opts) | ||
super | ||
@icon = icon | ||
@opts = opts | ||
end | ||
|
||
# @return [String] html turbo frame | ||
def call | ||
content_tag('turbo-frame', (content || @icon), **@opts) | ||
end | ||
|
||
# default value for icon | ||
def default_icon | ||
tag.span tag.i(class: 'fas fa-sync fa-spin fa-2x'), class: 'icon' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module Bulmacomp | ||
VERSION = '1.0.1' # Costant of bulmacomp version | ||
VERSION = '1.0.2' # Costant of bulmacomp version | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
module Bulmacomp | ||
class TurboFrameComponentTest < ViewComponent::TestCase | ||
# empty turbo frame | ||
test 'empty' do | ||
render_inline Bulmacomp::TurboFrameComponent.new | ||
assert_selector 'turbo-frame', text: nil | ||
assert_selector 'turbo-frame span.icon i.fas.fa-sync.fa-spin.fa-2x', text: nil | ||
end | ||
|
||
# turbo frame with id and src | ||
test 'with id and src' do | ||
render_inline Bulmacomp::TurboFrameComponent.new(id: 'nav1', src: '/books') | ||
assert_selector 'turbo-frame#nav1[src="/books"]', text: nil | ||
assert_selector 'turbo-frame span.icon i.fas.fa-sync.fa-spin.fa-2x', text: nil | ||
end | ||
|
||
# turbo frame without icon | ||
test 'no icon' do | ||
render_inline Bulmacomp::TurboFrameComponent.new(icon: nil) | ||
assert_selector 'turbo-frame:empty', text: nil | ||
end | ||
|
||
# turbo frame with yield content | ||
test 'with content' do | ||
render_inline Bulmacomp::TurboFrameComponent.new.with_content('some text') | ||
assert_selector 'turbo-frame', text: 'some text' | ||
assert_selector 'turbo-frame:not(:has(> *))' | ||
end | ||
end | ||
end |