Skip to content

Commit 32f8a6e

Browse files
committed
feat: add tags field support
1 parent 08ccb11 commit 32f8a6e

File tree

1 file changed

+146
-0
lines changed

1 file changed

+146
-0
lines changed

src/Html/Editor/Fields/Tags.php

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
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+
* @param array {
46+
* addButton?: string
47+
* inputPlaceholder?: string
48+
* noResults?: string
49+
* title?: string
50+
* placeholder?: string
51+
* } $i18n
52+
* @see https://editor.datatables.net/reference/field/tags#i18n
53+
*/
54+
public function i18n(array $i18n): static
55+
{
56+
$this->attributes['i18n'] = array_merge($this->attributes['i18n'] ?? [], $i18n);
57+
58+
return $this;
59+
}
60+
61+
/**
62+
* @see https://editor.datatables.net/reference/field/tags#i18n
63+
*/
64+
public function addButton(string $text): static
65+
{
66+
return $this->i18n(['addButton' => $text]);
67+
}
68+
69+
/**
70+
* @see https://editor.datatables.net/reference/field/tags#i18n
71+
*/
72+
public function inputPlaceholder(string $text): static
73+
{
74+
return $this->i18n(['inputPlaceholder' => $text]);
75+
}
76+
77+
/**
78+
* @see https://editor.datatables.net/reference/field/tags#i18n
79+
*/
80+
public function noResults(string $text): static
81+
{
82+
return $this->i18n(['noResults' => $text]);
83+
}
84+
85+
/**
86+
* @see https://editor.datatables.net/reference/field/tags#i18n
87+
*/
88+
public function title(string $text): static
89+
{
90+
return $this->i18n(['title' => $text]);
91+
}
92+
93+
/**
94+
* @see https://editor.datatables.net/reference/field/tags#i18n
95+
*/
96+
public function placeholder(string $text): static
97+
{
98+
return $this->i18n(['placeholder' => $text]);
99+
}
100+
101+
/**
102+
* @see https://editor.datatables.net/reference/field/tags#limit
103+
*/
104+
public function limit(int $limit): static
105+
{
106+
$this->attributes['limit'] = $limit;
107+
108+
return $this;
109+
}
110+
111+
/**
112+
* @see https://editor.datatables.net/reference/field/tags#multiple
113+
*/
114+
public function multiple(bool $multiple = true): static
115+
{
116+
$this->attributes['multiple'] = $multiple;
117+
118+
return $this;
119+
}
120+
121+
/**
122+
* @see https://editor.datatables.net/reference/field/tags#options
123+
*/
124+
public function options(array|Arrayable $options): static
125+
{
126+
return parent::options($options);
127+
}
128+
129+
/**
130+
* @see https://editor.datatables.net/reference/field/tags#separator
131+
*/
132+
public function separator(string $separator = ','): static
133+
{
134+
return parent::separator($separator);
135+
}
136+
137+
/**
138+
* @see https://editor.datatables.net/reference/field/tags#unique
139+
*/
140+
public function unique(bool $unique = true): static
141+
{
142+
$this->attributes['unique'] = $unique;
143+
144+
return $this;
145+
}
146+
}

0 commit comments

Comments
 (0)