Skip to content

Commit 33c47eb

Browse files
committed
basic version switcher
1 parent eb71a9a commit 33c47eb

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

app/Livewire/VersionSwitcher.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace App\Livewire;
4+
5+
use Illuminate\View\ViewException;
6+
use Livewire\Component;
7+
8+
class VersionSwitcher extends Component
9+
{
10+
public string $platform;
11+
12+
public array $versions;
13+
14+
public int $version;
15+
16+
public string $page;
17+
18+
public function mount(array $versions)
19+
{
20+
throw_unless(
21+
request()->route()->named('docs.show'),
22+
ViewException::class,
23+
"The version switcher can only be used on the 'docs.show' route."
24+
);
25+
26+
$this->platform = request()->route()->parameter('platform');
27+
$this->version = request()->route()->parameter('version');
28+
$this->page = request()->route()->parameter('page');
29+
$this->versions = $versions;
30+
}
31+
32+
public function updatedVersion()
33+
{
34+
return redirect()->route('docs.show', [
35+
'platform' => $this->platform,
36+
'version' => $this->version,
37+
'page' => $this->page,
38+
]);
39+
}
40+
}

resources/views/docs/index.blade.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
</x-slot>
55

66
<x-slot name="sidebarRight">
7+
{{-- Version switcher --}}
8+
@if($platform === 'desktop')
9+
<livewire:version-switcher :versions="[
10+
1 => 'v1.x',
11+
2 => 'v2.x'
12+
]" />
13+
@endif
14+
715
<x-docs.toc-and-sponsors :tableOfContents="$tableOfContents" />
816
</x-slot>
917

@@ -15,6 +23,15 @@
1523

1624
{{-- Table of contents --}}
1725
<div class="xl:hidden pt-5">
26+
27+
{{-- Version switcher --}}
28+
@if($platform === 'desktop')
29+
<livewire:version-switcher :versions="[
30+
1 => 'v1.x',
31+
2 => 'v2.x'
32+
]" />
33+
@endif
34+
1835
{{-- Copy as Markdown Button --}}
1936
<x-docs.copy-markdown-button class="mt-4" />
2037

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<form wire:submit="switch">
2+
3+
<select wire:model.live="version" name="version">
4+
5+
@foreach($versions as $number => $label)
6+
<option value="{{ $number }}">{{ $label }}</option>
7+
@endforeach
8+
9+
</select>
10+
11+
</form>

0 commit comments

Comments
 (0)