Properly managing variable overrides in an Angular library

I am currently developing a unique design library using the latest versions of Bootstrap 5 and Angular. In order to customize the look to fit my specific design needs, I am utilizing the core Bootstrap framework and adding extensions or custom styles.

My approach involves using Bootstrap as follows:

LIBRARY :

Within my library, I have two SCSS files:

design-library.core.scss

// Necessary import for bootstrap functionalities
@import '~bootstrap/scss/functions';

// Library default variables that override Bootstrap's
@import './variables'; 

design-library.extension.scss

// It is crucial to import the variables in order to prevent any undefined errors

@import './variables'
// Make necessary style overrides to Bootstrap components like 
.alert {
  background: $white;
}

PROJECT :

When integrating the design-library into my project, I follow this setup:

project.scss

// Importing the default variables from the design library
@import '~/design-library.core';

// Further overriding defaults with additional project-specific variables
@import './project-variables'

// Importing Bootstrap
@import '~bootstrap';

// Importing the customized Bootstrap extension from the design library
@import '~/design-library.extension'

This integration works well, however, I encounter issues with variable overrides. For example, if I set $red: #f00 as the default in the library, but then define $red: #e30000 in the project variables file, the CSS generated will still use $red: #f00 from the library instead of the overridden value. How can I ensure that the extension CSS uses the correct overridden variables defined by the implementing project?

EDIT : Just wondering if my explanation is clear enough? :x

Answer №1

It seems like you are interested in customizing certain variables within the design-library.extension.scss file. One way to achieve this is by importing another file.

@import './variables'
@import './overrides'
// customize bootstrap style like 
.alert {
  background: $white;
}

However, if you expect this file to be aware of the changes made in the project.scss file, that might not be feasible.

When you modify the variables in project.scss, they are isolated to that specific file and not automatically reflected elsewhere. To include these modifications in your extension, you would need to import project.scss.

In case you intend to distribute this library as a package, it's advisable to avoid importing external files as it could lead to potential issues.

If this customization is for personal use, consider importing your project-variables file after ./variables in design-library.extension.scss.

I hope this explanation helps clarify things for you.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Create unique hyperlinks that, when clicked, display distinct carousels in the same modal window

I've been developing a website with multiple links that trigger the same modal with different carousels. I attempted to pass an id into the data-target attribute of each link, but when the modal opens, it displays two carousels instead of just the sel ...

How to retrieve the AngularJS Object in JavaScript to trigger the Bootstrap modal popup

To trigger the logout() function, it should only execute if the value of an AngularJS object within rootscope is true. How can I validate this using JavaScript to check the content of the rootscope object? <body ng-controller="myController"> & ...

Ways to Prompt a User to Select the "Remember Me" Option

How can I implement the functionality of 'Remember Me' on a login page? I want users who click on 'Remember Me' to be able to reopen the page without logging in again, even after closing their browser. But how do I differentiate between ...

Please refrain from initiating the next action until the previous action has been completed

As a beginner, I am currently working on a photo viewer project using JavaScript and jQuery. My main issue arises when clicking on the arrow to view the next picture. I want the current picture to fade out smoothly before the new one fades in. However, th ...

Using image paths in CSS for styling purposes

As I develop an Asp.net website, I've encountered a surprising issue. Here is my folder structure: - Styles - master.css - Images -webPages -scripts When trying to access an image in the Images folder from the CSS file, I receive a ...

"Exploring Angular's versatile table component for dynamically displaying object values in a loop

I am facing an issue with my generic table component in the software I am currently developing. The problem arises when trying to loop through and display all the values in the table. My employeeList contains data fetched from the backend successfully, bu ...

Error message in Angular 2 RC-4: "Type 'FormGroup' is not compatible with type 'typeof FormGroup'"

I'm currently facing an issue with Angular 2 forms. I have successfully implemented a few forms in my project, but when trying to add this one, I encounter an error from my Angular CLI: Type 'FormGroup' is not assignable to type 'typeo ...

Angular2 - Actively selecting a checkbox in an ngFor loop with a reactive form

There is an object retrieved from a database that consists of a list of names with their corresponding IDs, as well as a flag to indicate whether they are selected or not. Object: let items = [{ ID: 1, Name: 'Item A', Selected: 'Y ...

Table Structure Misalignment Issue

Below is the code used to align contact details: <html> <body> <table width="900" class="contact-details"> <tr> <td><img src="./images/Mobile.png"></td> <td> <p> ...

Tips for customizing the appearance of a specific cell in the first column of a Material UI table

Currently, I am modifying the material ui table found in this codesandbox link. My goal is to adjust the style of the first column's cell in the table when it is selected to match the image provided below. https://i.sstatic.net/DGubN.png It seems lik ...

Unable to show the company logo in the navigation bar

Working on a pizza site and encountering an issue - trying to add the logo of the place to the navbar (which also links to the main page) but it's not displaying. Using Twitter Bootstrap for this project. Here is the code snippet: /*#557c3e green*/ ...

Tips to avoid displaying mat-menu when clicking

Is there a way to display and hide Mat-menu on mouseover and mouseout events, while also preventing the menu from showing on click? Here is the HTML code: <button mat-mini-fab color="primary" [matMenuTriggerFor]="menu" (mouseenter)="openMenu()"> ...

Testing Your Angular 7 Code: Unit Testing Made Easy

I am currently working on developing unit tests for this angular script: export class DataService { private csrfToken: string = ''; private isContentShown: BehaviorSubject<boolean> = new BehaviorSubject(true); constructor(private h ...

Updating the navigation with a dynamic CSS class using jQuery

Hey there, I'm on the lookout for a simple and discreet method to dynamically add an "active" class to a navigation menu based on the current directory. Unfortunately, I am unable to modify the body tag with a custom class, ruling out a pure CSS solut ...

Achieve a full-page height navigation bar using CSS

Currently in the process of building a website utilizing CSS and HTML, I have successfully added a navigation bar to the left side of the page using this specific CSS code. However, an issue arises when the screen is scrolled down as the navigation bar doe ...

Is there a way to modify the form's style to show "none" without submitting the form?

Clicking the Close button will submit the form to Lcar.php. The goal is to hide the CSS and remain on the current page after clicking the button. The issue of the form being submitted to Lcar.php when the Close button is clicked arises despite the fact t ...

The Zurb Foundation has a multitude of redundant CSS entries

I have been utilizing Zurb Foundation for a while now, with a bower + compass setup as outlined in the documentation here. Recently, I encountered an issue where a specific page was loading slowly. Upon investigating, I discovered that there were numerous ...

Output the name of the file while executing the ant process

Currently, I am utilizing YUI compressor within an ant build process to compress CSS and JavaScript files. I would like the compressor to display the name of each file it is processing as it goes along, so that in case of an error, I can easily pinpoint wh ...

Arranging elements within ngFor loop in Angular 2: positioning and aligning items

I am currently deepening my knowledge of Angular2. I am working on binding array values to the UI using ngFor and ngSwitch directives. I am aiming to display records based on various ngSwitchCase scenarios rather than just following the order in which they ...

The minmax() function is causing grid items to not wrap correctly

I have been working on creating a responsive web page where the "boxes" automatically adjust to a new row when the browser window is resized. To achieve this, I utilized the following CSS code: grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); ...