antd4-theme-vars
Version:
Generate different theme files for antd@4.x
102 lines (72 loc) • 3.66 kB
Markdown
[](https://npmjs.com/package/antd4-theme-vars)
[](https://npmjs.com/package/antd4-theme-vars)
`antd-theme-vars` helps you generate static theme css files based on the `prefixCls` config of `ConfigProvider`.
With this, you can easily customize the themes of various antd components.
An [online demo](https://orchardxyz.github.io/antd4-theme-vars).
```bash
$ npm install antd4-theme-vars --save-dev
$ yarn add antd4-theme-vars --dev
$ pnpm add antd4-theme-vars --save-dev
```
Use `.antd4tvrc.cjs` file to configure the theme variables.
An example:
```js
const { defineConfig } = require("antd4-theme-vars");
module.exports = defineConfig({
themes: [
{
prefixCls: "custom",
fileName: "custom",
variables: {
"primary-color": "#25b864",
},
},
],
});
```
Add the `antd4tv gen` command to the scripts section in package.json.
You can use it like:
```json
"scripts": {
"antd4tv": "antd4tv gen",
"dev": "npm run antd4tv && vite"
}
```
In your entry component(such as `App.tsx`). Add:
``` diff
+ import "antd4-theme-vars/themes/custom.css";
```
Use `ConfigProvider` in your component that needs to set `custom` theme:
```tsx
import { ConfigProvider } from "antd";
export default () => {
<ConfigProvider prefixCls="custom">
{/* do something... */}
</ConfigProvider>
}
```
| Name | Type | Default | Description |
| -------------------- | ------------------------------ | ----------------------------------------------------------- | ---------------------------------------- |
| themes | [ThemeConfig](
| outputDir | string | `join(process.cwd(), node_modules/antd4-theme-vars/themes)` | Output directory for generated css files |
| minifyCSS | boolean | `true` | Whether to minify css files |
| antdLessPath | string | `join(process.cwd(), "node_modules/antd/dist/antd.less")` | antd less file path |
| antdLessLookingPaths | string[] | `[join(process.cwd(), "node_modules/antd/lib")]` | antd less looking paths |
| Name | Type | Default | Description |
| --------- | ------ | ------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| prefixCls | string | - | not allowed to be `ant` |
| fileName | string | - | output file name |
| variables | object | - | antd less variables, see [default.less](https://github.com/ant-design/ant-design/blob/4.x-stable/components/style/themes/default.less) |
MIT