-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ebf78dc
commit e218f7c
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |