basic-css-in-js

Not to be used on production (at least not yet).
Created for learning how stuffs work.
Example codesandbox
APIs
-
css
;const blueClass = css`color: blue;`;const Component = {return <div className=blueClass>I am blue</div>;} -
keyframes
;const Spinning = keyframes`from {transform: rotate(0deg);}to {transform: rotate(360deg);}`;const blueClass = css`color: blue;animation: infinite 20s linear;`;const Component = {return <div className=blueClass>I am blue and spinning</div>;} -
sheet.extract()
for rendering HTML in node environment;const blue = css`color: blue;`;const getHtml = {return `<html><head><style></style></head><body><div class="">I should be blue colored</div></body></html>`;}
Running the example
-
Clone the repo
-
Install dependencies
yarn
-
Build the package
yarn build
-
Run example
yarn example
Goals:
- ✅
css
andkeyframes
works! - ✅ Support template literal syntaxcss`display: none;`
- ✅ vendor prefixing (via
tiny-css-prefixer
) - ✅ SSR support
- optimisation
References:
- https://medium.com/@tkh44/writing-a-css-in-js-library-from-scratch-96cd23a017b4
- https://mxstbr.blog/2016/11/styled-components-magic-explained/
- https://wesbos.com/tagged-template-literals
- https://github.com/thysultan/stylis.js
- https://levelup.gitconnected.com/a-brief-history-of-css-in-js-how-we-got-here-and-where-were-going-ea6261c19f04#:~:text=Javascript Does CSS,the University of Oslo 2006.