ReactJS: Create isolated component with own cssCreate GUID / UUID in JavaScript?Set cellpadding and cellspacing in CSS?Creating multiline strings in JavaScriptHow do I give text or an image a transparent background using CSS?Is there a CSS parent selector?When to use margin vs padding in CSSChange an HTML5 input's placeholder color with CSSHow do CSS triangles work?How do I vertically center text with CSS?Is it possible to apply CSS to half of a character?
Has there ever been an airliner design involving reducing generator load by installing solar panels?
Stopping power of mountain vs road bike
If human space travel is limited by the G force vulnerability, is there a way to counter G forces?
Intersection of two sorted vectors in C++
How can I prevent hyper evolved versions of regular creatures from wiping out their cousins?
What's the difference between 'rename' and 'mv'?
I Accidentally Deleted a Stock Terminal Theme
Modeling an IP Address
Can I ask the recruiters in my resume to put the reason why I am rejected?
Can a rocket refuel on Mars from water?
Why are electrically insulating heatsinks so rare? Is it just cost?
90's TV series where a boy goes to another dimension through portal near power lines
Will google still index a page if I use a $_SESSION variable?
Western buddy movie with a supernatural twist where a woman turns into an eagle at the end
Is the Joker left-handed?
What does it mean to describe someone as a butt steak?
Assassin's bullet with mercury
Is "remove commented out code" correct English?
What is a clear way to write a bar that has an extra beat?
Blender 2.8 I can't see vertices, edges or faces in edit mode
What is the word for reserving something for yourself before others do?
How to prevent "they're falling in love" trope
Fully-Firstable Anagram Sets
Can a virus destroy the BIOS of a modern computer?
ReactJS: Create isolated component with own css
Create GUID / UUID in JavaScript?Set cellpadding and cellspacing in CSS?Creating multiline strings in JavaScriptHow do I give text or an image a transparent background using CSS?Is there a CSS parent selector?When to use margin vs padding in CSSChange an HTML5 input's placeholder color with CSSHow do CSS triangles work?How do I vertically center text with CSS?Is it possible to apply CSS to half of a character?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm trying to develop a library of reactjs components in order to be reusable by different projects.
This components besides the functionality itself, must have a theme with different css styles.
I could write a css file, but then I must import the css in every project I will use any of that components. I need to set the style of this components inside itself, so when I import it in other project, I will looks exactly as I expect.
Is there any ReactJS library (or plugin perhaps?) to compile this styles inside the component or maybe apply a style on the componentDidMount
?
EDIT
I forgot to add that I'm using MaterialUI. which is a framework that implements Material Design for React.
It provides different components which it own styles, and I can modify some of them, but not all.
Since Material UI create a big HTML I cannot add inline styles, that's why I need to add a selector to apply styles from React directly
Meterial UI provides something like that, so I guess is possible. This is how I configure in Material UI
const muiTheme = getMuiTheme(
palette:
textColor: cyan500,
,
appBar:
height: 50,
,
);
Sadly only some styles are supported by this, and not all I need
javascript css reactjs dom material-ui
add a comment |
I'm trying to develop a library of reactjs components in order to be reusable by different projects.
This components besides the functionality itself, must have a theme with different css styles.
I could write a css file, but then I must import the css in every project I will use any of that components. I need to set the style of this components inside itself, so when I import it in other project, I will looks exactly as I expect.
Is there any ReactJS library (or plugin perhaps?) to compile this styles inside the component or maybe apply a style on the componentDidMount
?
EDIT
I forgot to add that I'm using MaterialUI. which is a framework that implements Material Design for React.
It provides different components which it own styles, and I can modify some of them, but not all.
Since Material UI create a big HTML I cannot add inline styles, that's why I need to add a selector to apply styles from React directly
Meterial UI provides something like that, so I guess is possible. This is how I configure in Material UI
const muiTheme = getMuiTheme(
palette:
textColor: cyan500,
,
appBar:
height: 50,
,
);
Sadly only some styles are supported by this, and not all I need
javascript css reactjs dom material-ui
what's wrong with inline styles?
– ZekeDroid
Mar 31 '16 at 14:33
sorry, forgot that part. I'm using materialUI (material-ui.com) for some of that elements, which has it own stylesheets and full HTML rendered inside that library. I can add a class or inline-style to the main container of that compoents, but I cannot go deeper with the inline styles
– Pablo
Mar 31 '16 at 14:46
so you absolutely need to somehow import css FILES into your component is what you're saying?
– ZekeDroid
Mar 31 '16 at 14:52
Yes import css in the component. Or maybe apply style some how as jquery does$('selector').css(...)
is there anything like that for React?
– Pablo
Mar 31 '16 at 14:53
add a comment |
I'm trying to develop a library of reactjs components in order to be reusable by different projects.
This components besides the functionality itself, must have a theme with different css styles.
I could write a css file, but then I must import the css in every project I will use any of that components. I need to set the style of this components inside itself, so when I import it in other project, I will looks exactly as I expect.
Is there any ReactJS library (or plugin perhaps?) to compile this styles inside the component or maybe apply a style on the componentDidMount
?
EDIT
I forgot to add that I'm using MaterialUI. which is a framework that implements Material Design for React.
It provides different components which it own styles, and I can modify some of them, but not all.
Since Material UI create a big HTML I cannot add inline styles, that's why I need to add a selector to apply styles from React directly
Meterial UI provides something like that, so I guess is possible. This is how I configure in Material UI
const muiTheme = getMuiTheme(
palette:
textColor: cyan500,
,
appBar:
height: 50,
,
);
Sadly only some styles are supported by this, and not all I need
javascript css reactjs dom material-ui
I'm trying to develop a library of reactjs components in order to be reusable by different projects.
This components besides the functionality itself, must have a theme with different css styles.
I could write a css file, but then I must import the css in every project I will use any of that components. I need to set the style of this components inside itself, so when I import it in other project, I will looks exactly as I expect.
Is there any ReactJS library (or plugin perhaps?) to compile this styles inside the component or maybe apply a style on the componentDidMount
?
EDIT
I forgot to add that I'm using MaterialUI. which is a framework that implements Material Design for React.
It provides different components which it own styles, and I can modify some of them, but not all.
Since Material UI create a big HTML I cannot add inline styles, that's why I need to add a selector to apply styles from React directly
Meterial UI provides something like that, so I guess is possible. This is how I configure in Material UI
const muiTheme = getMuiTheme(
palette:
textColor: cyan500,
,
appBar:
height: 50,
,
);
Sadly only some styles are supported by this, and not all I need
javascript css reactjs dom material-ui
javascript css reactjs dom material-ui
edited Mar 9 at 3:10
lazaruslarue
10912
10912
asked Mar 31 '16 at 14:30
PabloPablo
1,79793257
1,79793257
what's wrong with inline styles?
– ZekeDroid
Mar 31 '16 at 14:33
sorry, forgot that part. I'm using materialUI (material-ui.com) for some of that elements, which has it own stylesheets and full HTML rendered inside that library. I can add a class or inline-style to the main container of that compoents, but I cannot go deeper with the inline styles
– Pablo
Mar 31 '16 at 14:46
so you absolutely need to somehow import css FILES into your component is what you're saying?
– ZekeDroid
Mar 31 '16 at 14:52
Yes import css in the component. Or maybe apply style some how as jquery does$('selector').css(...)
is there anything like that for React?
– Pablo
Mar 31 '16 at 14:53
add a comment |
what's wrong with inline styles?
– ZekeDroid
Mar 31 '16 at 14:33
sorry, forgot that part. I'm using materialUI (material-ui.com) for some of that elements, which has it own stylesheets and full HTML rendered inside that library. I can add a class or inline-style to the main container of that compoents, but I cannot go deeper with the inline styles
– Pablo
Mar 31 '16 at 14:46
so you absolutely need to somehow import css FILES into your component is what you're saying?
– ZekeDroid
Mar 31 '16 at 14:52
Yes import css in the component. Or maybe apply style some how as jquery does$('selector').css(...)
is there anything like that for React?
– Pablo
Mar 31 '16 at 14:53
what's wrong with inline styles?
– ZekeDroid
Mar 31 '16 at 14:33
what's wrong with inline styles?
– ZekeDroid
Mar 31 '16 at 14:33
sorry, forgot that part. I'm using materialUI (material-ui.com) for some of that elements, which has it own stylesheets and full HTML rendered inside that library. I can add a class or inline-style to the main container of that compoents, but I cannot go deeper with the inline styles
– Pablo
Mar 31 '16 at 14:46
sorry, forgot that part. I'm using materialUI (material-ui.com) for some of that elements, which has it own stylesheets and full HTML rendered inside that library. I can add a class or inline-style to the main container of that compoents, but I cannot go deeper with the inline styles
– Pablo
Mar 31 '16 at 14:46
so you absolutely need to somehow import css FILES into your component is what you're saying?
– ZekeDroid
Mar 31 '16 at 14:52
so you absolutely need to somehow import css FILES into your component is what you're saying?
– ZekeDroid
Mar 31 '16 at 14:52
Yes import css in the component. Or maybe apply style some how as jquery does
$('selector').css(...)
is there anything like that for React?– Pablo
Mar 31 '16 at 14:53
Yes import css in the component. Or maybe apply style some how as jquery does
$('selector').css(...)
is there anything like that for React?– Pablo
Mar 31 '16 at 14:53
add a comment |
3 Answers
3
active
oldest
votes
If you use webpack for your transpiling, you can create a separate stylesheet for the component and then import it.
Example:
import './componentStyle.css';
Then setup your component style in that CSS. The component would need both the jsx and css files each time you use them in different projects, but you can easily customize the css for each project if you need, and you can use css classes instead of inline styles.
Your webpack.config.js would need to have this:
module:
loaders: [
test: /.css$/, loader: 'style-loader!css-loader'
]
1
As far as I can tell this doesn't isolate the CSS. It applies everywhere unless you use some sort of custom naming convention.
– James Hancock
Apr 9 '18 at 18:38
add a comment |
MaterialUI now includes CSS-in-JS docs functionality that will allow you to do just what you're asking.
you probably want to do something like what they suggest and make use of their HOC API:
import React from 'react';
import PropTypes from 'prop-types';
import withStyles from '@material-ui/styles';
import Button from '@material-ui/core/Button';
const styles =
root:
background: 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)',
border: 0,
borderRadius: 3,
boxShadow: '0 3px 5px 2px rgba(255, 105, 135, .3)',
color: 'white',
height: 48,
padding: '0 30px',
,
;
function HigherOrderComponent(props)
const classes = props;
return <Button className=classes.root>Higher-order component</Button>;
HigherOrderComponent.propTypes =
classes: PropTypes.object.isRequired,
;
export default withStyles(styles)(HigherOrderComponent);
add a comment |
If you created application with npx create-react-app
then
- Import your styles from
*.module.css
file. Example:import styles from './component.module.css'
with content.ssss color: red
- Apply your style using
styles.ssss
. Example:<div className=styles.ssss>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f36336335%2freactjs-create-isolated-component-with-own-css%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you use webpack for your transpiling, you can create a separate stylesheet for the component and then import it.
Example:
import './componentStyle.css';
Then setup your component style in that CSS. The component would need both the jsx and css files each time you use them in different projects, but you can easily customize the css for each project if you need, and you can use css classes instead of inline styles.
Your webpack.config.js would need to have this:
module:
loaders: [
test: /.css$/, loader: 'style-loader!css-loader'
]
1
As far as I can tell this doesn't isolate the CSS. It applies everywhere unless you use some sort of custom naming convention.
– James Hancock
Apr 9 '18 at 18:38
add a comment |
If you use webpack for your transpiling, you can create a separate stylesheet for the component and then import it.
Example:
import './componentStyle.css';
Then setup your component style in that CSS. The component would need both the jsx and css files each time you use them in different projects, but you can easily customize the css for each project if you need, and you can use css classes instead of inline styles.
Your webpack.config.js would need to have this:
module:
loaders: [
test: /.css$/, loader: 'style-loader!css-loader'
]
1
As far as I can tell this doesn't isolate the CSS. It applies everywhere unless you use some sort of custom naming convention.
– James Hancock
Apr 9 '18 at 18:38
add a comment |
If you use webpack for your transpiling, you can create a separate stylesheet for the component and then import it.
Example:
import './componentStyle.css';
Then setup your component style in that CSS. The component would need both the jsx and css files each time you use them in different projects, but you can easily customize the css for each project if you need, and you can use css classes instead of inline styles.
Your webpack.config.js would need to have this:
module:
loaders: [
test: /.css$/, loader: 'style-loader!css-loader'
]
If you use webpack for your transpiling, you can create a separate stylesheet for the component and then import it.
Example:
import './componentStyle.css';
Then setup your component style in that CSS. The component would need both the jsx and css files each time you use them in different projects, but you can easily customize the css for each project if you need, and you can use css classes instead of inline styles.
Your webpack.config.js would need to have this:
module:
loaders: [
test: /.css$/, loader: 'style-loader!css-loader'
]
answered Mar 31 '16 at 14:55
Kelly Keller-HeikkilaKelly Keller-Heikkila
1,76851728
1,76851728
1
As far as I can tell this doesn't isolate the CSS. It applies everywhere unless you use some sort of custom naming convention.
– James Hancock
Apr 9 '18 at 18:38
add a comment |
1
As far as I can tell this doesn't isolate the CSS. It applies everywhere unless you use some sort of custom naming convention.
– James Hancock
Apr 9 '18 at 18:38
1
1
As far as I can tell this doesn't isolate the CSS. It applies everywhere unless you use some sort of custom naming convention.
– James Hancock
Apr 9 '18 at 18:38
As far as I can tell this doesn't isolate the CSS. It applies everywhere unless you use some sort of custom naming convention.
– James Hancock
Apr 9 '18 at 18:38
add a comment |
MaterialUI now includes CSS-in-JS docs functionality that will allow you to do just what you're asking.
you probably want to do something like what they suggest and make use of their HOC API:
import React from 'react';
import PropTypes from 'prop-types';
import withStyles from '@material-ui/styles';
import Button from '@material-ui/core/Button';
const styles =
root:
background: 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)',
border: 0,
borderRadius: 3,
boxShadow: '0 3px 5px 2px rgba(255, 105, 135, .3)',
color: 'white',
height: 48,
padding: '0 30px',
,
;
function HigherOrderComponent(props)
const classes = props;
return <Button className=classes.root>Higher-order component</Button>;
HigherOrderComponent.propTypes =
classes: PropTypes.object.isRequired,
;
export default withStyles(styles)(HigherOrderComponent);
add a comment |
MaterialUI now includes CSS-in-JS docs functionality that will allow you to do just what you're asking.
you probably want to do something like what they suggest and make use of their HOC API:
import React from 'react';
import PropTypes from 'prop-types';
import withStyles from '@material-ui/styles';
import Button from '@material-ui/core/Button';
const styles =
root:
background: 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)',
border: 0,
borderRadius: 3,
boxShadow: '0 3px 5px 2px rgba(255, 105, 135, .3)',
color: 'white',
height: 48,
padding: '0 30px',
,
;
function HigherOrderComponent(props)
const classes = props;
return <Button className=classes.root>Higher-order component</Button>;
HigherOrderComponent.propTypes =
classes: PropTypes.object.isRequired,
;
export default withStyles(styles)(HigherOrderComponent);
add a comment |
MaterialUI now includes CSS-in-JS docs functionality that will allow you to do just what you're asking.
you probably want to do something like what they suggest and make use of their HOC API:
import React from 'react';
import PropTypes from 'prop-types';
import withStyles from '@material-ui/styles';
import Button from '@material-ui/core/Button';
const styles =
root:
background: 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)',
border: 0,
borderRadius: 3,
boxShadow: '0 3px 5px 2px rgba(255, 105, 135, .3)',
color: 'white',
height: 48,
padding: '0 30px',
,
;
function HigherOrderComponent(props)
const classes = props;
return <Button className=classes.root>Higher-order component</Button>;
HigherOrderComponent.propTypes =
classes: PropTypes.object.isRequired,
;
export default withStyles(styles)(HigherOrderComponent);
MaterialUI now includes CSS-in-JS docs functionality that will allow you to do just what you're asking.
you probably want to do something like what they suggest and make use of their HOC API:
import React from 'react';
import PropTypes from 'prop-types';
import withStyles from '@material-ui/styles';
import Button from '@material-ui/core/Button';
const styles =
root:
background: 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)',
border: 0,
borderRadius: 3,
boxShadow: '0 3px 5px 2px rgba(255, 105, 135, .3)',
color: 'white',
height: 48,
padding: '0 30px',
,
;
function HigherOrderComponent(props)
const classes = props;
return <Button className=classes.root>Higher-order component</Button>;
HigherOrderComponent.propTypes =
classes: PropTypes.object.isRequired,
;
export default withStyles(styles)(HigherOrderComponent);
answered Mar 8 at 23:27
lazaruslaruelazaruslarue
10912
10912
add a comment |
add a comment |
If you created application with npx create-react-app
then
- Import your styles from
*.module.css
file. Example:import styles from './component.module.css'
with content.ssss color: red
- Apply your style using
styles.ssss
. Example:<div className=styles.ssss>
add a comment |
If you created application with npx create-react-app
then
- Import your styles from
*.module.css
file. Example:import styles from './component.module.css'
with content.ssss color: red
- Apply your style using
styles.ssss
. Example:<div className=styles.ssss>
add a comment |
If you created application with npx create-react-app
then
- Import your styles from
*.module.css
file. Example:import styles from './component.module.css'
with content.ssss color: red
- Apply your style using
styles.ssss
. Example:<div className=styles.ssss>
If you created application with npx create-react-app
then
- Import your styles from
*.module.css
file. Example:import styles from './component.module.css'
with content.ssss color: red
- Apply your style using
styles.ssss
. Example:<div className=styles.ssss>
answered Mar 31 at 15:05
ValeriyValeriy
7011933
7011933
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f36336335%2freactjs-create-isolated-component-with-own-css%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
what's wrong with inline styles?
– ZekeDroid
Mar 31 '16 at 14:33
sorry, forgot that part. I'm using materialUI (material-ui.com) for some of that elements, which has it own stylesheets and full HTML rendered inside that library. I can add a class or inline-style to the main container of that compoents, but I cannot go deeper with the inline styles
– Pablo
Mar 31 '16 at 14:46
so you absolutely need to somehow import css FILES into your component is what you're saying?
– ZekeDroid
Mar 31 '16 at 14:52
Yes import css in the component. Or maybe apply style some how as jquery does
$('selector').css(...)
is there anything like that for React?– Pablo
Mar 31 '16 at 14:53