-
Notifications
You must be signed in to change notification settings - Fork 4
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
1 parent
faf7a2f
commit bf5d808
Showing
2 changed files
with
58 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module PhlexyUI | ||
class AvatarGroup < Base | ||
def initialize(*, as: :div, **) | ||
super(*, **) | ||
@as = as | ||
end | ||
|
||
def view_template(&) | ||
generate_classes!( | ||
component_html_class: :"avatar-group", | ||
options: | ||
).then do |classes| | ||
public_send(as, class: classes, **options, &) | ||
end | ||
end | ||
|
||
def avatar(*, **, &) | ||
render PhlexyUI::Avatar.new(*, **, &) | ||
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require "spec_helper" | ||
|
||
describe PhlexyUI::AvatarGroup do | ||
subject(:output) { render described_class.new } | ||
|
||
describe "rendering a full avatar group" do | ||
let(:component) do | ||
Class.new(Phlex::HTML) do | ||
def view_template(&) | ||
render PhlexyUI::AvatarGroup.new as: :span do |avatar_group| | ||
avatar_group.avatar :online do | ||
"JD" | ||
end | ||
avatar_group.avatar { "AB" } | ||
end | ||
end | ||
end | ||
end | ||
|
||
subject(:output) do | ||
render component.new | ||
end | ||
|
||
it "is expected to match the formatted HTML" do | ||
expected_html = html <<~HTML | ||
<span class="avatar-group"> | ||
<div class="avatar online">JD</div> | ||
<div class="avatar">AB</div> | ||
</span> | ||
HTML | ||
|
||
is_expected.to eq(expected_html) | ||
end | ||
end | ||
end |