forked from ontoportal/ontoportal_web_ui
-
Notifications
You must be signed in to change notification settings - Fork 5
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 #319 from ontoportal-lirmm/feature/extract-form-in…
…put-components Feature: Extract form input components
- Loading branch information
Showing
25 changed files
with
191 additions
and
93 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
class ChipsComponent < ViewComponent::Base | ||
def initialize(name:, value:) | ||
def initialize(id: '', name:, value:, checked: false) | ||
@id = id || name | ||
@name = name | ||
@value = value | ||
@checked = checked | ||
end | ||
|
||
def checked? | ||
@checked | ||
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
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,7 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class Input::DateComponent < InputFieldComponent | ||
class Input::DateComponent < Input::InputFieldComponent | ||
def initialize(label: '', name:, value: Date.today, placeholder: '', error_message: '', helper_text: '') | ||
super(label: label, name: name, value: value, placeholder: placeholder, error_message: error_message, helper_text: helper_text) | ||
end | ||
|
||
def call | ||
render Input::InputFieldComponent.new(label: @label, name: @name, value: @value, placeholder: @placeholder, error_message: @error_message, helper_text: @helper_text, type: 'date') | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class Input::EmailComponent < Input::InputFieldComponent | ||
def initialize(label: '', name:, value: nil, placeholder: '', error_message: '', helper_text: '') | ||
super(label: label, name: name, value: value, placeholder: placeholder, error_message: error_message, helper_text: helper_text) | ||
end | ||
|
||
def call | ||
render Input::InputFieldComponent.new(label: @label, name: @name, value: @value, placeholder: @placeholder, error_message: @error_message, helper_text: @helper_text, type: "email") | ||
end | ||
end |
2 changes: 1 addition & 1 deletion
2
app/components/input_field_component.rb → ...components/input/input_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
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 |
---|---|---|
|
@@ -20,9 +20,9 @@ | |
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
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,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class Input::PasswordComponent < Input::InputFieldComponent | ||
def initialize(label: '', name:, value: nil, placeholder: '', error_message: '', helper_text: '') | ||
super(label: label, name: name, value: value, placeholder: placeholder, error_message: error_message, helper_text: helper_text) | ||
end | ||
|
||
def call | ||
render Input::InputFieldComponent.new(label: @label, name: @name, value: @value, placeholder: @placeholder, error_message: @error_message, helper_text: @helper_text, type: "password") | ||
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
2 changes: 1 addition & 1 deletion
2
app/components/input/select_component/select_component.html.haml
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,2 +1,2 @@ | ||
= render InputFieldComponent.new(name: @name, error_message: @error_message, helper_text: @helper_text) do | ||
= render Input::InputFieldComponent.new(name: @name, error_message: @error_message, helper_text: @helper_text, label: @label) do | ||
= render SelectInputComponent.new(id: @id, name: @name, values: @values , selected: @selected , multiple: @multiple, open_to_add_values: @open_to_add_values ) |
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
5 changes: 3 additions & 2 deletions
5
app/components/input/text_area_component/text_area_component.html.haml
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,2 +1,3 @@ | ||
= render InputFieldComponent.new(label: @label, name: @name, value: @value, placeholder: @placeholder, error_message: @error_message, helper_text: @helper_text) do | ||
%textarea.input-field-component{name: @name, rows: @rows, placeholder: @placeholder, style: error_style, value: @value} | ||
= render Input::InputFieldComponent.new(label: @label, name: @name, value: @value, placeholder: @placeholder, error_message: @error_message, helper_text: @helper_text) do | ||
%textarea.input-field-component{name: @name, rows: @rows, placeholder: @placeholder, style: error_style} | ||
= @value |
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,7 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class Input::TextInputComponent < InputFieldComponent | ||
class Input::TextInputComponent < Input::InputFieldComponent | ||
def initialize(label: '', name:, value: nil, placeholder: '', error_message: '', helper_text: '') | ||
super(label: label, name: name, value: value, placeholder: placeholder, error_message: error_message, helper_text: helper_text) | ||
end | ||
|
||
def call | ||
render Input::InputFieldComponent.new(label: @label, name: @name, value: @value, placeholder: @placeholder, error_message: @error_message, helper_text: @helper_text, type: @type) | ||
end | ||
end |
1 change: 0 additions & 1 deletion
1
app/components/input/text_input_component/text_input_component.html.haml
This file was deleted.
Oops, something went wrong.
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,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class Input::UrlComponent < Input::InputFieldComponent | ||
def initialize(label: '', name:, value: nil, placeholder: '', error_message: '', helper_text: '') | ||
super(label: label, name: name, value: value, placeholder: placeholder, error_message: error_message, helper_text: helper_text) | ||
end | ||
|
||
def call | ||
render Input::InputFieldComponent.new(label: @label, name: @name, value: @value, placeholder: @placeholder, error_message: @error_message, helper_text: @helper_text, type: "url") | ||
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
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
5 changes: 0 additions & 5 deletions
5
app/components/select_input_component/select_input_component.html.haml
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
test/components/previews/input/file_input_component_preview.rb
This file was deleted.
Oops, something went wrong.
90 changes: 90 additions & 0 deletions
90
test/components/previews/input/input_field_component_preview.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,90 @@ | ||
# frozen_string_literal: true | ||
|
||
class Input::InputFieldComponentPreview < ViewComponent::Preview | ||
|
||
# This is a date input field: | ||
# - To use it without a label: don't give a value to the param label or leave it empty. | ||
# - To put it in error state: define the param error_message with the error message you want to be displayed. | ||
# - To give it a helper text (a text displayed under the input field): define the param helper_text with the helper text you want to be displayed. | ||
# @param label text | ||
# @param error_message text | ||
# @param helper_text text | ||
|
||
def date(label: "Label", placeholder: "", error_message: "", helper_text: "") | ||
render Input::DateComponent.new(label: label, name: "name", placeholder: placeholder, error_message: error_message, helper_text: helper_text) | ||
end | ||
|
||
|
||
# This is a url input field: | ||
# - To use it without a label: don't give a value to the param label or leave it empty. | ||
# - To put it in error state: define the param error_message with the error message you want to be displayed. | ||
# - To give it a helper text (a text displayed under the input field): define the param helper_text with the helper text you want to be displayed. | ||
# @param label text | ||
# @param error_message text | ||
# @param helper_text text | ||
|
||
def email(label: "Label", placeholder: "", error_message: "", helper_text: "") | ||
render Input::EmailComponent.new(label: label, name: "name", placeholder: placeholder, error_message: error_message, helper_text: helper_text) | ||
end | ||
|
||
|
||
def file | ||
render Input::FileInputComponent.new(name: "file") | ||
end | ||
|
||
|
||
# This is a url input field: | ||
# - To use it without a label: don't give a value to the param label or leave it empty. | ||
# - To put it in error state: define the param error_message with the error message you want to be displayed. | ||
# - To give it a helper text (a text displayed under the input field): define the param helper_text with the helper text you want to be displayed. | ||
# @param label text | ||
# @param error_message text | ||
# @param helper_text text | ||
|
||
def password(label: "Label", placeholder: "", error_message: "", helper_text: "") | ||
render Input::PasswordComponent.new(label: label, name: "name", placeholder: placeholder, error_message: error_message, helper_text: helper_text) | ||
end | ||
|
||
|
||
# This is a url input field: | ||
# - To use it without a label: don't give a value to the param label or leave it empty. | ||
# - To put it in error state: define the param error_message with the error message you want to be displayed. | ||
# - To give it a helper text (a text displayed under the input field): define the param helper_text with the helper text you want to be displayed. | ||
# @param label text | ||
# @param error_message text | ||
# @param helper_text text | ||
|
||
def url(label: "Label", placeholder: "", error_message: "", helper_text: "") | ||
render Input::UrlComponent.new(label: label, name: "name", placeholder: placeholder, error_message: error_message, helper_text: helper_text) | ||
end | ||
|
||
# This is a text input field: | ||
# - To use it without a label: don't give a value to the param label or leave it empty. | ||
# - To give it a hint (placeholder): define the param hint with the hind you want to be displayed. | ||
# - To put it in error state: define the param error_message with the error message you want to be displayed. | ||
# - To give it a helper text (a text displayed under the input field): define the param helper_text with the helper text you want to be displayed. | ||
# @param label text | ||
# @param placeholder text | ||
# @param error_message text | ||
# @param helper_text text | ||
|
||
def text(label: "Label", placeholder: "", error_message: "", helper_text: "") | ||
render Input::TextInputComponent.new(label: label, name: "name", placeholder: placeholder, error_message: error_message, helper_text: helper_text) | ||
end | ||
|
||
# This is a textarea field: | ||
# - To use it without a label: don't give a value to the param label or leave it empty. | ||
# - To give it a hint (placeholder): define the param hint with the hind you want to be displayed. | ||
# - To put it in error state: define the param error_message with the error message you want to be displayed. | ||
# - To give it a helper text (a text displayed under the input field): define the param helper_text with the helper text you want to be displayed. | ||
|
||
# @param label text | ||
# @param placeholder text | ||
# @param error_message text | ||
# @param helper_text text | ||
# @param rows number | ||
|
||
def text_area(label: "Label", placeholder: "", error_message: "", helper_text: "", rows: 5) | ||
render Input::TextAreaComponent.new(label: label, name: "name",value: '', placeholder: placeholder, error_message: error_message, helper_text: helper_text, rows: rows) | ||
end | ||
end |
19 changes: 0 additions & 19 deletions
19
test/components/previews/input/text_area_component_preview.rb
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
test/components/previews/input/text_input_component_preview.rb
This file was deleted.
Oops, something went wrong.