Update module to use CSS variables instead of adding inline CSS via Javascript.

Created on 9 August 2024, 3 months ago
Updated 19 August 2024, 3 months ago

Problem/Motivation

The current implementation of the Environment Indicator module adds inline CSS to the page to style the environment indicator banner. This approach can be limiting and doesn't leverage modern CSS best practices. Inline CSS can make it harder to customize and override styles, and it increases the overall size of the HTML. Using CSS variables instead of inline CSS would make the module more flexible, easier to maintain, and more compatible with various theming needs.

Steps to reproduce

Search the codebase for background-color: https://git.drupalcode.org/search?search=background-color&nav_source=nav...

  1. Install and enable the Environment Indicator module.
  2. Configure the environment indicator to display a banner for a specific environment (e.g., Development, Staging).
  3. Inspect the HTML elements where the environment indicator is applied.
  4. Observe that the styles for the environment indicator banner are added as inline CSS.

Proposed resolution

Refactor the module to use CSS variables instead of inline CSS for styling the environment indicator banner. This will involve:

  • Defining CSS variables in a global stylesheet that can be overridden by themes.
  • Updating the moduleโ€™s logic to apply styles using the defined CSS variables rather than injecting inline styles.

Remaining tasks

  1. Identify all instances where inline CSS is used within the module.
  2. Create a global CSS file for the module that defines the necessary CSS variables.
  3. Refactor the code to use CSS variables instead of inline styles.
  4. Test the changes across different environments to ensure consistency and compatibility.
  5. Update documentation to reflect the new approach.

User interface changes

  • Users may notice a slight change in how custom styles are applied to the environment indicator banner, depending on how CSS variables are overridden.
  • Theme developers will have the ability to easily customize the environment indicator banner by overriding CSS variables.

API changes

N/A

Data model changes

N/A

๐Ÿ“Œ Task
Status

Active

Version

4.0

Component

Code

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States trackleft2 Tucson, AZ ๐Ÿ‡บ๐Ÿ‡ธ

Live updates comments and jobs are added and updated live.
  • CSS

    It involves the content or handling of Cascading Style Sheets.

Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024