diff --git a/README.md b/README.md index 2ebf653..8600850 100644 --- a/README.md +++ b/README.md @@ -24,35 +24,29 @@ You can install the package via composer: composer require guava/filament-icon-picker ``` -[//]: # () -[//]: # (You can publish the config file with:) - -[//]: # () -[//]: # (```bash) +You can publish the config file with: -[//]: # (php artisan vendor:publish --tag=":package_slug-config") - -[//]: # (```) +```bash +php artisan vendor:publish --tag="filament-icon-picker-config") +``` -[//]: # (Optionally, you can publish the views using) +This is the contents of the published config file: -[//]: # () -[//]: # (```bash) +```php -[//]: # (php artisan vendor:publish --tag=":package_slug-views") + null, -[//]: # (This is the contents of the published config file:) + 'columns' => 1, -[//]: # () -[//]: # (```php) + 'layout' => \Guava\FilamentIconPicker\Layout::FLOATING, -[//]: # (return [) +]; -[//]: # (];) -[//]: # (```) +``` ## Usage @@ -103,7 +97,7 @@ public static function table(Table $table): Table #### Columns By default, a single-column icon picker will be displayed. -You can customize the amount of columns using `->columns()` like this: +You can customize the amount of columns via the `icon-picker.columns` configuration or using the `->columns()` option like this: ```php // Display 3 columns from lg and above IconPicker::make('icon') @@ -125,7 +119,7 @@ IconPicker::make('icon') #### Sets -By default, the plugin will use the heroicons set. If you have installed [additional icon sets](https://github.com/blade-ui-kit/blade-icons#icon-packages), you add them using this option: +By default, the plugin will use all available [blade icon sets](https://github.com/blade-ui-kit/blade-icons#icon-packages) installed. If you want to use only specific icon sets, you can change the default via the `icon-picker.sets` configuration or on a case-by-case basis: ```php // Search both herocions and fontawesome icons IconPicker::make('icon') diff --git a/config/icon-picker.php b/config/icon-picker.php new file mode 100644 index 0000000..b59981c --- /dev/null +++ b/config/icon-picker.php @@ -0,0 +1,63 @@ + null, +// example: +// 'sets' => 'heroicons', +// 'sets' => [ +// 'heroicons', +// 'fontawesome-solid', +// ], + + /* + |-------------------------------------------------------------------------- + | Default Columns + |-------------------------------------------------------------------------- + | + | This is the default value for the columns configuration. It is used by + | every icon picker, when not set explicitly. + | + | Can be either an integer from 1 - 12 or an array of integers + | with breakpoints (default, sm, md, lg, xl, 2xl) as the key. + | + */ + 'columns' => 1, +// example: +// 'columns' => [ +// 'default' => 1, +// 'lg' => 3, +// '2xl' => 5, +// ], + + /* + |-------------------------------------------------------------------------- + | Default Layout + |-------------------------------------------------------------------------- + | + | This is the default value for the layout configuration. It is used by + | every icon picker, when not set explicitly. + | + | FLOATING: The select will behave the same way as the default filament + | select. It will show when selected and hide when clicked outside. + | + | ON_TOP: The select options will always be visible in a catalogue-like + | grid view. + | + */ + 'layout' => \Guava\FilamentIconPicker\Layout::FLOATING, + +]; diff --git a/src/FilamentIconPickerServiceProvider.php b/src/FilamentIconPickerServiceProvider.php index 2088be3..4e808a8 100644 --- a/src/FilamentIconPickerServiceProvider.php +++ b/src/FilamentIconPickerServiceProvider.php @@ -15,6 +15,7 @@ public function configurePackage(Package $package): void $package ->name('filament-icon-picker') ->hasViews() + ->hasConfigFile('icon-picker') ; } diff --git a/src/Forms/IconPicker.php b/src/Forms/IconPicker.php index ae00da3..0ce8c5a 100644 --- a/src/Forms/IconPicker.php +++ b/src/Forms/IconPicker.php @@ -19,7 +19,7 @@ class IconPicker extends Select protected string $view = 'filament-icon-picker::forms.icon-picker'; - protected array|Closure|null $sets = ['heroicons']; + protected array|Closure|null $sets = null; protected array|Closure|null $allowedIcons = null; protected array|Closure|null $disallowedIcons = null; @@ -36,6 +36,10 @@ protected function setUp(): void { parent::setUp(); + $this->sets(config('icon-picker.sets', null)); + $this->columns(config('icon-picker.columns', 1)); + $this->layout(config('icon-picker.layout', Layout::FLOATING)); + $this->getSearchResultsUsing = function (IconPicker $component, string $search, Collection $icons) { return collect($icons) ->filter(fn(string $icon) => str_contains($icon, $search)) @@ -64,14 +68,14 @@ protected function setUp(): void * @param array|string|Closure|null $sets * @return $this */ - public function sets(array|Closure|string|null $sets): static + public function sets(array|Closure|string|null $sets = null): static { - $this->sets = is_array($sets) ? $sets : [$sets]; + $this->sets = $sets ? (is_string($sets) ? [$sets] : $sets) : null; return $this; } - public function getSets(): array + public function getSets(): ?array { return $this->evaluate($this->sets); } @@ -206,9 +210,11 @@ public function multiple(bool|Closure $condition = true): static private function loadIcons(): Collection { $iconsFactory = App::make(IconFactory::class); - $sets = collect($iconsFactory->all()) - ->filter(fn($value, $key) => in_array($key, $this->getSets())); - + $availableSets = $this->getSets(); + $sets = collect($iconsFactory->all()); + if ($availableSets) { + $sets = $sets->filter(fn($value, $key) => in_array($key, $availableSets)); + } $icons = []; $allowedIcons = $this->getAllowedIcons();