Skip to content

Commit

Permalink
✏️ Fix button href
Browse files Browse the repository at this point in the history
  • Loading branch information
siguici committed Jul 31, 2023
1 parent 5481bbb commit 1132fbf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ All notable changes to [Sikessem's UI kit](https://github.com/sikessem/ui) will

## [v0.4.0](https://github.com/sikessem/ui/releases/tag/v0.4.0) - 2023-07-31

- [0.x] Fix [link](https://github.com/sikessem/ui#link-component) and [form](https://github.com/sikessem/ui#form-component) urls
- [0.x] Fix [button](https://github.com/sikessem/ui#button-component) href
- [0.x] Fix [form](https://github.com/sikessem/ui#form-component) action
- [0.x] Fix [link](https://github.com/sikessem/ui#link-component) href
- [0.x] Add [**entry** component](https://github.com/sikessem/ui#entry-component)
- [0.x] Add [tag and endtag directives](https://github.com/sikessem/ui#blade-directives)
- [0.x] Change [ui directive](https://github.com/sikessem/ui#blade-directives)
Expand Down
5 changes: 0 additions & 5 deletions res/views/components/button.blade.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
@php
$type = strtolower($type);
$href = isset($route) ? route($route, $params) : ($href ? url($href) : null);
@endphp

@isset($href)
@tag('a', $attributes->merge(compact('href')), $slot)
@else
Expand Down
27 changes: 22 additions & 5 deletions src/Components/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,33 @@

class Button extends BladeComponent
{
public string $type = 'button';

public ?string $href = null;

/**
* @param array<mixed> $params
* @param array<mixed> $parameters
*/
public function __construct(
public string $type = 'button',
public ?string $href = null,
string $type = 'button',
string $href = null,
string $route = null,
string|array $parameters = [],
public ?string $text = null,
public ?string $route = null,
public array $params = [],
) {
$type = strtolower($type);
$parameters = (array) $parameters;
if (! is_null($href) || ! is_null($route)) {
$parameters = (array) $parameters;
if (is_null($route)) {
/** @var string */
$href = url($href, $parameters);
}
$href = $route ? route($route, $parameters) : $href;
}

$this->type = $type;
$this->href = $href;
}

public function render(): View|Factory
Expand Down

0 comments on commit 1132fbf

Please sign in to comment.