perhaps you are expecting to do too much with one button component.
Far easier to create a few that don't require you to specify a big long list of options.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi there!
So I'm refactoring my webapp and I'm thinking about what would be the best way to create a button component.
Would you mind sharing your own button component that you use in projects, using blade?
I'm creating something like this, and for some reason something feels off, but maybe that's just because I might not be used to this, as I used to do this in React usually.
@props([
'label' => '',
'class' => '',
'type' => 'button',
'size' => 'md',
'weight' => 'solid', // outline
'variant' => 'primary',
'variants' => [
'primary' => 'bg-brand-500'
'secondary' => ''
],
'variantsOutline' => [
'primary' => 'border border-brand-500'
'secondary' => ''
],
'sizes' => [
'xs' => '',
'sm' => '',
'md' => '',
'lg' => '',
'xl' => '',
]
])
{{-- outline? --}}
{{-- outiline
background
{{-- If weight is solid, show variants else variantsoutline --}}
<button type="{{ $type }}" {{ $attributes->merge(['class' => $class . "" . "{$sizes[$size]}" . "" . "{$variants[$variant]}" ]) }}">
{{ $slot ? $label : $slot}}
</button>
What do you think of the direction is is going?
And while yes there might be subjective parts and this and that... we can all agree every button component should have the ability to show text, outline/no-outline, colors, size and change its type.
I want to engeener a button so I can just re-use in other projects, create a small package later on perhaps or something.
Please or to participate in this conversation.