-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDrawer.php
More file actions
68 lines (58 loc) · 1.82 KB
/
Copy pathDrawer.php
File metadata and controls
68 lines (58 loc) · 1.82 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
<?php
declare(strict_types=1);
namespace MaterialBlade\Components;
use Illuminate\View\Component;
use Illuminate\View\ComponentAttributeBag;
use MaterialBlade\Components\Drawer\Properties\Variant;
/**
* @see https://mui.com/material-ui/react-drawer/
* @see https://github.com/material-components/material-components-web/tree/v14.0.0/packages/mdc-drawer
* @see https://m2.material.io/components/navigation-drawer
* @see https://material-components.github.io/material-components-web-catalog/#/component/drawer
*/
class Drawer extends Component
{
private Variant $variant;
/**
* Create a new component instance.
*
* @return void
*/
public function __construct(
string $variant = Variant::PERMANENT->value,
public ?string $title = null,
public ?string $subtitle = null,
) {
$this->variant = Variant::fromString($variant);
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|\Closure|string
*/
public function render()
{
return 'mbv::drawer';
}
public function attributesPreprocess(ComponentAttributeBag $attributes): ComponentAttributeBag
{
if ($this->variant !== Variant::PERMANENT) {
$attributes = $attributes->merge([
'data-mdc-auto-init' => 'MDCDrawer',
]);
}
return $attributes->style([
'height: auto',
'border-left-width: 1px',
'border-left-style: solid',
])->class([
'mdc-drawer',
'mdc-drawer--modal' => $this->variant === Variant::MODAL,
'mdc-drawer--dismissible' => $this->variant === Variant::DISMISSIBLE,
]);
}
public function isModal(): bool
{
return $this->variant === Variant::MODAL;
}
}