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
-[Loops and Child Components](#loops-and-child-components)
20
21
-[Decorator](#decorator)
21
22
-[Options](#options)
22
23
-[`allowMultiple`](#allowmultiple)
@@ -219,45 +220,99 @@ In this example, `table-custom-styles.css` selectively extends `table.css` (the
219
220
220
221
Refer to the [`UsingStylesProperty` example](https://github.com/gajus/react-css-modules-examples/tree/master/src/UsingStylesProperty) for an example of a working implementation.
221
222
222
-
### Styles Property
223
+
### `styles` Property
223
224
224
225
Decorated components inherit `styles` property that describes the mapping between CSS modules and CSS classes.
225
226
226
-
`styles` property within the component itself is designed to be used only when `styleNames` cannot be used.
227
+
```js
228
+
classextendsReact.Component {
229
+
render () {
230
+
<div>
231
+
<p styleName='foo'></p>
232
+
<p className={this.props.styles.foo}></p>
233
+
</div>;
234
+
}
235
+
}
236
+
```
237
+
238
+
In the above example, `styleName='foo'` and `className={this.props.styles.foo}` are equivalent.
239
+
240
+
`styles` property is designed to enable component decoration of [Loops and Child Components](#loops-and-child-components).
241
+
242
+
### Loops and Child Components
227
243
228
-
`styleNames` cannot be used within a component to define styles of a `ReactElement` that will be generated by another component (https://github.com/gajus/react-css-modules/issues/11), e.g.
244
+
`styleName` cannot be used to define styles of a `ReactElement` that will be generated by another component, e.g.
229
245
230
246
```js
231
-
classextendsReact.Component {
247
+
importReactfrom'react';
248
+
importCSSModulesfrom'react-css-modules';
249
+
importListfrom'./List';
250
+
importstylesfrom'./table.css';
251
+
252
+
classCustomListextendsReact.Component {
232
253
render () {
233
254
let itemTemplate;
234
255
235
256
itemTemplate= (name) => {
236
-
return<li styleName='foo'>{name}</li>;
257
+
return<li styleName='item-template'>{name}</li>;
237
258
};
238
259
239
-
return<List itemTemplate={name} />;
260
+
return<List itemTemplate={itemTemplate} />;
240
261
}
241
262
}
263
+
264
+
exportdefaultCSSModules(CustomList, styles);
242
265
```
243
266
244
-
For that purpose, the decorated component inherits `styles` property that you can use just as a regular CSS Modules object. The earlier example can be therefore rewritten to:
267
+
The above example will not work. `CSSModules` is used to decorate `CustomList` component. However, it is the `List` component that will render `itemTemplate`.
268
+
269
+
For that purpose, the decorated component inherits [`styles` property](#styles-property) that you can use just as a regular CSS Modules object. The earlier example can be therefore rewritten to:
`styles` property works with ES6 classes and stateless function components.
292
+
You can use `styleName` property within the child component if you decorate the child component using `CSSModules` before passing it to the rendering component, e.g.
0 commit comments