EN | ZH
Zero-runtime-with-atomic-class css in js library.
Here we provide:
- 🎨 The easiest way to write css in js.
- ⚡️ Zero runtime for static styles
- ✨ Dynamic for changing styles
- ⚛️ Atomic and utility based css classes
Other CSS-in-JS or atomic CSS frameworks are great, but they may have the following issues:
- Emotion JS and similar CSS-in-JS libraries can cause high runtime pressure, while Linaria only allows writing static parameters and cannot add dynamic ones.
- When developing a component library, it is preferable to have a fixed CSS class name that can be exposed for external modification rather than a randomly generated string of characters.
- To utilize both atomic classes and CSS-in-JS styles, do I need to import two libraries?
- Although atomic libraries provide a comprehensive set of styles, some specific atomic classes may be missing. How can this be addressed?
- How can I easily add my frequently used utilities to an atomic library?
Easy CSS resolves these issues by:
- Easy CSS combines static and dynamic capabilities to identify classes that can be inferred statically and parse them at build time. Additionally, it provides powerful dynamic capabilities to add types at runtime.
- We define a className by recognizing variable names, allowing your declared variable names to be either global or scoped.
- Easy CSS provides a pre-parsed atomic library based on static CSS-in-JS libraries, making it easy to use atomic CSS in Easy CSS.
- Atomic CSS in Easy CSS is in the form of a function call, so you can define any parameters you need, such as
margin("10px")
. - Easy CSS supports plug-ins for custom utility component libraries. It also provides two native libraries: Atomic - all native styles as atomic classes, and Utility - all utility classes supported by Tailwind.
npm install @iandx/easy-css
npm install -D vite-plugin-easy-css
// ~> vite.config.js
import easyCss from "vite-plugin-easy-css"
export default defineConfig({
plugins: [easyCss()]
})
npm install -D babel-preset-easy-css
{
"presets": ["easy-css"]
}
import { css } from "@iandx/easy-css"
const myCss = css`
color: red;
font-size: 16px;
`;
const myStyle = css({
color: "blue",
fontSize: "26px"
})
Generated CSS:
.my-css {
color: red;
font-size: 16px;
}
.my-style {
color: blue;
font-size: 26px;
}
import { margin, display } from "@iandx/easy-css-atomic"
import { border4, textRed500 } from "@iandx/easy-css-utility"
// atomic
margin("20px")
display("flex")
// utility
border4()
textRed500()
Generated CSS:
.margin-20px {
margin: 20px;
}
.display-flex {
display: flex;
}
.border4 {
border-width: 4px;
}
.text-red500 {
color: rgb(239 68 68);
}
If you're using it in SSR or any environment other than a browser, you can get a generated style html string with:
import { geneEasyStyle } from "@iandx/easy-css"
renderToString(YourApp) // contains easy-css code
console.log(geneEasyStyle())
// ~> <style data-tag="🎨easy-css">.my-style{color:red;}</style>
Great thanks to tailwindcss and emotion for inspiration.