Skip to content

Commit

Permalink
add pills version for the tabs component
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Jul 24, 2023
1 parent 2c08b69 commit 6858782
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 48 deletions.
1 change: 1 addition & 0 deletions app/assets/stylesheets/components/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
@import 'file_input_loader';
@import 'text_area_field';
@import 'tabs_container';
@import 'pill_tabs_container';

21 changes: 21 additions & 0 deletions app/assets/stylesheets/components/pill_tabs_container.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.pill-tabs-container {
display: flex;
}

.pill-tabs-container .tab-items{
margin-bottom: 10px;
}

.pill-tabs-container .nav-item {
display: block;
padding: 0.5rem 1rem;
}

.pill-tabs-container .nav-item.active {
border-radius: 5px;
background-color: var(--primary-color);
color: white !important;
a {
color: white !important;
}
}
87 changes: 49 additions & 38 deletions app/assets/stylesheets/components/tabs_container.scss
Original file line number Diff line number Diff line change
@@ -1,52 +1,63 @@
.tabs-container {
border-bottom: 1px solid #DFDFDF;
border-bottom: 1px solid #DFDFDF;
display: flex;

& > div {
display: flex;
justify-content: center;
& > div {
display: flex;
justify-content: space-between;
padding: 0 50px;
}
justify-content: space-between;
padding: 0 50px;
}
}

.tabs-container hr{
border: 1px solid #f3f3f3;
width: 100%;
margin: 0;
.tabs-container hr {
border: 1px solid #f3f3f3;
width: 100%;
margin: 0;
}
.tabs-container .tab-items{
display: flex;
margin: 0;

.tabs-container .tab-items {
display: flex;
margin: 0;
position: relative;

.tab-pinned-right {
position: absolute;
right: 40px;
}
}
.tabs-container .tab-items div{
font-size: 16px;
font-weight: 400;
color: #5e5e5e;
margin-right: 50px;
cursor: pointer;
opacity: 60%;
transition: opacity 0.3s ease;
a {
color: #5e5e5e !important;
}

.tabs-container .tab-items div {
font-size: 16px;
font-weight: 400;
color: #5e5e5e;
margin-right: 50px;
cursor: pointer;
opacity: 60%;
transition: opacity 0.3s ease;

a {
color: #5e5e5e !important;
}
}

.tabs-container .tab-items div:hover{
.tabs-container .tab-items div:hover {

opacity: 100%;
opacity: 100%;
}

.tabs-container .tab-items div hr{
display: none;
margin-top: 10px;
.tabs-container .tab-items div hr {
display: none;
margin-top: 10px;
}
.tabs-container .tab-items .active{
font-weight: 500;
color: black;
opacity: 100%;

.tabs-container .tab-items .active {
font-weight: 500;
color: black;
opacity: 100%;
}
.tabs-container .tab-items .active hr{
display: block;
border: 1px solid var(--primary-color);
opacity: 100%;

.tabs-container .tab-items .active hr {
display: block;
border: 1px solid var(--primary-color);
opacity: 100%;
}
16 changes: 12 additions & 4 deletions app/components/tab_item_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ class TabItemComponent < ViewComponent::Base

include ActionView::Helpers::UrlHelper

def initialize(title:, path:, page_name: '', selected: false)
def initialize(id: nil, title: nil, path: nil, page_name: '', selected: false)
super
@id = id
@title = title
@path = path
@page_name = page_name
Expand All @@ -29,18 +30,25 @@ def target
end

def id
@title
@title || @id
end

def title
@title.humanize
@title&.humanize
end

def active_class
selected_item? ? 'active show' : ''
end

def call
link_to(title, @path, id: "#{item_id}_tab")
if title && !title.empty?
link_to(title, @path, id: "#{item_id}_tab", class: "#{active_class} tab-link")
else
link_to(@path, id: "#{item_id}_tab", class: "#{active_class} tab-link") do
content
end
end
end

end
9 changes: 7 additions & 2 deletions app/components/tabs_container_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ class TabsContainerComponent < ViewComponent::Base

renders_many :items, TabItemComponent
renders_many :item_contents
renders_one :pinned_right

def initialize(url_parameter: nil)
def initialize(url_parameter: nil, pill: false)
super
@url_parameter = url_parameter
@pill = pill
end

def container_class
@pill ? 'pill-tabs-container' : 'tabs-container'
end

def tabs_container_data(item)
Expand All @@ -20,5 +26,4 @@ def tabs_container_data(item)
action: 'click->tabs-container#selectTab'
}
end

end
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
.tabs-container{data: {controller:'tabs-container'}}
.tab-items.nav-tabs.nav
%div{data: {controller:'tabs-container'}, class: container_class}
.tab-items.nav
- items.each do |item|
%div{data: tabs_container_data(item), class: item.active_class}
%div{data: tabs_container_data(item), class: item.active_class + ' nav-item'}
= item
%hr
- unless @pill
%hr

.tab-content
- item_contents.each_with_index do |item_content, index|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,22 @@ def default
end
end

def pill
render TabsContainerComponent.new(pill: true) do |c|
sections = ['section 1', 'section 2', 'section 3', 'section 4']

sections.each do |section_title|
c.item(title: section_title,
path: "#{section_title}path",
selected: section_title.eql?('section 2'),
page_name: "#{section_title}path")

c.item_content do
section_title
end
end

end
end

end

0 comments on commit 6858782

Please sign in to comment.