├── .github ├── CONTRIBUTING.md ├── FUNDING.yml ├── SECURITY.md └── workflows │ └── release.yml ├── .gitignore ├── .idea ├── .gitignore ├── laravel-idea.xml ├── misc.xml ├── modules.xml └── vcs.xml ├── LICENSE ├── README.md ├── composer.json ├── composer.lock ├── config └── icon-picker.php ├── dist └── plugin.css ├── package-lock.json ├── package.json ├── postcss.config.js ├── release.config.js ├── resources ├── css │ └── plugin.css └── views │ ├── forms │ └── icon-picker.blade.php │ ├── item.blade.php │ ├── placeholder.blade.php │ └── tables │ └── icon-column.blade.php ├── src ├── FilamentIconPickerServiceProvider.php ├── Forms │ ├── Concerns │ │ └── CanBeCacheable.php │ └── IconPicker.php ├── Layout.php └── Tables │ └── IconColumn.php └── tailwind.config.js /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | Please read and understand the contribution guide before creating an issue or pull request. 6 | 7 | ## Etiquette 8 | 9 | This project is open source, and as such, the maintainers give their free time to build and maintain the source code 10 | held within. They make the code freely available in the hope that it will be of use to other developers. It would be 11 | extremely unfair for them to suffer abuse or anger for their hard work. 12 | 13 | Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the 14 | world that developers are civilized and selfless people. 15 | 16 | It's the duty of the maintainer to ensure that all submissions to the project are of sufficient 17 | quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. 18 | 19 | ## Viability 20 | 21 | When requesting or submitting new features, first consider whether it might be useful to others. Open 22 | source projects are used by many developers, who may have entirely different needs to your own. Think about 23 | whether or not your feature is likely to be used by other users of the project. 24 | 25 | ## Procedure 26 | 27 | Before filing an issue: 28 | 29 | - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. 30 | - Check to make sure your feature suggestion isn't already present within the project. 31 | - Check the pull requests tab to ensure that the bug doesn't have a fix in progress. 32 | - Check the pull requests tab to ensure that the feature isn't already in progress. 33 | 34 | Before submitting a pull request: 35 | 36 | - Check the codebase to ensure that your feature doesn't already exist. 37 | - Check the pull requests to ensure that another person hasn't already submitted the feature or fix. 38 | 39 | ## Requirements 40 | 41 | If the project maintainer has any additional requirements, you will find them listed here. 42 | 43 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer). 44 | 45 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 46 | 47 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 48 | 49 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option. 50 | 51 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 52 | 53 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. 54 | 55 | **Happy coding**! 56 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: LukasFreyCZ 2 | -------------------------------------------------------------------------------- /.github/SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | If you discover any security related issues, please email office@guava.cz instead of using the issue tracker. 4 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | on: 3 | push: 4 | branches: 5 | - main 6 | jobs: 7 | release: 8 | name: Release 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: Checkout 12 | uses: actions/checkout@v2 13 | with: 14 | fetch-depth: 0 15 | - name: Setup Node.js 16 | uses: actions/setup-node@v2 17 | with: 18 | node-version: 'lts/*' 19 | - name: Install dependencies 20 | run: npm ci 21 | - name: Release 22 | env: 23 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 24 | run: npx semantic-release 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | /vendor/ 3 | node_modules/ 4 | npm-debug.log 5 | yarn-error.log 6 | 7 | # Laravel 4 specific 8 | bootstrap/compiled.php 9 | app/storage/ 10 | 11 | # Laravel 5 & Lumen specific 12 | public/storage 13 | public/hot 14 | 15 | # Laravel 5 & Lumen specific with changed public path 16 | public_html/storage 17 | public_html/hot 18 | 19 | storage/*.key 20 | .env 21 | Homestead.yaml 22 | Homestead.json 23 | /.vagrant 24 | .phpunit.result.cache 25 | 26 | .DS_Store 27 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /.idea/laravel-idea.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Lukas Frey 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![icon_picker_banner](https://user-images.githubusercontent.com/10926334/194752395-677e25f6-2878-4652-a95f-ef9c4392c093.png) 2 | 3 | # Filament Icon Picker 4 | 5 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/guava/filament-icon-picker.svg?style=flat-square)](https://packagist.org/packages/guava/filament-icon-picker) 6 | ![Packagist PHP Version](https://img.shields.io/packagist/dependency-v/guava/filament-icon-picker/php?style=flat-square) 7 | [![Total Downloads](https://img.shields.io/packagist/dt/guava/filament-icon-picker.svg?style=flat-square)](https://packagist.org/packages/guava/filament-icon-picker) 8 | 9 | [//]: # ([![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/:vendor_slug/:package_slug/run-tests?label=tests)](https://github.com/:vendor_slug/:package_slug/actions?query=workflow%3Arun-tests+branch%3Amain)) 10 | [//]: # ([![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/LukasFreyCZ/filament-icon-picker/Check%20&%20fix%20styling?label=code%20style)](https://github.com/LukasFreyCZ/filament-icon-picker/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain)) 11 | 12 | This plugin adds a new icon picker form field and a corresponding table column. You can use it to select from any blade-icons kit that you have installed. By default, heroicons are supported since it is shipped with Filament. 13 | 14 | This can be useful for when you want to customize icons rendered on your frontend, if you want your users to be able to customize navigation icons, add small icons to their models for easy recognition and similar. 15 | 16 | 17 | 18 | https://user-images.githubusercontent.com/10926334/194676916-446eb432-c859-4f94-bf52-2b1ee4416a93.mov 19 | 20 | 23 | 24 | 25 | 26 | ## Installation 27 | 28 | You can install the package via composer: 29 | 30 | **Filament v3:** 31 | ```bash 32 | composer require guava/filament-icon-picker:"^2.0" 33 | ``` 34 | 35 | **Filament v2:** 36 | ```bash 37 | composer require guava/filament-icon-picker:"^1.0" 38 | ``` 39 | 40 | You can publish the config file with: 41 | 42 | ```bash 43 | php artisan vendor:publish --tag="filament-icon-picker-config" 44 | ``` 45 | 46 | This is the contents of the published config file: 47 | 48 | ```php 49 | 50 | null, 54 | 55 | 'columns' => 1, 56 | 57 | 'layout' => \Guava\FilamentIconPicker\Layout::FLOATING, 58 | 59 | 'cache' => [ 60 | 'enabled' => true, 61 | 'duration' => '7 days', 62 | ], 63 | 64 | ]; 65 | ``` 66 | 67 | ## Usage 68 | 69 | ### Basic Usage 70 | Usage in Admin Panel: 71 | ```php 72 | use Guava\FilamentIconPicker\Forms\IconPicker; 73 | 74 | public static function form(Form $form): Form 75 | { 76 | return $form->schema([ 77 | IconPicker::make('icon'), 78 | ]); 79 | } 80 | ``` 81 | 82 | 83 | Usage in Livewire Component: 84 | ```php 85 | use Guava\FilamentIconPicker\Forms\IconPicker; 86 | 87 | protected function getFormSchema(): array 88 | { 89 | return [ 90 | IconPicker::make('icon'), 91 | ]; 92 | } 93 | ``` 94 | 95 | 96 | Usage in Tables: 97 | ```php 98 | // Make sure this is the correct import, not the filament one 99 | use Guava\FilamentIconPicker\Tables\IconColumn; 100 | 101 | public static function table(Table $table): Table 102 | { 103 | return $table 104 | ->columns([ 105 | IconColumn::make('icon'), 106 | ]) 107 | // ... 108 | ; 109 | } 110 | ``` 111 | 112 | The field's state returns the selected identifier of the icon. 113 | 114 | Assuming we saved the icon on our `$category` model under `$icon`, you can render it in your blade view using: 115 | ```php 116 | 117 | ``` 118 | More information on rendering the icon on the [blade-icons github](https://github.com/blade-ui-kit/blade-icons#default-component). 119 | 120 | ### Options 121 | 122 | #### Columns 123 | By default, a single-column icon picker will be displayed. 124 | You can customize the amount of columns via the `icon-picker.columns` configuration or using the `->columns()` option like this: 125 | ```php 126 | // Display 3 columns from lg and above 127 | IconPicker::make('icon') 128 | ->columns(3); 129 | 130 | // More detailed customization 131 | // This will display 1 column from xs to md, 3 columns from lg to xl and 5 columns from 2xl and above 132 | IconPicker::make('icon') 133 | ->columns([ 134 | 'default' => 1, 135 | 'lg' => 3, 136 | '2xl' => 5, 137 | ]); 138 | ``` 139 | 1 Column | 3 Columns 140 | :-------------------------:|:-------------------------: 141 | image | image 142 | 143 | 144 | 145 | #### Sets 146 | 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: 147 | ```php 148 | // Search both herocions and fontawesome icons 149 | IconPicker::make('icon') 150 | ->sets(['heroicons', 'fontawesome-solid']); 151 | ``` 152 | 153 | **When installing new sets, please make sure to clear your cache, if you can't find your icons in the icon picker.** 154 | 155 | 156 | #### Allow/Disallow icons 157 | For detailed control over the icons, there are two options available to allow and disallow certain icons. 158 | ```php 159 | // Allow ONLY heroicon-o-user and heroicon-o-users 160 | IconPicker::make('icon') 161 | ->allowIcons(['heroicon-o-user', 'heroicon-o-users']); 162 | ``` 163 | 164 | ```php 165 | // Allow ALL fontawesome icons, EXCEPT fas-user 166 | IconPicker::make('icon') 167 | ->disallowIcons(['fas-user']); 168 | ``` 169 | 170 | 171 | #### Layout 172 | The icon picker comes with two layouts. The default, `Layout::FLOATING` is the standard layout used in Filament Selects. The search results will appear in a pop over window. 173 | 174 | The `Layout::ON_TOP` will render the search results always on the page. 175 | 176 | ```php 177 | // 178 | IconPicker::make('icon') 179 | ->layout(Layout::FLOATING) // default 180 | //or 181 | ->layout(Layout::ON_TOP) 182 | ``` 183 | 184 | #### Custom Item Template 185 | Out of the box, the search results render a preview of the icon and their identifier. 186 | You are free to customize this using the `->itemTemplate()` option: 187 | 188 | ```php 189 | // Render your.blade.template instead of the default template. 190 | // Make sure to pass the $icon as parameter to be able to render it in your view. 191 | IconPicker::make('icon') 192 | ->itemTemplate( 193 | fn($icon) => view('your.blade.template', ['icon' => $icon]) 194 | ); 195 | ``` 196 | 197 | #### Caching 198 | Depending on how many icon packs you use and their size, the loading time 199 | for getting the search results can be high. In order to mitigate this 200 | issue a bit, search results are by default cached (for 7 days). 201 | 202 | You can configure the default caching options for all icon pickers in the configuration file. 203 | 204 | To configure a specific IconPicker, these methods are available: 205 | ```php 206 | IconPicker::make('icon') 207 | // Disable caching 208 | ->cacheable(false) 209 | 210 | // Cache for one hour 211 | ->cacheDuration(3600); 212 | ``` 213 | 214 | [//]: # (## Testing) 215 | 216 | [//]: # () 217 | [//]: # (```bash) 218 | 219 | [//]: # (composer test) 220 | 221 | [//]: # (```) 222 | 223 | ## Changelog 224 | 225 | Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. 226 | 227 | ## Contributing 228 | 229 | Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details. 230 | 231 | ## Security Vulnerabilities 232 | 233 | Please review [our security policy](../../security/policy) on how to report security vulnerabilities. 234 | 235 | ## Credits 236 | 237 | - [Lukas Frey](https://github.com/LukasFreyCZ) 238 | - [All Contributors](../../contributors) 239 | 240 | ## License 241 | 242 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 243 | 244 | ## Other packages 245 | - [Laravel Populator](https://github.com/GuavaCZ/laravel-populator) 246 | - [Filament Drafts](https://github.com/GuavaCZ/filament-drafts) 247 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "guava/filament-icon-picker", 3 | "description": "A filament plugin that adds an icon picker field.", 4 | "type": "library", 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Lukas Frey", 9 | "email": "mail@lukasfrey.cz" 10 | } 11 | ], 12 | "autoload": { 13 | "psr-4": { 14 | "Guava\\FilamentIconPicker\\": "src" 15 | } 16 | }, 17 | "require-dev": { 18 | "orchestra/testbench": "^7.0|^8.0|^9.0" 19 | }, 20 | "require": { 21 | "php": "^8.0", 22 | "filament/filament": "^3.0@stable" 23 | }, 24 | "extra": { 25 | "laravel": { 26 | "providers": [ 27 | "Guava\\FilamentIconPicker\\FilamentIconPickerServiceProvider" 28 | ] 29 | } 30 | }, 31 | "minimum-stability": "dev", 32 | "prefer-stable": true 33 | } 34 | -------------------------------------------------------------------------------- /config/icon-picker.php: -------------------------------------------------------------------------------- 1 | null, 19 | // example: 20 | // 'sets' => 'heroicons', 21 | // 'sets' => [ 22 | // 'heroicons', 23 | // 'fontawesome-solid', 24 | // ], 25 | 26 | /* 27 | |-------------------------------------------------------------------------- 28 | | Default Columns 29 | |-------------------------------------------------------------------------- 30 | | 31 | | This is the default value for the columns configuration. It is used by 32 | | every icon picker, when not set explicitly. 33 | | 34 | | Can be either an integer from 1 - 12 or an array of integers 35 | | with breakpoints (default, sm, md, lg, xl, 2xl) as the key. 36 | | 37 | */ 38 | 'columns' => 1, 39 | // example: 40 | // 'columns' => [ 41 | // 'default' => 1, 42 | // 'lg' => 3, 43 | // '2xl' => 5, 44 | // ], 45 | 46 | /* 47 | |-------------------------------------------------------------------------- 48 | | Default Layout 49 | |-------------------------------------------------------------------------- 50 | | 51 | | This is the default value for the layout configuration. It is used by 52 | | every icon picker, when not set explicitly. 53 | | 54 | | FLOATING: The select will behave the same way as the default filament 55 | | select. It will show when selected and hide when clicked outside. 56 | | 57 | | ON_TOP: The select options will always be visible in a catalogue-like 58 | | grid view. 59 | | 60 | */ 61 | 'layout' => \Guava\FilamentIconPicker\Layout::FLOATING, 62 | 63 | /* 64 | |-------------------------------------------------------------------------- 65 | | Caching 66 | |-------------------------------------------------------------------------- 67 | | 68 | | This section lets you configure the caching option of the plugin. 69 | | 70 | | Since icon packs are often packed with a lots of icons, 71 | | searching through all of them can take quite a lot of time, which is 72 | | why the plugin caches each field with it's configuration and search queries. 73 | | 74 | | This section let's you configure how caching should be done or disable it 75 | | if you wish. 76 | | 77 | */ 78 | 'cache' => [ 79 | 'enabled' => true, 80 | 'duration' => '7 days', 81 | ], 82 | 83 | ]; 84 | -------------------------------------------------------------------------------- /dist/plugin.css: -------------------------------------------------------------------------------- 1 | .filament-icon-picker .choices>.choices__list{padding-left:.5rem;padding-right:.5rem}.filament-icon-picker .choices>.choices__inner>.choices__list.choices__list--single{width:100%}.filament-icon-picker.filament-icon-picker-on_top .choices>.choices__list{visibility:visible;position:relative;padding-left:.5rem;padding-right:.5rem}.filament-icon-picker.filament-icon-picker-on_top .choices>.choices__inner{background-image:none;padding-left:.75rem;padding-right:.75rem}.filament-icon-picker.filament-icon-picker-on_top .choices>.choices__inner>.choices__list.choices__list--single{position:relative;padding-left:0;padding-right:0}.filament-icon-picker.filament-icon-picker-on_top .choices>.choices__inner>.choices__list.choices__list--single .choices__button{position:absolute;margin-right:.5rem}.filament-icon-picker .choices>.choices__list .choices__list{gap:.5rem;padding-bottom:.5rem}.filament-icon-picker .choices>.choices__list .choices__list .choices__item{border-radius:.5rem;border-width:1px;--tw-shadow:0 1px 2px 0 rgba(0,0,0,.05);--tw-shadow-colored:0 1px 2px 0 var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.filament-icon-picker .choices>.choices__list .choices__list .choices__item:hover{cursor:pointer}.filament-icon-picker .choices>.choices__list .choices__list .choices__item.choices__item--disabled,.filament-icon-picker .choices>.choices__list .choices__list .choices__item.has-no-choices,.filament-icon-picker .choices>.choices__list .choices__list .choices__item.has-no-results{border-style:none;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.filament-icon-picker .choices>.choices__list .choices__list{display:grid}.\!h-16{height:4rem!important}.h-12{height:3rem}.w-12{width:3rem}.shrink-0{flex-shrink:0}.grow-0{flex-grow:0}.filament-icon-picker .choices>.choices__list .choices__list .choices__item.choices__item--disabled,.filament-icon-picker .choices>.choices__list .choices__list .choices__item.has-no-choices,.filament-icon-picker .choices>.choices__list .choices__list .choices__item.has-no-results{grid-column:1/-1}.filament-icon-picker[default="1"] .choices>.choices__list .choices__list{grid-template-columns:repeat(1,minmax(0,1fr))}.filament-icon-picker[default="2"] .choices>.choices__list .choices__list{grid-template-columns:repeat(2,minmax(0,1fr))}.filament-icon-picker[default="3"] .choices>.choices__list .choices__list{grid-template-columns:repeat(3,minmax(0,1fr))}.filament-icon-picker[default="4"] .choices>.choices__list .choices__list{grid-template-columns:repeat(4,minmax(0,1fr))}.filament-icon-picker[default="5"] .choices>.choices__list .choices__list{grid-template-columns:repeat(5,minmax(0,1fr))}.filament-icon-picker[default="6"] .choices>.choices__list .choices__list{grid-template-columns:repeat(6,minmax(0,1fr))}.filament-icon-picker[default="7"] .choices>.choices__list .choices__list{grid-template-columns:repeat(7,minmax(0,1fr))}.filament-icon-picker[default="8"] .choices>.choices__list .choices__list{grid-template-columns:repeat(8,minmax(0,1fr))}.filament-icon-picker[default="9"] .choices>.choices__list .choices__list{grid-template-columns:repeat(9,minmax(0,1fr))}.filament-icon-picker[default="10"] .choices>.choices__list .choices__list{grid-template-columns:repeat(10,minmax(0,1fr))}.filament-icon-picker[default="11"] .choices>.choices__list .choices__list{grid-template-columns:repeat(11,minmax(0,1fr))}.filament-icon-picker[default="12"] .choices>.choices__list .choices__list{grid-template-columns:repeat(12,minmax(0,1fr))}@media (min-width:640px){.filament-icon-picker[sm="1"] .choices>.choices__list .choices__list{grid-template-columns:repeat(1,minmax(0,1fr))}.filament-icon-picker[sm="2"] .choices>.choices__list .choices__list{grid-template-columns:repeat(2,minmax(0,1fr))}.filament-icon-picker[sm="3"] .choices>.choices__list .choices__list{grid-template-columns:repeat(3,minmax(0,1fr))}.filament-icon-picker[sm="4"] .choices>.choices__list .choices__list{grid-template-columns:repeat(4,minmax(0,1fr))}.filament-icon-picker[sm="5"] .choices>.choices__list .choices__list{grid-template-columns:repeat(5,minmax(0,1fr))}.filament-icon-picker[sm="6"] .choices>.choices__list .choices__list{grid-template-columns:repeat(6,minmax(0,1fr))}.filament-icon-picker[sm="7"] .choices>.choices__list .choices__list{grid-template-columns:repeat(7,minmax(0,1fr))}.filament-icon-picker[sm="8"] .choices>.choices__list .choices__list{grid-template-columns:repeat(8,minmax(0,1fr))}.filament-icon-picker[sm="9"] .choices>.choices__list .choices__list{grid-template-columns:repeat(9,minmax(0,1fr))}.filament-icon-picker[sm="10"] .choices>.choices__list .choices__list{grid-template-columns:repeat(10,minmax(0,1fr))}.filament-icon-picker[sm="11"] .choices>.choices__list .choices__list{grid-template-columns:repeat(11,minmax(0,1fr))}.filament-icon-picker[sm="12"] .choices>.choices__list .choices__list{grid-template-columns:repeat(12,minmax(0,1fr))}}@media (min-width:768px){.filament-icon-picker[md="1"] .choices>.choices__list .choices__list{grid-template-columns:repeat(1,minmax(0,1fr))}.filament-icon-picker[md="2"] .choices>.choices__list .choices__list{grid-template-columns:repeat(2,minmax(0,1fr))}.filament-icon-picker[md="3"] .choices>.choices__list .choices__list{grid-template-columns:repeat(3,minmax(0,1fr))}.filament-icon-picker[md="4"] .choices>.choices__list .choices__list{grid-template-columns:repeat(4,minmax(0,1fr))}.filament-icon-picker[md="5"] .choices>.choices__list .choices__list{grid-template-columns:repeat(5,minmax(0,1fr))}.filament-icon-picker[md="6"] .choices>.choices__list .choices__list{grid-template-columns:repeat(6,minmax(0,1fr))}.filament-icon-picker[md="7"] .choices>.choices__list .choices__list{grid-template-columns:repeat(7,minmax(0,1fr))}.filament-icon-picker[md="8"] .choices>.choices__list .choices__list{grid-template-columns:repeat(8,minmax(0,1fr))}.filament-icon-picker[md="9"] .choices>.choices__list .choices__list{grid-template-columns:repeat(9,minmax(0,1fr))}.filament-icon-picker[md="10"] .choices>.choices__list .choices__list{grid-template-columns:repeat(10,minmax(0,1fr))}.filament-icon-picker[md="11"] .choices>.choices__list .choices__list{grid-template-columns:repeat(11,minmax(0,1fr))}.filament-icon-picker[md="12"] .choices>.choices__list .choices__list{grid-template-columns:repeat(12,minmax(0,1fr))}}@media (min-width:1024px){.filament-icon-picker[lg="1"] .choices>.choices__list .choices__list{grid-template-columns:repeat(1,minmax(0,1fr))}.filament-icon-picker[lg="2"] .choices>.choices__list .choices__list{grid-template-columns:repeat(2,minmax(0,1fr))}.filament-icon-picker[lg="3"] .choices>.choices__list .choices__list{grid-template-columns:repeat(3,minmax(0,1fr))}.filament-icon-picker[lg="4"] .choices>.choices__list .choices__list{grid-template-columns:repeat(4,minmax(0,1fr))}.filament-icon-picker[lg="5"] .choices>.choices__list .choices__list{grid-template-columns:repeat(5,minmax(0,1fr))}.filament-icon-picker[lg="6"] .choices>.choices__list .choices__list{grid-template-columns:repeat(6,minmax(0,1fr))}.filament-icon-picker[lg="7"] .choices>.choices__list .choices__list{grid-template-columns:repeat(7,minmax(0,1fr))}.filament-icon-picker[lg="8"] .choices>.choices__list .choices__list{grid-template-columns:repeat(8,minmax(0,1fr))}.filament-icon-picker[lg="9"] .choices>.choices__list .choices__list{grid-template-columns:repeat(9,minmax(0,1fr))}.filament-icon-picker[lg="10"] .choices>.choices__list .choices__list{grid-template-columns:repeat(10,minmax(0,1fr))}.filament-icon-picker[lg="11"] .choices>.choices__list .choices__list{grid-template-columns:repeat(11,minmax(0,1fr))}.filament-icon-picker[lg="12"] .choices>.choices__list .choices__list{grid-template-columns:repeat(12,minmax(0,1fr))}}@media (min-width:1280px){.filament-icon-picker[xl="1"] .choices>.choices__list .choices__list{grid-template-columns:repeat(1,minmax(0,1fr))}.filament-icon-picker[xl="2"] .choices>.choices__list .choices__list{grid-template-columns:repeat(2,minmax(0,1fr))}.filament-icon-picker[xl="3"] .choices>.choices__list .choices__list{grid-template-columns:repeat(3,minmax(0,1fr))}.filament-icon-picker[xl="4"] .choices>.choices__list .choices__list{grid-template-columns:repeat(4,minmax(0,1fr))}.filament-icon-picker[xl="5"] .choices>.choices__list .choices__list{grid-template-columns:repeat(5,minmax(0,1fr))}.filament-icon-picker[xl="6"] .choices>.choices__list .choices__list{grid-template-columns:repeat(6,minmax(0,1fr))}.filament-icon-picker[xl="7"] .choices>.choices__list .choices__list{grid-template-columns:repeat(7,minmax(0,1fr))}.filament-icon-picker[xl="8"] .choices>.choices__list .choices__list{grid-template-columns:repeat(8,minmax(0,1fr))}.filament-icon-picker[xl="9"] .choices>.choices__list .choices__list{grid-template-columns:repeat(9,minmax(0,1fr))}.filament-icon-picker[xl="10"] .choices>.choices__list .choices__list{grid-template-columns:repeat(10,minmax(0,1fr))}.filament-icon-picker[xl="11"] .choices>.choices__list .choices__list{grid-template-columns:repeat(11,minmax(0,1fr))}.filament-icon-picker[xl="12"] .choices>.choices__list .choices__list{grid-template-columns:repeat(12,minmax(0,1fr))}}@media (min-width:1536px){.filament-icon-picker[\2xl="1"] .choices>.choices__list .choices__list{grid-template-columns:repeat(1,minmax(0,1fr))}.filament-icon-picker[\2xl="2"] .choices>.choices__list .choices__list{grid-template-columns:repeat(2,minmax(0,1fr))}.filament-icon-picker[\2xl="3"] .choices>.choices__list .choices__list{grid-template-columns:repeat(3,minmax(0,1fr))}.filament-icon-picker[\2xl="4"] .choices>.choices__list .choices__list{grid-template-columns:repeat(4,minmax(0,1fr))}.filament-icon-picker[\2xl="5"] .choices>.choices__list .choices__list{grid-template-columns:repeat(5,minmax(0,1fr))}.filament-icon-picker[\2xl="6"] .choices>.choices__list .choices__list{grid-template-columns:repeat(6,minmax(0,1fr))}.filament-icon-picker[\2xl="7"] .choices>.choices__list .choices__list{grid-template-columns:repeat(7,minmax(0,1fr))}.filament-icon-picker[\2xl="8"] .choices>.choices__list .choices__list{grid-template-columns:repeat(8,minmax(0,1fr))}.filament-icon-picker[\2xl="9"] .choices>.choices__list .choices__list{grid-template-columns:repeat(9,minmax(0,1fr))}.filament-icon-picker[\2xl="10"] .choices>.choices__list .choices__list{grid-template-columns:repeat(10,minmax(0,1fr))}.filament-icon-picker[\2xl="11"] .choices>.choices__list .choices__list{grid-template-columns:repeat(11,minmax(0,1fr))}.filament-icon-picker[\2xl="12"] .choices>.choices__list .choices__list{grid-template-columns:repeat(12,minmax(0,1fr))}} -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@guava/filament-icon-picker", 3 | "scripts": { 4 | "dev": "npx tailwindcss -i resources/css/plugin.css -o dist/plugin.css --postcss --watch", 5 | "build": "npx tailwindcss -i resources/css/plugin.css -o dist/plugin.css --postcss --minify && npm run purge", 6 | "purge": "filament-purge -i dist/plugin.css -o dist/plugin.css -v 3.x" 7 | }, 8 | "devDependencies": { 9 | "@semantic-release/changelog": "^6.0.1", 10 | "@semantic-release/commit-analyzer": "^9.0.2", 11 | "@semantic-release/github": "^8.0.6", 12 | "@semantic-release/release-notes-generator": "^10.0.3", 13 | "autoprefixer": "^10.4.12", 14 | "postcss": "^8.4.17", 15 | "semantic-release": "^19.0.5", 16 | "tailwindcss": "^3.1.8" 17 | }, 18 | "dependencies": { 19 | "@awcodes/filament-plugin-purge": "^1.0.2", 20 | "conventional-changelog-conventionalcommits": "^5.0.0", 21 | "postcss-for": "^2.1.1" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | "postcss-for": {}, 4 | tailwindcss: {}, 5 | autoprefixer: {}, 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /release.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | "plugins": [ 3 | ["@semantic-release/commit-analyzer", { 4 | "preset": "conventionalcommits", 5 | "releaseRules": [ 6 | {"type": "docs", "scope":"README", "release": "patch"}, 7 | {"type": "refactor", "release": "patch"}, 8 | {"type": "chore", "release": "patch"}, 9 | {"type": "style", "release": "patch"}, 10 | {"type": "test", "release": "patch"}, 11 | {"type": "perf", "release": "patch"} 12 | ], 13 | "presetConfig": { 14 | "types": [ 15 | {"type": "feat", "section": "Features"}, 16 | {"type": "fix", "section": "Bug Fixes"}, 17 | {"type": "chore", "hidden": true}, 18 | {"type": "docs", "hidden": true}, 19 | {"type": "style", "hidden": true}, 20 | {"type": "refactor", "hidden": true}, 21 | {"type": "perf", "hidden": true}, 22 | {"type": "test", "hidden": true} 23 | ] 24 | } 25 | }], 26 | ["@semantic-release/release-notes-generator", { 27 | "preset": "conventionalcommits" 28 | }], 29 | ["@semantic-release/github", { 30 | "assets": [ 31 | {"path": "dist/plugin.css", "label": "CSS distribution"}, 32 | ] 33 | }], 34 | ["@semantic-release/changelog", 35 | { 36 | "changelogFile": "CHANGELOG.md" 37 | } 38 | ], 39 | ["@semantic-release/npm", { 40 | "tarballDir": "release", 41 | "npmPublish": false 42 | }], 43 | ], 44 | "branches": ["main", "next"], 45 | "tagFormat": "${version}" 46 | } 47 | -------------------------------------------------------------------------------- /resources/css/plugin.css: -------------------------------------------------------------------------------- 1 | @tailwind components; 2 | @tailwind utilities; 3 | 4 | @layer components { 5 | .filament-icon-picker .choices > .choices__list { 6 | @apply px-2; 7 | } 8 | 9 | .filament-icon-picker .choices > .choices__inner > .choices__list.choices__list--single { 10 | @apply w-full; 11 | } 12 | 13 | .filament-icon-picker.filament-icon-picker-on_top .choices > .choices__list { 14 | @apply visible relative px-2; 15 | } 16 | 17 | .filament-icon-picker.filament-icon-picker-on_top .choices > .choices__inner { 18 | @apply bg-none px-3; 19 | } 20 | 21 | .filament-icon-picker.filament-icon-picker-on_top .choices > .choices__inner > .choices__list.choices__list--single { 22 | @apply relative px-0; 23 | } 24 | 25 | .filament-icon-picker.filament-icon-picker-on_top .choices > .choices__inner > .choices__list.choices__list--single .choices__button { 26 | @apply absolute mr-2; 27 | } 28 | 29 | .filament-icon-picker .choices > .choices__list .choices__list { 30 | @apply pb-2 gap-2; 31 | } 32 | 33 | .filament-icon-picker .choices > .choices__list .choices__list .choices__item { 34 | @apply hover:cursor-pointer border-[1px] rounded-lg shadow-sm; 35 | } 36 | 37 | .filament-icon-picker .choices > .choices__list .choices__list .choices__item.has-no-choices, 38 | .filament-icon-picker .choices > .choices__list .choices__list .choices__item.has-no-results, 39 | .filament-icon-picker .choices > .choices__list .choices__list .choices__item.choices__item--disabled { 40 | @apply border-none shadow-none; 41 | } 42 | 43 | .filament-icon-picker .choices > .choices__list .choices__list { 44 | @apply grid; 45 | } 46 | } 47 | .filament-icon-picker .choices > .choices__list .choices__list .choices__item.has-no-choices, 48 | .filament-icon-picker .choices > .choices__list .choices__list .choices__item.has-no-results, 49 | .filament-icon-picker .choices > .choices__list .choices__list .choices__item.choices__item--disabled { 50 | @apply col-span-full; 51 | } 52 | 53 | @for $i from 1 to 12 { 54 | .filament-icon-picker[default="$(i)"] .choices > .choices__list .choices__list { 55 | @apply grid-cols-[repeat($(i),_minmax(0,_1fr))] 56 | } 57 | } 58 | 59 | @for $i from 1 to 12 { 60 | .filament-icon-picker[sm="$(i)"] .choices > .choices__list .choices__list { 61 | @apply sm:grid-cols-[repeat($(i),_minmax(0,_1fr))] 62 | } 63 | } 64 | @for $i from 1 to 12 { 65 | .filament-icon-picker[md="$(i)"] .choices > .choices__list .choices__list { 66 | @apply md:grid-cols-[repeat($(i),_minmax(0,_1fr))] 67 | } 68 | } 69 | @for $i from 1 to 12 { 70 | .filament-icon-picker[lg="$(i)"] .choices > .choices__list .choices__list { 71 | @apply lg:grid-cols-[repeat($(i),_minmax(0,_1fr))] 72 | } 73 | } 74 | @for $i from 1 to 12 { 75 | .filament-icon-picker[xl="$(i)"] .choices > .choices__list .choices__list { 76 | @apply xl:grid-cols-[repeat($(i),_minmax(0,_1fr))] 77 | } 78 | } 79 | @for $i from 1 to 12 { 80 | .filament-icon-picker[\2xl="$(i)"] .choices > .choices__list .choices__list { 81 | @apply 2xl:grid-cols-[repeat($(i),_minmax(0,_1fr))] 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /resources/views/forms/icon-picker.blade.php: -------------------------------------------------------------------------------- 1 |
merge([ 2 | 'class' => "filament-icon-picker filament-icon-picker-{$getLayout()}", 3 | ])->merge($getColumnsConfig()) }}> 4 | @include('filament-forms::components.select') 5 |
6 | -------------------------------------------------------------------------------- /resources/views/item.blade.php: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | 9 | {{-- Ugly fix for choices.js not registering clicks on SVGs. --}} 10 |
11 |
12 | {{$icon}} 13 |
14 |
15 | -------------------------------------------------------------------------------- /resources/views/placeholder.blade.php: -------------------------------------------------------------------------------- 1 |
2 |
3 |
No icon selected
4 |
5 |
6 | -------------------------------------------------------------------------------- /resources/views/tables/icon-column.blade.php: -------------------------------------------------------------------------------- 1 |
2 | @if($icon = $getState()) 3 | 4 | @endif 5 |
6 | -------------------------------------------------------------------------------- /src/FilamentIconPickerServiceProvider.php: -------------------------------------------------------------------------------- 1 | name('filament-icon-picker') 16 | ->hasViews() 17 | ->hasConfigFile('icon-picker') 18 | ; 19 | } 20 | 21 | public function bootingPackage() 22 | { 23 | parent::bootingPackage(); 24 | 25 | FilamentAsset::register([ 26 | Css::make('filament-icon-picker-stylesheet', __DIR__ . '/../dist/plugin.css'), 27 | ], package: 'guava/filament-icon-picker'); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/Forms/Concerns/CanBeCacheable.php: -------------------------------------------------------------------------------- 1 | cacheable = $cacheable; 20 | 21 | return $this; 22 | } 23 | 24 | public function getCacheable(): bool 25 | { 26 | $cacheable = $this->cacheable ?? config('icon-picker.cache.enabled', true); 27 | 28 | return $this->evaluate($cacheable); 29 | } 30 | 31 | public function cacheDuration(int|DateInterval|DateTimeInterface|Closure $cacheDuration): static 32 | { 33 | $this->cacheDuration = $cacheDuration; 34 | 35 | return $this; 36 | } 37 | 38 | public function getCacheDuration() 39 | { 40 | $duration = $this->cacheDuration ?? now()->add(config('icon-picker.cache.duration', '7 days')); 41 | 42 | return $this->evaluate($duration); 43 | } 44 | 45 | protected function tryCache(string $key, Closure $callback) 46 | { 47 | if (!$this->getCacheable()) { 48 | return $callback->call($this); 49 | } 50 | 51 | return Cache::remember($key, $this->getCacheDuration(), $callback); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/Forms/IconPicker.php: -------------------------------------------------------------------------------- 1 | sets(config('icon-picker.sets', null)); 43 | $this->columns(config('icon-picker.columns', 1)); 44 | $this->layout(config('icon-picker.layout', Layout::FLOATING)); 45 | 46 | $this->getSearchResultsUsing = function (IconPicker $component, string $search, Collection $icons) { 47 | 48 | $iconsHash = md5(serialize($icons)); 49 | $key = "icon-picker.results.$iconsHash.$search"; 50 | 51 | return $this->tryCache($key, function () use ($component, $search, $icons) { 52 | return collect($icons) 53 | ->filter(fn(string $icon) => str_contains($icon, $search)) 54 | ->mapWithKeys(function (string $icon) use ($component) { 55 | return [$icon => $component->getItemTemplate(['icon' => $icon])]; 56 | }) 57 | ->toArray(); 58 | }); 59 | }; 60 | 61 | $this->getOptionLabelUsing = function (IconPicker $component, $value) { 62 | if ($value) { 63 | return $component->getItemTemplate(['icon' => $value]); 64 | } 65 | }; 66 | 67 | $this 68 | ->itemTemplate(function (IconPicker $component, string $icon) { 69 | return \view('filament-icon-picker::item', [ 70 | 'icon' => $icon, 71 | ])->render(); 72 | }) 73 | ->placeholder(function () { 74 | return $this->view('filament-icon-picker::placeholder')->render(); 75 | }); 76 | } 77 | 78 | /** 79 | * @param array|string|Closure|null $sets 80 | * @return $this 81 | */ 82 | public function sets(array|Closure|string|null $sets = null): static 83 | { 84 | $this->sets = $sets ? (is_string($sets) ? [$sets] : $sets) : null; 85 | 86 | return $this; 87 | } 88 | 89 | public function getSets(): ?array 90 | { 91 | return $this->evaluate($this->sets); 92 | } 93 | 94 | public function allowedIcons(array|Closure|string $allowedIcons): static 95 | { 96 | $this->allowedIcons = $allowedIcons; 97 | 98 | return $this; 99 | } 100 | 101 | public function getAllowedIcons(): ?array 102 | { 103 | return $this->evaluate($this->allowedIcons, [ 104 | 'sets' => $this->getSets(), 105 | ]); 106 | } 107 | 108 | public function disallowedIcons(array|Closure|string $disallowedIcons): static 109 | { 110 | $this->disallowedIcons = $disallowedIcons; 111 | 112 | return $this; 113 | } 114 | 115 | public function getDisallowedIcons(): ?array 116 | { 117 | return $this->evaluate($this->disallowedIcons, [ 118 | 'sets' => $this->getSets(), 119 | ]); 120 | } 121 | 122 | public function layout(string|Closure $layout): static 123 | { 124 | $this->layout = $layout; 125 | 126 | return $this; 127 | } 128 | 129 | public function getLayout(): string 130 | { 131 | return $this->evaluate($this->layout); 132 | } 133 | 134 | public function itemTemplate(Htmlable|Closure|View $template): static 135 | { 136 | $this->itemTemplate = $template; 137 | 138 | return $this; 139 | } 140 | 141 | public function getItemTemplate(array $options = []): string 142 | { 143 | return $this->evaluate($this->itemTemplate, $options); 144 | } 145 | 146 | public function getSearchResults(string $search): array 147 | { 148 | if (!$this->getSearchResultsUsing) { 149 | return []; 150 | } 151 | 152 | $results = $this->evaluate($this->getSearchResultsUsing, [ 153 | 'query' => $search, 154 | 'search' => $search, 155 | 'searchQuery' => $search, 156 | 'icons' => $this->loadIcons(), 157 | ]); 158 | 159 | if ($results instanceof Arrayable) { 160 | $results = $results->toArray(); 161 | } 162 | 163 | return $results; 164 | } 165 | 166 | /** 167 | * Enact the preload logic (if, and only if, the user wants to preload the icons) 168 | */ 169 | protected function doPreload(): void 170 | { 171 | if (!$this->isPreloaded()) { 172 | return; 173 | } 174 | 175 | // To actually preload the icons, we trigger a search on the empty string. 176 | // `str_contains` will return true for any haystack if the needle is the empty string. 177 | // This is exactly how we know we get all the icons AND respect the user-land 178 | // configuration applied to this field instance. 179 | $options = $this->getSearchResults(''); 180 | 181 | // To avoid recursively and needlessly loading the icons each time 182 | // anything requests the options or uses the `doPreload` method, 183 | // we set the `preload` option to false right before setting the 184 | // resolved/computed icons. 185 | $this->preload(false); 186 | 187 | // We delegate back to the parent's `options` method as a setter 188 | // to keep our own as a throwing-method in user-land. 189 | // This sets the icons on the back-end and front-end. 190 | // It also make it work as soon as the component is mounted, 191 | // which means there's no need for user interaction to get the 192 | // full list of options loaded directly. 193 | parent::options($options); 194 | } 195 | 196 | public function getOptions(): array 197 | { 198 | $this->doPreload(); 199 | return parent::getOptions(); 200 | } 201 | 202 | 203 | /** 204 | * Marks the calling method as not allowed (whether because it's not supported or because it's meaningless when using this field) 205 | * @throws \BadMethodCallException Always 206 | */ 207 | protected function markAsNotAllowed(string $reason = 'Method not allowed.'): void { 208 | throw new \BadMethodCallException($reason); 209 | } 210 | 211 | /** 212 | * @deprecated Method inherited from `\Filament\Forms\Components\Select` but not supported (or meaningless) when using this field 213 | * @throws \BadMethodCallException 214 | */ 215 | public function relationship(string|Closure|null $name = null, string|Closure|null $titleAttribute = null, ?Closure $modifyQueryUsing = null, bool $ignoreRecord = false): static 216 | { 217 | $this->markAsNotAllowed(); 218 | } 219 | 220 | /** 221 | * @deprecated Method inherited from `\Filament\Forms\Components\Select` but not supported (or meaningless) when using this field 222 | * @throws \BadMethodCallException 223 | */ 224 | public function options(Arrayable|Closure|array|string|null $options): static 225 | { 226 | $this->markAsNotAllowed(); 227 | } 228 | 229 | /** 230 | * @deprecated Method inherited from `\Filament\Forms\Components\Select` but not supported (or meaningless) when using this field 231 | * @throws \BadMethodCallException 232 | */ 233 | public function allowHtml(bool|Closure $condition = true): static 234 | { 235 | $this->markAsNotAllowed(); 236 | } 237 | 238 | /** 239 | * @deprecated Method inherited from `\Filament\Forms\Components\Select` but not supported (or meaningless) when using this field 240 | * @throws \BadMethodCallException 241 | */ 242 | public function searchable(bool|array|Closure $condition = true): static 243 | { 244 | $this->markAsNotAllowed(); 245 | } 246 | 247 | /** 248 | * @deprecated Method inherited from `\Filament\Forms\Components\Select` but not supported (or meaningless) when using this field 249 | * @throws \BadMethodCallException 250 | */ 251 | public function getSearchResultsUsing(?Closure $callback): static 252 | { 253 | $this->markAsNotAllowed(); 254 | } 255 | 256 | /** 257 | * @deprecated Method inherited from `\Filament\Forms\Components\Select` but not supported (or meaningless) when using this field 258 | * @throws \BadMethodCallException 259 | */ 260 | public function getOptionLabelFromRecordUsing(?Closure $callback): static 261 | { 262 | $this->markAsNotAllowed(); 263 | } 264 | 265 | /** 266 | * @deprecated Method inherited from `\Filament\Forms\Components\Select` but not supported (or meaningless) when using this field 267 | * @throws \BadMethodCallException 268 | */ 269 | public function createOptionUsing(?Closure $callback): static 270 | { 271 | $this->markAsNotAllowed(); 272 | } 273 | 274 | /** 275 | * @deprecated Method inherited from `\Filament\Forms\Components\Select` but not supported (or meaningless) when using this field 276 | * @throws \BadMethodCallException 277 | */ 278 | public function createOptionAction(?Closure $callback): static 279 | { 280 | $this->markAsNotAllowed(); 281 | } 282 | 283 | /** 284 | * @deprecated Method inherited from `\Filament\Forms\Components\Select` but not supported (or meaningless) when using this field 285 | * @throws \BadMethodCallException 286 | */ 287 | public function createOptionForm(array|Closure|null $schema): static 288 | { 289 | $this->markAsNotAllowed(); 290 | } 291 | 292 | /** 293 | * @deprecated Method inherited from `\Filament\Forms\Components\Select` but not supported (or meaningless) when using this field 294 | * @throws \BadMethodCallException 295 | */ 296 | public function schema(array|Closure $components): static 297 | { 298 | $this->markAsNotAllowed(); 299 | } 300 | 301 | /** 302 | * @deprecated Method inherited from `\Filament\Forms\Components\Select` but not supported (or meaningless) when using this field 303 | * @throws \BadMethodCallException 304 | */ 305 | public function multiple(bool|Closure $condition = true): static 306 | { 307 | $this->markAsNotAllowed(); 308 | } 309 | 310 | private function loadIcons(): Collection 311 | { 312 | $iconsHash = md5(serialize($this->getSets())); 313 | $key = "icon-picker.fields.{$iconsHash}.{$this->getStatePath()}"; 314 | 315 | [$sets, $allowedIcons, $disallowedIcons] = $this->tryCache( 316 | $key, 317 | function () { 318 | $allowedIcons = $this->getAllowedIcons(); 319 | $disallowedIcons = $this->getDisallowedIcons(); 320 | 321 | $iconsFactory = App::make(IconFactory::class); 322 | $allowedSets = $this->getSets(); 323 | $sets = collect($iconsFactory->all()); 324 | 325 | if ($allowedSets) { 326 | $sets = $sets->filter(fn($value, $key) => in_array($key, $allowedSets)); 327 | } 328 | 329 | return [$sets, $allowedIcons, $disallowedIcons]; 330 | }); 331 | 332 | 333 | $allowedSetsHash = md5(serialize($sets)); 334 | $allowedHash = md5(serialize($allowedIcons)); 335 | $disallowedHash = md5(serialize($disallowedIcons)); 336 | $iconsKey = "icon-picker.fields.icons.{$iconsHash}.{$allowedSetsHash}.{$allowedHash}.{$disallowedHash}.{$this->getStatePath()}"; 337 | 338 | $icons = $this->tryCache($iconsKey, function() use($sets, $allowedIcons, $disallowedIcons) { 339 | $icons = []; 340 | 341 | foreach ($sets as $set) { 342 | $prefix = $set['prefix']; 343 | foreach ($set['paths'] as $path) { 344 | // To include icons from sub-folders, we use File::allFiles instead of File::files 345 | // See https://github.com/blade-ui-kit/blade-icons/blob/ce60487deeb7bcbccd5e69188dc91b4c29622aff/src/IconsManifest.php#L40 346 | foreach (File::allFiles($path) as $file) { 347 | // Simply ignore files that aren't SVGs 348 | if ($file->getExtension() !== 'svg') { 349 | continue; 350 | } 351 | 352 | $iconName = $this->getIconName($file, parentPath: $path, prefix: $prefix); 353 | 354 | if ($allowedIcons && !in_array($iconName, $allowedIcons)) { 355 | continue; 356 | } 357 | if ($disallowedIcons && in_array($iconName, $disallowedIcons)) { 358 | continue; 359 | } 360 | 361 | $icons[] = $iconName; 362 | } 363 | } 364 | } 365 | 366 | return $icons; 367 | }); 368 | 369 | return collect($icons); 370 | } 371 | 372 | /** 373 | * @see https://github.com/blade-ui-kit/blade-icons and its IconsManifest.php 374 | * @see https://github.com/blade-ui-kit/blade-icons/blob/ce60487deeb7bcbccd5e69188dc91b4c29622aff/src/IconsManifest.php#L78 375 | */ 376 | private function getIconName(SplFileInfo $file, string $parentPath, string $prefix): string { 377 | // BladeIcons uses a simple (and view-compliant) naming convention for icon names 378 | // `xtra-icon` is the `icon.svg` from the `xtra` icon set 379 | // `xtra-dir.icon` is the `icon.svg` from the `dir/` folder from the `xtra` icon set 380 | // `xtra-sub.dir.icon` is the `icon.svg` from the `sub/dir/` folder from the `xtra` icon set 381 | // 382 | // As such, we: 383 | // - get the string after the parent directory's path 384 | // - replace every directory separator by a dot 385 | // - add the prefix at the beginning, followed by a dash 386 | 387 | $iconName = str($file->getPathname()) 388 | ->after($parentPath . DIRECTORY_SEPARATOR) 389 | ->replace(DIRECTORY_SEPARATOR, '.') 390 | ->basename('.svg') 391 | ->toString(); 392 | 393 | return "$prefix-$iconName"; 394 | } 395 | } 396 | -------------------------------------------------------------------------------- /src/Layout.php: -------------------------------------------------------------------------------- 1 |