Configurable theme manager for filament.
We recommend reading the official documentation about how to create themes on the Filament web site
You can install the package via composer:
composer require yepsua/filament-themes
You can publish the config file with:
php artisan vendor:publish --tag="yepsua-filament-themes-config"
Notice: The next steps assume the .css file is located in the folder '/resources/css/app.css' but you can change the name and location of this file, just take into account if you copy and paste some code on this guide.
php artisan vendor:publish --tag="yepsua-filament-themes-assets"
tailwind.config.js:
const colors = require('tailwindcss/colors')
const defaultTheme = require('tailwindcss/defaultTheme')
function withOpacityValue(variable) {
return ({ opacityValue }) => {
if (opacityValue === undefined) {
return `rgb(var(${variable}))`
}
return `rgb(var(${variable}) / ${opacityValue})`
}
}
module.exports = {
content: [
'./resources/**/*.blade.php',
'./vendor/filament/**/*.blade.php',
],
darkMode: 'class',
theme: {
extend: {
colors: {
primary: {
'50': withOpacityValue('--color-primary-50'),
'100': withOpacityValue('--color-primary-100'),
'200': withOpacityValue('--color-primary-200'),
'300': withOpacityValue('--color-primary-300'),
'400': withOpacityValue('--color-primary-400'),
'500': withOpacityValue('--color-primary-500'),
'600': withOpacityValue('--color-primary-600'),
'700': withOpacityValue('--color-primary-700'),
'800': withOpacityValue('--color-primary-800'),
'900': withOpacityValue('--color-primary-900')
},
danger: colors.red,
success: colors.green,
warning: colors.amber,
},
fontFamily: {
sans: ['DM Sans', ...defaultTheme.fontFamily.sans],
},
},
},
plugins: [
require('@tailwindcss/forms'),
require('@tailwindcss/typography'),
],
}
resources/css/app.css the next content:resources/css/app.css:
@import './../../vendor/filament/filament/resources/css/app.css';
webpack.mix.js:
...
mix.js('resources/js/app.js', 'public/js')
.postCss('resources/css/app.css', 'public/css', [
require('tailwindcss'),
require('autoprefixer'),
]);
...
config/filament-themes.php
[
...
'enable_vite' => true,
...
]
postcss.config.js:
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};
vite.config.js
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
export default defineConfig({
plugins: [
laravel({
input: [
'resources/css/app.css',
'resources/js/app.js'
],
refresh: true,
}),
],
});
config/filament-themes.php:
[
...
'color_public_path' => 'vendor/yepsua-filament-themes/css/red.css',
...
]
Available colors (based on the tailwind color pallet):
npm run dev
__
Now, you should see the app using the color defined in your config file. You can change the color without recompiling the resources, just updating the config file.
Notice: The theme manager uses the Mix or Vite to import the css resources. If you need to change the default behavior, you can do it by the next way:
Disable the auto_register in the config file filament-themes.php:
Register the theme inside your AppServiceProvider
use Yepsua\Filament\Themes\Facades\FilamentThemes;
public function boot()
{
...
FilamentThemes::register(function($path) {
// Using Vite:
return app(\Illuminate\Foundation\Vite::class)('resources/' . $path);
// Using Mix:
return app(\Illuminate\Foundation\Mix::class)($path);
// Using asset()
return asset($path);
});
...
}
Finally, as you can see, you don't need a package to get this functionality, You just need to configure tailwind using css variables and add new styles defining the primary color variables, however just installing this plugin is pretty easy to manage the themes colors from a config file.
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.
How can I help you explore Laravel packages today?