-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5385 from solidusio/elia/admin/form-components-cl…
…eanup [admin] Streamline form inputs
- Loading branch information
Showing
51 changed files
with
428 additions
and
1,776 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
admin/app/assets/images/solidus_admin/arrow_down_s_fill_gray_700.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
admin/app/assets/images/solidus_admin/arrow_down_s_fill_red_400.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
28 changes: 28 additions & 0 deletions
28
admin/app/components/solidus_admin/ui/forms/field/component.html.erb
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,28 @@ | ||
<label class="flex flex-col gap-2 w-full"> | ||
<div class="flex gap-1 items-center"> | ||
<span class=" | ||
text-gray-700 | ||
body-tiny-bold | ||
body-text-xs-semibold | ||
"><%= @label %></span> | ||
|
||
<%= render component('ui/toggletip').new(text: @tip) if @tip.present? %> | ||
</div> | ||
|
||
<% if @input_attributes.present? %> | ||
<%= render component('ui/forms/input').new(**@input_attributes) %> | ||
<% else %> | ||
<%= content %> | ||
<% end %> | ||
|
||
<% if @hint.present? || @error.present? %> | ||
<div class=" | ||
body-tiny | ||
[:disabled~&]:text-gray-300 text-gray-500 | ||
flex gap-1 flex-col | ||
"> | ||
<%= tag.span @hint if @hint.present? %> | ||
<%= tag.span safe_join(@error, tag.br), class: "text-red-400" if @error.present? %> | ||
</div> | ||
<% end %> | ||
</label> |
72 changes: 72 additions & 0 deletions
72
admin/app/components/solidus_admin/ui/forms/field/component.rb
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,72 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::UI::Forms::Field::Component < SolidusAdmin::BaseComponent | ||
def initialize(label:, hint: nil, tip: nil, error: nil, input_attributes: nil, **attributes) | ||
@label = label | ||
@hint = hint | ||
@tip = tip | ||
@error = [error] if error.present? | ||
@attributes = attributes | ||
@input_attributes = input_attributes | ||
|
||
raise ArgumentError, "provide either a block or input_attributes" if content? && input_attributes | ||
end | ||
|
||
def self.text_field(form, method, hint: nil, tip: nil, size: :m, **attributes) | ||
errors = form.object.errors.messages_for(method).presence | ||
|
||
new( | ||
label: form.object.class.human_attribute_name(method), | ||
hint: hint, | ||
tip: tip, | ||
error: errors, | ||
input_attributes: { | ||
name: "#{form.object_name}[#{method}]", | ||
tag: :input, | ||
size: size, | ||
value: form.object.public_send(method), | ||
error: (errors.to_sentence.capitalize if errors), | ||
**attributes, | ||
} | ||
) | ||
end | ||
|
||
def self.select(form, method, choices, hint: nil, tip: nil, size: :m, **attributes) | ||
errors = form.object.errors.messages_for(method).presence | ||
|
||
new( | ||
label: form.object.class.human_attribute_name(method), | ||
hint: hint, | ||
tip: tip, | ||
error: errors, | ||
input_attributes: { | ||
name: "#{form.object_name}[#{method}]", | ||
tag: :select, | ||
choices: choices, | ||
size: size, | ||
value: form.object.public_send(method), | ||
error: (errors.to_sentence.capitalize if errors), | ||
**attributes, | ||
} | ||
) | ||
end | ||
|
||
def self.text_area(form, method, hint: nil, tip: nil, size: :m, **attributes) | ||
errors = form.object.errors.messages_for(method).presence | ||
|
||
new( | ||
label: form.object.class.human_attribute_name(method), | ||
hint: hint, | ||
tip: tip, | ||
error: errors, | ||
input_attributes: { | ||
name: "#{form.object_name}[#{method}]", | ||
size: size, | ||
tag: :textarea, | ||
value: form.object.public_send(method), | ||
error: (errors.to_sentence.capitalize if errors), | ||
**attributes, | ||
} | ||
) | ||
end | ||
end |
4 changes: 0 additions & 4 deletions
4
admin/app/components/solidus_admin/ui/forms/fieldset/component.erb
This file was deleted.
Oops, something went wrong.
64 changes: 0 additions & 64 deletions
64
admin/app/components/solidus_admin/ui/forms/fieldset/component.rb
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
admin/app/components/solidus_admin/ui/forms/form/component.erb
This file was deleted.
Oops, something went wrong.
44 changes: 0 additions & 44 deletions
44
admin/app/components/solidus_admin/ui/forms/form/component.rb
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.