-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathHasLabel.php
60 lines (44 loc) · 1.3 KB
/
HasLabel.php
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
<?php
namespace Filament\Forms\Components\Concerns;
use Closure;
use Illuminate\Contracts\Support\Htmlable;
trait HasLabel
{
protected bool | Closure $isLabelHidden = false;
protected string | Htmlable | Closure | null $label = null;
protected bool $shouldTranslateLabel = false;
/**
* @deprecated Use `hiddenLabel()` instead.
*/
public function disableLabel(bool | Closure $condition = true): static
{
$this->hiddenLabel($condition);
return $this;
}
public function hiddenLabel(bool | Closure $condition = true): static
{
$this->isLabelHidden = $condition;
return $this;
}
public function label(string | Htmlable | Closure | null $label): static
{
$this->label = $label;
return $this;
}
public function translateLabel(bool $shouldTranslateLabel = true): static
{
$this->shouldTranslateLabel = $shouldTranslateLabel;
return $this;
}
public function getLabel(): string | Htmlable | null
{
$label = $this->evaluate($this->label);
return (is_string($label) && $this->shouldTranslateLabel) ?
__($label) :
$label;
}
public function isLabelHidden(): bool
{
return (bool) $this->evaluate($this->isLabelHidden);
}
}