Skip to content

Commit

Permalink
Merge pull request #1368 from moonshine-software/remove-url
Browse files Browse the repository at this point in the history
Remove url
  • Loading branch information
lee-to authored Dec 12, 2024
2 parents ca82821 + e4d596e commit 2d208d4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 18 deletions.
7 changes: 7 additions & 0 deletions src/UI/src/Components/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ public function tooltip(?string $tooltip = null): self
return $this;
}

public function blank(): self
{
return $this->customAttributes([
'target' => '_blank',
]);
}

public function getView(): string
{
return 'moonshine::components.link-'
Expand Down
5 changes: 4 additions & 1 deletion src/UI/src/Components/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

namespace MoonShine\UI\Components;

/** @method static static make(string $href, string $value, ?string $icon = '', bool $withoutIcon = false, bool $blank = false) */
/**
* @method static static make(string $href, string $value, ?string $icon = '', bool $withoutIcon = false, bool $blank = false)
* @deprecated use \MoonShine\UI\Components\Link
*/
final class Url extends MoonShineComponent
{
protected string $view = 'moonshine::components.url';
Expand Down
20 changes: 13 additions & 7 deletions src/UI/src/Fields/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use MoonShine\Support\DTOs\AsyncCallback;
use MoonShine\Support\Enums\HttpMethod;
use MoonShine\UI\Components\Badge;
use MoonShine\UI\Components\Url;
use MoonShine\UI\Components\Link;
use MoonShine\UI\Traits\Fields\WithBadge;
use MoonShine\UI\Traits\Fields\WithHint;
use MoonShine\UI\Traits\Fields\WithLink;
Expand Down Expand Up @@ -377,13 +377,19 @@ private function previewDecoration(Renderable|string $value): Renderable|string
if ($this->hasLink()) {
$href = $this->getLinkValue($value);

$value = (string) Url::make(
$value = (string) Link::make(
href: $href,
value: $this->getLinkName($value) ?: $value,
icon: $this->getLinkIcon(),
withoutIcon: $this->isWithoutIcon(),
blank: $this->isLinkBlank()
)->render();
label: $this->getLinkName($value) ?: $value,
)
->when(
! $this->isWithoutIcon() && $this->getLinkIcon() !== null,
fn (Link $ctx): Link => $ctx->icon($this->getLinkIcon())
)
->when(
$this->isLinkBlank(),
fn (Link $ctx): Link => $ctx->blank()
)
->render();
}

if ($this->isBadge()) {
Expand Down
8 changes: 0 additions & 8 deletions tests/Feature/ComponentsEqualsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
use MoonShine\UI\Components\Tabs\Tab;
use MoonShine\UI\Components\Thumbnails;
use MoonShine\UI\Components\Title;
use MoonShine\UI\Components\Url;
use MoonShine\UI\Components\When;

uses()->group('components');
Expand Down Expand Up @@ -525,13 +524,6 @@ function renderBlade(string $alias, array $parameters = [], array $attributes =
);
});

it('url', function () {
compare(
Url::make('/', 'Link', icon: 'users', blank: true)->withoutIcon(),
['href' => '/', 'value' => 'Link', 'icon' => 'users', 'blank' => true, 'without-icon' => true]
);
});

it('when', function () {
compare(
When::make(fn () => false, fn () => $this->components),
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Fields/PreviewFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use MoonShine\UI\Components\Badge;
use MoonShine\UI\Components\Boolean;
use MoonShine\UI\Components\FormBuilder;
use MoonShine\UI\Components\Url;
use MoonShine\UI\Components\Link;
use MoonShine\UI\Fields\Preview;

uses()->group('fields');
Expand Down Expand Up @@ -107,7 +107,7 @@
it('link value', function (): void {
expect((string) $this->field->link('/')->preview())
->toBe(
(string) Url::make('/', $this->item->no_input)->render()
(string) Link::make('/', $this->item->no_input)->render()
);
});

Expand Down

0 comments on commit 2d208d4

Please sign in to comment.