TSS React

Dynamic CSS-in-TS solution, based on Emotion

README


tss-react


You can think of tss-react as @emotion/jss.

It's, in essence, the JSS API but powered by Emotion.

Just like @emotion/styled is the styled-components API but powered by Emotion.


-   🚀 Seamless integration with MUI.
-   🌐 Works in Next.js App and Page Router.
-   🙅‍♂️ No custom styling syntax to learn, no shorthand, just plain CSS.
-   💫 Dynamic Style Generation: TSS enables to generate styles based on the props and internal states of components.  
    This unfortunately prevents us from supporting Server Component (RSC) in Next.js.
    We remain hopeful for future support of RSC, contingent on the provision of a suitable solution by Vercel and React.
    If you need RSC support today, you can consider _zero runtime_ solutions like Panda-CSS or Vanilla Extract,
    but the expression of complex styles is significantly harder in this paradigm.
-   📚 Your JSX remains readable. Unlike other styling solution that tend to clutter the JSX, TSS enables isolating the styles from the component structure.
    That been said, sometime it's just easier to inline the styles directly within your components, TSS enables this as well.
-   🛡️ Eliminate CSS priority conflicts! With TSS you can determine the precedence of multiple classes applied to a component and arbitrarily increase specificity of some rules.
-   🧩 Offers a [type-safe equivalent of the JSS $ syntax](https://docs.tss-react.dev/nested-selectors).
-   ⚙️ Freely customize the underlying @emotion cache.
-   ✨ Improved [withStyles](https://v4.mui.com/styles/api/#withstyles-styles-options-higher-order-component) API featured, to help you migrate away from @material-ui v4.
-   🛠️ Build on top of [@emotion/react](https://emotion.sh/docs/@emotion/react), it has very little impact on the bundle size alongside mui (~5kB minziped).
-   ⬆️ 'tss-react' can be used as an advantageous replacement for [@material-ui v4 makeStyles](https://material-ui.com/styles/basics/#hook-api) and ['react-jss'](https://cssinjs.org/react-jss/?v=v10.9.0).
-   🎯 Maintained for the foreseeable future, issues are dealt with within good delays.
-   📦 Library authors: [tss-react won’t be yet another entry in your peerDependencies](https://docs.tss-react.dev/publish-a-module-that-uses-tss).


While this module is written in TypeScript, using TypeScript in your application is optional

(but recommended as it comes with outstanding benefits to both you and your codebase).



Get started 🚀


The more ⭐️ the project gets, the more time I spend improving and maintaining it. Thank you for your support 😊

Needless to mention, this library is heavily inspired by JSS, the OG CSS-in-JS solution.

Development


Running the demo apps:

  1. ```bash
  2. git clone https://github.com/garronej/tss-react
  3. cd tss-react
  4. yarn
  5. yarn build
  6. npx tsc -w & npx tsc --module es2015 --outDir dist/esm -w
  7. # Open another Terminal
  8. yarn start_spa  # For testing in in a Create React App setup
  9. yarn start_ssr # For testing in a Next.js setup
  10. yarn start_appdir #  Next.js 13 setup in App directory mode
  11. ```