-
-
Save kakonbarman/297db76bf72a2792b32555ef45f44708 to your computer and use it in GitHub Desktop.
React Component for Internal CSS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*STYLIS : https://www.npmjs.com/package/stylis*/ | |
import {compile, serialize, stringify, middleware, prefixer} from 'stylis'; | |
/*Process the Raw CSS*/ | |
const getProcessedCss = (rawCss) =>{ | |
return serialize(compile(rawCss), middleware([prefixer, stringify])) | |
} | |
/*Render CSS inside style tag*/ | |
const RenderCss = (props) => { | |
return ( | |
<style>{getProcessedCss(props.children)}</style> | |
); | |
}; | |
export default RenderCss; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*How to call render CSS*/ | |
/*Import Render CSS*/ | |
import RenderCss from "../style"; | |
/*Component with Internal CSS*/ | |
const ComponentWithInternalCss= (props) => { | |
return ( | |
<> | |
<RenderCss> | |
{` | |
.parent-class { | |
min-height:200px; | |
.child-class{ | |
color:orange; | |
} | |
} | |
`} | |
</RenderCss> | |
<div className='parent-class'> | |
<div className='child-class'> | |
</div> | |
</div> | |
</> | |
) | |
} | |
export default ComponentWithInternalCss |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Output Style/CSS*/ | |
<style>.parent-class{min-height:200px;}.parent-class .child-class{color:orange;}</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment