Refactor modal component and add new functionality

This commit is contained in:
Andras Bacsai 2024-02-04 14:07:08 +01:00
parent 9dfce48380
commit e06e31642f
2 changed files with 34 additions and 18 deletions

View File

@ -4,15 +4,22 @@
'isErrorButton' => false, 'isErrorButton' => false,
'disabled' => false, 'disabled' => false,
'action' => 'delete', 'action' => 'delete',
'content' => null,
]) ])
<div x-data="{ modalOpen: false }" @keydown.escape.window="modalOpen = false" :class="{ 'z-40': modalOpen }" <div x-data="{ modalOpen: false }" @keydown.escape.window="modalOpen = false" :class="{ 'z-40': modalOpen }"
class="relative w-auto h-auto"> class="relative w-auto h-auto">
@if ($disabled) @if ($content)
<x-forms.button isError disabled>{{ $buttonTitle }}</x-forms.button> <div @click="modalOpen=true">
@elseif ($isErrorButton) {{ $content }}
<x-forms.button isError @click="modalOpen=true">{{ $buttonTitle }}</x-forms.button> </div>
@else @else
<x-forms.button @click="modalOpen=true">{{ $buttonTitle }}</x-forms.button> @if ($disabled)
<x-forms.button isError disabled>{{ $buttonTitle }}</x-forms.button>
@elseif ($isErrorButton)
<x-forms.button isError @click="modalOpen=true">{{ $buttonTitle }}</x-forms.button>
@else
<x-forms.button @click="modalOpen=true">{{ $buttonTitle }}</x-forms.button>
@endif
@endif @endif
<template x-teleport="body"> <template x-teleport="body">
<div x-show="modalOpen" class="fixed top-0 left-0 z-[99] flex items-center justify-center w-screen h-screen" <div x-show="modalOpen" class="fixed top-0 left-0 z-[99] flex items-center justify-center w-screen h-screen"
@ -30,13 +37,13 @@
class="relative w-full py-6 border rounded shadow-lg bg-coolgray-100 px-7 border-coolgray-300 sm:max-w-lg"> class="relative w-full py-6 border rounded shadow-lg bg-coolgray-100 px-7 border-coolgray-300 sm:max-w-lg">
<div class="flex items-center justify-between pb-3"> <div class="flex items-center justify-between pb-3">
<h3 class="text-2xl font-bold">{{ $title }}</h3> <h3 class="text-2xl font-bold">{{ $title }}</h3>
<button @click="modalOpen=false" {{-- <button @click="modalOpen=false"
class="absolute top-0 right-0 flex items-center justify-center w-8 h-8 mt-5 mr-5 text-white rounded-full hover:bg-coolgray-300"> class="absolute top-0 right-0 flex items-center justify-center w-8 h-8 mt-5 mr-5 text-white rounded-full hover:bg-coolgray-300">
<svg class="w-5 h-5" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" <svg class="w-5 h-5" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
stroke-width="1.5" stroke="currentColor"> stroke-width="1.5" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" /> <path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
</svg> </svg>
</button> </button> --}}
</div> </div>
<div class="relative w-auto pb-8"> <div class="relative w-auto pb-8">
{{ $slot }} {{ $slot }}
@ -48,14 +55,13 @@
<div class="flex-1"></div> <div class="flex-1"></div>
@if ($isErrorButton) @if ($isErrorButton)
<x-forms.button @click="modalOpen=false" class="w-24" isError type="button" <x-forms.button @click="modalOpen=false" class="w-24" isError type="button"
wire:click.prevent='{{ $action }}'>Continue wire:click.prevent="{{ $action }}">Continue
</x-forms.button> </x-forms.button>
@else @else
<x-forms.button @click="modalOpen=false" class="w-24" isHighlighted type="button" <x-forms.button @click="modalOpen=false" class="w-24" isHighlighted type="button"
wire:click.prevent='{{ $action }}'>Continue wire:click.prevent="{{ $action }}">Continue
</x-forms.button> </x-forms.button>
@endif @endif
</div> </div>
</div> </div>
</div> </div>

View File

@ -11,10 +11,15 @@
<div> <div>
<div class="grid grid-cols-1 gap-2 pb-4 lg:grid-cols-4"> <div class="grid grid-cols-1 gap-2 pb-4 lg:grid-cols-4">
@foreach ($server->destinations() as $destination) @foreach ($server->destinations() as $destination)
<div class="flex flex-col gap-2 box" wire:click="cloneTo('{{ data_get($destination, 'id') }}')"> <x-new-modal action="cloneTo({{ data_get($destination, 'id') }})">
<div class="font-bold text-white">{{ $server->name }}</div> <x:slot name="content">
<div>{{ $destination->name }}</div> <div class="flex flex-col gap-2 box">
</div> <div class="font-bold text-white">{{ $server->name }}</div>
<div>{{ $destination->name }}</div>
</div>
</x:slot>
<div>You are about to clone this resource.</div>
</x-new-modal>
@endforeach @endforeach
</div> </div>
</div> </div>
@ -32,10 +37,15 @@
@forelse ($projects as $project) @forelse ($projects as $project)
<div class="flex flex-row flex-wrap gap-2"> <div class="flex flex-row flex-wrap gap-2">
@foreach ($project->environments as $environment) @foreach ($project->environments as $environment)
<div class="flex flex-col gap-2 box" wire:click="moveTo('{{ data_get($environment, 'id') }}')"> <x-new-modal action="moveTo({{ data_get($environment, 'id') }})">
<div class="font-bold text-white">{{ $project->name }}</div> <x:slot name="content">
<div><span class="text-warning">{{ $environment->name }}</span> environment</div> <div class="flex flex-col gap-2 box">
</div> <div class="font-bold text-white">{{ $project->name }}</div>
<div><span class="text-warning">{{ $environment->name }}</span> environment</div>
</div>
</x:slot>
<div>You are about to move this resource.</div>
</x-new-modal>
@endforeach @endforeach
</div> </div>
@empty @empty