How to import custom css files using Chakra UI for React? - css

This is a very specific question, but I am using the Chakra UI component library for React and I want to import my own custom css files, although it doesn't allow me to do this.
I don't know if this is a bug or if it is intended, but is there any way I can go around it?
Thanks.

Make sure that you import css files in right place. Try to import your css files into App.js or if be more specific into the file where you init ChakraProvider. This approach works fine for my project:
import { ChakraProvider } from '#chakra-ui/react';
import './yourCssFile.css';

You can extend or override a token in the default theme by importing the extendTheme function. You can override properties as well as add new ones.
But if you want to add an external CSS file, I've found out from reading the docs that in order to import other file types (.css, .woff or .svg) in your theme file, you'll need to move those imports out of the theme file.

Related

Importing style file into Nextjs Component

Can I Import css files directly into a component in Nextjs and use the classnames directy without the default named import method.
I have a huge html project and I want to convert it into Nextjs, But the styles are conflicting when I import it in the _app.js file, and if I convert the style files into .module.css files and import with a name, then I have to manually change every where.
Is there anyway to solve this?

Importing css from node_modules but having it isolated to just a single react component

I'd like to use this calendar package in my react project: https://www.npmjs.com/package/#zach.codes/react-calendar.
It comes with a css import, without it, the app effectively doesn't work. If I import the suggested css file import "#zach.codes/react-calendar/dist/calendar-tailwind.css" the calendar package works well but it messes with the rest of my app's styling. If I import the "no-reset" version import "#zach.codes/react-calendar/dist/calendar-tailwind-no-reset.css", the rest of my app looks fine but it does make the calendar look funky, it mostly looks like it works but I'd have to add my own css to make up for some styling that's lost.
That said, it would be ideal if I didn't have to add any css. Is there a way to import a css file and have the css be isolated to just the react component that is in the same file?

How to add different css styles to pages in ReactJS?

I am creating a multi-page application using ReactJS and I want different styles for different pages, especially the logo position.
This is my App.js file
import React from 'react';
import Login from './user/Login';
import Auth from './user/Auth';
import Home from './user/Home';
import ResetPassword from './user/ResetPassword';
import './App.css';
const App=()=>{
//ROUTING
}
export default App;
The last imported file always overwrites the styling properties of the entire app. I need to change the position of the logo in each page accordingly and also other things. How do I add different css properties for each page?
You can use or module css (for this you have to do changes in webpack).
https://programmingwithmosh.com/react/css-modules-react/
Also you can use package styled components https://www.styled-components.com/
In this case, you have unique styles for all components.
Create a folder structure as below. And import their own css files. If you are using sass use unique class names. For the 3rd party components, you may need using "!important" in the css files.
common/
Avatar.js
Avatar.css
feed/
index.js
Feed.js
Feed.css
profile/
index.js
Profile.js
ProfileHeader.js
ProfileHeader.css
and you can read this : https://codeburst.io/4-four-ways-to-style-react-components-ac6f323da822

How to automatically add import in less from the react app

I have an app created using react-create-app tool and I use a style.less file in src/assets/less that is compiled automatically.
In my style.less I import the style I have in the various react components in my app. I like the idea to have every component with his own style.less in there.
The first problem is the reference I have to add or update in the src/assets/less/style.less, every time I add a component or I rename it or I move it. Is there any way I can get all the import automatically?
If your webpack.config.js is configured correctly, you should be able to import each components styles like:
import './style.less';

Importing css styles from a 3rd party library in React

Dumb question. How do you import styles from a 3rd party library? The css file for this library is located in the node modules folder in my app.
I try to require it into my components css file like so...
#import url(~react-input-range/lib/css/index.css);
But I don't think that is working. Also, after importing successfully do I edit the 3rd party css file to make changes or do I need to import the class names into my components css file and edit them there?
You can directly use
import 'react-input-range/lib/css/index.css';
to import the default styling. Remember to have css loader in your webpack config.

Resources