Skip to content

Commit

Permalink
wip(profile) wip
Browse files Browse the repository at this point in the history
  • Loading branch information
irineujunior committed Mar 26, 2024
1 parent 6e12982 commit 2be8336
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 21 deletions.
54 changes: 33 additions & 21 deletions src/View/Components/Forms/Inputs/Toggle.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public function __construct(
public string $name = '',
public string $label = '',
public string $hint = '',
public string $inline = '',
public array $values = [],
public string $labelOn = '',
public string $labelOff = '',
) {
$this->uuid = '-' . str(serialize($this))
->pipe('md5')
Expand All @@ -24,33 +24,45 @@ public function __construct(

public function render(): string|View
{
// $classCollection = Str::of($attributes->get('class'))->explode(' ');
// $labelClass = $classCollection->filter(function (string $value, string $key) {
// return Str::of($value)->startsWith('form-switch');
// })->values();
// $inputClass = $classCollection->filter(function (string $value, string $key) {
// return !Str::of($value)->startsWith('form-switch');
// })->values();
// <label class="form-check form-switch">
// <input class="form-check-input" type="checkbox" checked="">
// <span class="form-check-label">Option 1</span>
// </label>


return <<<'HTML'
@if($label)
<x-form.label for="{{ $name . $uuid }}" @class(['required' => $attributes->has('required')])>
{{ str($label)->lower()->ucfirst() }}
</x-form.label>
@endif
@foreach($values as $key => $value)
<label class="form-check @if($inline) form-check-inline @endif form-switch">
<input type="checkbox" @if($value['value'] == 'Disabled toggle') disabled @endif @if($value['value'] == 'Checked toggle') checked @endif name="{{ $name }}" wire:model="{{ $name }}" {{ $attributes->merge([
<label @class([
'form-check',
'form-switch',
'required' => $attributes->has('required'),
])>
<input wire:model.change="{{ $name }}" {{ $attributes->merge([
'type' => 'checkbox',
'name' => $name,
'id' => $name . $uuid,
'value' => $value['value'],
])->class([
'form-check-input',
'is-invalid' => $errors->has($name),
])
}}
/>
<span class="form-check-label" for="{{ $name . $uuid }}" @class(['required' => $attributes->has('required')])>
{{ str($value['value'])->lower()->ucfirst() }}
</span>
@if(array_key_exists('description',$value))
<span class="form-check-description">
{{ str($value['description'])->lower()->ucfirst() }}
</span>
@endif
</label>
@endforeach
@if($label)
<span class="form-check-label">{{ str($label)->lower()->ucfirst() }}</span>
@endif
@if($labelOn)
<span class="form-check-label form-check-label-on">{{ str($labelOn)->lower()->ucfirst() }}</span>
@endif
@if($labelOff)
<span class="form-check-label form-check-label-off">{{ str($labelOff)->lower()->ucfirst() }}</span>
@endif
</label>
<x-form.error field="{{ $name }}"/>
<x-form.hint message="{{ $hint }}"/>
HTML;
Expand Down
59 changes: 59 additions & 0 deletions src/View/Components/Forms/Inputs/__Toggle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace Agenciafmd\Ui\View\Components\Forms\Inputs;

use Illuminate\Support\Facades\View;
use Illuminate\View\Component;

class Toggle extends Component
{
public string $uuid;

public function __construct(
public string $name = '',
public string $label = '',
public string $hint = '',
public string $inline = '',
public array $values = [],
)
{
$this->uuid = '-' . str(serialize($this))
->pipe('md5')
->limit(5, '')
->toString();
}

public function render(): string|View
{
return <<<'HTML'
@if($label)
<x-form.label for="{{ $name . $uuid }}" @class(['required' => $attributes->has('required')])>
{{ str($label)->lower()->ucfirst() }}
</x-form.label>
@endif
@foreach($values as $key => $value)
<label class="form-check @if($inline) form-check-inline @endif form-switch">
<input type="checkbox" @if($value['value'] == 'Disabled toggle') disabled @endif @if($value['value'] == 'Checked toggle') checked @endif name="{{ $name }}" wire:model="{{ $name }}" {{ $attributes->merge([
'id' => $name . $uuid,
'value' => $value['value'],
])->class([
'form-check-input',
'is-invalid' => $errors->has($name),
])
}}
/>
<span class="form-check-label" for="{{ $name . $uuid }}" @class(['required' => $attributes->has('required')])>
{{ str($value['value'])->lower()->ucfirst() }}
</span>
@if(array_key_exists('description',$value))
<span class="form-check-description">
{{ str($value['description'])->lower()->ucfirst() }}
</span>
@endif
</label>
@endforeach
<x-form.error field="{{ $name }}"/>
<x-form.hint message="{{ $hint }}"/>
HTML;
}
}

0 comments on commit 2be8336

Please sign in to comment.