Skip to content

Commit 5c416d7

Browse files
committed
refactor: add alpine tabs component
1 parent 3097949 commit 5c416d7

File tree

4 files changed

+39
-55
lines changed

4 files changed

+39
-55
lines changed

resources/js/app.js

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import './components/alpine/dislikeButton';
4545
import './components/alpine/likeButton';
4646
import './components/alpine/livewireDialog';
4747
import './components/alpine/smallBookmarkButton';
48+
import './components/alpine/tabs';
4849
import './components/alpine/toggle';
4950
import './components/alpine/torrentGrouping';
5051

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
document.addEventListener('alpine:init', () => {
2+
Alpine.data('tabs', () => ({
3+
tab: null,
4+
init() {
5+
this.tab = this.$root.dataset.defaultTab;
6+
},
7+
tabButton: {
8+
['x-on:click']() {
9+
this.tab = this.$el.dataset.tab;
10+
},
11+
['x-bind:role']() {
12+
return 'tab';
13+
},
14+
['x-bind:class']() {
15+
return this.tab === this.$el.dataset.tab
16+
? 'panel__tab panel__tab--active'
17+
: 'panel__tab';
18+
},
19+
},
20+
tabPanel: {
21+
['x-show']() {
22+
return this.tab === this.$el.dataset.tab;
23+
},
24+
},
25+
}));
26+
});

resources/views/torrent/partials/buttons.blade.php

+5-19
Original file line numberDiff line numberDiff line change
@@ -187,26 +187,12 @@ class="form__button form__button--outlined form__button--centered"
187187
</div>
188188
</div>
189189
</header>
190-
<div x-bind="dialogForm" x-data="{ tab: 'hierarchy' }">
190+
<div x-bind="dialogForm" x-data="tabs" data-default-tab="hierarchy">
191191
<menu class="panel__tabs">
192-
<li
193-
class="panel__tab"
194-
role="tab"
195-
x-bind:class="tab === 'hierarchy' && 'panel__tab--active'"
196-
x-on:click="tab = 'hierarchy'"
197-
>
198-
Hierarchy
199-
</li>
200-
<li
201-
class="panel__tab"
202-
role="tab"
203-
x-bind:class="tab === 'list' && 'panel__tab--active'"
204-
x-on:click="tab = 'list'"
205-
>
206-
List
207-
</li>
192+
<li x-bind="tabButton" data-tab="hierarchy">Hierarchy</li>
193+
<li x-bind="tabButton" data-tab="list">List</li>
208194
</menu>
209-
<div class="dialog__form" x-show="tab === 'hierarchy'" style="gap: 0">
195+
<div class="dialog__form" x-bind="tabPanel" data-tab="hierarchy" style="gap: 0">
210196
@if ($torrent->folder !== null)
211197
<span
212198
style="
@@ -329,7 +315,7 @@ class="text-info"
329315
@endforeach
330316
@endforeach
331317
</div>
332-
<div class="data-table-wrapper" x-show="tab === 'list'">
318+
<div class="data-table-wrapper" x-bind="tabPanel" data-tab="list">
333319
<table class="data-table">
334320
<thead>
335321
<tr>
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,17 @@
1-
<section
2-
class="panelV2"
3-
x-data="{
4-
tab: window.location.hash ? window.location.hash.substring(1) : 'recommendations',
5-
}"
6-
id="tab_wrapper"
7-
>
8-
<!-- The tabs navigation -->
1+
<section class="panelV2" x-data="tabs" data-default-tab="recommendations" id="tab_wrapper">
92
<h2 class="panel__heading">Relations</h2>
103
<menu class="panel__tabs">
11-
<li
12-
class="panel__tab"
13-
role="tab"
14-
x-bind:class="tab === 'recommendations' && 'panel__tab--active'"
15-
x-on:click="tab = 'recommendations'; window.location.hash = 'recommendations'"
16-
>
17-
Recommendations
18-
</li>
19-
<li
20-
class="panel__tab"
21-
role="tab"
22-
x-bind:class="tab === 'collection' && 'panel__tab--active'"
23-
x-on:click="tab = 'collection'; window.location.hash = 'collection'"
24-
>
25-
Collection
26-
</li>
27-
<li
28-
class="panel__tab"
29-
role="tab"
30-
x-bind:class="tab === 'playlists' && 'panel__tab--active'"
31-
x-on:click="tab = 'playlists'; window.location.hash = 'playlists'"
32-
>
33-
Playlists
34-
</li>
4+
<li class="panel__tab" x-bind="tabButton" data-tab="recommendations">Recommendations</li>
5+
<li class="panel__tab" x-bind="tabButton" data-tab="collection">Collection</li>
6+
<li class="panel__tab" x-bind="tabButton" data-tab="playlists">Playlists</li>
357
</menu>
36-
<!-- The tabs content -->
37-
<div x-show="tab === 'recommendations'">
8+
<div x-bind="tabPanel" data-tab="recommendations">
389
@include('torrent.partials.recommendations')
3910
</div>
40-
<div x-show="tab === 'collection'" x-cloak>
11+
<div x-bind="tabPanel" data-tab="collection" x-cloak>
4112
@include('torrent.partials.collection')
4213
</div>
43-
<div x-show="tab === 'playlists'" x-cloak>
14+
<div x-bind="tabPanel" data-tab="playlists" x-cloak>
4415
@include('torrent.partials.playlists')
4516
</div>
4617
</section>

0 commit comments

Comments
 (0)