Skip to content

Commit

Permalink
Support as="div" to render a button as a div
Browse files Browse the repository at this point in the history
  • Loading branch information
calebporzio committed Oct 29, 2024
1 parent c55edb3 commit 7ad9432
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion stubs/resources/views/flux/button-or-link.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
'type',
'current',
'href',
'as',
]));
@endphp

@props([
'type' => 'button',
'current' => null,
'href' => null,
'as' => null,
])

@php
Expand All @@ -24,7 +26,11 @@
: false) : $current;
@endphp

<?php if ($href): ?>
<?php if ($as === 'div'): ?>
<div {{ $attributes }}>
{{ $slot }}
</div>
<?php elseif ($as === 'a' || $href): ?>
{{-- We are using e() here to escape the href attribute value instead of "{{ }}" because the latter will escape the entire attribute value, including the "&" character... --}}
<a href="{!! e($href) !!}" {{ $attributes->merge(['data-current' => $current]) }}>
{{ $slot }}
Expand Down

0 comments on commit 7ad9432

Please sign in to comment.