Skip to content

Commit dd40155

Browse files
authored
Merge pull request #232 from yajra/tags
feat: add tags field support
2 parents 08ccb11 + bf85ccb commit dd40155

15 files changed

+309
-16
lines changed

phpstan.neon.dist

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ parameters:
1010

1111
ignoreErrors:
1212
- '#Unsafe usage of new static\(\).#'
13+
- identifier: missingType.generics
14+
- identifier: missingType.iterableValue
1315

1416
excludePaths:
15-
16-
checkMissingIterableValueType: false
17-
18-
checkGenericClassInNonGenericObjectType: false
17+
- ./src/Html/Fluent.php

src/Html/Editor/Fields/Tags.php

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
<?php
2+
3+
namespace Yajra\DataTables\Html\Editor\Fields;
4+
5+
use Illuminate\Contracts\Support\Arrayable;
6+
7+
/**
8+
* @see https://editor.datatables.net/reference/field/tags
9+
*/
10+
class Tags extends Field
11+
{
12+
protected string $type = 'tags';
13+
14+
/**
15+
* @see https://editor.datatables.net/reference/field/tags#ajax
16+
*/
17+
public function ajax(bool|string|null $url = true): static
18+
{
19+
$this->attributes['ajax'] = $url;
20+
21+
return $this;
22+
}
23+
24+
/**
25+
* @see https://editor.datatables.net/reference/field/tags#display
26+
*/
27+
public function display(string $display): static
28+
{
29+
$this->attributes['display'] = $display;
30+
31+
return $this;
32+
}
33+
34+
/**
35+
* @see https://editor.datatables.net/reference/field/tags#escapeLabelHtml
36+
*/
37+
public function escapeLabelHtml(bool $escape): static
38+
{
39+
$this->attributes['escapeLabelHtml'] = $escape;
40+
41+
return $this;
42+
}
43+
44+
/**
45+
* @see https://editor.datatables.net/reference/field/tags#i18n
46+
*/
47+
public function i18n(array $i18n): static
48+
{
49+
$options = isset($this->attributes['i18n'])
50+
? (array) $this->attributes['i18n']
51+
: [];
52+
53+
$this->attributes['i18n'] = array_merge($options, $i18n);
54+
55+
return $this;
56+
}
57+
58+
/**
59+
* @see https://editor.datatables.net/reference/field/tags#i18n
60+
*/
61+
public function addButton(string $text): static
62+
{
63+
return $this->i18n(['addButton' => $text]);
64+
}
65+
66+
/**
67+
* @see https://editor.datatables.net/reference/field/tags#i18n
68+
*/
69+
public function inputPlaceholder(string $text): static
70+
{
71+
return $this->i18n(['inputPlaceholder' => $text]);
72+
}
73+
74+
/**
75+
* @see https://editor.datatables.net/reference/field/tags#i18n
76+
*/
77+
public function noResults(string $text): static
78+
{
79+
return $this->i18n(['noResults' => $text]);
80+
}
81+
82+
/**
83+
* @see https://editor.datatables.net/reference/field/tags#i18n
84+
*/
85+
public function title(string $text): static
86+
{
87+
return $this->i18n(['title' => $text]);
88+
}
89+
90+
/**
91+
* @see https://editor.datatables.net/reference/field/tags#i18n
92+
*/
93+
public function placeholder(string $text): static
94+
{
95+
return $this->i18n(['placeholder' => $text]);
96+
}
97+
98+
/**
99+
* @see https://editor.datatables.net/reference/field/tags#limit
100+
*/
101+
public function limit(int $limit): static
102+
{
103+
$this->attributes['limit'] = $limit;
104+
105+
return $this;
106+
}
107+
108+
/**
109+
* @see https://editor.datatables.net/reference/field/tags#multiple
110+
*/
111+
public function multiple(bool $multiple = true): static
112+
{
113+
$this->attributes['multiple'] = $multiple;
114+
115+
return $this;
116+
}
117+
118+
/**
119+
* @see https://editor.datatables.net/reference/field/tags#options
120+
*/
121+
public function options(array|Arrayable $options): static
122+
{
123+
return parent::options($options);
124+
}
125+
126+
/**
127+
* @see https://editor.datatables.net/reference/field/tags#separator
128+
*/
129+
public function separator(string $separator = ','): static
130+
{
131+
return parent::separator($separator);
132+
}
133+
134+
/**
135+
* @see https://editor.datatables.net/reference/field/tags#unique
136+
*/
137+
public function unique(bool $unique = true): static
138+
{
139+
$this->attributes['unique'] = $unique;
140+
141+
return $this;
142+
}
143+
}

tests/BuilderOptionsLanguageTest.php renamed to tests/Html/Builder/BuilderOptionsLanguageTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
22

3-
namespace Yajra\DataTables\Html\Tests;
3+
namespace Yajra\DataTables\Html\Tests\Html\Builder;
44

55
use PHPUnit\Framework\Attributes\Test;
6+
use Yajra\DataTables\Html\Tests\TestCase;
67

