Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions stubs/resources/views/flux/textarea.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,24 @@
->add('block p-3 w-full')
->add('shadow-xs disabled:shadow-none border rounded-lg')
->add('bg-white dark:bg-white/10 dark:disabled:bg-white/[7%]')
->add($resize ? 'resize-y' : 'resize-none')
->add($rows === 'auto' ? 'field-sizing-content' : '')
->add($resize ? match ($resize) {
default => 'resize', // to prevent unhandled match type when user only provide the attribute without value
'none' => 'resize-none',
'both' => 'resize',
'horizontal' => 'resize-x',
'vertical' => 'resize-y',
} : 'resize-none')
Comment on lines +22 to +28

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be improved.

If $resize is not defined this would use resize-none but the original default was resize-y.

To make sure that $resize is always defined, and defaults to vertical, you can use

$resize ??= 'vertical';

just before setting the classes, and maybe remove the default in the props.

Then this block can be simplified as

Suggested change
->add($resize ? match ($resize) {
default => 'resize', // to prevent unhandled match type when user only provide the attribute without value
'none' => 'resize-none',
'both' => 'resize',
'horizontal' => 'resize-x',
'vertical' => 'resize-y',
} : 'resize-none')
->add(match ($resize) {
'none' => 'resize-none',
'both' => 'resize',
'horizontal' => 'resize-x',
'vertical' => 'resize-y',
default => 'resize-y'
})

what do you thnk?

->add('text-base sm:text-sm text-zinc-700 disabled:text-zinc-500 placeholder-zinc-400 disabled:placeholder-zinc-400/70 dark:text-zinc-300 dark:disabled:text-zinc-400 dark:placeholder-zinc-400 dark:disabled:placeholder-zinc-500')
->add('border-zinc-200 border-b-zinc-300/80 dark:border-white/10')
->add('data-invalid:shadow-none data-invalid:border-red-500 dark:data-invalid:border-red-500')
;

$resizeStyle = match ($resize) {
'none' => 'resize: none',
'both' => 'resize: both',
'horizontal' => 'resize: horizontal',
'vertical' => 'resize: vertical',
};
@endphp

<flux:with-field :$attributes>
<textarea
{{ $attributes->class($classes) }}
rows="{{ $rows }}"
style="{{ $resizeStyle }}; {{ $rows === 'auto' ? 'field-sizing: content' : '' }}"
@isset ($name) name="{{ $name }}" @endisset
@unblaze(scope: ['name' => $name ?? null, 'invalid' => $invalid ?? false])
<?php if ($scope['invalid'] || ($scope['name'] && $errors->has($scope['name']))): ?>
Expand Down