66
77class FilterPillData
88{
9+ public string $ separatedValues = '' ;
10+
911 public function __construct (
12+ protected string $ filterKey ,
1013 protected string $ filterPillTitle ,
11- protected string $ filterSelectName ,
1214 protected string |array |null $ filterPillValue ,
1315 protected string $ separator ,
1416 public bool $ isAnExternalLivewireFilter ,
1517 public bool $ hasCustomPillBlade ,
1618 protected ?string $ customPillBlade ,
1719 protected array $ filterPillsItemAttributes ,
18- protected ?string $ separatedValues ,
1920 protected bool $ renderPillsAsHtml ,
2021 protected bool $ watchForEvents ,
21- protected array $ customResetButtonAttributes , ) {}
22+ protected array $ customResetButtonAttributes ,
23+ protected bool $ renderPillsTitleAsHtml ) {}
2224
23- public static function make (string $ filterPillTitle , string $ filterSelectName , string |array |null $ filterPillValue , string $ separator = ', ' , bool $ isAnExternalLivewireFilter = false , bool $ hasCustomPillBlade = false , ?string $ customPillBlade = null , array $ filterPillsItemAttributes = [], ? string $ separatedValues = null , bool $ renderPillsAsHtml = false , bool $ watchForEvents = false , array $ customResetButtonAttributes = []): FilterPillData
25+ public static function make (string $ filterKey , string $ filterPillTitle , string |array |null $ filterPillValue , string $ separator = ', ' , bool $ isAnExternalLivewireFilter = false , bool $ hasCustomPillBlade = false , ?string $ customPillBlade = null , array $ filterPillsItemAttributes = [], bool $ renderPillsAsHtml = false , bool $ watchForEvents = false , array $ customResetButtonAttributes = [], bool $ renderPillsTitleAsHtml = false ): FilterPillData
2426 {
2527 if ($ isAnExternalLivewireFilter ) {
2628 $ watchForEvents = true ;
2729 }
2830
29- return new self ($ filterPillTitle , $ filterSelectName , $ filterPillValue , $ separator , $ isAnExternalLivewireFilter , $ hasCustomPillBlade , $ customPillBlade , $ filterPillsItemAttributes , $ separatedValues , $ renderPillsAsHtml , $ watchForEvents , $ customResetButtonAttributes );
31+ return new self ($ filterKey , $ filterPillTitle , $ filterPillValue , $ separator , $ isAnExternalLivewireFilter , $ hasCustomPillBlade , $ customPillBlade , $ filterPillsItemAttributes , $ renderPillsAsHtml , $ watchForEvents , $ customResetButtonAttributes, $ renderPillsTitleAsHtml );
3032 }
3133
3234 public function getTitle (): string
3335 {
3436 return $ this ->filterPillTitle ;
3537 }
3638
37- public function getSelectName (): string
39+ public function getPillValue (): array | string | null
3840 {
39- return $ this ->filterSelectName ;
41+ return $ this ->filterPillValue ;
4042 }
4143
42- public function getPillValue (): array | string | null
44+ public function getHasCustomPillBlade (): bool
4345 {
44- return $ this ->filterPillValue ;
46+ return $ this ->hasCustomPillBlade ?? false ;
4547 }
4648
47- public function isPillValueAnArray (): bool
49+ public function getCustomPillBlade (): ? string
4850 {
49- return ! is_null ( $ this ->filterPillValue ) && is_array ( $ this -> filterPillValue ) ;
51+ return $ this ->customPillBlade ;
5052 }
5153
52- public function getSeparatedPillValue (): array | string | null
54+ public function getCustomResetButtonAttributes (): array
5355 {
54- if ($ this ->isPillValueAnArray ()) {
55- return implode ($ this ->getSeparator (), $ this ->getPillValue ());
56- } else {
57- return $ this ->getPillValue ();
58- }
56+ return $ this ->customResetButtonAttributes ?? [];
5957 }
6058
61- public function getValueFromPillData (): array | string | null
59+ public function getIsAnExternalLivewireFilter (): int
6260 {
63- if ($ this ->isPillValueAnArray ()) {
64- return implode ($ this ->getSeparator (), $ this ->getPillValue ());
65- } else {
66- return $ this ->getPillValue ();
67- }
61+ return intval ($ this ->isAnExternalLivewireFilter ?? false );
6862 }
6963
70- public function getHasCustomPillBlade (): bool
64+ public function getSeparator (): string
7165 {
72- return $ this ->hasCustomPillBlade ?? false ;
66+ return $ this ->separator ?? ' , ' ;
7367 }
7468
75- public function getCustomPillBlade (): ? string
69+ public function shouldUsePillsAsHtml (): int
7670 {
77- return $ this ->customPillBlade ;
71+ return intval ( $ this ->renderPillsAsHtml ?? false ) ;
7872 }
7973
80- public function getIsAnExternalLivewireFilter (): int
74+ public function shouldUsePillsTitleAsHtml (): int
8175 {
82- return intval ($ this ->isAnExternalLivewireFilter ?? false );
76+ return intval ($ this ->renderPillsTitleAsHtml ?? false );
8377 }
8478
85- public function getSeparator (): string
79+ public function shouldWatchForEvents (): int
8680 {
87- return $ this ->separator ?? ' , ' ;
81+ return intval ( $ this ->watchForEvents ?? false ) ;
8882 }
8983
90- public function getSeparatedValues (): string
84+ public function isPillValueAnArray (): bool
9185 {
92- return $ this ->separatedValues ?? $ this ->getSeparatedPillValue ( );
86+ return ! is_null ( $ this ->filterPillValue ) && is_array ( $ this ->filterPillValue );
9387 }
9488
95- public function getFilterPillsItemAttributes (): array
89+ public function getSeparatedPillValue (): ? string
9690 {
97- return array_merge (['default ' => true , 'default-colors ' => true , 'default-styling ' => true , 'default-text ' => true ], $ this ->filterPillsItemAttributes );
91+ if ($ this ->isPillValueAnArray ()) {
92+ return implode ($ this ->getSeparator (), $ this ->getPillValue ());
93+ } else {
94+ return $ this ->getPillValue ();
95+ }
9896 }
9997
100- public function shouldUsePillsAsHtml (): int
98+ public function getSafeSeparatedPillValue (): ? string
10199 {
102- return intval ($ this ->renderPillsAsHtml ?? false );
100+ $ string = $ this ->getSeparatedPillValue ();
101+
102+ return htmlentities ($ string , ENT_QUOTES , 'UTF-8 ' );
103+
103104 }
104105
105- public function shouldWatchForEvents (): int
106+ public function getFilterPillsItemAttributes (): array
106107 {
107- return intval ( $ this -> watchForEvents ?? false );
108+ return array_merge ([ ' default ' => true , ' default-colors ' => true , ' default-styling ' => true , ' default-text ' => true ], $ this -> filterPillsItemAttributes );
108109 }
109110
110- public function getFilterPillDisplayData (): ComponentAttributeBag
111+ public function getFilterPillDisplayDataArray (): array
111112 {
113+ $ array = [];
112114 if ($ this ->getIsAnExternalLivewireFilter ()) {
113- return $ this ->getExternalFilterPillDisplayData ( );
115+ return $ this ->getExternalFilterPillDisplayDataArray ( $ array );
114116 }
115117
116- return $ this ->getInternalFilterPillDisplayData ( );
118+ return $ this ->getInternalFilterPillDisplayDataArray ( $ array );
117119 }
118120
119- public function getInternalFilterPillDisplayData ( ): ComponentAttributeBag
121+ public function getExternalFilterPillDisplayDataArray ( array $ array = [] ): array
120122 {
121- return new ComponentAttributeBag ([
122- 'x-data ' => "{ internalDisplayString: ''} " ,
123- 'x-init ' => "internalDisplayString = updatePillValues(' " .$ this ->getSeparatedValues ()."'); " ,
124- $ this ->shouldUsePillsAsHtml () ? 'x-html ' : 'x-text ' => 'internalDisplayString ' ,
125- ]);
123+ $ array [$ this ->shouldUsePillsAsHtml () ? 'x-html ' : 'x-text ' ] = 'displayString ' ;
124+
125+ return $ array ;
126126 }
127127
128- public function getExternalFilterPillDisplayData ( ): ComponentAttributeBag
128+ public function getInternalFilterPillDisplayDataArray ( array $ array = [] ): array
129129 {
130- return new ComponentAttributeBag ([
131- $ this ->shouldUsePillsAsHtml () ? 'x-html ' : 'x-text ' => 'displayString ' ,
132- ]);
130+
131+ $ array ['x-data ' ] = "{ internalDisplayString: ''} " ;
132+ $ array ['x-init ' ] = 'internalDisplayString = updatePillValues( ' .json_encode ($ this ->getSafeSeparatedPillValue ()).') ' ;
133+ $ array [$ this ->shouldUsePillsAsHtml () ? 'x-html ' : 'x-text ' ] = 'internalDisplayString ' ;
134+
135+ return $ array ;
133136 }
134137
135- public function getPillSetupData ( string $ filterKey = '' , bool $ shouldWatch = false ): array
138+ public function getFilterTitleDisplayDataArray ( array $ array = [] ): array
136139 {
137- $ array = array_merge ([ ' filterKey ' => $ filterKey , ' watchForEvents ' => $ shouldWatch ], $ this -> toArray ()) ;
140+ $ array[ $ this -> shouldUsePillsTitleAsHtml () ? ' x-html ' : ' x-text ' ] = " localFilterTitle + ': ' " ;
138141
139142 return $ array ;
140143 }
141144
142- public function getCustomResetButtonAttributes ( ): array
145+ public function getPillSetupData ( string $ filterKey = '' , bool $ shouldWatch = false ): array
143146 {
144- return $ this ->customResetButtonAttributes ?? [];
147+ $ array = array_merge (['filterKey ' => $ filterKey , 'watchForEvents ' => $ shouldWatch ], $ this ->toArray ());
148+
149+ return $ array ;
145150 }
146151
147152 public function getCalculatedCustomResetButtonAttributes (string $ filterKey , array $ filterPillsResetFilterButtonAttributes ): array
@@ -163,16 +168,17 @@ public function getCalculatedCustomResetButtonAttributes(string $filterKey, arra
163168 public function toArray (): array
164169 {
165170 return [
171+ 'filterKey ' => $ this ->filterKey ,
166172 'filterPillTitle ' => $ this ->getTitle (),
167- 'filterSelectName ' => $ this ->getSelectName (),
168173 'filterPillValue ' => $ this ->getPillValue (),
169174 'isAnExternalLivewireFilter ' => $ this ->getIsAnExternalLivewireFilter (),
170175 'hasCustomPillBlade ' => $ this ->getHasCustomPillBlade (),
171176 'customPillBlade ' => $ this ->getCustomPillBlade (),
172177 'separator ' => $ this ->getSeparator (),
178+ 'separatedValues ' => $ this ->getSafeSeparatedPillValue (),
173179 'filterPillsItemAttributes ' => $ this ->getFilterPillsItemAttributes (),
174- 'separatedValues ' => $ this ->getSeparatedValues (),
175180 'renderPillsAsHtml ' => $ this ->shouldUsePillsAsHtml (),
181+ 'renderPillsTitleAsHtml ' => $ this ->shouldUsePillsTitleAsHtml (),
176182 'watchForEvents ' => $ this ->shouldWatchForEvents (),
177183 ];
178184 }
0 commit comments