定制 filafly/filament-icons 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

filafly/filament-icons

Composer 安装命令:

composer require filafly/filament-icons

包简介

Core package for managing Filament icon drivers via a common interface.

README 文档

README

Banner

A package to replace Filament's default Heroicons with your preferred icon set, providing unified icon management with style variations and overrides.

Features

  • Unified Icon Management: Standardize all icons across your Filament project.
  • Style Variations: Switch between icon styles (e.g., solid, regular, light) with a single method call.
  • Granular Overrides: Override specific icons or aliases at the global or component level.
  • Extensible: Easily create your own icon set implementations for any icon library with a Blade Icons package.
  • Developer-Focused: Designed for developers creating icon set implementations, not just end-users.

Available Icon Sets

The following icon sets are available as separate packages that work with this core package:

Official Implementations

Community Implementations

Creating Your Own Icon Set

The best and most straightforward way to create your own set is by using the Filament Icons Template repository. Just click "use this template" and follow the instructions on the page.

If you want to create your own implementation manually, this package enables you to integrate any icon library that has a Blade Icons implementation with Filament. Here's how to get started:

Requirements

  • An icon set with a Blade Icons implementation. If one doesn't exist, you'll need to create it.
  • Your project must use Filament v4 or v5. For older versions, use the 1.x branch of this package.

Implementation Steps

1. Define the Icon Enum

Create a PHP enum that defines all icons in your set. The enum cases should have styles baked into their names (e.g., SearchRegular, SearchSolid).

<?php

namespace App\Enums;

enum MyIcon: string
{
    case SearchRegular = 'search';
    case SearchSolid = 'search-solid';
    // ... other icons
}

2. (Optional) Define the Style Enum

If your icon set supports multiple styles (e.g., regular, solid, duotone), create a StyleEnum that implements Filafly\Icons\Contracts\StyleEnum. This ensures your enum provides the necessary methods for the style system.

<?php

namespace App\Enums;

use Filafly\Icons\Contracts\StyleEnum as StyleEnumContract;

enum MyIconStyle: string implements StyleEnumContract
{
    case Regular = 'regular';
    case Solid = 'solid';

    public function getStyleName(): string
    {
        return $this->value;
    }

    public function getEnumSuffix(): string
    {
        return ucfirst($this->value);
    }

    public static function getStyleNames(): array
    {
        return array_column(self::cases(), 'value');
    }

    public static function fromStyleName(string $styleName): ?self
    {
        foreach (self::cases() as $case) {
            if ($case->getStyleName() === $styleName) {
                return $case;
            }
        }
        return null;
    }
}

3. Create the IconSet Class

Create a class that extends Filafly\Icons\IconSet. This class will manage your icon set's integration with Filament.

<?php

namespace App\Icons;

use App\Enums\MyIcon;
use App\Enums\MyIconStyle;
use Filafly\Icons\IconSet;

class MyIcon extends IconSet
{
    protected string $pluginId = 'vendor-filament-my-icons';
    protected string $iconPrefix = 'my-icon'; // Optional: if different from guessed prefix
    protected mixed $iconEnum = MyIcon::class;
    protected ?string $styleEnum = MyIconStyle::class; // Optional
}

Icon Prefix: The system automatically guesses the icon prefix from your $iconEnum's class name (e.g., MyIcon becomes myicon). If your Blade Icons package uses a different prefix, set it with $iconPrefix.

4. Map Filament Icon Aliases

In your IconSet class, map Filament's icon aliases to your icon enum cases in the $iconMap array.

protected array $iconMap = [
    'panels::global-search.field' => MyIcon::SearchRegular,
    'panels::pages.dashboard.actions.filter' => MyIcon::SearchSolid,
    // ... other mappings
];

Advanced Usage

The IconSet class provides powerful methods for style transformations and granular overrides.

Global Styling

You can set a global style for all icons in your set. This is useful for applying a consistent look across your application.

Using the style() method:

MyIcon::make()->style('solid');

Using dynamic style methods:

If you have a StyleEnum defined, you can use dynamic methods named after your styles:

MyIcon::make()->solid();
MyIcon::make()->regular();

Granular Overrides

Overrides allow you to change icons for specific aliases or replace one icon with another. The override precedence is:

  1. Exact Overrides: overrideAlias() and overrideIcon()
  2. Style Overrides: overrideStyleForAlias() and overrideStyleForIcon()
  3. Global Style: style() or dynamic methods
  4. Default: The original mapping in $iconMap

overrideAlias(string $alias, mixed $iconCase)

Overrides a specific Filament alias to use a different icon.

MyIcon::make()->overrideAlias('panels::global-search.field', MyIcon::SearchSolid);

overrideAliases(array $overrides)

Overrides multiple aliases at once.

MyIcon::make()->overrideAliases([
    'panels::global-search.field' => MyIcon::SearchSolid,
    'panels::pages.dashboard.actions.filter' => MyIcon::SearchRegular,
]);

overrideIcon(mixed $fromIconCase, mixed $toIconCase)

Replaces one icon enum case with another across all its uses.

MyIcon::make()->overrideIcon(MyIcon::SearchRegular, MyIcon::SearchSolid);

overrideIcons(array $overrides)

Replaces multiple icons at once.

MyIcon::make()->overrideIcons([
    MyIcon::SearchRegular => MyIcon::SearchSolid,
]);

overrideStyleForAlias(string|array $aliases, string|object $style)

Applies a specific style to one or more aliases.

MyIcon::make()->overrideStyleForAlias('panels::global-search.field', 'solid');
// or
MyIcon::make()->overrideStyleForAlias(['panels::global-search.field'], MyIconStyle::Solid);

overrideStyleForIcon(mixed $iconCases, string|object $style)

Applies a specific style to one or more icon enum cases.

MyIcon::make()->overrideStyleForIcon(MyIcon::SearchRegular, 'solid');
// or
MyIcon::make()->overrideStyleForIcon([MyIcon::SearchRegular], MyIconStyle::Solid);

License

The MIT License (MIT). Please see License File for more information.

filafly/filament-icons 适用场景与选型建议

filafly/filament-icons 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 77.17k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2025 年 04 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「icons」 「replace」 「carbon」 「font awesome」 「swap」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 filafly/filament-icons 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 filafly/filament-icons 我们能提供哪些服务?
定制开发 / 二次开发

基于 filafly/filament-icons 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 77.17k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 29
  • 依赖项目数: 9
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-30