Skip to content

Commit bd181dc

Browse files
committed
Add support for Form Sliders.
1 parent 75dbb4e commit bd181dc

File tree

5 files changed

+220
-0
lines changed

5 files changed

+220
-0
lines changed

assets/sample-slider-form.png

125 KB
Loading

examples.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
2+
## Examples
3+
4+
5+
### FormComponent Example
6+
7+
```php
8+
namespace App\Http\Livewire\Clients;
9+
10+
use Bastinald\LaravelLivewireForms\Components\Button;
11+
use Bastinald\LaravelLivewireForms\Components\FormComponent;
12+
use Bastinald\LaravelLivewireForms\Components\Input;
13+
use Bastinald\LaravelLivewireForms\Components\Select;
14+
15+
class CreateClientForm extends FormComponent
16+
{
17+
public $gridClass = 'row';
18+
19+
public function fields()
20+
{
21+
return [
22+
Input::make('name', 'Name')
23+
->col_md()
24+
->placeholder('Full Name'),
25+
Input::make('email', 'Email')
26+
->type('email')
27+
->placeholder('Email, example: [email protected]')
28+
->col_md(),
29+
Select::make('gender', 'Gender')
30+
->placeholder('Gender')
31+
->options(['Male', 'Female'])
32+
->col_md()
33+
->addAttrs(['class' => 'd-block w-full']),
34+
Input::make('phone_no', 'Contact Number')
35+
->placeholder('(xxx) xxx xxxxx')
36+
->col_md(),
37+
Input::make('street_address', 'Street Address')
38+
->col_md(),
39+
Input::make('city', 'City')
40+
->col_md(),
41+
Input::make('state', 'State / Parist')
42+
->col_md(),
43+
Input::make('country', 'Country')
44+
->col_md(),
45+
];
46+
}
47+
48+
public function buttons()
49+
{
50+
return [
51+
Button::make('Cancel', 'secondary')->url(route('team.index')),
52+
Button::make()->click('submit'),
53+
];
54+
}
55+
}
56+
```
57+
58+
#### Form View
59+
60+
![Example Form](assets/sample-form.png)
61+
62+
63+
### FormSliderComponent Example
64+
65+
```php
66+
namespace App\Http\Livewire\Clients;
67+
68+
use Bastinald\LaravelLivewireForms\Components\Button;
69+
use Bastinald\LaravelLivewireForms\Components\FormSliderComponent;
70+
use Bastinald\LaravelLivewireForms\Components\Input;
71+
use Bastinald\LaravelLivewireForms\Components\Select;
72+
73+
class CreateClientForm extends FormSliderComponent
74+
{
75+
76+
public $btnIcon = 'fa fa-user';
77+
public $btnText = 'Add Client';
78+
public $gridClass = 'row';
79+
80+
...
81+
82+
}
83+
```

readme.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,27 @@ class Login extends FormComponent
9191
->name('login')
9292
->middleware('guest');
9393
}
94+
}
95+
```
96+
97+
## Form Slider
98+
99+
Create a form that slides out by specifying a `title`, `layout` and `route` to use:
100+
101+
```php
102+
class Login extends FormSliderComponent
103+
{
104+
public $title = 'Login';
105+
public $layout = 'layouts.card';
106+
public $btnText = 'Login';
107+
108+
public function route()
109+
{
110+
return Route::get('/login', static::class)
111+
->name('login')
112+
->middleware('guest');
113+
}
114+
}
94115
```
95116

96117
The `route` method is made available by using my [laravel-livewire-routes](https://github.com/bastinald/laravel-livewire-routes) package.
@@ -115,6 +136,7 @@ class UpdateUserForm extends FormComponent
115136
{
116137
$this->data = $user->toArray();
117138
}
139+
}
118140
```
119141

120142
## Accessing Data
@@ -422,3 +444,7 @@ class CreateClientForm extends FormComponent
422444

423445
![Example Form](assets/sample-form.png)
424446

447+
448+
### Other Examples
449+
450+
For more examples, read the [example.md](example.md) document.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Bastinald\LaravelLivewireForms\Components;
4+
5+
class FormSliderComponent extends FormComponent {
6+
7+
8+
public $btnIcon = '';
9+
public $btnText = 'Execute';
10+
public $btnAttrs = [];
11+
public $sliderActive = false;
12+
13+
public function toggleSlider() {
14+
$this->sliderActive = ! $this->sliderActive;
15+
}
16+
17+
public function showSlider() {
18+
$this->sliderActive = true;
19+
}
20+
21+
public function hideSlider() {
22+
$this->sliderActive = false;
23+
}
24+
25+
public function render()
26+
{
27+
return view('laravel-livewire-forms::form-slider-component')
28+
->layout($this->layout ?? config('livewire.layout'));
29+
}
30+
31+
}
32+
33+
?>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<div>
2+
<button wire:click="showSlider" type='button' class='px-3 py-2 btn btn-success shadow-none uppercase tracking-wider hover:bg-blue-200 focus:outline-none'>
3+
<i class="{{ $btnIcon }}"></i>
4+
<span>{{ __($btnText) }}</span>
5+
</button>
6+
7+
8+
@if( $sliderActive )
9+
<div class="lw-slider-form-holder" >
10+
<div class="lw-slider-form slider-active" >
11+
<button wire:click="hideSlider" type='button' class='btn-close px-3 py-2 btn btn-danger btn-xs'>
12+
<i class="fa fa-close"></i>
13+
</button>
14+
15+
@section('title', __($title))
16+
<form class="{{ $gridClass }}" >
17+
@foreach($this->fields() as $field)
18+
{{ $field->render()->with($field->data()) }}
19+
@endforeach
20+
21+
<div class="col-md-12">
22+
<div class="d-flex justify-content-end gap-2">
23+
@foreach($this->buttons() as $button)
24+
{{ $button->render()->with($button->data()) }}
25+
@endforeach
26+
</div>
27+
</div>
28+
</form>
29+
</div>
30+
</div>
31+
@endif
32+
<style>
33+
.lw-slider-form-holder {
34+
width: 100%;
35+
height: 100vh;
36+
z-index: 1000000;
37+
background-color: #80808069;
38+
position: fixed;
39+
top: 0;
40+
bottom: 0;
41+
left: 0;
42+
right: 0;
43+
}
44+
.lw-slider-form-holder .lw-slider-form {
45+
background-color: white;
46+
position: absolute;
47+
right: 0;
48+
width: 40%;
49+
max-width: 720px;
50+
padding: 40px;
51+
height: 100%;
52+
padding-top: 100px;
53+
box-shadow: 4px 4px 10px black;
54+
}
55+
.lw-slider-form-holder .lw-slider-form button.btn-close {
56+
padding: 2px 10px !important;
57+
float: right;
58+
margin-top: -30px;
59+
}
60+
61+
@media (max-width: 576px) {
62+
.lw-slider-form-holder .lw-slider-form {
63+
width: 100%;
64+
}
65+
}
66+
@media (max-width: 768px) {
67+
.lw-slider-form-holder .lw-slider-form {
68+
width: 100%;
69+
}
70+
}
71+
@media (max-width: 992px) {
72+
.lw-slider-form-holder .lw-slider-form {
73+
width: 100%;
74+
}
75+
}
76+
</style>
77+
</div>
78+

0 commit comments

Comments
 (0)