Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: basic theming support #148

Merged
merged 29 commits into from
Mar 10, 2021
Merged

feature: basic theming support #148

merged 29 commits into from
Mar 10, 2021

Conversation

ryangjchandler
Copy link
Member

@ryangjchandler ryangjchandler commented Mar 9, 2021

This pull request adds support for very basic theming. With the changes here, you will be able to change the three main colours used by Filament.

Customising colours

The main colours used by Filament can be customised using CSS variables.

The colours available are:

  • primary
  • success
  • danger
  • white
  • blue
  • gray

All of the colours, apart from white, can be adjusted on a scale of 100-900 (just like Tailwind), e.g.

:root {
    --f-primary-100: #450fff;
}

To customise the colour white, use --f-white: #ffffff as the CSS variable.

Quickly generating a theme

If you want to quickly generate a theme with all of the variable names stubbed out, you can use the make:filament-theme command:

php artisan make:filament-theme custom-theme

This will generate a new CSS file resources/css/filament/custom-theme.css with all of the CSS variables commented out. Uncomment the variables you wish to modify and insert your own colours.

You can then use the instructions below to include / enqueue the CSS file on the Filament pages.

Enqueuing custom scripts and styles

This pull request also adds support for including your own styles and scripts inside of Filament, this can be done using the 2 methods:

  • Filament::registerScript($name, $script)
  • Filament::registerStyle($name, $style)

These scripts will be included after Filament's own scripts and Livewire's scripts but before any stacks. @danharrin Do we want to change this so that they come after stacks instead?

Passing data to the front-end

If your custom scripts rely on some data from the server, you can pass this along using Filament::provideToScript($variables):

Filament::provideToScript([
    'model' => Model::first()
])

Calling these new methods

You should call these new methods inside of a service provider's boot method. This will ensure Filament's core classes as well as Laravel's are registered with the container.

Filament::serving

There is also a new Filament::serving($callback) method that can be used to only run your Filament related logic when Filament is actually being served to the user.

You can use it like this:

Filament::serving(function () {
    Filament::registerScript('script-name, asset('js/script.js'));
});

Behind the scenes, this will just register an event listener for the Filament\Events\ServingFilament event. This means you could also pass through a Laravel-style callable array too.

Filament::serving([ListenerClass::class, 'method']);

The callback function will receive the ServingFilament event too, which has a public $request variable so you can run some logic based on the current request context.

You could also register an event using Event::listen(ServingFilament::class) directly, but the Filament::serving method is recommended since any under-the-hood changes won't result in any code breaks.

@danharrin danharrin changed the base branch from main to develop March 9, 2021 21:34
@ryangjchandler ryangjchandler marked this pull request as ready for review March 9, 2021 21:42
@danharrin danharrin added the enhancement New feature or request label Mar 9, 2021
resources/views/components/layouts/base.blade.php Outdated Show resolved Hide resolved
resources/views/components/layouts/base.blade.php Outdated Show resolved Hide resolved
resources/views/components/layouts/base.blade.php Outdated Show resolved Hide resolved
resources/views/components/layouts/base.blade.php Outdated Show resolved Hide resolved
src/FilamentManager.php Outdated Show resolved Hide resolved
src/FilamentManager.php Outdated Show resolved Hide resolved
src/FilamentManager.php Outdated Show resolved Hide resolved
src/FilamentManager.php Outdated Show resolved Hide resolved
src/FilamentManager.php Outdated Show resolved Hide resolved
ryangjchandler and others added 3 commits March 10, 2021 10:35
Co-authored-by: Dan Harrin <git@danharrin.com>
Co-authored-by: Dan Harrin <git@danharrin.com>
Co-authored-by: Dan Harrin <git@danharrin.com>
@danharrin danharrin merged commit be681d9 into develop Mar 10, 2021
@ryangjchandler ryangjchandler deleted the feature/theming branch March 10, 2021 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants