-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDialog.php
More file actions
74 lines (67 loc) · 2.09 KB
/
Copy pathDialog.php
File metadata and controls
74 lines (67 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
declare(strict_types=1);
namespace MaterialBlade\Components;
use Illuminate\View\Component;
use Illuminate\View\ComponentAttributeBag;
use InvalidArgumentException;
/**
* Material Design Dialog Component
*
* @see https://m2.material.io/components/dialogs/web
* @see https://github.com/material-components/material-components-web/tree/master/packages/mdc-dialog
*/
class Dialog extends Component
{
/**
* Create a new component instance.
*
* @param bool $open Whether the dialog is open by default
* @param bool $fullscreen Whether to render as fullscreen dialog
* @param bool $scrollable Whether the dialog content is scrollable
* @param string|null $title Dialog title
* @return void
*/
public function __construct(
public bool $open = false,
public bool $fullscreen = false,
public bool $scrollable = false,
public ?string $title = null,
) {
//
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|\Closure|string
*/
public function render()
{
return function (array $data): string {
throw_if(
$data['slot']->isEmpty(),
new InvalidArgumentException('<mbc::dialog /> component requires content in the slot')
);
return 'mbv::dialog';
};
}
/**
* Preprocess attributes for the dialog container
*
* @return ComponentAttributeBag
*/
public function attributesPreprocess(ComponentAttributeBag $attributes)
{
return $attributes->merge([
'data-mdc-auto-init' => 'MDCDialog',
'role' => 'alertdialog',
'aria-modal' => 'true',
'aria-labelledby' => $this->title ? 'dialog-title' : null,
'aria-describedby' => 'dialog-content',
])->class([
'mdc-dialog',
'mdc-dialog--open' => $this->open,
'mdc-dialog--fullscreen' => $this->fullscreen,
'mdc-dialog--scrollable' => $this->scrollable,
]);
}
}