name($name); } public static function make(?string $name = null): static { $static = app(static::class, [ 'name' => $name ?? static::getDefaultName(), ]); $static->configure(); return $static; } public function isBadge(): bool { return $this->getView() === static::BADGE_VIEW; } public function button(): static { return $this->view(static::BUTTON_VIEW); } public function isButton(): bool { return $this->getView() === static::BUTTON_VIEW; } public function grouped(): static { return $this->view(static::GROUPED_VIEW); } public function iconButton(): static { return $this->view(static::ICON_BUTTON_VIEW); } public function isIconButton(): bool { return $this->getView() === static::ICON_BUTTON_VIEW; } public function link(): static { return $this->view(static::LINK_VIEW); } public function isLink(): bool { return $this->getView() === static::LINK_VIEW; } public function alpineClickHandler(string | Closure | null $handler): static { $this->alpineClickHandler = $handler; $this->livewireClickHandlerEnabled(blank($handler)); return $this; } public static function getDefaultName(): ?string { return null; } public function getLivewireClickHandler(): ?string { if (! $this->isLivewireClickHandlerEnabled()) { return null; } if (is_string($this->action)) { return $this->action; } if ($event = $this->getLivewireEventClickHandler()) { return $event; } if ($handler = $this->getParentActionCallLivewireClickHandler()) { $handler .= '('; $handler .= Js::from($this->getArguments()); $handler .= ')'; return $handler; } return null; } public function getLivewireEventClickHandler(): ?string { $event = $this->getEvent(); if (blank($event)) { return null; } $arguments = ''; if ($component = $this->getDispatchToComponent()) { $arguments .= Js::from($component)->toHtml(); $arguments .= ', '; } $arguments .= Js::from($event)->toHtml(); if ($this->getEventData()) { $arguments .= ', '; $arguments .= Js::from($this->getEventData())->toHtml(); } return match ($this->getDispatchDirection()) { 'self' => "\$dispatchSelf($arguments)", 'to' => "\$dispatchTo($arguments)", default => "\$dispatch($arguments)" }; } public function getAlpineClickHandler(): ?string { if (filled($handler = $this->evaluate($this->alpineClickHandler))) { return $handler; } if (! $this->shouldClose()) { return null; } return 'close()'; } public function livewireTarget(?string $target): static { $this->livewireTarget = $target; return $this; } public function getLivewireTarget(): ?string { return $this->livewireTarget; } /** * @deprecated Use `extraAttributes()` instead. * * @param array $attributes */ public function withAttributes(array $attributes): static { return $this->extraAttributes($attributes); } }