Button   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

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

3 Methods

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