Filament Icon Picker

repository·main·Indexed 41 days ago

https://github.com/lukas-frey/filament-icon-picker

A Filament plugin providing an icon picker form field and table column. It allows users to select icons from any installed Blade-icons kit, with Heroicons supported by default. Features include responsive column layouts, floating or on-top display modes, search result caching, and custom item templates via Blade views.

Tokens
22.9K
Snippets
123
Records
159
Agent score
49%

What's inside Filament Icon Picker

  1. Where uploaded icons are stored

    main

    Uploaded icons are stored on the public disk within a directory structure organized by scope. The package automatically registers this directory as a blade-icons set, allowing uploaded files to be used like any other icon in your application.

    Storage paths:

    • Unscoped icons: storage/app/public/icon-picker-icons/unscoped/{filename}.svg
    • Scoped icons: storage/app/public/icon-picker-icons/{scope}/{filename}.svg

    Note: Because files are on the public disk, they are directly accessible via the /storage URL. Ensure you restrict upload permissions accordingly.

  2. How custom icon sets are displayed and filtered

    main

    Custom icons are grouped into a specific set called Custom icons, which appears in the set dropdown.

    Key behaviors:

    • The Custom icons set is only visible on fields where customIconsUploadEnabled() has been called.
    • If you use the sets() method to restrict which icon sets are available on a field, the Custom icons set will be hidden unless you explicitly include it in your allowed sets.
  3. Understand where uploaded icons are stored

    main

    Uploaded icons are stored on the public disk within directories organized by scope. The package automatically registers these directories as a blade-icons set, allowing uploaded files to function like standard icons.

    Storage paths:

    • Unscoped: storage/app/public/icon-picker-icons/unscoped/{filename}.svg
    • Scoped: storage/app/public/icon-picker-icons/{scope}/{filename}.svg

    Security Note: Because files are stored on the public disk, they are directly accessible via the /storage URL. Ensure you restrict upload permissions accordingly.

  4. Understand the custom icon upload process and constraints

    main

    When a user clicks the upload action, a modal appears with two fields:

    1. Icon: Accepts a single SVG file (maximum size: 512 KB).
    2. Label: A name for the icon. Labels are restricted to letters, numbers, and spaces. The system automatically converts the label into a slug (e.g., My Nice Icon becomes my-nice-icon).

    Once uploaded, the icon is immediately selected in the field and becomes available in the icon picker.

  5. Alpine.js variables and methods available in custom search views

    main

    When creating a custom search results view, you have access to the following Alpine.js properties and methods to manage the UI and icon rendering:

    NameDescription
    resultsVisibleAn array of currently visible icons: { id, label, set, custom }
    stateThe ID of the currently selected icon
    isLoadingBoolean indicating if icons are still being loaded
    updateState(icon)Selects an icon (pass one entry from resultsVisible)
    setElementIcon($el, id)Loads the SVG of an icon into a specific element
    addSearchResultsChunk()Triggers the rendering of the next chunk of results

    Important Note on Icon Rendering: Icons are transmitted to the browser as IDs and labels, not as SVG markup. To display an icon, you must call setElementIcon($el, icon.id) on the target element. For performance with large sets, it is recommended to call this when the element scrolls into view using x-intersect.

    <div x-intersect="setElementIcon($el, icon.id)"></div>
  6. How the icon picker retrieves icons

    main

    Icons are served via two package-registered endpoints (not via Livewire). Access is secured using an encrypted token issued by the field during rendering.

    This token is scoped to specific sets and scopes. A token issued for a specific field or scope cannot be used to access icons from a different scope or a set that the field does not have permission to serve.

  7. How icon scoping is implemented

    main

    The icon scope is automatically derived from the model's morph class and its primary key. This ensures that icons from different models never share the same scope.

    Because the scope is part of the icon name stored in the database, moving a record between tenants (or changing its scope) will not automatically move the associated icon files. To move icons, you must manually move the files on the public disk and update the stored icon names in your database.

  8. Understand IconPicker validation

    main

    The IconPicker field includes built-in validation. When a form is submitted, the component automatically verifies that:

    1. The selected icon exists.
    2. The icon belongs to the set(s) offered by the field (respecting any exclusions made via sets()).
    3. If using custom icons, the icon's scope is verified.

    This validation prevents users from submitting arbitrary or non-existent icon strings from the browser.