66
77class TimezoneSelect extends Select
88{
9- public null |string $ placeholder ;
10-
119 public function __construct (
12- public null | string $ name = null ,
13- public null | string $ id = null ,
10+ public null | string $ name = null ,
11+ public null | string $ id = null ,
1412 public mixed $ value = null ,
1513 public bool $ multiple = false ,
16- public null | string $ maxWidth = null ,
14+ public null | string $ maxWidth = null , // Native only
1715 bool $ showErrors = true ,
18- $ leadingAddon = false ,
19- $ inlineAddon = false ,
20- $ inlineAddonPadding = self ::DEFAULT_INLINE_ADDON_PADDING ,
21- $ leadingIcon = false ,
22- $ trailingAddon = false ,
23- $ trailingAddonPadding = self ::DEFAULT_TRAILING_ADDON_PADDING ,
24- $ trailingIcon = false ,
25- public bool | array | string | null $ only = null ,
16+ $ leadingAddon = false , // Native only
17+ $ inlineAddon = false , // Native only
18+ $ inlineAddonPadding = self ::DEFAULT_INLINE_ADDON_PADDING , // Native only
19+ $ leadingIcon = false , // Native only
20+ $ trailingAddon = false , // Native only
21+ $ trailingAddonPadding = self ::DEFAULT_TRAILING_ADDON_PADDING , // Native only
22+ $ trailingIcon = false , // Native only
23+ public bool | array | string | null $ only = null ,
2624 public bool $ useCustomSelect = false ,
27- public bool $ filterable = true ,
25+ public bool $ searchable = true ,
2826 public bool $ optional = false ,
29- null |string $ placeholder = ' form-components::messages.timezone_select_placeholder ' ,
30- public null | string $ containerClass = null ,
27+ public bool | null |string $ placeholder = null ,
28+ public null | string $ containerClass = null , // Native only
3129 public $ extraAttributes = '' ,
32- public $ after = null ,
30+ public $ after = null , // Native only
31+ public int $ minSelected = 1 ,
32+ public null |int $ maxSelected = null ,
33+ public bool $ disabled = false ,
34+ public null |string $ clearIcon = null ,
35+ public null |bool $ showCheckbox = null ,
36+ public bool $ autofocus = false ,
3337 ) {
3438 parent ::__construct (
3539 name: $ name ,
@@ -50,19 +54,45 @@ public function __construct(
5054 );
5155
5256 $ this ->only = is_null ($ only ) ? config ('form-components.timezone_subset ' , false ) : $ only ;
53- $ this ->placeholder = __ ($ placeholder );
57+
58+ $ this ->resolveLang ();
5459 }
5560
5661 public function optionsForCustomSelect (): array
5762 {
58- return collect (app ('fc-timezone ' )->only ($ this ->only )->all ())
63+ $ groups = app ('fc-timezone ' )->only ($ this ->only )->all ();
64+ $ options = [];
65+
66+ foreach ($ groups as $ regionName => $ timezones ) {
67+ $ options [] = [
68+ 'name ' => $ regionName ,
69+ 'is_opt_group ' => true ,
70+ ];
71+
72+ $ options = array_merge ($ options , collect ($ timezones )->map (fn ($ id , $ name ) => compact ('id ' , 'name ' ))->values ()->toArray ());
73+ }
74+
75+ return $ options ;
76+
77+ $ opts = collect (app ('fc-timezone ' )->only ($ this ->only )->all ())
5978 ->map (function (array $ timezones , string $ region ) {
6079 return [
61- 'label ' => $ region ,
62- 'options ' => collect ($ timezones )->map (fn (string $ text , string $ value ) => compact ('value ' , 'text ' ))->values ()->toArray (),
80+ 'name ' => $ region ,
81+ 'is_opt_group ' => true ,
82+ 'options ' => collect ($ timezones )->map (fn (string $ name , string $ id ) => compact ('id ' , 'name ' ))->values ()->toArray (),
6383 ];
6484 })
6585 ->values ()
86+ ->flatten (1 )
6687 ->toArray ();
88+
89+ return $ opts ;
90+ }
91+
92+ protected function resolveLang (): void
93+ {
94+ if ($ this ->placeholder !== false ) {
95+ $ this ->placeholder = $ this ->placeholder ?? __ ('form-components::messages.timezone_select_placeholder ' );
96+ }
6797 }
6898}
0 commit comments