I have a SCSS map in a file called '_colors.scss' which I want to call it from another file called 'app.scss'. I have tried some methods but I can´t find the right way.
This is my '_colors.scss' file:
/* Functions */
@function color($elem, $variant) {
@return map-get(map-get($color, $elem), $variant);
}
/* Variables */
$colors: (
text: (
1: #162c5b,
2: #565678,
3: #ababc9,
soft: #718097,
footer: #ff2a91,
1i: #fff,
),
bg: (
hero: #038aff,
awards: purple,
features: #5ccaa7,
tools: #febd3d,
3: #d2daf0,
infinite: #161348,
footer: #161348,
line-footer: #2f2c5b,
pink: #f1ecfd,
white: #fff,
),
);
And this is my 'app.scss' file where I want to call it from, but it does not seem to call the map, so I can use it in my scss file, like I am doing with the background color of the '.box' class. What am I missing?
@use 'colors' as cl;
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: "Inter", sans-serif;
}
.hero {
width: 100%;
.container {
margin: 0 auto;
padding: 90px 0;
width: min(1200px, 100%);
.box {
width: 300px;
height: 300px;
padding: 28px;
background-color: color(bg, hero);
h2 {
font-size: 2rem;
padding-bottom: 20px;
font-weight: 800;
}
p {
font-size: 0.9rem;
font-weight: 400;
color: color(text, 1);
}
}
}
}
Doesn't simple @use work for your case? "@use as" lets use @include for mixings with a namespace. like namespace.mixingname
@use 'colors';
or
@import 'colors';