diff --git a/lib/phlexy_ui/label.rb b/lib/phlexy_ui/label.rb new file mode 100644 index 0000000..99ee680 --- /dev/null +++ b/lib/phlexy_ui/label.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module PhlexyUI + class Label < Base + def view_template(&) + generate_classes!( + component_html_class: :label, + options: + ).then do |classes| + label(class: classes, **options, &) + end + end + + def text(as: :span, **options, &) + generate_classes!( + component_html_class: :"label-text", + options: + ).then do |classes| + public_send(as, class: classes, **options, &) + end + end + end +end diff --git a/spec/lib/phlexy_ui/label_spec.rb b/spec/lib/phlexy_ui/label_spec.rb new file mode 100644 index 0000000..beab71c --- /dev/null +++ b/spec/lib/phlexy_ui/label_spec.rb @@ -0,0 +1,33 @@ +require "spec_helper" + +describe PhlexyUI::Label do + subject(:output) { render described_class.new } + + describe "rendering a label" do + let(:component) do + Class.new(Phlex::HTML) do + def view_template(&) + render PhlexyUI::Label.new do |label| + label.text class: "foo", data: {my: :foos} do + "Username" + end + end + end + end + end + + subject(:output) do + render component.new + end + + it "is expected to match the formatted HTML" do + expected_html = html <<~HTML + + HTML + + is_expected.to eq(expected_html) + end + end +end