Skip to content

Commit 4492d1f

Browse files
Merge pull request #12 from luvi-ui/sheet-as-dialog
Sheet as dialog
2 parents 52fbc54 + b3b4b5b commit 4492d1f

File tree

9 files changed

+65
-82
lines changed

9 files changed

+65
-82
lines changed

app/Services/DialogCvaService.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace App\Services;
4+
5+
use FeatureNinja\Cva\ClassVarianceAuthority;
6+
7+
class DialogCvaService
8+
{
9+
public static function new(): ClassVarianceAuthority
10+
{
11+
return ClassVarianceAuthority::new(
12+
[
13+
'transition ease-in-out backdrop:bg-black/80 backdrop:duration-300 backdrop:opacity-0 backdrop:transition-[opacity,display,overlay] backdrop:[transition-behavior:allow-discrete] open:backdrop:opacity-100 [@starting-style]:open:backdrop:opacity-0',
14+
],
15+
[
16+
'variants' => [
17+
'variant' => [
18+
'dialog' => 'w-full max-w-lg border bg-background p-6 shadow-lg sm:rounded-lg',
19+
'sheet' => 'open:grid grid-rows-[auto_1fr_auto] m-0 gap-4 bg-background p-6 shadow-lg transition-[display,overlay,transform] ease-in-out duration-500 [transition-behavior:allow-discrete] ',
20+
],
21+
'side' => [
22+
'top' => 'max-w-full min-w-full overflow-x-auto !mb-auto border-b -translate-y-full open:translate-y-0 [@starting-style]:open:-translate-y-full',
23+
'bottom' => 'max-w-full min-w-full overflow-x-auto !mt-auto border-t translate-y-full open:translate-y-0 [@starting-style]:open:translate-y-full',
24+
'left' => 'max-h-dvh min-h-dvh overflow-y-auto !mr-auto w-3/4 border-r sm:max-w-sm -translate-x-full open:translate-x-0 [@starting-style]:open:-translate-x-full',
25+
'right' => 'max-h-dvh min-h-dvh overflow-y-auto !ml-auto w-3/4 border-l sm:max-w-sm translate-x-full open:translate-x-0 [@starting-style]:open:translate-x-full',
26+
'center' => 'open:fade-in-0 open:zoom-in-95 fade-out-0 zoom-out-95 ',
27+
],
28+
],
29+
'defaultVariants' => [
30+
'side' => 'center',
31+
'variant' => 'dialog',
32+
],
33+
],
34+
);
35+
}
36+
}

app/Services/SheetCvaService.php

Lines changed: 0 additions & 30 deletions
This file was deleted.

resources/views/components/sheet/close.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<x-button
2-
@click="open = false"
2+
x-on:click="__sheetOpen = false"
33
{{ $attributes->twMerge('') }}
44
>
55
{{ $slot }}

resources/views/components/sheet/content.blade.php

Lines changed: 16 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,20 @@
22
'side' => 'right',
33
])
44

5-
@php
6-
$one = match ($side) {
7-
'top' => '-translate-y-full',
8-
'right' => 'translate-x-full',
9-
'bottom' => 'translate-y-full',
10-
'left' => '-translate-x-full',
11-
};
5+
@inject('sheet', 'App\Services\DialogCvaService')
126

13-
$two = match ($side) {
14-
'top' => '-translate-y-0',
15-
'right' => 'translate-x-0',
16-
'bottom' => 'translate-y-0',
17-
'left' => 'translate-x-0',
18-
};
19-
@endphp
20-
21-
@inject('sheet', 'App\Services\SheetCvaService')
22-
23-
<div @keydown.escape.window="open = false">
24-
<template x-teleport="body">
25-
<x-sheet.overlay />
26-
</template>
27-
28-
<template x-teleport="body">
29-
<div
30-
x-show="open"
31-
x-transition:enter="transition ease-out duration-500"
32-
x-transition:enter-start="{{ $one }}"
33-
x-transition:enter-end="{{ $two }}"
34-
x-transition:leave="transition ease-in duration-300"
35-
x-transition:leave-start="{{ $two }}"
36-
x-transition:leave-end="{{ $one }}"
37-
{{ $attributes->twMerge($sheet(['side' => $side])) }}
38-
>
39-
<x-sheet.close
40-
variant="icon"
41-
class="noway absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none"
42-
>
43-
<x-lucide-x class="size-4" />
44-
</x-sheet.close>
45-
{{ $slot }}
46-
</div>
47-
48-
</template>
49-
50-
</div>
7+
<dialog
8+
wire:ignore.self
9+
x-on:cancel="__sheetOpen = false"
10+
x-trap.noscroll="__sheetOpen"
11+
x-effect="__sheetOpen ? $el.showModal() : $el.close()"
12+
{{ $attributes->twMerge($sheet(['side' => $side, 'variant' => 'sheet'])) }}
13+
>
14+
<x-sheet.close
15+
variant="icon"
16+
class="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none"
17+
>
18+
<x-lucide-x class="size-4" />
19+
</x-sheet.close>
20+
{{ $slot }}
21+
</dialog>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<div {{ $attributes->twMerge('flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2') }}>
1+
<div {{ $attributes->twMerge('row-start-3 flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2') }}>
22
{{ $slot }}
33
</div>
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
<div x-data="{ open: false }">
1+
<div
2+
x-data="{ __sheetOpen: false }"
3+
x-modelable="__sheetOpen"
4+
>
25
{{ $slot }}
36
</div>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div {{ $attributes->twMerge('row-start-2') }}>
2+
{{ $slot }}
3+
</div>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<div @click="open = ! open">
1+
<div x-on:click="__sheetOpen = true">
22
{{ $slot }}
33
</div>

src/LaravelLuviServiceProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use App\Services\AlertCvaService;
66
use App\Services\BadgeCvaService;
77
use App\Services\ButtonCvaService;
8-
use App\Services\SheetCvaService;
8+
use App\Services\DialogCvaService;
99
use Illuminate\Support\ServiceProvider;
1010

1111
class LaravelLuviServiceProvider extends ServiceProvider
@@ -52,7 +52,7 @@ public function register(): void
5252
$this->app->singleton(AlertCvaService::class, fn () => AlertCvaService::new());
5353
$this->app->singleton(BadgeCvaService::class, fn () => BadgeCvaService::new());
5454
$this->app->singleton(ButtonCvaService::class, fn () => ButtonCvaService::new());
55-
$this->app->singleton(SheetCvaService::class, fn () => SheetCvaService::new());
55+
$this->app->singleton(DialogCvaService::class, fn () => DialogCvaService::new());
5656
}
5757

5858
public function boot(): void
@@ -86,7 +86,7 @@ public function boot(): void
8686
], 'badge');
8787

8888
$this->publishes([
89-
__DIR__.'/../app/Services/SheetCvaService.php' => app_path('Services/SheetCvaService.php'),
89+
__DIR__.'/../app/Services/DialogCvaService.php' => app_path('Services/DialogCvaService.php'),
9090
], 'sheet');
9191

9292
// plugins

0 commit comments

Comments
 (0)