-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from codions/develop
Added fieldset component and minor improvements
- Loading branch information
Showing
5 changed files
with
116 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
@php | ||
if ( !empty($props['prefix']) ) { | ||
$name = $props['prefix']; | ||
} else { | ||
$name = ''; | ||
} | ||
@endphp | ||
|
||
<fieldset class="{{ $row_class }}"> | ||
@isset($props['label']) | ||
<legend> | ||
{{ __($props['label']) }} | ||
</legend> | ||
@endisset | ||
@foreach($props['fields'] as $field) | ||
@if ( !method_exists($field, 'prefix') ) | ||
{{ $field->render()->with($field->data()) }} | ||
@else | ||
<div class="{{ $field->getColClass() ?? 'col-md-6'}} mb-3"> | ||
{{ $field->render()->with($field->data()) }} | ||
</div> | ||
@endif | ||
@endforeach | ||
</fieldset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace Codions\LaravelLivewireForms\Components; | ||
|
||
use Codions\LaravelLivewireForms\Traits\WithHelp; | ||
use Codions\LaravelLivewireForms\Traits\WithPrefix; | ||
use Illuminate\View\Component; | ||
|
||
class Fieldset extends Component | ||
{ | ||
use WithHelp; | ||
use WithPrefix; | ||
|
||
public $props = []; | ||
|
||
public $attrs = []; | ||
|
||
public $column_class = 'col-md-6 mb-2 mb-md-0'; | ||
|
||
public $row_class = ''; | ||
|
||
public static function make($label = null) | ||
{ | ||
$component = new static; | ||
|
||
$component->props = [ | ||
// 'name' => $name, | ||
'label' => $label, | ||
'fields' => [], | ||
'help' => null, | ||
]; | ||
|
||
$component->attrs = [ | ||
'disabled' => false, | ||
]; | ||
|
||
return $component; | ||
} | ||
|
||
public function fields($fields = []) | ||
{ | ||
$this->props['fields'] = $fields; | ||
|
||
return $this; | ||
} | ||
|
||
public function isColumn($field) | ||
{ | ||
return Column::class == get_class($field); | ||
} | ||
|
||
public function colSize($col = 'mb-2') | ||
{ | ||
$this->column_class = "$col mb-2 mb-md-0"; | ||
|
||
return $this; | ||
} | ||
|
||
public function render() | ||
{ | ||
$fieldset = $this; | ||
|
||
return view('laravel-livewire-forms::fieldset', compact('fieldset')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters