How to include Materialize in Meteor? - meteor

I first do this on the command line inside my Meteor project:
meteor npm install --save materialuze-css
This includes materialize to package.json.
Then, I added this to main.js:
import M from 'materialize-css';
But, this does not include the stylesheet to my project.
How to make this work as expected?

Use SCSS
Materialze is scss based, so you should use the scss compiler (but you are not forced to do, see the section below):
$ meteor remove standard-minifier-css
$ meteor add fourseven:scss seba:minifiers-autoprefixer
You also need to import the scss file:
import M from 'materialize-css';
import 'materialize-css/sass/materialize.scss'
Use plain css
If you only need the default css and don't intend to customize colors etc.
you may be fine by importing the dist css:
import M from 'materialize-css';
import 'materialize-css/dist/css/materialize.css'
No need to use the scss compiler then. Note, that you can safely use the materialize.css and don't require the materialize.min.css since it will be minified later when your Meteor app build for production using the standard-minifier-css.

Related

default bootstrap is overriding my custom css in react

Link to project picture
I am creating a project in react and needed bootstrap. But it is overriding my custom css. Some of default bootstrap changing my headings. I have tried everything like putting my css link below bootstrap and also importing it into my index.js file but nothing working. i have attached the picture of my project.
Try maybe using bootstrap as a dependency:
npm i bootstrap
and import in index.js:
import 'bootstrap/dist/css/bootstrap.min.css';
or even try a react-bootstrap dependency
npm i react-bootstrap
Bootstrap is written with !important rules, so they has the highest priority if given!
Maybe you can try inline css in React elements (although not recomended in a simple HTML)
All the best!
As you haven't added any codes example or link of your live project, please check if CSS file has been linked properly. Go to page source and click on styles.css. It should open all your codes inside CSS file. If you can't open this file, or there's nothing found, you should check CSS file linking once again.
But if you can see css file properly but still not working, as a final option, you can use "!important" in CSS class. It will work fine.
Install bootstrap as npm package using npm i bootstrap. Then place your styles.css in the src folder and import styles.css in your App.jsx.
import 'bootstrap/dist/css/bootstrap.min.css';
import './styles.css'
Or you can even try using !important. This will definitely work but you will need to to it every time you want to override a style.
As mentioned, bootstrap adds !important to seemingly everything. In order to remove all of them you'll need to install the npm package instead of linking to a CDN (like you're currently doing). So:
npm install bootstrap or yarn add bootstrap
Then create an app.scss (naming is arbitrary here) and add the following lines
$enable-important-utilities: false; //this disables !important
#import "../../node_modules/bootstrap/scss/bootstrap";
Then, import that app.scss file into your index.js file:
import './app.scss'
The next time your run npm start (or whatever command you're using) it should generate a new css file to use. You may need to install sass if your project isn't already using it. But, that's beyond the scope of this answer.

How to import and use materialize (or any other css library) sass in React

How should I correctly use materialize Sass in a react project created with create-react-app? Where should I keep the scss and js files?
I suppose if I use sass, I'm not supposed to be importing minified css and js files in my index.html?
3 easy steps and you're set!
install node-sass (npm install node-sass)
if your materialize file is .css, change it to .scss
import it! (import "./materialize.scss";)
more info: https://scotch.io/tutorials/using-sass-in-create-react-app-v2
Here is an article that discusses creating a custom css build and importing javascript on a per-component basis:
https://medium.com/#mattdlockyer/youre-using-materialize-css-wrong-470b593e78e9

Using sass-loader won't import classes dynamically in React

My goal is to import scss-classes using dynamic classes.
I've seem several usages such as in Ambar opensource, and wish to do something similar in my project.
// App.js
import classes from './App.scss'
...
<div className={classes.App}/>
// App.scss
.App {
text-align: center;
}
The Problem is that those css changes won't occur, using dev-tools I can see that none of the classes are a part of the HTML.
Changing the className='App', will work.
I've used the command npm install node-sass -S for the SCSS installation process.
I've found module called sass-loader that handle the request, but after completing the steps on their guide - it still won't work.
This structure is called CSS Modules. If you use create-react-app, apply these steps.
1) First install node-sass module.
npm install node-sass
2) Save your SCSS file with .module.scss extension. For example:
App.module.scss
3) Import this file like this:
import classes from "./App.module.scss";
4) Now, you can apply your styles like this:
<div className={classes.App}>

Include Gutenberg scss Variables in Custom Gutenberg Block

I use the create-guten-block repo to create a nice ES6-enabled Gutenberg block for Wordpress. However I want to be able to use scss-variables that are defined in the gutenberg repository here:
https://github.com/WordPress/gutenberg/blob/master/assets/stylesheets/_variables.scss
Unfortunately the assets cannot be installed via an npm package. So how would I include the variables in my custom gutenberg block? I want to do something like this in the block's style.css
import "~#wordpress/assets/styles/variables"
How can I achieve what I want
Install
npm install #wordpress/base-styles --save-dev
Import
#import "node_modules/#wordpress/base-styles/colors";
#import "node_modules/#wordpress/base-styles/variables";
#import "node_modules/#wordpress/base-styles/mixins";
#import "node_modules/#wordpress/base-styles/breakpoints";
#import "node_modules/#wordpress/base-styles/animations";
#import "node_modules/#wordpress/base-styles/z-index";
They also support postCSS and a few other things, check here for the full docs.
That is not possible unless you copied the exact file and referred to it like this inside your scss file
#import "./variables";
What you need to do is create _variables.scss inside the same folder as your main scss file is, then use the code above to import it. You'll have to go inside the file _variables.scss as well and make sure all variables are defined, meaning, import any dependency that is needed for this file. I'm pointing here to the _colors.scss dependency in the same folder, and that's all you need.
You can't use
import "~#wordpress/assets/styles/variables"
this won't work because you're trying to import an npm package, which does not recognize styles.
If I understand your question correctly. You want to use SASS variables inside your custom Gutenberg block, right ?
If you are using create-guten-block. You don't need to install anything. Just include your sass variable in that block's scss files.For example -
If this is your block directory then inside style.scss and editor.scss put the SASS variables.
I hope this helps

Smartly import js lib with css in webpack

I was tired of downloading js and css lib manually every time, then I jump into npm and webpack as I started a react project. But there are some awkwark:
Using npm install is fine, but I have to know where css/js/scss placed, they may be :
node_modules\materialize-css\sass\materialize.scss
node_modules\materialize-css\dist\js\materialize.min.js
node_modules\sweetalert\dist\sweetalert.min.js
node_modules\sweetalert\dist\sweetalert.css
node_modules\hint.css\hint.min.css
...
I still need found the correct path by myself, and add to index.html or import at index.js, like before , but it does reduce the time for searching lib's download link)
There are many js lib contain css file, but webpack is not so easy to add a lib with both css and js:
Such as webpack-import-bootstrap-js-and-css, have to add so much config code to make css import, why don't I just include the css at index.html? It just one line. However separate js,css import in different file make me feel uncomfortable too.
I hope there is a way like:
npm install --save sweetalert
add webpack config, something like(no need to know structure of a lib ):
...
new webpack.ProvidePlugin({
swal: "sweetalert",
use_css: true, // false for someone need custom theme
use_js: true
}),
...
But I don't found a good way now.
You can provide path to the .css file. This works for me:
import swal from 'sweetalert'
import 'sweetalert/dist/sweetalert.css'

Resources