Skip to content

Commit

Permalink
Add variants callback syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
brijeshb42 committed Jan 25, 2024
1 parent 662fb43 commit d2b8bbb
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions packages/zero-runtime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

A zero-runtime CSS-in-JS library that extracts the colocated css to it's own css files at build-time.

### Getting started
## Getting started

Zero-runtime supports Next.js and Vite—you must install the corresponding plugin, as shown below. The package currently has a dependency on `@mui/material` to initialize the theme object, but this is only at build time. There won't be any Material UI code at runtime if you're not using it otherwise—in that case, you can move it to dev dependencies instead (as shown with the plugins).
Zero-runtime supports Next.js and Vite with future support for more bundlers—you must install the corresponding plugin, as shown below.

### Installation

Expand All @@ -16,6 +16,7 @@ npm install --save-dev @mui/zero-next-plugin
npm install --save-dev @mui/zero-vite-plugin
```

The package currently has a dependency on `@mui/material` to initialize the theme object, but this is only at build time. There won't be any Material UI code at runtime if you're not using it otherwise—in that case, you can move it to dev dependencies instead (as shown with the plugin packages).

#### Next.js

Expand All @@ -38,16 +39,12 @@ const theme = extendTheme();

```js
module.exports = withZeroPlugin(nextConfig, {
sourceMap: true,
theme,
});
```

Setting `sourceMap` to true will take you to the style definition in the JS file when you click on the class name in the browser dev tools. It should ideally be off in production.

#### Vite


In your vite config file,

1. Import the plugin
Expand All @@ -70,7 +67,6 @@ export default defineConfig({
plugins: [
zeroVitePlugin({
theme,
sourceMap: true,
}),
// ... Your other plugins.
],
Expand Down Expand Up @@ -173,6 +169,16 @@ const Button = styled.button(() => ({
// Styles to be applied when <Button size="small" color="primary" />
},
},
{
// If key value pair doesn't suffice, you can use the callback syntax
// to return `true` if you want the styles to be applied
props({ children }) {
return !!children;
},
style: {
// CSS
},
},
],
}));
```
Expand Down

0 comments on commit d2b8bbb

Please sign in to comment.