GithubHelp home page GithubHelp logo

themes's Introduction

Themes for Filament panels

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.

themes's People

Contributors

atmonshi avatar dependabot[bot] avatar github-actions[bot] avatar hasnayeen avatar kaanxweb avatar lloricode avatar majdghithan avatar maxime9446 avatar stephenjude avatar tabatii avatar thethunderturner avatar thijmenkort avatar valpuia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

themes's Issues

[Bug]: error Filament\Support\Colors\ColorManager::Filament\Support\Colors{closure}(): Argument #1 ($color) must be of type string, array given

What happened?

Enabling Sunset them creates error Filament\Support\Colors\ColorManager::Filament\Support\Colors{closure}(): Argument #1 ($color) must be of type string, array given

How to reproduce the bug

Enable Sunset Theme

Package Version

3.0.0

PHP Version

8.2.0

Laravel Version

10.0.0

Notes

Filament\Support\Colors\ColorManager::Filament\Support\Colors{closure}(): Argument #1 ($color) must be of type string, array given

Panel Switch plugin [Bug]:

What happened?

PanelSwitch::configureUsing(function (PanelSwitch $panelSwitch) {
$panelSwitch->labels([
'admin' => 'PAGRINDINIS',
'maiseliai' => 'MAIŠELIAI',
'pakuotes' => 'PAKUOTĖS',])
->iconSize(16)
->icons([
'admin' => 'heroicon-o-square-2-stack',
'pakuotes' => 'heroicon-o-cube',
'maiseliai' => 'heroicon-o-shopping-bag',
], $asImage = false)
->modalHeading('Pasirinkti')
->modalWidth('sm')
//->slideOver();
->simple();
});
works with simple(), not works slideOver or Modal.
theme Nord, other theme all good

How to reproduce the bug

no

Package Version

3.0.67

Filament Version

3.0.67

PHP Version

8.1.5

Laravel Version

10

Notes

No response

[Bug]: Call to undefined method Filament\Support\Colors\Color::all()

What happened?

After installing this plugin and registering it in the Filament AdminPanelProvider, I encountered the following error: "I received an error stating 'Call to undefined method Filament\Support\Colors\Color::all()'."

Also

Not working (Class "App\Providers\Filament\Hasnayeen\Themes\ThemesPlugin" not found)

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

Working

use Hasnayeen\Themes\ThemesPlugin;

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




How to reproduce the bug

After registering the plugin in AdminPanelProvider, I encountered an error. By the way, I'm testing this on Docker.

Package Version

3.0

PHP Version

8.1

Laravel Version

10.10

Which operating systems does with happen with?

No response

Notes

No response

[Bug]: url domain.com/themes not work if PanelServiceProvider use ->path('admin')

What happened?

multiple panelProvider example admin / tenant
If there are multiple panels that use ->path('something') can't use domain.com/themes correct url is domain.com/something/themes.

i solve issue modify

SetTheme.php



 MenuItem::make('Themes')
                    ->label('Themes')
                    ->icon('heroicon-o-swatch')
                    ->url('/'.$panel->getPath().'/themes'),
            ] : []

How to reproduce the bug

After installation

i have TenantPanelServiceProvider.php where i use ->path('tenant')
and i have AdminPanelServiceProvider.php where i use ->path('admin')

Package Version

lasted

PHP Version

8.2.0

Laravel Version

lasted

Which operating systems does with happen with?

No response

Notes

No response

[Bug]: Call to a member function can() on null

What happened?

When a Filament user logs out this method canViewThemesPage(fn () => auth()->user()->is_admin) returns a Call to a member function can() on null error due to the absence of authenticated user object.

How to reproduce the bug

  • Call the authorization check method canViewThemesPage(fn () => auth()->user()->is_admin).
  • Log out of your Filament dashboard.
image

Package Version

3.0

Filament Version

3.0

PHP Version

8.2

Laravel Version

10

Notes

No response

Error when I use the override option

What happened?

Error message: Hasnayeen\Themes\Themes::make(): Return value must be of type Hasnayeen\Themes\Contracts\Theme, none returned

How to reproduce the bug

Set the "override" option to "true".

Package Version

latest

Filament Version

3.0.62

PHP Version

8.2.4

Laravel Version

10.25.1

Notes

I use this code:

ThemesPlugin::make()
    ->registerTheme(
        [
            MyTheme::getName() => MyTheme::class
        ],
        true,
    ),

[Bug]: Plugin not working when mode is user

What happened?

Currently the plugin only works if is set to global mode.
If is set to user mode, the plugin correctly update the columns in the database for the user but the theme is not changed.

How to reproduce the bug

  • Follow the guide to enable per user theme
  • Try to change theme or color
  • The theme or color is not applied

Package Version

3.0.22

Filament Version

3.2.61

PHP Version

8.1.25

Laravel Version

10.48.4

Notes

No response

[Bug]: Install package bugs

What happened?

Hello,

I have a serie of bug when installing this package on an existing installation.
Run upgrade/update, in order to use he last version if Laravel, filament & your package.

pages/themes.blade.php

@if ($this->getCurrentTheme() instanceof \Hasnayeen\Themes\Contracts\HasChangeableColor)

