定制 hasnayeen/themes 二次开发

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

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

hasnayeen/themes

Composer 安装命令:

composer require hasnayeen/themes

包简介

Themes for Filament panels

README 文档

README

preview

Latest Version on Packagist Total Downloads

Themes is a Filament plugin that allows users to set themes from a collection and customize the color of the selected theme. The package provides a simple and easy-to-use interface for selecting and applying themes to Filament panels.

Available For Hire

For custom theme please reach out via email or discord

I'm also available for contractual work on this stack (Filament, Laravel, Livewire, AlpineJS, TailwindCSS). Reach me via email or discord

Installation

You can install the package via composer:

composer require hasnayeen/themes

Publish plugin assets by running following commands

php artisan vendor:publish --tag="themes-assets"

If you want to set theme per user then you'll need to run the package migration. You can publish and run the migrations with:

php artisan vendor:publish --tag="themes-migrations"
php artisan migrate

You need to publish config file and change 'mode' => 'user' in order to set theme for user separately

You can publish the config file with:

php artisan vendor:publish --tag="themes-config"

This is the contents of the published config file:

return [

    /*
    |--------------------------------------------------------------------------
    | Theme mode
    |--------------------------------------------------------------------------
    |
    | This option determines how the theme will be set for the application.
    | By default global mode is set to use one theme for all user. If you
    |  want to set theme for each user separately, then set to 'user'.
    |
    */

    'mode' => 'global',

    /*
    |--------------------------------------------------------------------------
    | Theme Icon
    |--------------------------------------------------------------------------
    */

    'icon' => 'heroicon-o-swatch',

];

Optionally, you can publish the views using

php artisan vendor:publish --tag="themes-views"

Usage

You'll have to register the plugin in your panel provider

    public function panel(Panel $panel): Panel
    {
        return $panel
            ...
            ->plugin(
                \Hasnayeen\Themes\ThemesPlugin::make()
            );
    }

Add Hasnayeen\Themes\Http\Middleware\SetTheme middleware to your provider middleware method or if you're using filament multi-tenancy then instead add to tenantMiddleware method.

    public function panel(Panel $panel): Panel
    {
        return $panel
            ...
            ->middleware([
                ...
                \Hasnayeen\Themes\Http\Middleware\SetTheme::class
            ])
            // or in `tenantMiddleware` if you're using multi-tenancy
            ->tenantMiddleware([
                ...
                \Hasnayeen\Themes\Http\Middleware\SetTheme::class
            ])
    }

This plugin provides a themes setting page. You can visit the page from user menu.

page-menu-link

Authorization

You can configure the authorization of themes settings page and user menu option by providing a closure to the canViewThemesPage method on ThemesPlugin.

    public function panel(Panel $panel): Panel
    {
        return $panel
            ->plugin(
                \Hasnayeen\Themes\ThemesPlugin::make()
                    ->canViewThemesPage(fn () => auth()->user()?->is_admin)
            );
    }

Customize theme collection

You can create new custom theme and register them via registerTheme method on plugin.

    public function panel(Panel $panel): Panel
    {
        return $panel
            ->plugin(
                \Hasnayeen\Themes\ThemesPlugin::make()
                    ->registerTheme([MyCustomTheme::getName() => MyCustomTheme::class])
            );
    }

You can also remove plugins default theme set by providing override argument as true. You may choose to pick some of the themes from plugin theme set.

    public function panel(Panel $panel): Panel
    {
        return $panel
            ->plugin(
                \Hasnayeen\Themes\ThemesPlugin::make()
                    ->registerTheme(
                        [
                            MyCustomTheme::class,
                            \Hasnayeen\Themes\Themes\Sunset::class,
                        ],
                        override: true,
                    )
            );
    }

Create custom theme

You can create custom theme and register them in themes plugin. To create a new theme run following command in the terminal and follow the steps

php artisan themes:make Awesome --panel=App

This will create the following class

use Filament\Panel;
use Hasnayeen\Themes\Contracts\CanModifyPanelConfig;
use Hasnayeen\Themes\Contracts\Theme;

class Awesome implements CanModifyPanelConfig, Theme
{
    public static function getName(): string
    {
        return 'awesome';
    }

    public static function getPublicPath(): string
    {
        return 'resources/css/filament/app/themes/awesome.css';
    }

    public function getThemeColor(): array
    {
        return [
            'primary' => '#000',
            'secondary' => '#fff',
        ];
    }

    public function modifyPanelConfig(Panel $panel): Panel
    {
        return $panel
            ->viteTheme($this->getPath());
    }
}

If your theme support changing primary color then implement Hasnayeen\Themes\Contracts\HasChangeableColor interface and getPrimaryColor method.

If your theme need to change panel config then do so inside modifyPanelConfig method in your theme.

use Hasnayeen\Themes\Contracts\CanModifyPanelConfig;
use Hasnayeen\Themes\Contracts\Theme;

class Awesome implement CanModifyPanelConfig, Theme
{
    public function modifyPanelConfig(Panel $panel): Panel
    {
        return $panel
            ->viteTheme($this->getPath())
            ->topNavigation();
    }
}

Next add a new item to the input array of vite.config.js: resources/css/awesome.css

Available Themes

Dracula (dark)

dracula-dark

Nord (light)

nord-light

Nord (dark)

nord-dark

Sunset (light)

sunset-light

Sunset (dark)

sunset-dark

Upgrading

Everytime you update the package you should run package upgrade command so that necessary assets have been published.

composer update

php artisan themes:upgrade

Alternatively you can add this command to composer.json on post-autoload-dump hook so that upgrade command run automatically after every update.

"post-autoload-dump": [
    // ...
    "@php artisan themes:upgrade"
],

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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

hasnayeen/themes 适用场景与选型建议

hasnayeen/themes 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 243.42k 次下载、GitHub Stars 达 345, 最近一次更新时间为 2023 年 09 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 hasnayeen/themes 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 243.42k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 345
  • 点击次数: 24
  • 依赖项目数: 10
  • 推荐数: 0

GitHub 信息

  • Stars: 345
  • Watchers: 6
  • Forks: 54
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-09-01