|
2 | 2 |
|
3 | 3 | A simple way to create an antd theme css file with zero configuration. |
4 | 4 |
|
5 | | -[Ant Design](https://ant.design/) provides plenty of UI components, styled with [less](http://lesscss.org/). |
6 | | -You can customize the default theme modifying less variables, [check the doc](https://ant.design/docs/react/customize-theme) for multiple ways to achieve this.\ |
7 | | -The main issue being that you don't have a simple way to create a static `css` file with zero configuration. |
| 5 | +[Ant Design](https://ant.design/) provides plenty of UI components, styled with less. |
| 6 | +You can customize the default theme modifying less variables (check [their doc](https://ant.design/docs/react/customize-theme) for multiple ways to achieve this), but the main issue being that you don't have a simple way to create a static `.css` file with zero configuration. |
8 | 7 |
|
9 | | -This package was created with `Antd Design v4.6.6` and aims to ease the theme's customization process without having to install more dependencies yourself, set up `less` or eject your [React](reactjs.org) project. |
| 8 | +This package was created with `Antd Design v4.6.6` and aims to ease the theme's customization process without having to install more dependencies yourself, set up [less](https://lesscss.org/) or eject your [React](reactjs.org) project. |
10 | 9 |
|
11 | 10 | ## Usage |
12 | 11 |
|
13 | 12 | ### Generate custom theme styles |
14 | 13 |
|
15 | | -1. Create your own custom theme overriding Antd's less variables (by default: `./custom-theme.less`). |
16 | | - |
17 | | -2. Generate theme's custom `.css` file. |
18 | | - |
19 | | - - **Option A:** Without installing this plugin: |
20 | | - ```sh |
21 | | - $ npx @emeks/antd-custom-theme-generator |
22 | | - |
23 | | - output > ./custom-theme.css |
24 | | - ``` |
25 | | - |
26 | | - - **Option B:** Installing the package as a dev dependency: |
27 | | - |
28 | | - ```sh |
29 | | - $ npm i -E --save-dev @emeks/antd-custom-theme-generator |
30 | | - ``` |
31 | | - |
32 | | - Then generating your theme: |
33 | | - ```sh |
34 | | - $ generate-theme |
35 | | -
|
36 | | - output > ./custom-theme.css |
37 | | - ``` |
38 | | - |
39 | | -3. Replace `antd/dist/antd.css` import in your project, with the output file (by default: `./custom-theme.css`) generated by this plugin. |
| 14 | +1. Define your custom theme creating a `.less` file overriding Antd's variables (by default: `./custom-theme.less`). |
| 15 | + - _Example:_ |
| 16 | + ```less |
| 17 | + @primary-color: #9063cd; |
| 18 | + @success-color: #a8d3c4; |
| 19 | + ``` |
| 20 | + |
| 21 | +2. Generate custom theme's `.css` file. |
| 22 | + - _Option A:_\ |
| 23 | + Without installing this package: |
| 24 | + ```sh |
| 25 | + $ npx @emeks/antd-custom-theme-generator |
| 26 | +
|
| 27 | + output > ./custom-theme.css |
| 28 | + ``` |
| 29 | + - _Option B:_\ |
| 30 | + Installing this package as a dev dependency: |
| 31 | + ```sh |
| 32 | + $ npm i -E --save-dev @emeks/antd-custom-theme-generator |
| 33 | + ``` |
| 34 | + Then generating your theme: |
| 35 | + ```sh |
| 36 | + $ generate-theme |
| 37 | +
|
| 38 | + default output > ./custom-theme.css |
| 39 | + ``` |
| 40 | +3. Replace `"antd/dist/antd.css"` import in your project, with the output file of your custom theme generated by this script (by default: `./custom-theme.css`). |
40 | 41 |
|
41 | 42 | ### Options |
42 | 43 |
|
43 | 44 | | Name | Default | Description | |
44 | 45 | | --- | --- | --- | |
45 | | -| `--verbose` or `-v` | | Print more info for debugging | |
46 | | -| `--antd` | ./node_modules/antd | Path of the antd library | |
47 | | -| `--theme` | default | Antd theme you want to override (e.g. `dark` or `compact`) - [Check available options](https://github.com/ant-design/ant-design/tree/master/components/style/themes). | |
48 | | -| `<customThemeFilePath>` | ./custom-theme.less | Path of the less file with the variables your want to override | |
49 | | -| `<generatedThemeFilePath>` | ./custom-theme.css | Output path where the script give you the css file with your new theme | |
50 | | - |
51 | | -> **Notes**: |
52 | | -> |
53 | | -> The order of the paths **is** important. |
54 | | -> ```sh |
55 | | -> $ generate-theme [--verbose] [--antd] [--theme] [<customThemeFilePath>] [<generatedThemeFilePath>] |
56 | | -> ``` |
57 | | -> |
58 | | - |
59 | | -### Examples |
60 | | - |
61 | | -- Generate dark theme |
| 46 | +| `--verbose` or `-v` | | Prints a little bit more info for debugging purposes | |
| 47 | +| `--watch` or `-w` | | Keeps script running, recompile on `<customThemeFilePath>` change | |
| 48 | +| `--antd` | ./node_modules/antd | Path to the antd library directory | |
| 49 | +| `--theme` | default | Antd theme you want to use as base (e.g. `dark` or `compact`) - [Check available options](https://github.com/ant-design/ant-design/tree/master/components/style/themes) | |
| 50 | +| `<customThemeFilePath>` | ./custom-theme.less | Path to the custom `.less` file with Antd variables overriden | |
| 51 | +| `<generatedThemeFilePath>` | ./custom-theme.css | Output Path to the compiled `.css` file containing your new theme | |
| 52 | +
|
| 53 | +> **Notes**:\ |
| 54 | +> The order of paths **is** important. |
| 55 | +```sh |
| 56 | + $ generate-theme [--verbose] [--watch] [--antd <dir>] [--theme <theme>] [<customThemeFilePath>] [<generatedThemeFilePath>] |
| 57 | +``` |
62 | 58 |
|
| 59 | +#### Examples |
| 60 | +- Generate a custom theme using dark theme as base: |
63 | 61 | ```sh |
64 | 62 | $ npx @emeks/antd-custom-theme-generator --theme dark |
65 | 63 | ``` |
66 | | - |
67 | | -- Generate default theme with non default paths |
| 64 | +- Generate a custom theme using default theme as base specifying non default paths: |
68 | 65 | ```sh |
69 | 66 | $ npx @emeks/antd-custom-theme-generator ./styles/custom-theme.less ./styles/custom-theme.css |
70 | 67 | ``` |
71 | 68 |
|
72 | 69 | ### FAQ |
73 | | - |
74 | 70 | > **Q1: Which variables can I override?** |
75 | 71 |
|
76 | 72 | You may override any variable exposed by Antd in [this file](https://github.com/ant-design/ant-design/blob/master/components/style/themes/default.less). |
77 | 73 |
|
78 | 74 | > **Q2: Should I run this command every time I change my `custom-theme.less` file?** |
79 | 75 |
|
80 | | -Yes, we don't provide hot-reload yet. |
| 76 | +No, you could pass the `-w` argument to let the script observe `<customThemeFilePath>` file and recompile it if it changes. |
81 | 77 |
|
82 | 78 | ## Development |
83 | | -
|
84 | 79 | - Inside package folder, link it globally: |
85 | | -
|
86 | | -```sh |
87 | | -$ npm link |
88 | | -``` |
89 | | -
|
90 | | -- Use the package in your project (with antd already installed and a `custom-theme.less` file created as well): |
91 | | -
|
92 | | -```sh |
93 | | -$ generate-theme |
94 | | -``` |
95 | | -
|
96 | | -## TODO List: |
97 | | -
|
98 | | -- [ ] Add hot-reload generation. |
| 80 | + ```sh |
| 81 | + $ npm link |
| 82 | + ``` |
| 83 | +- Use the package in your project (with antd already installed and a `<customThemeFilePath>` file created as well): |
| 84 | + ```sh |
| 85 | + $ generate-theme |
| 86 | + ``` |
0 commit comments