GetCurrentTheme() is a class, but getCurrentTheme return a string (getName)

    public function getCurrentTheme()
    {
        return app(\Hasnayeen\Themes\Themes::class)->getCurrentTheme(); //->getName();
    }

Themes.php

For the function getCurrentThemeColor(), I had to modify like this:

        if (Arr::has($this->getCurrentTheme()->getThemeColor(), $color)) {
            return ['primary' => Arr::get($this->getCurrentTheme()->getThemeColor(), $color)];
        } else {
            return $this->getCurrentTheme()->getPrimaryColor();
        }

The ['primary' => null] always exists. And Arr::get(Array, null) return the full array. Need to check existence with has (or use collect()->get(null, default)).

Sunset Theme

Here I removed the Color:rgb in order to avoid Filament\Support\Colors\Color::rgb(): Argument #1 ($color) must be of type string, array given. Maybe DefaultTheme too ?

    public function getPrimaryColor(): array
    {
        return ['primary' => $this->getThemeColor()['blue']];
    }

How to reproduce the bug

Follow installation notes.
Go to Themes, and play with options

Package Version

v3.0.8

PHP Version

8.2.4

Laravel Version

v3.0.39

Which operating systems does with happen with?

Windows

Notes

(Thank you for this great package :) )

[Bug]: Call to undefined method Filament\Support\Colors\Color::all()

What happened?

When I try to put Hasnayeen\Themes\Http\Middleware\SetTheme::class on middleware, its return error `Call to undefined method Filament\Support\Colors\Color::all()'

How to reproduce the bug

Its fine when I add ThemesPlugin inside plugins() panel but when I add SetTheme on middleware() it return error

Package Version

3.0

PHP Version

8.1.17

Laravel Version

10.10

Notes

Filament version 3.0-stable

[Bug]: Call to undefined method Hasnayeen\Themes\Themes\Dracula::getPrimaryColor()

What happened?

After Update composer
themes 3.0.13 to 3.0.16

How to reproduce the bug

when updated composer
and applied new theme then

Call to undefined method Hasnayeen\Themes\Themes\Dracula::getPrimaryColor()

Package Version

3.0.16

Filament Version

3.0

PHP Version

8.1

Laravel Version

10

Notes

Call to undefined method Hasnayeen\Themes\Themes\Dracula::getPrimaryColor()

Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/117.0

[Bug]: Theme collection

What happened?

Hello,

I think, we got a regression.

On class Themes, the collection definition is Name=>class

        $this->collection = collect([
            DefaultTheme::getName() => DefaultTheme::class,
            Nord::getName() => Nord::class,
            Sunset::getName() => Sunset::class,
        ]);

but make is returning "default". By the way, this collection is key=>class. No need to first, but a simple get().
Or need to reverse the collection key/value.

    public function make(string $theme): Theme
    {
        $name = $this->collection->get($theme);
        if ($name) {
            return new $name;
        }
    }

Between the __construct & make, the collection changed :

Illuminate\Support\Collection {#1478 ▼ // vendor\hasnayeen\themes\src\Themes.php:42
  #items: array:3 [▼
    "default" => "default"
    "nord" => "nord"
    "sunset" => "sunset"
  ]
  #escapeWhenCastingToString: false
}

How to reproduce the bug

Install

Package Version

v3.0.10

PHP Version

8.2.4

Laravel Version

v3.0.39

Notes

No response

[Bug]: Call to undefined method Filament\Support\Colors\Color::all()

What happened?

When adding the plugin to my panel, I encounter the above exception. The error occurs at 'Hasnayeen\Themes\Themes\DefaultTheme:23'.

I have already verified 'Filament\Support\Colors,' and there is no static method named 'all().' Please double-check.

How to reproduce the bug

I just added the plugin to my panel.

Package Version

3.0.13

PHP Version

8.1.22

Laravel Version

10.22.0

Notes

I decided to create this static method 'all' in 'Filament\Support\Colors,' and the problem was solved.

Filament v3.0

[Bug]: Duplicated right hand scrollbar

What happened?

After update to latest FilamentPHP version (3.1.23) themes started having a secondary scrollbar on right.

image

This happens on resource edit page that has a relationmanager view below it. Both the relation manager and edit page have separate scrollbars. Every other page looks fine, even the resource manager view page. Issue happens only on edit page.

How to reproduce the bug

Install latest version of this package and currently latest version of filament (3.1.23)

Package Version

3.0.21

Filament Version

3.1.23

PHP Version

8.2.13

Laravel Version

10.37.3

Notes

No response

[Bug]:

What happened?

Login Page Full On Sunset Theme

image

How to reproduce the bug

?

Package Version

3

PHP Version

8.2

Laravel Version

10

Notes

No response

[Bug]: Theme Navigation item Duplication

What happened?

When Running the theme package on an application with Laravel Octane the Theme navigation item duplicates

Screenshot 2024-03-20 at 11 19 02

How to reproduce the bug

Laravel App with Octane

Package Version

^3.0

Filament Version

^3.2.55

PHP Version

^8.3

Laravel Version

^10.48

Notes

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.