Passed
Push — 5.0.0 ( 9fcb89...47cf5a )
by Fèvre
05:30
created

Button   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 42
rs 10
c 1
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 19 4
A spinnerTarget() 0 7 2
A render() 0 3 1
1
<?php
2
3
namespace Xetaravel\View\Components;
4
5
use Closure;
6
use Illuminate\Contracts\View\View;
7
use Illuminate\View\Component;
8
9
class Button extends Component
10
{
11
    public string $uuid;
12
13
    public string $tooltipPosition = 'lg:tooltip-top';
14
15
    public function __construct(
16
        public ?string $label = null,
17
        public ?string $icon = null,
18
        public ?string $iconRight = null,
19
        public ?string $spinner = null,
20
        public ?string $link = null,
21
        public ?bool $external = false,
22
        public ?bool $noWireNavigate = false,
23
        public ?bool $responsive = false,
24
        public ?string $badge = null,
25
        public ?string $badgeClasses = null,
26
        public ?string $tooltip = null,
27
        public ?string $tooltipLeft = null,
28
        public ?string $tooltipRight = null,
29
        public ?string $tooltipBottom = null,
30
    ) {
31
        $this->uuid = md5(serialize($this));
32
        $this->tooltip = $this->tooltip ?? $this->tooltipLeft ?? $this->tooltipRight ?? $this->tooltipBottom;
33
        $this->tooltipPosition = $this->tooltipLeft ? 'lg:tooltip-left' : ($this->tooltipRight ? 'lg:tooltip-right' : ($this->tooltipBottom ? 'lg:tooltip-bottom' : 'lg:tooltip-top'));
34
    }
35
36
    public function spinnerTarget(): ?string
37
    {
38
        if ($this->spinner == 1) {
39
            return $this->attributes->whereStartsWith('wire:click')->first();
40
        }
41
42
        return $this->spinner;
43
    }
44
45
    /**
46
     * Get the view / contents that represent the component.
47
     */
48
    public function render(): View|Closure|string
49
    {
50
        return view('components.button');
51
    }
52
}
53