diff --git a/src/Flatpickr.php b/src/Flatpickr.php index 05d26f4..d9755bf 100755 --- a/src/Flatpickr.php +++ b/src/Flatpickr.php @@ -7,24 +7,33 @@ class Flatpickr extends Field { protected string $view = 'filament-flatpickr::flatpickr'; + protected bool $monthSelect = false; + protected bool $weekSelect = false; + protected bool $rangePicker = false; + protected bool $multiplePicker = false; + protected bool $altInput = true; + protected ?string $altFormat = 'F j, Y'; + protected bool $enableTime = false; + protected ?string $dateFormat = 'Y-m-d'; - protected ?string $theme; + protected ?string $theme; /** - * @param bool $weekSelect + * @param bool $weekSelect * @return Flatpickr */ public function weekSelect(bool $weekSelect = true): Flatpickr { $this->weekSelect = $weekSelect; + return $this; } @@ -37,12 +46,13 @@ public function isWeekSelect(): bool } /** - * @param bool $rangePicker + * @param bool $rangePicker * @return Flatpickr */ public function rangePicker(bool $rangePicker = true): Flatpickr { $this->rangePicker = $rangePicker; + return $this; } @@ -55,12 +65,13 @@ public function isRangePicker(): bool } /** - * @param bool $multiplePicker + * @param bool $multiplePicker * @return Flatpickr */ public function multiplePicker(bool $multiplePicker = true): Flatpickr { $this->multiplePicker = $multiplePicker; + return $this; } @@ -75,18 +86,19 @@ public function isMultiplePicker(): bool protected function setUp(): void { parent::setUp(); - $theme = config('filament-flatpickr.default_theme','default'); + $theme = config('filament-flatpickr.default_theme', 'default'); $this->theme($theme); $this->reactive(); } /** - * @param bool $monthSelect + * @param bool $monthSelect * @return Flatpickr */ public function monthSelect(?bool $monthSelect = true): Flatpickr { $this->monthSelect = $monthSelect; + return $this; } @@ -99,12 +111,13 @@ public function isMonthSelect(): bool } /** - * @param bool $altInput + * @param bool $altInput * @return Flatpickr */ public function altInput(bool $altInput = true): Flatpickr { $this->altInput = $altInput; + return $this; } @@ -117,7 +130,7 @@ public function isAltInput(): bool } /** - * @param bool $enableTime + * @param bool $enableTime * @return Flatpickr */ public function enableTime(bool $enableTime = true): Flatpickr @@ -128,6 +141,7 @@ public function enableTime(bool $enableTime = true): Flatpickr $this->altInput(false); $this->altFormat('Z'); } + return $this; } @@ -140,12 +154,13 @@ public function isEnableTime(): bool } /** - * @param string $dateFormat + * @param string $dateFormat * @return Flatpickr */ public function dateFormat(string $dateFormat): Flatpickr { $this->dateFormat = $dateFormat; + return $this; } @@ -158,12 +173,13 @@ public function getDateFormat(): ?string } /** - * @param string $altFormat + * @param string $altFormat * @return Flatpickr */ public function altFormat(string $altFormat): Flatpickr { $this->altFormat = $altFormat; + return $this; } @@ -176,14 +192,17 @@ public function getAltFormat(): ?string } /** - * @param string $theme + * @param string $theme * @description Possible values: 'default','dark','material_blue','material_green','material_red','material_orange','airbnb','confetti' + * * @see https://flatpickr.js.org/themes/ + * * @return Flatpickr */ public function theme(string $theme): Flatpickr { $this->theme = $theme; + return $this; } diff --git a/src/FlatpickrServiceProvider.php b/src/FlatpickrServiceProvider.php index e35787e..24cbb49 100644 --- a/src/FlatpickrServiceProvider.php +++ b/src/FlatpickrServiceProvider.php @@ -2,25 +2,23 @@ namespace Savannabits\Flatpickr; -use Filament\FilamentServiceProvider; use Filament\PluginServiceProvider; -use Illuminate\Foundation\Vite; use Spatie\LaravelPackageTools\Package; -use Savannabits\Flatpickr\Commands\FlatpickrCommand; class FlatpickrServiceProvider extends PluginServiceProvider { protected array $styles = [ - 'flatpickr-css' => __DIR__.'/../public/dist/flatpickr.min.css', - 'month-select-style' =>__DIR__.'/../public/dist/plugins/monthSelect/style.css', - 'confirm-date-style' =>__DIR__.'/../public/dist/plugins/confirmDate/confirmDate.css', + 'flatpickr-css' => __DIR__.'/../public/dist/flatpickr.min.css', + 'month-select-style' => __DIR__.'/../public/dist/plugins/monthSelect/style.css', + 'confirm-date-style' => __DIR__.'/../public/dist/plugins/confirmDate/confirmDate.css', ]; + protected array $beforeCoreScripts = [ - 'flatpickr-core' => __DIR__.'/../public/dist/flatpickr.min.js', - 'flatpickr-range-plugin' => __DIR__.'/../public/dist/plugins/rangePlugin.js', - 'flatpickr-month-select' => __DIR__.'/../public/dist/plugins/monthSelect/index.js', - 'flatpickr-week-select' => __DIR__.'/../public/dist/plugins/weekSelect/weekSelect.js', - 'flatpickr-confirm-date' => __DIR__.'/../public/dist/plugins/confirmDate/confirmDate.js', + 'flatpickr-core' => __DIR__.'/../public/dist/flatpickr.min.js', + 'flatpickr-range-plugin' => __DIR__.'/../public/dist/plugins/rangePlugin.js', + 'flatpickr-month-select' => __DIR__.'/../public/dist/plugins/monthSelect/index.js', + 'flatpickr-week-select' => __DIR__.'/../public/dist/plugins/weekSelect/weekSelect.js', + 'flatpickr-confirm-date' => __DIR__.'/../public/dist/plugins/confirmDate/confirmDate.js', ]; protected array $scripts = [ @@ -38,6 +36,7 @@ public function configurePackage(Package $package): void ->hasConfigFile() ->hasViews(); } + protected function getScriptData(): array { return [];