Utilize a SCSS class defined in one file within a different SCSS file

In my React project, I have a day/night theme button that changes the main body color in the App.scss. It's a simple setup using body.light and body.dark. However, I need to also change the text color in the navigation bar, which is located in a different folder with Navbar.jsx and Navbar.scss. Since I can only edit the App.scss file due to how the button is set up, I'm wondering how I can export or add the .site-nav class from Navbar.scss into my App.scss so that I can include .site-nav.dark and .site-nav.light for it to function correctly.

I attempted renaming Navbar.scss to _Navbar.scss and using a mixin:

@mixin nav {
  //code
  .site-nav {
    //code
  }
}

Then I tried adding this to my App.scss:

@use './Navbar/Navbar.scss' as Navi;

body.dark {
  color: #a58c6f;
  background-color: #1c221f;
  @include Navi.site-nav;
}

But I received an error:

Invalid CSS after "  @include Navi": expected "}", was  ".site-nav;"
. Any suggestions on how to resolve this?

Answer №1

When you import Navbar.scss using @use, there is no need to use @include. All classes within Navbar will automatically be accessible in your App.scss. You can define the light and dark classes in either your App.scss or Navbar.scss. Using @import also allows you to import Sass files into other Sass files.

@use 'Navbar/Navbar';
.nav {
   .light { //...}
   .dark { //...}
}

Alternatively

@import 'Navbar/Navbar';
.nav {
   .light { //...}
   .dark { //...}
}

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

What is the best way to navigate users to a different page when they click on a button?

I recently designed a button in Dreamweaver software. Could you please guide me on how to set up the button so that when clicked, it redirects the user to a different page using Dreamweaver? Below is the HTML code for the button: <input type="submit" ...

Is the order of execution of extraReducers before or after the reducers?

I was curious about the createSlice function in redux-toolkit and how it handles the order of execution for extraReducers compared to reducers. Can we determine if the extraReducers are executed before or after the reducers, or is the order indeterminate? ...

Emotion, material-ui, and typescript may lead to excessively deep type instantiation that could potentially be infinite

I encountered an issue when styling a component imported from the Material-UI library using the styled API (@emotion/styled). Error:(19, 5) TS2589: Type instantiation is excessively deep and possibly infinite. Despite attempting to downgrade to typescript ...

Customizing a ControlsFX PopOver in a JavaFX application

I am looking to personalize the appearance of a JavaFX PopOver control. I have a button that triggers the display of the PopOver. Below is a functional example: package custompopover; import javafx.application.Application; import javafx.event.ActionEvent ...

Alert: ER_NO_SUCH_TABLE: The table 'companyapp.prescription' is not found

I am developing a basic CRUD application using React, Node.js, and Express. I have connected to my MySQL database named "managementapp" and attempted to insert information into the database. However, I keep receiving an error stating "table doesn't ex ...

The Material UI dialog is causing issues for CKEditor 4

In the midst of my React project, I have incorporated CKEditor 4 into a Material UI dialog. However, when attempting to utilize advanced features like Math, I encounter an issue where I am unable to input any text into input or textarea fields. Despite sea ...

The border length of the unordered list is equal to half of the length

I would like the blue borders of these "ul" elements to be centered beneath the black "li" elements, with a width that is 50% of the child width. However, I'm unsure about how to achieve this. I attempted using ":before", but it only seems to work for ...

What is the best way to restrict the selection of specific days of the week on an HTML form date input using a combination of JavaScript, React, and HTML?

I need help customizing my Forms Date Input to only allow selection of Thursdays, Fridays, and Saturdays. I've searched for a solution but haven't been successful so far. Is there any JavaScript or HTML code that can help me achieve this? Below ...

Enhancing the state of a child component in react

I'm facing a challenge with updating the state of my child component by utilizing props. My parent component, InputForm, holds a 2d array that gets modified as the user inputs data into a form. While this functionality is working as expected, I' ...

You have attempted to make an invalid hook call in the react chat app. Hooks can only be called within the body of a function component

Encountering problems like manifest.json:1 Manifest: Line: 1, column: 1, Syntax error. **Important Error Message/User Notification:** react-dom.development.js:20085 The above error occurred in the <WithStyles(ForwardRef(AppBar))> component: Arrange ...

What are some methods to design distinct angular ui bootstrap dialogs?

Is there a way to customize angular-ui bootstrap modal dialogs so that they have distinct colors and sizes from each other? I can style them globally for the site but not individually. I came across a similar question, but it only addresses changing all d ...

What could be causing my input to fail to update? - React

I can't seem to understand why my input field isn't updating properly. Here's the code snippet: state = { org: { orgName: '' } }; updateInput = field => event => { this.setState({ [field]: event. ...

Excessive re-renders can be problematic in React as the framework has set limitations to avoid getting stuck in an endless loop

Currently, I am in the process of establishing a logged-in session that connects to the Firebase realtime database when the user refreshes the browser. Although it is operational, I am encountering this specific error: Experiencing too many re-renders. ...

Leveraging react-redux-firebase for integrating cloud functions into React JS applications

I recently started learning React JS and I'm working on a project where I need to display data from cloud firestore. To fetch the data, I am utilizing react-redux-firebase. It's all working smoothly so far. However, now I want to switch to retrie ...

Extract the entire div including all its elements and then transmit it using the PHP mail function

Currently, I am developing a feature that allows users to send an email. The email should include only one div from the page which contains elements added using the jQuery drag and clone function. I am unsure how to copy the entire div along with its child ...

Aligning the Bootstrap navbar to the right causes the items to shift to the left

UPDATE: The issue has been resolved. It turns out that the navbar was not extending to 100% width and reaching the edges of the screen. I am currently facing a challenge with a Bootstrap 4 navbar, similar to issues I encountered with the previous version. ...

Navigating through the complexities of managing asynchronous props and state in React-components

I'm really struggling to understand this concept. My current challenge involves passing asynchronously fetched data as props. The issue is that the props themselves are also asynchronous. Below is a simplified version of the component in question: i ...

arranging elements within a container

<td id="name_3869-0_0" style="position: relative; " colspan="4"> <div style="float:left;width:100%"> <img src="/img/1.gif" align="middle" style="margin-right: 10px;" class="company_symbol" border="0"> <strong style= ...

Unusual dark streak beneath the Wordpress emblem

I recently created my website using Wordpress and decided to use a PNG image (140*82 px) as the logo instead of the default "site-title". However, I encountered an unusual issue where a black line appeared just below the image. After checking my "header.ph ...

"Step-by-step guide on using Proptypes in your code

Just starting out with React, so please be patient :) I'm having trouble getting prop types to validate in my code. Despite not finding any errors in the console, I can't seem to figure it out after spending quite some time on it. Any help or gu ...