File tree Expand file tree Collapse file tree 4 files changed +83
-46
lines changed
Expand file tree Collapse file tree 4 files changed +83
-46
lines changed Original file line number Diff line number Diff line change 1+ .tabs {
2+ & --headers {
3+ & -container {
4+ display : flex ;
5+ flex-direction : row ;
6+ justify-content : space-between ;
7+ }
8+
9+ & -wrapper {
10+ display : flex ;
11+ flex-direction : row ;
12+ }
13+ }
14+
15+ & --header {
16+ padding : 16px ;
17+ border-radius : 2px ;
18+ border-bottom : 1px solid lightgray ;
19+
20+ & :hover {
21+ cursor : pointer ;
22+ background-color : #DEF2F1 ;
23+ }
24+
25+ & -active {
26+ @extend .tabs--header ;
27+
28+ // text-decoration: underline;
29+ // text-decoration-color: #3AAFA9;
30+ border-bottom : 2px solid #3AAFA9 ;
31+ }
32+ }
33+ }
Original file line number Diff line number Diff line change 1+ import { Controller } from 'stimulus'
2+
3+ export default class extends Controller {
4+ static targets = [ 'tab' , 'panel' ] ;
5+
6+ change ( event ) {
7+ this . markTabAsActive ( event )
8+ this . displayPanel ( event )
9+ }
10+
11+ markTabAsActive ( ) {
12+ this . tabTargets . forEach ( tab => tab . classList . remove ( 'tabs--header-active' ) )
13+ event . currentTarget . classList . add ( 'tabs--header-active' )
14+ }
15+
16+ displayPanel ( ) {
17+ const index = this . tabTargets . indexOf ( event . currentTarget )
18+ const activePanel = this . panelTargets [ index ]
19+
20+ this . panelTargets . forEach ( tab => tab . classList . add ( 'hidden' ) )
21+ activePanel . classList . remove ( 'hidden' )
22+ }
23+ }
Original file line number Diff line number Diff line change @@ -40,39 +40,3 @@ export default {
4040 }
4141}
4242 </script >
43-
44- <style lang="scss" scoped>
45- .tabs {
46- & --headers {
47- & -container {
48- display : flex ;
49- flex-direction : row ;
50- justify-content : space-between ;
51- }
52-
53- & -wrapper {
54- display : flex ;
55- flex-direction : row ;
56- }
57- }
58-
59- & --header {
60- padding : 16px ;
61- border-radius : 2px ;
62- border-bottom : 1px solid lightgray ;
63-
64- & :hover {
65- cursor : pointer ;
66- background-color : #DEF2F1 ;
67- }
68-
69- & -active {
70- @extend .tabs--header ;
71-
72- // text-decoration: underline;
73- // text-decoration-color: #3AAFA9;
74- border-bottom : 2px solid #3AAFA9 ;
75- }
76- }
77- }
78- </style >
Original file line number Diff line number Diff line change 55 />
66</ card >
77
8- <%# <card> %>
9- < tabs >
10- < tab name ="<%= @user . snippets_count %> Snippets " selected ="true ">
8+ < div data-controller ="tabs ">
9+ < div class ="tabs--headers-container ">
10+ < div > </ div >
11+ < div class ="tabs--headers-wrapper ">
12+ < div data-target ="tabs.tab " data-action ="click->tabs#change " class ="tabs--header tabs--header-active ">
13+ < span > <%= @user . snippets . size %> Snippets</ span >
14+ </ div >
15+ < div data-target ="tabs.tab " data-action ="click->tabs#change " class ="tabs--header ">
16+ < span > <%= @followers . size %> Followers</ span >
17+ </ div >
18+ < div data-target ="tabs.tab " data-action ="click->tabs#change " class ="tabs--header ">
19+ < span > <%= @following . size %> Following</ span >
20+ </ div >
21+ </ div >
22+ </ div >
23+
24+ < div class ="tabs-details ">
25+ < div data-target ="tabs.panel ">
1126 <% @user . snippets . order ( created_at : :desc ) . each do |snippet | %>
1227 < snippet-preview
1328 :key ="<%= snippet . id %> "
1429 :snippet ="<%= snippet . serialize ( current_user ) . to_json %> ">
1530 </ snippet-preview >
1631 <% end %>
17- </ tab >
18- < tab name ="<%= @followers . size %> Followers ">
32+ </ div >
33+
34+ < div data-target ="tabs.panel " class ="hidden ">
1935 <% @followers . each_with_index do |follower , index | %>
2036 < card >
2137 < a href ="<%= user_path ( follower ) %> " class ="follow--container ">
2440 </ a >
2541 </ card >
2642 <% end %>
27- </ tab >
28- < tab name ="<%= @following . size %> Following ">
43+ </ div >
44+
45+ < div data-target ="tabs.panel " class ="hidden ">
2946 <% @following . each_with_index do |following_user , index | %>
3047 < card >
3148 < a href ="<%= user_path ( following_user ) %> " class ="follow--container ">
3451 </ a >
3552 </ card >
3653 <% end %>
37- </ tab >
38- </ tabs >
39- <%# </card> % >
54+ </ div >
55+ </ div >
56+ </ div >
You can’t perform that action at this time.
0 commit comments