@stylezjs/postcss-plugin
Version:
@stylezjs/postcss-plugin is a PostCSS plugin for integrating `@stylezjs/stylez` to generate static CSS styles. Stylez → 'Z' of Zero Runtime.
81 lines (57 loc) • 1.64 kB
Markdown
# /postcss-plugin
`/postcss-plugin` is a PostCSS plugin for integrating `@stylezjs/stylez` to generate static CSS styles. Stylez → 'Z' of Zero Runtime.
## Installation
To use `/stylez`, you'll need to install both the package and the PostCSS plugin:
```bash
pnpm add /stylez @stylezjs/postcss-plugin
```
or with npm:
```bash
npm install /stylez @stylezjs/postcss-plugin
```
or with yarn:
```bash
yarn add /stylez @stylezjs/postcss-plugin
```
## Setup PostCSS
To enable `/postcss-plugin`, you need to configure your `postcss.config.js` file:
```ts
export default {
plugins: {
'/postcss-plugin': {
patterns: ['src/**/*.{js,ts,jsx,tsx}'],
},
},
};
```
## Usage
### Creating and using styles
You can now create dynamic CSS class names and apply them to your React components.
```ts
import * as stylez from '@stylezjs/stylez';
// Define styles
const styles = stylez.create({
color: 'red',
fontSize: '16px',
'&::before': {
height: '100%',
color: 'red',
},
});
// Apply class names to your component
const Home = () => (
<div {...stylez.className(styles)}>
Remember to keep a clear head in difficult times!
</div>
);
export default Home;
```
### Global Styles
In order for `` to work correctly, include the `` directive in your global CSS file. Create a `.css` file, for example `globals.css`, and add the following at the top:
```css
;
```
Then, import this CSS file into your project, ideally in your root file (e.g., `index.tsx` or `App.tsx`):
```ts
import './globals.css';
```