Skip to content

Commit

Permalink
Add FormControl component
Browse files Browse the repository at this point in the history
  • Loading branch information
davidalejandroaguilar committed Sep 26, 2024
1 parent ebf78dc commit e218f7c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/phlexy_ui/form_control.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module PhlexyUI
class FormControl < Base
def initialize(*, as: :div, **)
super(*, **)
@as = as
end

def view_template(&)
generate_classes!(
component_html_class: "form-control",
options:
).then do |classes|
public_send(as, class: classes, **options, &)
end
end
end
end
33 changes: 33 additions & 0 deletions spec/lib/phlexy_ui/form_control_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require "spec_helper"

describe PhlexyUI::FormControl do
subject(:output) { render described_class.new }

describe "rendering a full form control" do
let(:component) do
Class.new(Phlex::HTML) do
def view_template(&)
render PhlexyUI::FormControl.new(as: :section) do
span { "Username" }
input(type: "text", placeholder: "Enter username")
end
end
end
end

subject(:output) do
render component.new
end

it "is expected to match the formatted HTML" do
expected_html = html <<~HTML
<section class="form-control">
<span>Username</span>
<input type="text" placeholder="Enter username">
</section>
HTML

is_expected.to eq(expected_html)
end
end
end

0 comments on commit e218f7c

Please sign in to comment.