I am including a mixin from one SASS file into another file but I've got an error with the ionic serve
command:
Error: "Sass Error
Invalid CSS after " @include": expected identifier, was '"../../../theme/mai'"
This is the file where I am importing the mixin:
action-sheet-layout-1 {
@include '../../../theme/main.scss'
@include "settingAnimationHeader"; // this mixin is defined in main.scss
[button-action-shit] {
z-index: 99999; right: 16px; top: 56px;
...
}
The mixin as defined in main.scss
:
@mixin settingAnimationHeader {
@keyframes headerOff {
from {
background-color: theme-colors('mainColors', 'primary');
}
to {
background-color: transparent;
}
}
...
}
I am new to ionic and SASS, is what I am doing right or am I missing something?
The directory structure of both files from the app root:
src/theme/main.scss # the mixin is defined in this file.
src/components/action-sheet/layout-1/action-sheet-layout-1.scss # the mixin is imported here.
To use variables across multiple files in SASS is carried out by @import rule of SASS. @import rule which import Sass and CSS stylesheets for providing variables, @mixins and functions. Such that combine all stylesheets together for compiled css. It also imports URL such as frameworks like Bootstrap etc..
Sass extends CSS's @import rule with the ability to import Sass and CSS stylesheets, providing access to mixins, functions, and variables and combining multiple stylesheets' CSS together.
The new @use rule is the replacement for @import which allows other stylesheets to use its variables, functions, and mixins. What makes the @use import different is that the module (file imported using @use ) is only imported once, no matter how many times you reference it in your project.
Sass Importing Files Just like CSS, Sass also supports the @import directive. The @import directive allows you to include the content of one file in another.
at the top of your SASS file (action-sheet-layout-1.scss
) you need to include: @import "../../../theme/main.scss"
then you can access the mixins inside main.scss
by doing @include settingAnimationHeader;
inside the css rule where you want to apply this mixin
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With