Angular: Implementing a Dark and Light Mode Toggle with Bootstrap 4

Looking for suggestions on the most effective way to incorporate dark mode and light mode into my bootstrap 4 (scss) angular application. Since the Angular cli compiles scss files, I'm not keen on the traditional method of using separate css files for each theme. Should I set a body class and apply .dark / .light classes throughout my scss files? Or maybe use mixins? Perhaps utilize bootstrap color themes? Any thoughts or ideas are appreciated!

Answer №1

Not entirely sure if this was the most efficient method, but here's what I ended up doing.

I implemented [ngClass]="setPrimary() on the main component

The setPrimary function would determine the time of day () and assign a class to the main component based on whether it was night, sunrise/sunset, or day

In the scss file, I defined 3 different color palettes for day, night, and sunrise/sunset

Upon page load, the default class was set to day, but as soon as setPrimary() was triggered, the styling would adjust accordingly

Answer №2

I struggled to tackle this issue using Angular CLI and Bootstrap 4 scss. My attempt to set up the project for compiling 2 lazy bundles was successful, but I hit a roadblock when trying to create two separate scss files - one for dark mode and one for light mode - each with unique values for the same variables. In the end, I had to settle for one scss file containing variables and styles for both dark and light modes, which then compiled into two bundles with dark.scss and light.scss, each containing CSS overrides tailored to their specific styles. I appreciate the suggestions, though!

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

"Implementing AngularJS bidirectional data binding to dynamically link user inputs with corresponding fields

Having trouble automatically outputting data with angularJS. One of the great features of angular is two-way data binding, but I can't seem to bind input with a JSON file. What I want to achieve is if the user's input matches a key, the correspon ...

Utilizing jspm for installing npm packages along with their dependencies

When using jspm, I can easily install npm packages by running: jspm install npm:<pkg-name>. This allows me to use the package in development, like so: import myPackage from 'myPackage';. If the package.json file of the npm package includes ...

"Enhance your Angular configuration with the powerful ngBootbox plugin

Is there a way to permanently change the locale of ngBootbox? I tried adding an extra angular configuration: var app = angular.module('some_module', ['highcharts-ng', 'ui.router', 'oc.lazyLoad', 'ui.selec ...

Securing your express.js app: The ultimate guide to safeguarding sensitive routes

Currently, I am in the process of developing a Node.js application that utilizes Express.js. In my app.js file, I have set up a route as follows: router.get("/db/:dbName", (req, res) => { var dbName = req.params.dbName ...

What is the best way to retrieve all collections and their respective documents in Firestore using cloud functions?

Seeking to retrieve an array structured as [1year, 1month, etc] with each containing arrays of documents. Currently encountering a challenge where the returned array is empty despite correct snapshot sizes. Unsure if issue lies with push() method implemen ...

Guide on integrating external libraries with Angular CLI

I've been working on incorporating external libraries into my project, and I've been following the instructions provided here. While I know it's possible to use CDNs in my index.html, I'm interested in learning how to do it using TypeS ...

Definitions for Typescript types that describe a custom hook responsible for fetching a specific part of the Redux state

I've created a custom hook called useReduxState to fetch a specific piece of state from Redux like so: const STATE_A = useReduxState("STATE_A"); Now, I'm running into issues when trying to integrate Typescript. These are the types I a ...

Referencing a variable within a string: Discord.js Hyperlink

Essentially, when attempting to use a discord hyperlink, I found that breaking the string to add a variable does not work as expected. I have tried calling it using $ and {} but it still doesn't work. .addField('Shortcuts', $'[Profil ...

Webpack compilation encountering an issue

I encountered an error while attempting to run my angular2 project. This issue arose after transitioning from a PC with Ubuntu to MacOS X. The Node version is 7.7.4, and the npm version is 4.1.2. I am executing npm webpack-dev-server --inline --progress ...

Having trouble closing my toggle and experiencing issues with the transition not functioning properly

Within my Next.js project, I have successfully implemented a custom hook and component. The functionality works smoothly as each section opens independently without interfering with others, which is great. However, there are two issues that I am facing. Fi ...

Inspecting JavaScript for any attachments

Before hitting the submit button, I need to verify if a file has been uploaded and display a warning message prompting the user to attach a file if it hasn't been done yet. I am looking for guidance on how to achieve this using JavaScript, Prototype, ...

What is the best way to combine TypedArrays in JavaScript?

Looking to combine multiple arraybuffers into a Blob, but facing limitations with TypedArrays that lack handy methods like "push". For example: var x = new Int8Array( [ 1, 2, 3 ] ); var y = new Int8Array( [ 4, 5, 6 ] ); The desired outcome is to have [ ...

Issues with relocating function during the NgOnInit lifecycle hook in an Angular 2 application

Currently, I am facing an issue with my Angular 2 app where the data sometimes lags in populating, causing a page component to load before the information is ready to display. When this happens, I can manually refresh the page for the data to appear correc ...

Creating a modal in Ruby on Rails with Bootstrap

I'm attempting to utilize bootstrap modal with ajax, but I'm facing an issue where the screen darkens upon clicking, but the modal never appears. Any tips or a better approach to tackle this problem? measures/index.html.erb <%= link_to &apo ...

Transforming JQuery Output into an HTML Table Layout

Hello there! I am currently working on parsing an XML file within my web page using jQuery. Here is a snippet of the code: function loadCards(lang) { $.ajax({ type: "GET", url: 'data.xml', dataType: "xml", suc ...

Adjust the height of an element using CSS based on the height of another

Is there a way to have two divs per row, where the second div always displays its full content and the height of the first div matches the height of the second div? If the content in the first div exceeds the height, it should be scrollable. I've atte ...

Tips for fixing typing problems (Document undefined) while including ES2017 library in the node_modules directory

When working on a legacy TypeScript project running [email protected], I encountered the need to access methods from ES2017, such as the array.includes method. To enable this, I made changes to my tsconfig.json file. Initially, it looked like this: ...

Steps for adding a favicon to Content-Type: application/json

In my implementation using node.js, I have an API that returns a response with Content-Type: application/json. Here is an example: module.exports={ api: (req, res) => { let data = {"data": [1, 2, 3]}; res.status(200).json(d ...

Once the print dialog is canceled or saved, the current window remains open

Whenever I try to print the data, a new window opens displaying all the respective data of the HTML page. The print dialog then quickly appears, but if I cancel or close the dialog, the current window does not close. Can someone please provide suggestions ...

Adjust jqGrid dimensions automatically as browser window is resized?

Does anyone know of a method to adjust the size of a jqGrid when the browser window is resized? I attempted the approach mentioned here, but unfortunately, it does not function correctly in IE7. ...