From 6f22b8ae2ebf214fceea95ed55eb611f3997b20b Mon Sep 17 00:00:00 2001 From: philipp lang Date: Sun, 20 Oct 2024 01:32:04 +0200 Subject: [PATCH] Add modal component --- app/View/Page/Modal.php | 101 +++++++++++++++++++++++++++ resources/js/components/ui/Popup.vue | 45 ------------ 2 files changed, 101 insertions(+), 45 deletions(-) create mode 100644 app/View/Page/Modal.php delete mode 100644 resources/js/components/ui/Popup.vue diff --git a/app/View/Page/Modal.php b/app/View/Page/Modal.php new file mode 100644 index 00000000..072ff59f --- /dev/null +++ b/app/View/Page/Modal.php @@ -0,0 +1,101 @@ +component = $component; + $this->props = $props; + $this->size = $size; + $this->title = $title; + $this->key = md5(json_encode(['component' => $component, 'props' => $props])); + $this->actions = $this->parseActions($actions); + } + + public function parseActions(array $actions): array + { + return collect($actions)->map(function ($action) { + if ($action === 'closeable') { + return ['event' => 'closeModal', 'icon' => 'close', 'label' => 'Schließen']; + } + + if ($action === 'storeable') { + return ['event' => 'onStoreFromModal', 'icon' => 'save', 'label' => 'Speichern']; + } + + return $action; + })->toArray(); + } + + #[On('closeModal')] + public function onCloseModal(): void + { + $this->reset(); + } + + public function sizeClass(): string + { + if ($this->size === 'lg') { + return 'max-w-lg'; + } + + if ($this->size === 'xl') { + return 'max-w-xl'; + } + + return ''; + } + + public function render() + { + return <<<'HTML' +
+ @if($component) +
+
+
+

{{$title}}

+
+ @foreach ($this->actions as $action) + + + + @endforeach +
+
+
+
+ @if ($component) + @livewire($component, $props, key($key)) + @endif +
+
+
+
+ @else +
+ @endif +
+ HTML; + } +} diff --git a/resources/js/components/ui/Popup.vue b/resources/js/components/ui/Popup.vue deleted file mode 100644 index 0c84fa42..00000000 --- a/resources/js/components/ui/Popup.vue +++ /dev/null @@ -1,45 +0,0 @@ - - -