How to change breakpoints in the scss in vuetify v2? - css

I'm using scss files and I want to change the breakpoints in the css side in vuetify v2.
I Can't find any reference in vuetify upgrade guide for this.
In version 1.5 I did style-x.styl:
$grid-breakpoints := {
xs: 0
sm: 476px
md: 668px
lg: 1000px
xl: 1300px
}
#import '~vuetify/src/styles/styles.sass';
$material-light.background = #f5f5f5;
#import '~vuetify/src/stylus/main';
And then I import the file:
import '../style-x.styl';
...
Vue.use(Vuetify);
...

So look at the documentation: https://vuetifyjs.com/en/customization/sass-variables/#vue-cli-install, it says:
Once installed, create a folder called sass, scss or styles in your
src directory with a file named variables.scss or variables.sass
That is, after we have created the project using the Vue CLI, we manually:
Сreate the new sass folder in our src folder.
Next, in our new sass folder, create the new variables.scss file.
Next, in our new variables.scss file, write these lines, these
are the standard settings for bootstrap-4:
*
$grid-breakpoints: (
xs: 0,
sm: 576px,
md: 768px,
lg: 992px,
xl: 1200px
);
Now restart npm run serve and you are ready. You can change the values in the $grid-breakpoints variable to your own.

For version 2.0 you have to change the SASS variables by creating a custom SASS file which you import into your vue.config.js file: https://vuetifyjs.com/en/customization/sass-variables.
For the SASS variables to be available globally, you can to first
// src/sass/main.scss
#import '~vuetify/src/styles/styles.sass';
// You need to map-merge your new SASS variables
$grid-breakpoints: map-merge($grid-breakpoints, (
xs: 0,
sm: 476px,
md: 668px,
lg: 1000px,
xl: 1300px
))
And then have your config file import the variable globally:
// vue.config.js
module.exports = {
css: {
loaderOptions: {
sass: {
data: `#import "~#/sass/main.scss"`,
},
},
},
}
You also have to specify your custom breakpoints when you specify Vuetify options:
https://vuetifyjs.com/en/customization/breakpoints
//import this into your main.js
import Vue from 'vue'
import Vuetify from 'vuetify/lib'
export default new Vuetify({
breakpoint: {
thresholds: {
xs: 0,
sm: 476,
md: 668,
lg: 1000,
xl: 1300
}
}
})

Related

Breakpoints from props not working (Tailwindcss)

