I have a Vue only project and I am using Sass for styling. Currently, I have a Sass mixin defined as shown below; the code is simple because I am testing if it works only.
@mixin border {
border-radius: 1px;
}
I also have a component file where I create button components, and that's where I want to @use my border mixin:
@use "../abstracts/variables" as v;
@use "../abstracts/mixins" as m;
@mixin ripple-effect($bg-color: $text) {
background-position: center;
transition: background 0.6s;
&:hover {
background: rgba($bg-color, 0.6) radial-gradient(circle, transparent 1%, $bg-color 1%);
background-size: 15000%;
background-position: center;
}
&:active {
background-color: rgba($bg-color, 0.6);
background-size: 100%;
transition: background 0s;
}
}
.ui-icon-button {
--border-width: 1px;
@include border; // here is I use the mixin
border-radius: 90px;
border-style: solid;
border-width: var(--border-width);
cursor: pointer;
padding-block: calc(8px - var(--border-width));
padding-inline: calc(22px - var(--border-width));
position: relative;
&[aria-current="true"] {
@include ripple-effect($light-green);
background-color: $light-green;
border-color: $light-green;
color: white;
}
&:not([aria-current]) {
@include ripple-effect;
background-color: transparent;
border-color: $gray;
color: $gray;
}
& * {
margin-right: 6px;
}
}
The first @use, the one for the variables, works ok, but the second doesn't work at all, and raises the following error:
./node_modules/css-loader?{"sourceMap":true}!./node_modules/vue-loader/lib/style-compiler?{"vue":true,"id":"data-v-5275f051","scoped":true,"hasInlineConfig":false}!./node_modules/sass-loader/dist/cjs.js?{"sourceMap":true}!./node_modules/vue-loader/lib/selector.js?type=styles&index=0!./src/pages/TheUI.vue
Module build failed:
@include border;
^
No mixin named border
in proj_name/src/assets/scss/components/_buttons.scss (line 21, column 12)
@ ./node_modules/vue-style-loader!./node_modules/css-loader?{"sourceMap":true}!./node_modules/vue-loader/lib/style-compiler?{"vue":true,"id":"data-v-5275f051","scoped":true,"hasInlineConfig":false}!./node_modules/sass-loader/dist/cjs.js?{"sourceMap":true}!./node_modules/vue-loader/lib/selector.js?type=styles&index=0!./src/pages/TheUI.vue 4:14-370 13:3-17:5 14:22-378
@ ./src/pages/TheUI.vue
@ ./src/router/index.js
@ ./src/main.js
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js
I know you might be thinking that I should be calling my mixin properly, using its namespace (like @include m.border()), but that changes nothing. It's a second problem that I'd like to address: namespacing my Sass modules simply don't work. When I try doing that, it raises the following error:
./node_modules/css-loader?{"sourceMap":true}!./node_modules/vue-loader/lib/style-compiler?{"vue":true,"id":"data-v-5275f051","scoped":true,"hasInlineConfig":false}!./node_modules/sass-loader/dist/cjs.js?{"sourceMap":true}!./node_modules/vue-loader/lib/selector.js?type=styles&index=0!./src/pages/TheUI.vue
Module build failed:
@mixin ripple-effect($bg-color: v.$text) {
^
Invalid CSS after "...ct($bg-color: v": expected expression (e.g. 1px, bold), was ".$text) {"
in /home/bernardo/Documentos/Projetos/brsbet_webapp_2023/src/assets/scss/components/_buttons.scss (line 4, column 34)
@ ./node_modules/vue-style-loader!./node_modules/css-loader?{"sourceMap":true}!./node_modules/vue-loader/lib/style-compiler?{"vue":true,"id":"data-v-5275f051","scoped":true,"hasInlineConfig":false}!./node_modules/sass-loader/dist/cjs.js?{"sourceMap":true}!./node_modules/vue-loader/lib/selector.js?type=styles&index=0!./src/pages/TheUI.vue 4:14-370 13:3-17:5 14:22-378
@ ./src/pages/TheUI.vue
@ ./src/router/index.js
@ ./src/main.js
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js