From e8a2761c63fe9054edcde34d5e0fa574d896bad3 Mon Sep 17 00:00:00 2001 From: mhenrixon Date: Sat, 8 Nov 2025 08:17:24 +0100 Subject: [PATCH 1/2] Add Join component - Implements Join component with DaisyUI styling - Adds comprehensive test coverage - Includes responsive class comments for Tailwind --- lib/phlexy_ui/join.rb | 50 +++++++++++++++++ spec/lib/phlexy_ui/join_spec.rb | 96 +++++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+) create mode 100644 lib/phlexy_ui/join.rb create mode 100644 spec/lib/phlexy_ui/join_spec.rb diff --git a/lib/phlexy_ui/join.rb b/lib/phlexy_ui/join.rb new file mode 100644 index 0000000..27f869c --- /dev/null +++ b/lib/phlexy_ui/join.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +module PhlexyUI + # @component html class="join" + class Join < Base + def initialize(*, as: :div, **) + super(*, **) + @as = as + end + + def view_template(&) + generate_classes!( + # "join" + component_html_class: :join, + modifiers_map: modifiers, + base_modifiers:, + options: + ).then do |classes| + public_send(as, class: classes, **options, &) + end + end + + def item(**options, &) + generate_classes!( + # "join-item" + component_html_class: :"join-item", + options: + ).then do |classes| + div(class: classes, **options, &) + end + end + + register_modifiers( + # "sm:join-vertical" + # "@sm:join-vertical" + # "md:join-vertical" + # "@md:join-vertical" + # "lg:join-vertical" + # "@lg:join-vertical" + vertical: "join-vertical", + # "sm:join-horizontal" + # "@sm:join-horizontal" + # "md:join-horizontal" + # "@md:join-horizontal" + # "lg:join-horizontal" + # "@lg:join-horizontal" + horizontal: "join-horizontal" + ) + end +end diff --git a/spec/lib/phlexy_ui/join_spec.rb b/spec/lib/phlexy_ui/join_spec.rb new file mode 100644 index 0000000..516c09b --- /dev/null +++ b/spec/lib/phlexy_ui/join_spec.rb @@ -0,0 +1,96 @@ +require "spec_helper" + +describe PhlexyUI::Join do + subject(:output) { render described_class.new } + + it "is expected to match the formatted HTML" do + expected_html = html <<~HTML +
+ HTML + + is_expected.to eq(expected_html) + end + + describe "with item method" do + subject(:output) do + render described_class.new do |j| + j.item { "Item 1" } + j.item { "Item 2" } + end + end + + it "renders items" do + expected_html = html <<~HTML +
+
Item 1
+
Item 2
+
+ HTML + + expect(output).to eq(expected_html) + end + end + + describe "conditions" do + { + vertical: "join-vertical", + horizontal: "join-horizontal" + }.each do |modifier, css| + context "when given :#{modifier} modifier" do + subject(:output) { render described_class.new(modifier) } + + it "renders it apart from the main class" do + expected_html = html <<~HTML +
+ HTML + + expect(output).to eq(expected_html) + end + end + end + end + + describe "data" do + subject(:output) do + render described_class.new(data: {foo: "bar"}) + end + + it "renders it correctly" do + expected_html = html <<~HTML +
+ HTML + + expect(output).to eq(expected_html) + end + end + + describe "responsiveness" do + %i[sm md lg xl @sm @md @lg @xl].each do |viewport| + context "when given an :#{viewport} responsive option" do + subject(:output) do + render described_class.new(:vertical, responsive: {viewport => :horizontal}) + end + + it "renders it separately with a responsive prefix" do + expected_html = html <<~HTML +
+ HTML + + expect(output).to eq(expected_html) + end + end + end + end + + describe "passing :as option" do + subject(:output) { render described_class.new(as: :section) } + + it "renders as the given tag" do + expected_html = html <<~HTML +
+ HTML + + expect(output).to eq(expected_html) + end + end +end From cd5619010f36c9167ff1867029770419f3b301bc Mon Sep 17 00:00:00 2001 From: David Alejandro <15317732+davidalejandroaguilar@users.noreply.github.com> Date: Wed, 12 Nov 2025 21:01:48 -0600 Subject: [PATCH 2/2] Remove unneeded @component comment --- lib/phlexy_ui/join.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/phlexy_ui/join.rb b/lib/phlexy_ui/join.rb index 27f869c..f1ec12d 100644 --- a/lib/phlexy_ui/join.rb +++ b/lib/phlexy_ui/join.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true module PhlexyUI - # @component html class="join" class Join < Base def initialize(*, as: :div, **) super(*, **)