Skip to content

Commit 7ac75e8

Browse files
committed
Update README.md
1 parent c5a05b6 commit 7ac75e8

1 file changed

Lines changed: 46 additions & 35 deletions

File tree

README.md

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -89,50 +89,43 @@ Under the hood, `classier-react` assumes any unknown props are declared as modif
8989

9090
- Sentence-casing is preserved but not added
9191

92-
## Passing down styles
93-
94-
`<Comp />` only injects the props it merges, it can't make sure they are rendered. If you're wrapping or writing a component, it's a good idea to pass any props you don't use onward to what is rendered.
95-
96-
Most components are already written this way.
97-
98-
```jsx
99-
const MyComponent = ({ option, ...rest }) => <div {...rest} />
100-
```
101-
10292
## CSS Modules
10393

104-
`classier-react` supports CSS Modules by letting you wrap them with `createModuleElement` and `wrapModule`.
105-
94+
`classier-react` can wrap CSS Modules with `elementModule` and `boxedModule`.
10695

107-
`wrapModule` will expose every style name in your module:
108-
96+
`boxedModule` creates an Element that checks the provided module for a mapping after transformation:
10997
```jsx
110-
// feature/block.js
111-
import { wrapModule } from 'classier-react'
98+
import { createModuleElement } from 'classier-react'
11299
import styles from './styles.css'
113100

114-
export default wrapModule(styles)
101+
const MBox = boxedModule(styles)
102+
103+
...
104+
105+
<MBox someProp='someValue' children={...} />
115106
```
116107

117-
Often, selectors are not elements. You might find it better to pick which elements to export:
108+
`elementModule` will expose the optionally listed blocks as Elements from the module:
118109
```jsx
119-
// feature/block.js
120110
import { createModuleElement } from 'classier-react'
121111
import styles from './styles.css'
122112

123-
export {
124-
Element: createModuleElement('element', styles)
125-
}
126-
```
113+
const Block = elementModule(styles, ['element'])
127114

128-
Your elements can then be used in your other components
129-
```jsx
130-
// feature/component.jsx
131-
import Block from './block'
132115

133116
...
134117

135-
<Block.Element fontSize='md' {...props} />
118+
<Block.Element fontSize="md" {...props} />
119+
```
120+
121+
## Passing down styles
122+
123+
`<Comp />` only injects the props it merges, it can't make sure they are rendered. If you're wrapping or writing a component, it's a good idea to pass the `style` and `className` props onward to what is rendered.
124+
125+
Most components are already written this way.
126+
127+
```jsx
128+
const MyComponent = ({ option, ...rest }) => <div {...rest} />
136129
```
137130

138131
## Avoiding mixing domains
@@ -149,8 +142,9 @@ const containerClassName = cx(props.styled)
149142

150143
## API
151144

145+
### React
152146
```js
153-
import { Box, Text, Comp, cx, configure } from 'classier-react'
147+
import { Box, Text, Comp, createElement } from 'classier-react'
154148
```
155149

156150
---
@@ -187,19 +181,36 @@ Returns a customized `Box` that nests its CSS classes under the {name} block.
187181

188182
---
189183

190-
### `createModuleElement(name, module)`
184+
### CSS Modules
185+
```js
186+
import { boxedModule, createModuleElement, elementModule } from 'classier-react'
187+
```
191188

192-
Returns a customized `Box` that tries to map its CSS classes to the ones in the provided module.
189+
---
193190

194-
#### members
191+
### `boxedModule(module, pick)`
195192

196-
- **Comp** - a `Comp` with the same customization.
193+
Returns an `Element` that tries to map its CSS classes to the ones in the provided module.
197194

198195
---
199196

200-
### `wrapModule(module)`
197+
### `createModuleElement(module, name)`
201198

202-
Returns an object that maps the selectors of `module` to `createModuleElement`. Might create a lot of elements.
199+
Returns an `Element` that tries to map its CSS classes to the ones in the provided module under the {name} block.
200+
201+
---
202+
203+
### `elementModule(module, pick)`
204+
205+
Returns an object that picks selectors of `module` to `createModuleElement`.
206+
207+
---
208+
209+
### Utility
210+
211+
```js
212+
import { cx, configure } from 'classier-react'
213+
```
203214

204215
---
205216

0 commit comments

Comments
 (0)