Questions tagged [sass-modules]

This tag covers @use and Sass: Built-in Modules such as sass:color, sass:list, sass:map, sass:math, sass:meta, sass:selector, sass:string,

Overview:

The @use rule loads mixins, functions, and variables from other Sass files, and combines CSS from multiple files together.

Sass files loaded by @use are called modules.

Example:

@use 'buttons';

Sass also provides built-in modules full of useful functions.

The @use is quite similar to @import. but has a few differences:

  • The file is only imported once, no matter how many times you @use it.

  • Variables, mixins, and functions that start with an underscore (_) or hyphen (-) are considered private, and not imported.

  • Members (Variables, mixins, and functions) from the used file are only made available locally, but not passed along to future imports.

  • Similarly, @extends will only apply up the chain; extending selectors in imported files, but not extending files that import this one.

  • All imported members are namespaced by default.

When we @use a file, Sass automatically generates a namespace based on the file name:

@use 'buttons'; // creates a `buttons` namespace

Built-in Modules:

From the official documentation

Sass provides many built-in modules which contain useful functions (and the occasional mixin). These modules can be loaded with the @use rule like any user-defined stylesheet, and their functions can be called like any other module member. All built-in module URLs begin with sass: to indicate that they're part of Sass itself.

Sass provides the following built-in modules:

  • The sass:math module provides functions that operate on numbers.

  • The sass:string module makes it easy to combine, search, or split apart strings.

  • The sass:color module generates new colors based on existing ones, making it easy to build color themes.

  • The sass:list module lets you access and modify values in lists.

  • The sass:map module makes it possible to look up the value associated with a key in a map, and much more.

  • The sass:selector module provides access to Sass’s powerful selector engine.

  • The sass:meta module exposes the details of Sass’s inner workings.

12 questions
3
votes
1 answer

How can I import SCSS modules in React-Typescript?

I am trying to import styles from Navbar.module.scss file in my Navbar.tsx component. But it says I have already installed node-sass and @types/node-sass packages. Here's my package.json :
Abhishek Ram
  • 111
  • 2
  • 11
2
votes
0 answers

How can you use Sass Modules with Shopify Hydrogen V2?

I'm exploring using Hydrogen instead of Next.js Commerce for building out an ecommerce platform that I'm working on, but the only styling option for Hydrogen V2 seems to be tailwind or vanilla CSS. I can't find any documentation anywhere for using…
1
vote
0 answers

How to use scss modules in Next.js server components

I am trying to implement server components in my Next.js app. I'm using scss modules for styling. A typical component in my project looks like this: //MyComponent.client.jsx import s from './MyComponent.module.scss'; export const MyComponent = ({…
1
vote
1 answer

Sass modules multiple classes styles changes not being reflected

I thought I understood how modules worked but apparently not I have nested scss/sass styles that I'm trying to apply on an element but when I add those multiple styles to my element it doesn't take any of the styles while other elements that only…
Baby Coder
  • 759
  • 1
  • 7
  • 14
0
votes
1 answer

Why is css/ sass modules not working with third party library?

I wonder why my sass modules is not affected when I use third party component. In particular, I use react-horizontal-scrolling-menu
0
votes
1 answer

I am importing a variable file in every sass module would it affect my css bundle size?

I am using sass mixed with sass modules to scope styles for each component I found myself importing the variables file at every sass module I import by the new "@use" would that make my final compiled css bundle bigger or sass handles it under…
0
votes
0 answers

unable to pass value to the sass mixin variable

I am trying to write a mixin that will take the HEX color code and convert it to HSL. Every time the code is compiled it gives an error. tried to use @return to pass the variable but that also not working. help me fix the code. Thanks in…
0
votes
0 answers

Override/Replace Angular Material component theme mixin

In my project I would like to extent/override an existing theme e.g. with another property value or with another palette color or remove some definitions: // Excerpt: node_modules/@angular/material/radio/_radio-theme.scss // Angular Material Design…
mangei
  • 747
  • 7
  • 16
0
votes
0 answers

CSS/Sass Module :- attr doesn't work inside url

I have a Scss Code like this: .section-features { padding: 20rem 0; background-size: cover; background-position: center; margin-top: 6rem; transform: skewY(-5deg); &::before { content: attr(data-src); } background-image:…
0
votes
0 answers

How to pass CSS custom properties to sass Built-In Modules?

I am working on a vue project. In one of my components I used sass and tried to access a mixin that gives a hover effect. This is the code of my component: