-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Lukas Frey <mail@lukasfrey.cz>
- Loading branch information
1 parent
4c11168
commit 04a12a5
Showing
11 changed files
with
288 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export default function modalsComponent() { | ||
return { | ||
|
||
init: async function () { | ||
this.hashChanged(); | ||
window.addEventListener('hashchange', ()=>this.hashChanged()); | ||
}, | ||
|
||
hashChanged: function() { | ||
const fragment = location.hash.substring(1); | ||
const prefix = 'modal-'; | ||
|
||
if (fragment.startsWith(prefix)) { | ||
const modal = fragment.substring(fragment.indexOf(prefix) + prefix.length); | ||
|
||
console.log('Open modal via wire: ', modal); | ||
this.$wire.showDocumentation(modal); | ||
// window.dispatchEvent(new CustomEvent('open-modal', {detail: {id: modal}})); | ||
history.replaceState(null, null, ' '); | ||
} | ||
}, | ||
|
||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
@php | ||
use Filament\Facades\Filament; | ||
$hasModalPreviews = Filament::getPlugin('guava::filament-knowledge-base')->hasModalPreviews(); | ||
$hasSlideOverPreviews = Filament::getPlugin('guava::filament-knowledge-base')->hasSlideOverPreviews(); | ||
$hasModalTitleBreadcrumbs = Filament::getPlugin('guava::filament-knowledge-base')->hasModalTitleBreadcrumbs(); | ||
$target = Filament::getPlugin('guava::filament-knowledge-base')->shouldOpenDocumentationInNewTab() ? '_blank' : '_self'; | ||
$articleClass = \Guava\FilamentKnowledgeBase\Facades\KnowledgeBase::panel()->getArticleClass(); | ||
@endphp | ||
|
||
<div | ||
x-ignore | ||
ax-load | ||
ax-load-src="{{ \Filament\Support\Facades\FilamentAsset::getAlpineComponentSrc('modals-component', 'guava/filament-knowledge-base') }}" | ||
x-data="modalsComponent()" | ||
> | ||
@if($documentable) | ||
<x-filament::modal id="kb-custom-modal" | ||
:close-by-clicking-away="true" | ||
:close-button="true" | ||
width="2xl" | ||
:slide-over="$hasSlideOverPreviews" | ||
class="[&_.fi-modal-content]:px-12 [&_.fi-modal-content]:gap-y-0" | ||
:footer-actions-alignment="\Filament\Support\Enums\Alignment::End" | ||
:sticky-footer="true" | ||
:sticky-header="true"> | ||
|
||
<x-slot name="heading"> | ||
@if($hasModalTitleBreadcrumbs && !empty($documentable->getBreadcrumbs())) | ||
{{ KnowledgeBase::breadcrumbs($documentable) }} | ||
@else | ||
{{ $documentable->getTitle() }} | ||
@endif | ||
</x-slot> | ||
|
||
<x-filament-knowledge-base::content @class([ | ||
"gu-kb-article-modal", | ||
$articleClass => ! empty($articleClass), | ||
])> | ||
{!! $documentable->getSimpleHtml() !!} | ||
</x-filament-knowledge-base::content> | ||
<x-slot name="footerActions"> | ||
<x-filament::button tag="a" | ||
:href="$documentable->getUrl()" | ||
:target="$target"> | ||
{{ __('filament-knowledge-base::translations.open-documentation') }} | ||
</x-filament::button> | ||
<x-filament::button color="gray" | ||
x-on:click.prevent="$dispatch('close-modal', { id: 'kb-custom-modal' })"> | ||
|
||
{{ __('filament-knowledge-base::translations.close') }} | ||
</x-filament::button> | ||
</x-slot> | ||
</x-filament::modal> | ||
@endif | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
@php | ||
use Filament\Facades\Filament; | ||
$hasModalPreviews = Filament::getPlugin('guava::filament-knowledge-base')->hasModalPreviews(); | ||
$hasSlideOverPreviews = Filament::getPlugin('guava::filament-knowledge-base')->hasSlideOverPreviews(); | ||
$hasModalTitleBreadcrumbs = Filament::getPlugin('guava::filament-knowledge-base')->hasModalTitleBreadcrumbs(); | ||
$target = Filament::getPlugin('guava::filament-knowledge-base')->shouldOpenDocumentationInNewTab() ? '_blank' : '_self'; | ||
$articleClass = \Guava\FilamentKnowledgeBase\Facades\KnowledgeBase::panel()->getArticleClass(); | ||
@endphp | ||
|
||
<div | ||
x-ignore | ||
ax-load | ||
ax-load-src="{{ \Filament\Support\Facades\FilamentAsset::getAlpineComponentSrc('modals-component', 'guava/filament-knowledge-base') }}" | ||
x-data="modalsComponent()" | ||
> | ||
<x-filament::modal id="kb-custom-modal" | ||
:close-by-clicking-away="true" | ||
:close-button="true" | ||
width="2xl" | ||
:slide-over="$hasSlideOverPreviews" | ||
class="[&_.fi-modal-content]:px-12 [&_.fi-modal-content]:gap-y-0" | ||
:footer-actions-alignment="\Filament\Support\Enums\Alignment::End" | ||
:sticky-footer="true" | ||
:sticky-header="true"> | ||
|
||
<x-slot name="heading"> | ||
@if($hasModalTitleBreadcrumbs && !empty($documentable->getBreadcrumbs())) | ||
{{ KnowledgeBase::breadcrumbs($documentable) }} | ||
@else | ||
{{ $documentable->getTitle() }} | ||
@endif | ||
</x-slot> | ||
|
||
<x-filament-knowledge-base::content @class([ | ||
"gu-kb-article-modal", | ||
$articleClass => ! empty($articleClass), | ||
])> | ||
{!! $documentable->getSimpleHtml() !!} | ||
</x-filament-knowledge-base::content> | ||
<x-slot name="footerActions"> | ||
<x-filament::button tag="a" | ||
:href="$documentable->getUrl()" | ||
:target="$target"> | ||
{{ __('filament-knowledge-base::translations.open-documentation') }} | ||
</x-filament::button> | ||
<x-filament::button color="gray" | ||
x-on:click.prevent="$dispatch('close-modal', { id: '{{$documentable->getId()}}' })"> | ||
|
||
{{ __('filament-knowledge-base::translations.close') }} | ||
</x-filament::button> | ||
</x-slot> | ||
</x-filament::modal> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Guava\FilamentKnowledgeBase\Concerns; | ||
|
||
trait CanDisableModalLinks | ||
{ | ||
protected bool $disableModalLinks = false; | ||
|
||
public function disableModalLinks(bool $condition = true): static | ||
{ | ||
$this->disableModalLinks = $condition; | ||
|
||
return $this; | ||
} | ||
|
||
public function shouldDisableModalLinks(): bool | ||
{ | ||
return $this->disableModalLinks; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace Guava\FilamentKnowledgeBase\Livewire; | ||
|
||
use Filament\Actions\Concerns\InteractsWithActions; | ||
use Filament\Actions\Contracts\HasActions; | ||
use Filament\Facades\Filament; | ||
use Filament\Forms\Concerns\InteractsWithForms; | ||
use Filament\Forms\Contracts\HasForms; | ||
use Guava\FilamentKnowledgeBase\Contracts\Documentable; | ||
use Guava\FilamentKnowledgeBase\Facades\KnowledgeBase; | ||
use Livewire\Attributes\On; | ||
use Livewire\Component; | ||
|
||
class Modals extends Component implements HasActions, HasForms | ||
{ | ||
use InteractsWithActions; | ||
use InteractsWithForms; | ||
|
||
public ?Documentable $documentable = null; | ||
protected bool $shouldOpenDocumentationInNewTab; | ||
|
||
public function mount(): void | ||
{ | ||
$this->shouldOpenDocumentationInNewTab = Filament::getPlugin('guava::filament-knowledge-base')->shouldOpenDocumentationInNewTab(); | ||
} | ||
|
||
#[On('close-modal')] | ||
public function onClose($id) { | ||
if ($id !== 'kb-custom-modal') { | ||
return; | ||
} | ||
$this->js(<<<JS | ||
\$nextTick(() => { | ||
\$wire.resetDocumentation(); | ||
}); | ||
JS); | ||
} | ||
|
||
public function showDocumentation(string $id) | ||
{ | ||
$this->documentable = KnowledgeBase::documentable($id); | ||
|
||
$this->js(<<<JS | ||
\$nextTick(() => { | ||
\$dispatch('open-modal', { id: 'kb-custom-modal' }); | ||
}); | ||
JS); | ||
} | ||
|
||
public function resetDocumentation() { | ||
$this->documentable = null; | ||
} | ||
|
||
public function render() | ||
{ | ||
return view('filament-knowledge-base::livewire.modals'); | ||
} | ||
} |