diff --git a/lib/phlexy_ui/avatar_group.rb b/lib/phlexy_ui/avatar_group.rb new file mode 100644 index 0000000..1dcea6b --- /dev/null +++ b/lib/phlexy_ui/avatar_group.rb @@ -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 diff --git a/spec/lib/phlexy_ui/avatar_group_spec.rb b/spec/lib/phlexy_ui/avatar_group_spec.rb new file mode 100644 index 0000000..6d2861e --- /dev/null +++ b/spec/lib/phlexy_ui/avatar_group_spec.rb @@ -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 + +
JD
+
AB
+
+ HTML + + is_expected.to eq(expected_html) + end + end +end