You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -195,6 +196,7 @@ Configure the options for the plugin within your `.babelrc` as follows:
195
196
|`removeImport`|`boolean`|Remove the matching style import. This option is used to enable server-side rendering.|`false`|
196
197
|`webpackHotModuleReloading`|`boolean`|Enables hot reloading of CSS in webpack|`false`|
197
198
|`handleMissingStyleName`|`"throw"`, `"warn"`, `"ignore"`|Determines what should be done for undefined CSS modules (using a `styleName` for which there is no CSS module defined). Setting this option to `"ignore"` is equivalent to setting `errorWhenNotFound: false` in [react-css-modules](https://github.com/gajus/react-css-modules#errorwhennotfound). |`"throw"`|
199
+
|`attributeNames`|`?AttributeNameMapType`|Refer to [Custom Attribute Mapping](#custom-attribute-mapping)|`{"styleName": "className"}`|
198
200
199
201
Missing a configuration? [Raise an issue](https://github.com/gajus/babel-plugin-react-css-modules/issues/new?title=New%20configuration:).
type GenerateScopedNameConfigurationType = GenerateScopedNameType | string;
219
221
222
+
type AttributeNameMapType = {
223
+
[key: string]: string
224
+
};
225
+
220
226
```
221
227
222
228
### Configurate syntax loaders
@@ -250,6 +256,16 @@ To add support for different CSS syntaxes (e.g. SCSS), perform the following two
250
256
}
251
257
```
252
258
259
+
### Custom Attribute Mapping
260
+
261
+
You can set your own attribute mapping rules using the `attributeNames` option.
262
+
263
+
It's an object, where keys are source attribute names and values are destination attribute names.
264
+
265
+
For example, the [<NavLink>](https://github.com/ReactTraining/react-router/blob/master/packages/react-router-dom/docs/api/NavLink.md) component from [React Router](https://github.com/ReactTraining/react-router) has a `activeClassName` attribute to accept an additional class name. You can set `"attributeNames": { "activeStyleName": "activeClassName" }` to transform it.
266
+
267
+
The default `styleName` -> `className` transformation **will not** be affected by an `attributeNames` value without a `styleName` key. Of course you can use `{ "styleName": "somethingOther" }` to change it, or use `{ "styleName": null }` to disable it.
268
+
253
269
## Installation
254
270
255
271
When `babel-plugin-react-css-modules` cannot resolve CSS module at a compile time, it imports a helper function (read [Runtime `styleName` resolution](#runtime-stylename-resolution)). Therefore, you must install `babel-plugin-react-css-modules` as a direct dependency of the project.
@@ -271,7 +287,7 @@ module.exports = {
271
287
}
272
288
```
273
289
274
-
Remember, also, that the bundler caches things like plugins and presets. If you want to change your `.babelrc` (to add this plugin) then you'll want to add the `--reset-cache` flag to the end of the package command.
290
+
Remember, also, that the bundler caches things like plugins and presets. If you want to change your `.babelrc` (to add this plugin) then you'll want to add the `--reset-cache` flag to the end of the package command.
0 commit comments