78
class BuilderOptionsLanguageTest extends TestCase
89
{

tests/BuilderOptionsPluginsTest.php renamed to tests/Html/Builder/BuilderOptionsPluginsTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?php
22

3-
namespace Yajra\DataTables\Html\Tests;
3+
namespace Yajra\DataTables\Html\Tests\Html\Builder;
44

55
use PHPUnit\Framework\Attributes\Test;
66
use Yajra\DataTables\Html\Builder;
77
use Yajra\DataTables\Html\Button;
88
use Yajra\DataTables\Html\SearchPane;
9+
use Yajra\DataTables\Html\Tests\TestCase;
910

1011
class BuilderOptionsPluginsTest extends TestCase
1112
{

tests/BuilderOptionsTest.php renamed to tests/Html/Builder/BuilderOptionsTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?php
22

3-
namespace Yajra\DataTables\Html\Tests;
3+
namespace Yajra\DataTables\Html\Tests\Html\Builder;
44

55
use PHPUnit\Framework\Attributes\Test;
66
use Yajra\DataTables\Html\Builder;
77
use Yajra\DataTables\Html\Column;
8+
use Yajra\DataTables\Html\Tests\TestCase;
89

910
class BuilderOptionsTest extends TestCase
1011
{

tests/BuilderTest.php renamed to tests/Html/Builder/BuilderTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Yajra\DataTables\Html\Tests;
3+
namespace Yajra\DataTables\Html\Tests\Html\Builder;
44

55
use Illuminate\Support\HtmlString;
66
use PHPUnit\Framework\Attributes\Test;
@@ -9,6 +9,7 @@
99
use Yajra\DataTables\Html\ColumnDefinition;
1010
use Yajra\DataTables\Html\ColumnDefinitions;
1111
use Yajra\DataTables\Html\Editor\Editor;
12+
use Yajra\DataTables\Html\Tests\TestCase;
1213

1314
class BuilderTest extends TestCase
1415
{

tests/LayoutTest.php renamed to tests/Html/Builder/LayoutTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<?php
22

3-
namespace Yajra\DataTables\Html\Tests;
3+
namespace Yajra\DataTables\Html\Tests\Html\Builder;
44

55
use InvalidArgumentException;
66
use Livewire\Exceptions\ComponentNotFoundException;
77
use PHPUnit\Framework\Attributes\Test;
88
use Yajra\DataTables\Html\Builder;
99
use Yajra\DataTables\Html\Enums\LayoutPosition;
1010
use Yajra\DataTables\Html\Layout;
11+
use Yajra\DataTables\Html\Tests\TestCase;
1112
use Yajra\DataTables\Html\Tests\TestComponents\TestInlineView;
1213
use Yajra\DataTables\Html\Tests\TestComponents\TestLivewire;
1314
use Yajra\DataTables\Html\Tests\TestComponents\TestView;

tests/ColumnDefinitionTest.php renamed to tests/Html/Column/ColumnDefinitionTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?php
22

3-
namespace Yajra\DataTables\Html\Tests;
3+
namespace Yajra\DataTables\Html\Tests\Html\Column;
44

55
use PHPUnit\Framework\Attributes\Test;
66
use Yajra\DataTables\Html\ColumnDefinition;
7+
use Yajra\DataTables\Html\Tests\TestCase;
78

89
class ColumnDefinitionTest extends TestCase
910
{

tests/ColumnTest.php renamed to tests/Html/Column/ColumnTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?php
22

3-
namespace Yajra\DataTables\Html\Tests;
3+
namespace Yajra\DataTables\Html\Tests\Html\Column;
44

55
use PHPUnit\Framework\Attributes\Test;
66
use Yajra\DataTables\Html\Column;
7+
use Yajra\DataTables\Html\Tests\TestCase;
78

89
class ColumnTest extends TestCase
910
{

tests/EditorFormOptionsTest.php renamed to tests/Html/Editor/EditorFormOptionsTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?php
22

3-
namespace Yajra\DataTables\Html\Tests;
3+
namespace Yajra\DataTables\Html\Tests\Html\Editor;
44

55
use PHPUnit\Framework\Attributes\Test;
66
use Yajra\DataTables\Html\Editor\FormOptions;
7+
use Yajra\DataTables\Html\Tests\TestCase;
78

89
class EditorFormOptionsTest extends TestCase
910
{

tests/EditorTest.php renamed to tests/Html/Editor/EditorTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?php
22

3-
namespace Yajra\DataTables\Html\Tests;
3+
namespace Yajra\DataTables\Html\Tests\Html\Editor;
44

55
use PHPUnit\Framework\Attributes\Test;
66
use Yajra\DataTables\Html\Editor\Editor;
77
use Yajra\DataTables\Html\Editor\Fields\Text;
8+
use Yajra\DataTables\Html\Tests\TestCase;
89

910
class EditorTest extends TestCase
1011
{

tests/FieldOptionsTest.php renamed to tests/Html/Editor/Fields/FieldOptionsTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?php
22

3-
namespace Yajra\DataTables\Html\Tests;
3+
namespace Yajra\DataTables\Html\Tests\Html\Editor\Fields;
44

55
use Illuminate\Foundation\Testing\DatabaseTransactions;
66
use Illuminate\Support\Facades\DB;
77
use PHPUnit\Framework\Attributes\Test;
88
use Yajra\DataTables\Html\Editor\Fields\Options;
99
use Yajra\DataTables\Html\Tests\Models\User;
10+
use Yajra\DataTables\Html\Tests\TestCase;
1011

1112
class FieldOptionsTest extends TestCase
1213
{

tests/FieldTest.php renamed to tests/Html/Editor/Fields/FieldTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?php
22

3-
namespace Yajra\DataTables\Html\Tests;
3+
namespace Yajra\DataTables\Html\Tests\Html\Editor\Fields;
44

55
use PHPUnit\Framework\Attributes\Test;
66
use Yajra\DataTables\Html\Editor\Fields;
77
use Yajra\DataTables\Html\Tests\Models\User;
8+
use Yajra\DataTables\Html\Tests\TestCase;
89

910
class FieldTest extends TestCase
1011
{

0 commit comments

Comments
 (0)