Skip to content

Commit

Permalink
Update textarea, add FormSelect component
Browse files Browse the repository at this point in the history
Enhanced the textarea's styles to take up the full width to improve alignment and user experience. Also, a new FormSelect component was added for better code reusability and standardization of select inputs. All changes have been tested.
  • Loading branch information
CrazyBoy49z committed Oct 15, 2023
1 parent 1f6fe24 commit e64fc43
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
48 changes: 48 additions & 0 deletions resources/views/form/select.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@props([
'label' => '',
'help' => '',
'hr' => ''
])

@php
$required = $attributes['required'] ?? null;
if ($label) {
$label .= ($required ? '<i class="text-error">*</i>' : '');
}
$model = $attributes->wire('model');
$parameter = $model->value();
$class = [];
@endphp


<div class="{{ $label ? 'form-control' : 'inline-block' }}">
<label class="label cursor-pointer{{ $hr ? ' flex flex-col items-start' : '' }}">
<span class="label-text{{ $hr ? ' mb-1' : '' }}">{!! $label !!}</span>
<x-lazy-select :attributes="$attributes">
{{ $slot }}
</x-lazy-select>
</label>
@if ($help)
<div class="tooltip w-6" data-tip="{{ $help }}">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
class="stroke-info h-6 w-6 flex-shrink-0">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
</div>
@endif
@if ($parameter)
@error($parameter)
<div class="alert alert-error mt-1 mb-2 shadow-lg">
<div>
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 flex-shrink-0 stroke-current" fill="none"
viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
{{ $message }}
</div>
</div>
@enderror
@endif
</div>
2 changes: 1 addition & 1 deletion resources/views/textarea.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
'hasError' => false,
'value' => ''
])
<textarea {{ $attributes->merge(['class' => 'textarea'.($hasError ? ' textarea-error' : '')]) }}>{{ $value ?: $slot }}</textarea>
<textarea {{ $attributes->merge(['class' => 'w-full'.($hasError ? ' textarea-error' : '')]) }}>{{ $value ?: $slot }}</textarea>
25 changes: 25 additions & 0 deletions src/Components/Form/FormSelect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Step2dev\LazyUI\Components\Form;

use Illuminate\Contracts\View\View;
use Step2dev\LazyUI\LazyComponent;

class FormSelect extends LazyComponent
{
public ?string $placeholder;

public function __construct(public string $label = '', string $placeholder = '', public bool $required = false)
{
$this->placeholder = (string) str($placeholder ?: $this->label)->trim()->ucfirst();
}

public function render(): \Closure|View
{
return function (array $data) {
$data['attributes']['required'] = $this->required;

return view('lazy::form.select', $this->mergeData($data))->render();
};
}
}
2 changes: 2 additions & 0 deletions src/LazyUiServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Step2dev\LazyUI\Components\Form\FormImage;
use Step2dev\LazyUI\Components\Form\FormInput;
use Step2dev\LazyUI\Components\Form\FormRichtext;
use Step2dev\LazyUI\Components\Form\FormSelect;
use Step2dev\LazyUI\Components\Form\FormTextarea;
use Step2dev\LazyUI\Components\Form\FormToggle;
use Step2dev\LazyUI\Components\FormGroup;
Expand Down Expand Up @@ -97,6 +98,7 @@ public function configurePackage(Package $package): void
FormImage::class,
FormInput::class,
FormRichtext::class,
FormSelect::class,
FormTextarea::class,
FormToggle::class,
Image::class,
Expand Down

0 comments on commit e64fc43

Please sign in to comment.