-
-
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.
Reimplement text_field, selext, and text_area with the input component
- Loading branch information
Showing
19 changed files
with
94 additions
and
729 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
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
65 changes: 63 additions & 2 deletions
65
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 |
---|---|---|
@@ -1,11 +1,72 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::UI::Forms::Field::Component < SolidusAdmin::BaseComponent | ||
def initialize(label:, hint: nil, tip: nil, error: nil, **attributes) | ||
def initialize(label:, hint: nil, tip: nil, error: nil, input_attributes: nil, **attributes) | ||
@label = label | ||
@hint = hint | ||
@tip = tip | ||
@error = error | ||
@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 |
33 changes: 0 additions & 33 deletions
33
admin/app/components/solidus_admin/ui/forms/select/component.js
This file was deleted.
Oops, something went wrong.
71 changes: 0 additions & 71 deletions
71
admin/app/components/solidus_admin/ui/forms/select/component.rb
This file was deleted.
Oops, something went wrong.
52 changes: 0 additions & 52 deletions
52
admin/app/components/solidus_admin/ui/forms/text_area/component.rb
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.