Skip to content

Commit

Permalink
Fix CSS overrides in applications (#12646)
Browse files Browse the repository at this point in the history
* Declare new override entrypoint for frontend

* Declare new override entrypoint for admin

* Declare new override entrypoint for system panel

* Add documentation

* Add overrides in the design app to facilitate the development of new themes

* Apply suggestions from code review

Co-authored-by: Andrés Pereira de Lucena <andreslucena@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Andrés Pereira de Lucena <andreslucena@users.noreply.github.com>

* Add docs

* Add Readme

* Lint

* Apply suggestions from code review

Co-authored-by: Andrés Pereira de Lucena <andreslucena@users.noreply.github.com>

---------

Co-authored-by: Andrés Pereira de Lucena <andreslucena@users.noreply.github.com>
  • Loading branch information
alecslupu and andreslucena committed May 9, 2024
1 parent 2457682 commit 359b793
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 8 deletions.
15 changes: 14 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,20 @@ bin/rails decidim:upgrade:fix_orphan_categorizations

You can read more about this change on PR [\#12143](https://github.com/decidim/decidim/pull/12143).

### 3.5. [[TITLE OF THE ACTION]]
### 3.5. Improved CSS overrides

We have improved the CSS overriding mechanism. This is what allows you to change the CSS of decidim in your application in a more granular way.

Previously, you could do this by adding CSS rules in the `app/packs/stylesheets/decidim/decidim_application.scss` file. This file remains in place but is loaded as the last file in the application, so it will take precedence over all the CSS rules from the Decidim modules.

Additionally, if you need, you can also customize the `admin` and `system` interfaces by creating in your application the following files:

- `app/packs/stylesheets/decidim/admin/decidim_application.scss` for admin interface
- `app/packs/stylesheets/decidim/system/decidim_application.scss` for system interface

You can read more about this change on PR [\#12646](https://github.com/decidim/decidim/pull/12646).

### 3.6. [[TITLE OF THE ACTION]]

You can read more about this change on PR [\#XXXX](https://github.com/decidim/decidim/pull/XXXX).

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Application specific styles: https://docs.decidim.org/en/customize/styles/
@import "stylesheets/decidim/admin/decidim_application";
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// This is a file that can be overridden by the application in order to override styles
// Notice that this file is included at the very end of the stylesheets packs to have
// more priority
//
// By default this is empty.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<%= legacy_favicon %>
<%= favicon %>
<%= apple_favicon %>
<%= append_stylesheet_pack_tag "decidim_admin_overrides", media: "all" %>
<%= stylesheet_pack_tag "decidim_core", "decidim_admin", media: "all" %>
<%= javascript_pack_tag "decidim_core", "decidim_admin", defer: false %>
<%= snippets.display(:head) %>
1 change: 1 addition & 0 deletions decidim-admin/config/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@

Decidim::Webpacker.register_path("#{base_path}/app/packs")
Decidim::Webpacker.register_entrypoints(
decidim_admin_overrides: "#{base_path}/app/packs/entrypoints/decidim_admin_overrides.scss",
decidim_admin: "#{base_path}/app/packs/entrypoints/decidim_admin.js"
)
2 changes: 2 additions & 0 deletions decidim-core/app/packs/entrypoints/decidim_overrides.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Application specific styles: https://docs.decidim.org/en/customize/styles/
@import "stylesheets/decidim/decidim_application";
3 changes: 0 additions & 3 deletions decidim-core/app/packs/stylesheets/decidim/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,3 @@
// This imports all the Decidim module stylesheet imports registered at
// `config/assets.rb` of the module for the "app" group.
@import "!decidim-style-imports[app]";

// Application specific styles: https://docs.decidim.org/en/customize/styles/#_webpacker
@import "stylesheets/decidim/decidim_application";
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
// Notice that this file is included at the very end of the stylesheets packs to have
// more priority
//
// Please note this file is only targeting the end user interface and not the admin interface.
// To change the Tailwind CSS configuration, or to override the admin, system or design interface
// styles follow the instructions in https://docs.decidim.org/en/customize/styles/
//
// By default this is empty.
1 change: 1 addition & 0 deletions decidim-core/app/views/layouts/decidim/_head.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<link rel="manifest" href="/manifest.webmanifest">

<%= prepend_javascript_pack_tag "decidim_core", defer: false %>
<%= append_stylesheet_pack_tag "decidim_overrides", media: "all" %>
<%= stylesheet_pack_tag "decidim_core", media: "all" %>
<%= yield :css_content %>
Expand Down
1 change: 1 addition & 0 deletions decidim-core/config/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

Decidim::Webpacker.register_path("#{base_path}/app/packs")
Decidim::Webpacker.register_entrypoints(
decidim_overrides: "#{base_path}/app/packs/entrypoints/decidim_overrides.scss",
decidim_core: "#{base_path}/app/packs/entrypoints/decidim_core.js",
decidim_sw: "#{base_path}/app/packs/entrypoints/decidim_sw.js",
decidim_conference_diploma: "#{base_path}/app/packs/entrypoints/decidim_conference_diploma.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<%= javascript_pack_tag "decidim_core", "decidim_design", defer: false %>
<%= stylesheet_pack_tag "decidim_core", "decidim_design", media: "all" %>
<%= append_stylesheet_pack_tag "decidim_overrides", media: "all" %>
<%= append_stylesheet_pack_tag "decidim_design", media: "all" %>
<%= stylesheet_pack_tag "decidim_core", media: "all" %>
<%= organization_colors %>
<%= render partial: "layouts/decidim/js_configuration" %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Application specific styles: https://docs.decidim.org/en/customize/styles/
@import "stylesheets/decidim/system/decidim_application";
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// This is a file that can be overridden by the application in order to override styles
// Notice that this file is included at the very end of the stylesheets packs to have
// more priority
//
// By default this is empty.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<%= csrf_meta_tags %>
<%= append_stylesheet_pack_tag "decidim_system_overrides", media: "all" %>
<%= stylesheet_pack_tag "decidim_core", "decidim_system", media: "all" %>
<%= javascript_pack_tag "decidim_core", "decidim_system", defer: false %>
1 change: 1 addition & 0 deletions decidim-system/config/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@

Decidim::Webpacker.register_path("#{base_path}/app/packs")
Decidim::Webpacker.register_entrypoints(
decidim_system_overrides: "#{base_path}/app/packs/entrypoints/decidim_system_overrides.scss",
decidim_system: "#{base_path}/app/packs/entrypoints/decidim_system.js"
)
17 changes: 14 additions & 3 deletions docs/modules/customize/pages/styles.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ image::header-snippet.png[Header snippet]

Notice that you can resize this textarea.

== Webpacker
== Shakapacker

Decidim uses Webpacker to compile assets. There are two ways to customize CSS:
Decidim uses Shakapacker to compile assets. There are two ways to customize CSS:

1. if you want to redefine a specific snippet of CSS (say a few classes but not a whole file) you can use decidim_application.scss
1. if you want to redefine a specific snippet of CSS (say a few classes but not a whole file) you can use decidim_application.scss. You can read more about this in the <<Overriding CSS and styles>> section.
2. and of course you can overwrite whole files by copying them into the application i.e: to replace `decidim-core/app/packs/stylesheets/decidim/modules/_data-consent.scss` you should create in your Rails app a file in `app/packs/stylesheets/decidim/modules/_data-consent.scss` and it will have more priority over the Decidim file.
3. if you want to customize the application colors yo can use the admin interface.

Expand All @@ -68,6 +68,17 @@ Since this file is being managed by Decidim, it will be impossible to customize

You can override the default configuration by creating a file `config/tailwind.config.js.erb` starting from the following https://github.com/decidim/decidim/blob/develop/decidim-core/lib/decidim/assets/tailwind/tailwind.config.js.erb[content]

== Overriding CSS and styles

If you want to override a specific CSS class, you can do so by adding a new CSS class in your `app/assets/stylesheets/decidim_application.scss` file. This will allow you to override the default styles provided by Decidim.

*Please note:* the above file is created by default when you install Decidim. Also the file is empty. This file allows you to edit *only* the end user styles.

If you want to override other layouts, you can do so by creating new files:

. /admin: `app/packs/stylesheets/decidim/admin/decidim_application.scss`
. /system: `app/packs/stylesheets/decidim/system/decidim_application.scss`

== Accessibility

To maintain accessibility level, if you add new colors use a http://webaim.org/resources/contrastchecker/[Color contrast checker] (WCAG AA is mandatory, WCAG AAA is recommended)
Expand Down

0 comments on commit 359b793

Please sign in to comment.