Skip to content

Commit

Permalink
Add wrapper_class option to Ui::Field::Text* components (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobmaerten authored Mar 22, 2024
1 parent 1696905 commit e380f12
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/components/ui/field/text_area_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div>
<div class=<%= wrapper_classes %>>
<% if label %>
<label class="label">
<%= form_builder.label label, class: "label-text" %>
Expand Down
18 changes: 12 additions & 6 deletions app/components/ui/field/text_area_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ class Ui::Field::TextAreaComponent < ApplicationComponent
renders_one :top_right_label

param :name, optional: true
option :form_builder, type: Dry::Types["nominal.any"], optional: true
option :label, type: Dry::Types["strict.false"] | Dry::Types["coercible.string"], optional: true
option :error, type: Dry::Types["coercible.string"], optional: true
option :hint, type: Dry::Types["coercible.string"], optional: true
option :value, type: Dry::Types["coercible.string"], optional: true
option :form_builder, type: Dry::Types['nominal.any'], optional: true
option :label, type: Dry::Types['strict.false'] | Dry::Types['coercible.string'], optional: true
option :error, type: Dry::Types['coercible.string'], optional: true
option :hint, type: Dry::Types['coercible.string'], optional: true
option :value, type: Dry::Types['coercible.string'], optional: true
option :class, type: Dry::Types['coercible.string'], optional: true
option :wrapper_class, type: Dry::Types['coercible.string'], optional: true

private

Expand All @@ -20,7 +22,11 @@ def value

def field_classes
classes = attributes.delete(:class)
[class_names("textarea textarea-bordered w-full", "input-error": errors), classes].compact.join(" ")
[class_names('textarea textarea-bordered w-full', "input-error": errors), classes].compact.join(' ')
end

def wrapper_classes
attributes.delete(:wrapper_class)
end

def errors
Expand Down
2 changes: 1 addition & 1 deletion app/components/ui/field/text_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div>
<div class=<%= wrapper_classes %>>
<% if label %>
<label class="label">
<%= form_builder.label label, class: "label-text" %>
Expand Down
18 changes: 12 additions & 6 deletions app/components/ui/field/text_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ class Ui::Field::TextComponent < ApplicationComponent
renders_one :top_right_label

param :name, optional: true
option :form_builder, type: Dry::Types["nominal.any"], optional: true
option :label, type: Dry::Types["strict.false"] | Dry::Types["coercible.string"], optional: true
option :error, type: Dry::Types["coercible.string"], optional: true
option :hint, type: Dry::Types["coercible.string"], optional: true
option :value, type: Dry::Types["coercible.string"], optional: true
option :form_builder, type: Dry::Types['nominal.any'], optional: true
option :label, type: Dry::Types['strict.false'] | Dry::Types['coercible.string'], optional: true
option :error, type: Dry::Types['coercible.string'], optional: true
option :hint, type: Dry::Types['coercible.string'], optional: true
option :value, type: Dry::Types['coercible.string'], optional: true
option :class, type: Dry::Types['coercible.string'], optional: true
option :wrapper_class, type: Dry::Types['coercible.string'], optional: true

private

Expand All @@ -20,7 +22,11 @@ def value

def field_classes
classes = attributes.delete(:class)
[class_names("input input-bordered w-full", "input-error": errors), classes].compact.join(" ")
[class_names('input input-bordered w-full', "input-error": errors), classes].compact.join(' ')
end

def wrapper_classes
attributes.delete(:wrapper_class)
end

def errors
Expand Down

0 comments on commit e380f12

Please sign in to comment.