The brand-new MOD-CSS v4.x is here with some great news: itβs now fully compatible with React and most modern JavaScript/TypeScript frameworks.
In this article, Iβll show you how to integrate it effortlessly into your project and unleash its full potential to create fast, modular, and highly customizable interfaces.
π¦ Quick Installation
Simply add MOD-CSS to your project via npm:
npm i @dev-geos/mod-css
β‘ Integrating MOD-CSS into React
Integration is incredibly simple: just call the init() method once in your root component. MOD-CSS will then automatically apply your dynamic styles across all components inside it.
import React, { useCallback } from 'react';
import MODCSS from '@dev-geos/mod-css';
function MainComponent() {
const init = useCallback((node) => {
if (node) {
const MD = new MODCSS();
MD.init();
}
}, []);
return (
<div className="grid" ref={init}>
{/* Your content */}
</div>
);
}
export default MainComponent;
π― The Two Key Attributes: mod / data-mod and var / data-var
With MOD-CSS, you only need two attributes to handle all your styling:
mod or data-mod β to apply predefined styles
var or data-var β to manage/edit your selectors
They are fully interchangeable, so you can use the data-* convention or keep it short for faster writing.
π οΈ A Few Examples
1οΈβ£ A Responsive flexgrid in few Line
<div mod="row$[100%]">
<div mod="col$[80%] || lg? col$[60%]">Block 1</div>
<div mod="col$[20%] || lg? col$[40%]">Block 2</div>
...
</div>
2οΈβ£ Reactive Behavior Based on Screen Size
<div mod="w[100%] bg[blue] || lg? w[75%] || 2xl? w[50%] bg[pink]">
{/* I change background and width depending on the screen size */}
</div>
3οΈβ£ Easily Customize a Component
<Button mod="bg[lightblue] co[#333] br[9px] && focus*hover: co[blue] br[4px]">
{/* Button (background, color, Radius 4px) */}
</Button>
π Why Choose MOD-CSS?
Ultra-lightweight β no unnecessary overhead
Minimal syntax β write less, do more
Highly customizable β built-in variables and reactive behavior
More than 200 properties - support most CSS properties
Fresh rendering - Your settings are deleted after rendering. Nothing appears on client side
Universal compatibility β works with React, Vue, Svelte, Angular, Vanilla JSβ¦
Developers around the world have already adopted it !
In an upcoming article, Iβll dive into all the advanced MOD-CSS features that can supercharge your front-end projects.
See you soon π
Top comments (0)