From 8b5421b0440c0ed555565058b263524140881849 Mon Sep 17 00:00:00 2001 From: mhenrixon Date: Sat, 8 Nov 2025 08:17:03 +0100 Subject: [PATCH] Add Filter component - Implements Filter component with DaisyUI styling - Adds comprehensive test coverage - Includes responsive class comments for Tailwind --- lib/phlexy_ui/filter.rb | 33 ++++++++++++++++++ spec/lib/phlexy_ui/filter_spec.rb | 57 +++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 lib/phlexy_ui/filter.rb create mode 100644 spec/lib/phlexy_ui/filter_spec.rb diff --git a/lib/phlexy_ui/filter.rb b/lib/phlexy_ui/filter.rb new file mode 100644 index 0000000..dfc67c0 --- /dev/null +++ b/lib/phlexy_ui/filter.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +module PhlexyUI + # @component html class="filter" + class Filter < Base + def initialize(*, as: :div, **) + super(*, **) + @as = as + end + + def view_template(&) + generate_classes!( + # "filter" + component_html_class: :filter, + modifiers_map: modifiers, + base_modifiers:, + options: + ).then do |classes| + public_send(as, class: classes, **options, &) + end + end + + def reset(**options, &) + generate_classes!( + # "filter-reset" + component_html_class: :"filter-reset", + options: + ).then do |classes| + input(type: :radio, class: classes, **options, &) + end + end + end +end diff --git a/spec/lib/phlexy_ui/filter_spec.rb b/spec/lib/phlexy_ui/filter_spec.rb new file mode 100644 index 0000000..3166790 --- /dev/null +++ b/spec/lib/phlexy_ui/filter_spec.rb @@ -0,0 +1,57 @@ +require "spec_helper" + +describe PhlexyUI::Filter 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 reset method" do + subject(:output) do + render described_class.new do |f| + f.reset(name: "filter") + end + end + + it "renders reset" do + expected_html = html <<~HTML +
+ +
+ HTML + + expect(output).to eq(expected_html) + 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 "passing :as option" do + subject(:output) { render described_class.new(as: :form) } + + it "renders as the given tag" do + expected_html = html <<~HTML +
+ HTML + + expect(output).to eq(expected_html) + end + end +end