Skip to content

Commit 474f56e

Browse files
committed
- Added search form component
Signed-off-by: Arushad Ahmed <dash-8x@hotmail.com>
1 parent 40d3b99 commit 474f56e

File tree

9 files changed

+99
-3
lines changed

9 files changed

+99
-3
lines changed

config/config.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
'inline-input-class' => 'col-sm-9 col-lg-10',
4343
'inline-entry-label-class' => 'col-sm-6 col-md-4',
4444
'inline-entry-class' => 'col-sm-6 col-md-8',
45+
'search-icon' => 'fa-search',
4546
],
4647

4748
'material-admin-26' => [
@@ -59,6 +60,7 @@
5960
'inline-input-class' => 'col-sm-9 col-lg-10',
6061
'inline-entry-label-class' => 'col-sm-6 col-md-4',
6162
'inline-entry-class' => 'col-sm-6 col-md-8',
63+
'search-icon' => 'zmdi-search',
6264
]
6365
],
6466

lang/dv/strings.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@
2323
'image_hint' => 'ރަނގަޅުވާނީ :widthpx x :heightpx.',
2424
'text_list_separator' => '، ',
2525
'text_list_separator_last_glue' => ' އަދި ',
26-
'map_search_string' => 'ހޯދާ...'
26+
'map_search_string' => 'ހޯދާ...',
27+
'search_form_placeholder' => 'ހޯދާ...'
2728
];

lang/en/strings.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@
2323
'image_hint' => 'Recommended :widthpx x :heightpx.',
2424
'text_list_separator' => ', ',
2525
'text_list_separator_last_glue' => ' and ',
26-
'map_search_string' => 'Search...'
26+
'map_search_string' => 'Search...',
27+
'search_form_placeholder' => 'Search...'
2728
];
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<x-forms::form :action="route($route, $params)" class="search" :method="$method" :framework="$framework" :files="$files">
2+
<x-forms::text
3+
:name="$name"
4+
:placeholder="$placeholder ?: trans('search_form_placeholder')"
5+
:show-label="false"
6+
:framework="$framework"
7+
/>
8+
</x-forms::form>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<x-forms::form :action="route($route, $params)" class="search" :method="$method" :framework="$framework" :files="$files">
2+
<div class="search__inner">
3+
<x-forms::text
4+
:name="$name"
5+
:placeholder="$placeholder ?: trans('search_form_placeholder')"
6+
class="search__text"
7+
:show-label="false"
8+
:framework="$framework"
9+
/>
10+
<i class="{{ $icon }} search__helper" data-ma-action="search-close"></i>
11+
</div>
12+
</x-forms::form>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Javaabu\Forms\Views\Components;
4+
5+
class SearchForm extends Form
6+
{
7+
protected string $view = 'search-form';
8+
9+
public string $icon;
10+
11+
/**
12+
* Create a new component instance.
13+
*
14+
* @return void
15+
*/
16+
public function __construct(
17+
public string $name = 'search',
18+
public string $route = '',
19+
public array $params = [],
20+
public string $placeholder = '',
21+
string $icon = '',
22+
string $method = 'GET',
23+
$model = null,
24+
bool $files = false,
25+
string $framework = ''
26+
) {
27+
if (! $model) {
28+
$model = request()->query();
29+
}
30+
31+
parent::__construct($method, $model, $files, $framework);
32+
33+
$this->icon = $icon ?: $this->getFrameworkIcon($this->frameworkConfig('search-icon'));
34+
}
35+
}

tests/Feature/SearchFormTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Javaabu\Forms\Tests\Feature;
4+
5+
use Javaabu\Forms\Tests\TestCase;
6+
7+
class SearchFormTest extends TestCase
8+
{
9+
/** @test */
10+
public function it_can_render_a_material_admin_26_search_form()
11+
{
12+
$this->setFrameworkMaterialAdmin26();
13+
14+
$this->registerTestRoute('search-form');
15+
$this->registerTestRoute('pagination');
16+
17+
$this->visit('/search-form?search=hello')
18+
->seeElement('form.search[action="http://localhost/pagination"]')
19+
->seeElement('input[name="search"][value="hello"]');
20+
}
21+
22+
/** @test */
23+
public function it_can_render_a_bootstrap_5_search_form()
24+
{
25+
$this->setFrameworkBootstrap5();
26+
27+
$this->registerTestRoute('search-form');
28+
$this->registerTestRoute('pagination');
29+
30+
$this->visit('/search-form?search=hello')
31+
->seeElement('form[action="http://localhost/pagination"]')
32+
->seeElement('input[name="search"][value="hello"]');
33+
}
34+
}

tests/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ protected function setFrameworkMaterialAdmin26(): self
9090
protected function registerTestRoute($uri, callable $post = null): self
9191
{
9292
Route::middleware('web')->group(function () use ($uri, $post) {
93-
Route::view($uri, $uri);
93+
Route::view($uri, $uri)->name($uri);
9494

9595
if ($post) {
9696
Route::post($uri, $post);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<x-forms::search-form
2+
route="pagination"
3+
:placeholder="__('Search for test...')" />

0 commit comments

Comments
 (0)