feat: replace form helper functions with components in admin template

This commit is contained in:
Yassine Doghri 2021-09-15 15:58:21 +00:00
commit e64548b982
70 changed files with 1461 additions and 2571 deletions

View file

@ -8,8 +8,6 @@ use ViewComponents\Component;
class Button extends Component
{
protected string $label = '';
protected string $uri = '';
protected string $variant = 'default';
@ -22,6 +20,11 @@ class Button extends Component
protected bool $isSquared = false;
public function setIsSquared(string $value): void
{
$this->isSquared = $value === 'true';
}
public function render(): string
{
$baseClass =
@ -80,19 +83,31 @@ class Button extends Component
$this->slot .= '<Icon glyph="' . $this->iconRight . '" class="ml-2" />';
}
unset($this->attributes['slot']);
unset($this->attributes['variant']);
unset($this->attributes['size']);
unset($this->attributes['iconLeft']);
unset($this->attributes['iconRight']);
unset($this->attributes['isSquared']);
unset($this->attributes['uri']);
unset($this->attributes['label']);
if ($this->uri !== '') {
return anchor($this->uri, $this->label, array_merge([
'class' => $buttonClass,
], $this->attributes));
$tagName = 'a';
$defaultButtonAttributes = [
'href' => $this->uri,
];
} else {
$tagName = 'button';
$defaultButtonAttributes = [
'type' => 'button',
];
}
$defaultButtonAttributes = [
'type' => 'button',
];
$attributes = stringify_attributes(array_merge($defaultButtonAttributes, $this->attributes));
return <<<HTML
<button class="{$buttonClass}" {$attributes}>{$this->slot}</button>
<{$tagName} class="{$buttonClass}" {$attributes}>{$this->slot}</{$tagName}>
HTML;
}
}