Skip to content

Commit

Permalink
Merge pull request #284 from ontoportal-lirmm/feature/update-nested-f…
Browse files Browse the repository at this point in the history
…rom-input-component-design

Feature: Update nested form input component design
  • Loading branch information
syphax-bouazzouni authored Jul 12, 2023
2 parents bb1eaf6 + 4272999 commit 7e32ada
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 12 deletions.
3 changes: 3 additions & 0 deletions app/assets/images/icons/delete.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 app/assets/images/icons/plus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion app/assets/stylesheets/components/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
@import 'summary_section';
@import 'dropdown';
@import 'field_container';
@import 'nested_form';
@import 'input_field';
@import 'file_input_loader';
@import 'text_area_field';
@import 'text_area_field';

50 changes: 50 additions & 0 deletions app/assets/stylesheets/components/nested_form.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
.nested-form-input-container .titles{
display: flex;
font-size: 11px;
color: #666666;
margin-bottom: 5px;
width: 90%;
}


.nested-form-input-container input:focus{
border: 1px solid #31B404 !important;
}

.nested-form-input-container .delete{
display: flex;
border: 1px dashed #BDBDBD;
justify-content: center;
align-items: center;
height: 43px;
width: 43px;
border-radius: 5px;
cursor: pointer;
}

.nested-form-input-container .add-another-object{
border: 1px dashed #BDBDBD;
border-radius: 5px;
display: flex;
justify-content: center;
align-items: center;
padding: 10px;
cursor: pointer;
margin-top: 10px;
}
.nested-form-input-container svg path{
fill: #DADADA;
}
.nested-form-input-container .add-another-object div{
color: #DADADA;
margin-left: 10px;
}









6 changes: 6 additions & 0 deletions app/components/nested_form_inputs_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,11 @@
class NestedFormInputsComponent < ViewComponent::Base

renders_one :template
renders_one :header
renders_many :rows

def initialize(object_name: '')
super
@object_name = object_name
end
end
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
%div{data: {controller: "nested-form"}}
%div.nested-form-input-container{data: {controller: "nested-form"}}
%template{'data-nested-form-target':"template"}
%div.d-flex.align-items-center.nested-form-wrapper{'data-new-record': 'true'}
%div.d-flex.align-items-center.nested-form-wrapper.my-1{'data-new-record': 'true'}
%div{style: 'width: 90%'}
= template
%div.d-flex.justify-content-end{style: 'width: 10%'}
%button.btn.btn-danger{data: {action:"nested-form#remove"}}
%i.fas.fa-minus.fa-lg
%div.delete{data: {action:"click->nested-form#remove"}}
= inline_svg 'icons/delete.svg'
%div.titles
= header
- rows.each_with_index do |row , index|
%div.d-flex.align-items-center.nested-form-wrapper{'data-new-record': 'true'}
%div.d-flex.align-items-center.nested-form-wrapper.my-1{'data-new-record': 'true'}
%div{style: 'width: 90%'}
= row
%div.d-flex.justify-content-end{style: 'width: 10%'}
- unless index == 0
%button.btn.btn-danger{data: {action:"nested-form#remove"}}
%i.fas.fa-minus.fa-lg
%div.delete{data: {action:"click->nested-form#remove"}}
= inline_svg 'icons/delete.svg'

%div{'data-nested-form-target': "target"}
%div.float-right
%button.btn.btn-success{data: {action:"nested-form#add"}}
%i.fas.fa-plus.fa-lg
%div.add-another-object{data: {action:"click->nested-form#add"}}
= inline_svg 'icons/plus.svg'
%div
Add another #{@object_name}
18 changes: 18 additions & 0 deletions test/components/previews/nested_form_input_component_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class NestedFormInputComponentPreview < ViewComponent::Preview

include ActionView::Helpers::TagHelper
include ActionView::Helpers::FormTagHelper

# @param object_name text
def default(object_name: 'contact')
render NestedFormInputsComponent.new(object_name: object_name) do |c|
c.header do
content_tag(:div, 'Contact name', class: 'w-50 mx-1') + content_tag(:div, 'Contact email', class: 'w-50 mx-1')
end

c.template do
raw "<div class='d-flex'> <input class='form-control w-50 mx-1'/> <input class='form-control w-50 mx-1'/></div>".html_safe
end
end
end
end

0 comments on commit 7e32ada

Please sign in to comment.