I have a problem with my project, I don't understand why when trying to pass 'width' from props it won't work
https://i.stack.imgur.com/SoXzx.png
code looks like this
<div className={'border-b-[1px] w-[50%] lg:' + props.width + ' text-thirdMainColor ' + props.margin }></div>
I will add that I also tried to add breakpoints in 'tailwind.config.js', but this did not change anything.
theme: {
screens: {
sm: '480px',
md: '768px',
lg: '976px',
xl: '1440px',
},
The following form works normally.
https://i.stack.imgur.com/siSaq.png

tailwind - some class not works

I use tailwind in nextjs project, and when I restart the server (I mean start the server again with npm run dev) some tailwind code not working when I write class property in "inspect Element" it works but not tailwind code.
not works: w-1/2 (width: 25%), lg:w-0 (media screen and(max-width: 1024px) {code})
my tailwind.config.js
/** #type {import('tailwindcss').Config} */
module.exports = {
content: [
"./app/**/*.{js,ts,jsx,tsx}",
"./pages/**/*.{js,ts,jsx,tsx}",
"./components/**/*.{js,ts,jsx,tsx}",
],
theme: {
screens: {
sm: { max: "640px" },
md: { max: "768px" },
lg: { max: "1024px" },
xl: { max: "1280px" },
"2xl": { max: "1536px" },
}
},
plugins: [],
};
my global.css file:
#tailwind base;
#tailwind components;
#tailwind utilities;
#import "./reset.css";
You need to pass the classes fully w-1/2 instead of partially like 1/2. As tailwind doesn't support dynamic classes.
Try the following code.
function Component({ width}) {
return (
<div
className={`${width}`}
>
Hello there
</div>
);
}
And use it as
<Component
width={"w-1/2"}
/>
Edit: Using Safelisting classes
As a last resort, Tailwind offers Safelisting classes
Safelisting is a last-resort, and should only be used in situations where it’s impossible to scan certain content for class names. These situations are rare, and you should almost never need this feature.
In your example,you want to have different width. You can use regular expressions to include all the widths you want using pattern
In tailwind.config.js
module.exports = {
content: [
'./pages/**/*.{html,js}',
'./components/**/*.{html,js}',
],
safelist: [
{
pattern: /w-(1/2|2/2|1/6|2/6)/, // You can define all the width you desire
},
],
// ...
}
you have to create an extend object with your personalized code inside like this:
theme: {
extend: {
screens: {
'clg': '1090px',
'cxl': '1159px',
'c2xl': '1213px',
'c3x1': '1373px',
'c4x1': '1480px',
'c5x1': '1579px',
'c6x1': '1679px',
'c7x1': '1740px',
'c8x1': '1820px',
},

react-image-gallery doesn't apply styles

I want to use react-image gallery to create a thumbnail carousel, but it doesn't apply the styles from the package, and I did everything as the documentation says .
# SCSS
#import "~react-image-gallery/styles/scss/image-gallery.scss";
# CSS
#import "~react-image-gallery/styles/css/image-gallery.css";
I put both of these 2 in my css/scss file, but nothing. I also change the path so that they will point exactly to the node_modules package folder, like this "../../node_modules/react-image-gallery/styles/css/image-gallery.css", but still doesn't work.
Any idea what I am doing wrong ?
Look at my question I found the solution if you are interested in the solution to now
import React from 'react'
import "react-image-gallery/styles/css/image-gallery.css";
import ImageGallery from 'react-image-gallery';
import {ImgGallery} from "./Styled.js"
export function ShopDetails() {
const images = [
{
original: 'https://picsum.photos/id/1018/1000/600/',
thumbnail: 'https://picsum.photos/id/1018/250/150/',
},
{
original: 'https://picsum.photos/id/1015/1000/600/',
thumbnail: 'https://picsum.photos/id/1015/250/150/',
},
{
original: 'https://picsum.photos/id/1019/1000/600/',
thumbnail: 'https://picsum.photos/id/1019/250/150/',
},
];
return (
<ImgGallery>
<ImageGallery thumbnailPosition="left" useBrowserFullscreen={false} showPlayButton={false} autoPlay={true} items={images} />;
</ImgGallery>
)
}

How to extend a variable's map in SCSS?

I am using a package called Buefy which is a Vue.js wrapper for the Bulma CSS framework library. Buefy puts an attribute/property on its template components called type (e.g., type="is-warning"). As per the Buefy documentation, the term "is-warning" is pre-defined according to the $colors variable set within SCSS:
So I followed these instructions from Buefy to be able to customize the the $colors map, but what I would like to do, however, is keep the initial SCSS defined in those instructions within a single base.scss file, and then extend with my own customized SCSS file.
I have included the base.scss file in my Vue project with the following snippet in the vue.config.js file:
module.exports = {
css: {
loaderOptions: {
sass: {
prependData: `
#import "#/assets/scss/base.scss";
`
}
}
}
}
So my question is, how can I extend the $colors map in the base.scss with my own names and values?
This is a snippet from base.scss, where the $colors map is defined:
```css
$colors: (
"white": ($white, $black),
"black": ($black, $white),
"light": ($light, $light-invert),
"dark": ($dark, $dark-invert),
"primary": ($primary, $primary-invert),
"info": ($info, $info-invert),
"success": ($success, $success-invert),
"warning": ($warning, $warning-invert),
"danger": ($danger, $danger-invert),
"twitter": ($twitter, $twitter-invert)
);
```
So, again, my question is how can I extend the $colors map in a different file outside of base.scss (perhaps in App.vue) to leave the original untouched? I didn't see any solution shown in the scss docs.
Your custom color values would go in a variable (later merged into $colors) called $custom-colors, and it's actually described in the docs on "derived variables".
And to customize it:
// Import Bulma's core
#import "~bulma/sass/utilities/_all";
// Set your colors
$custom-colors: (
"facebook": ($blue, $white),
"linkedin": ($dark-blue, $white)
// etc.
);
// Setup $colors to use as bulma classes (e.g. 'is-twitter')
$colors: (
"white": ($white, $black),
"black": ($black, $white),
"light": ($light, $light-invert),
"dark": ($dark, $dark-invert),
"primary": ($primary, $primary-invert),
"info": ($info, $info-invert),
"success": ($success, $success-invert),
"warning": ($warning, $warning-invert),
"danger": ($danger, $danger-invert),
"twitter": ($twitter, $twitter-invert)
);
// Import Bulma and Buefy styles
#import "~bulma";
#import "~buefy/src/scss/buefy";
It's internally using a custom function called mergeColorMaps.

Next.JS: Using SASS variables from global scss

I have a Next.js Application with a main.scss global css file imported in the pages/_app.js file.
_app.js
import '../global-styles/main.scss'
export default function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}
The styles from this file work.
I also have some modular scss files attached to components, using [component].module.scss.
I have written a variable in my variables.scss file, one of the files which I #import in main.scss,
variables.scss
$mobile: 750px;
main.scss
#import './fonts.scss';
#import './variables.scss';
#import './global.scss';
However, when I try to use this variable in one my modular css, I get an error
./module-styles/navbar.module.scss (./node_modules/css-loader/dist/cjs.js??ref--5-oneOf-3-1!./node_modules/postcss-loader/src??__nextjs_postcss!./node_modules/resolve-url-loader??ref--5-oneOf-3-3!./node_modules/sass-loader/dist/cjs.js??ref--5-oneOf-3-4!./module-styles/navbar.module.scss)
SassError: Undefined variable: "$mobile".
on line 19 of /Users/Parv/Documents/reactx/module-styles/navbar.module.scss
>> #media (max-width: $mobile) {
---------------------------^
My question is, why aren't my global variables which I declare in my main.scss coming through?
the easier way is to add a file with variable import and add alias to tsconfig
sassOptions: {
includePaths: ['./src'],
prependData: `#import "~#styles/variable.scss";`,
}
Update:
In file next.config.js need add this code (you need to create it if there is no such file)
module.exports = (phase, {defaultConfig}) => {
if ('sassOptions' in defaultConfig) {
defaultConfig['sassOptions'] = {
includePaths: ['./src'],
prependData: `#import "~#styles/variables.scss";`,
}
}
return defaultConfig;
}
In file tsconfig.json need add alias
"baseUrl": ".",
"paths": {
...
"#styles/*": [
"src/styles/*"
],
...
Then create file with styles on path: src/styles/variable.scss in variable.scss you can import other scss file
It is not related to Next.js, but to the way sass-loader works.
Each import of scss file from js file is treated as an isolated sass env, therefore, there is no such thing "global variables".
This behaviour requires you to import the variables.scss file from each scss file that uses one of the variables.
Side note, It is important that these common scss files (such your variables.scss) will not contain "regular" css, because if so, they will be duplicated many times (the amount of imports).
Just add this to your next.config.js file and restart
const path = require('path')
module.exports = {
sassOptions: {
includePaths: [path.join(__dirname, 'styles')],
prependData: `#import "main.scss";`
}
}
Apparently you can only import variables from a module file, not a global file.
Import variables.scss into your module's SCSS file, then import your variables from your module:
variables.scss:
$my-color = #123456;
:export {
myColor: $my-color;
}
page.module.scss:
#import './variables.scss';
page.jsx:
import color from './page.module.scss'
console.log(color.myColor); // '#123456'
This worked for me.
I solve it by adding my global variables to next.config.js. It is not a good solution but it works.
module.exports = {
sassOptions: {
includePaths: [path.join(__dirname, 'styles')],
prependData: `
$primary-font-regular: 'Gotham';
$primary-font-medium: 'Gotham';
$default-font-size: 16px;
$h1: 5.208vw;
$h4: 1.458vw;
$primary-color: #000000;
$gray: #CCCCCC;
`,
},
};
You can follow this link for the answer: https://github.com/vercel/next.js/pull/12277

Resources