• Stars
    star
    128
  • Rank 272,238 (Top 6 %)
  • Language
    PHP
  • License
    MIT License
  • Created 9 months ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Themes for Filament panels.

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.

More Repositories

1

invobook

Self-hosted app for Time Tracking, Invoice Generation, Project & Client Management, built with Laravel & Filament.
PHP
1,960
star
2

laravel-developer-roadmap

Roadmap to becoming a Laravel developer in 2020
644
star
3

vps

A laravel 5 package to easily create and maintain vps on digital ocean
PHP
56
star
4

goodwork

Self hosted project management and collaboration tool built with Laravel & VueJS
PHP
47
star
5

fluent-facebook

A laravel 5 package for reading and writing to facebook graph object with ease in laravelish syntax
PHP
47
star
6

zorum

A modern take on forum application
PHP
24
star
7

zucart

Open source self-hosted single/multi vendor ecommerce marketplace built with Filament (Laravel, Livewire, Alpine, TailwindCSS).
PHP
9
star
8

blade-eva-icons

A package to easily make use of Eva icons in your Laravel Blade views.
PHP
7
star
9

zinker

Laravel code runner (like tinkerwell but as webapp)
PHP
7
star
10

design-pattern

design pattern examples in php
PHP
5
star
11

ubuntu-mono-with-ligatures

Ubuntu Mono fonts with ligatures
4
star
12

laravel-meetup-2017

Source code from the laravel meetup presentation
PHP
3
star
13

mdb

MDX for laravel blade
PHP
3
star
14

language-trends

This is an experimental project for learning elixir. Target is to analyze language trends using twitters global tweet via language hashtags.
Elixir
2
star
15

lambdas

Go
2
star
16

getinzone

CSS
1
star
17

larks

Rust
1
star
18

src-gh-page

CSS
1
star
19

hasnayeen.github.io

My online home
HTML
1
star
20

gravit-designer-resources

A collection of resource for gravit designer software
1
star
21

planner

PHP
1
star
22

glow-chart

PHP
1
star