In a lot of cases, you'll likely want to provide some styles with your Filament plugin. We'll be focusing on an admin panel plugin here for simplicity.
package.json
file in the root of your plugin.{ "private": true}
npm install tailwindcss -D
npx tailwindcss init
content
array in the configuration file.module.exports = { content: [ './resources/views/**/*.blade.php' ], theme: { extend: {}, }, plugins: []}
preflight
plugin to prevent the reset styles being duplicated.module.exports = { content: [ './resources/views/**/*.blade.php' ], theme: { extend: {}, }, plugins: [], corePlugins: { preflight: false, } }
class
configuration.module.exports = { content: [ './resources/views/**/*.blade.php' ], darkMode: 'class', theme: { extend: {}, }, plugins: [], corePlugins: { preflight: false, }}
important
specifier to ensure the generated styles are scoped to your plugin.module.exports = { content: [ './resources/views/**/*.blade.php' ], important: '.my-filament-plugin', darkMode: 'class', theme: { extend: {}, }, plugins: [], corePlugins: { preflight: false }}
Ensure that your important
specifier is added to your Blade views, e.g. around the field class or page components that you're providing.
Generate your CSS using the Tailwind CLI.
npx tailwindcss -o ./dist/my-plugin.css
PluginServiceProvider
.class MyPluginServiceProvider extends PluginServiceProvider{ public static string $name = 'my-plugin'; protected array $styles = [ 'my-plugin' => __DIR__ . '/../dist/my-plugin.css', ]; }
Your plugin's CSS will now be loaded inside of the admin panel.
I've found that using
breaks dark mode in plugins since it generates classes like '.my-filament-plugin .dark' insetead of '.dark .my-filament-plugin'. This is due to that fact that class based dark mode only add's '.dark' to the html element in Filament and not anywhere under '.my-filament-plugin'.
Best way to support default Filament classes, dark mode and user overwritten themes is to simply include the Filament defalut color pallete in your plugin's tailwind config.