-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Emotion 10 docs #799
Emotion 10 docs #799
Changes from 1 commit
1957b95
2139992
77dde4a
398d18d
d9839aa
29ac451
10c8ffb
40cf8f1
02a4c38
5482846
4abec7f
7302258
d548df8
be96cea
103d927
db05db4
c43169d
b347e49
370cf0c
97d0ef0
a68af25
393a158
bf708a9
1c01c4f
f67422e
7458d8f
73fa3cc
5b45535
b734f26
3803426
1eda8d7
3d3c024
3e4604b
c3c6222
324673a
e703139
e057d2e
60e3d50
9c6391c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
title: 'Class Names' | ||
--- | ||
|
||
It can be useful to create to create a className that is not passed to a component, for example if a component accepts a `wrapperClassName` prop or similar. To do this, Emotion exposes a render prop component which you can pass a function which accepts `css` and `cx`. If you have used versions of Emotion prior to Emotion 10 or used vanilla Emotion, the `css` and `cx` functions work exactly like they do in versions. | ||
|
||
```jsx | ||
// @live | ||
import { ClassNames } from '@emotion/core' | ||
|
||
// this might be a component from npm that accepts a wrapperClassName prop | ||
let SomeComponent = props => ( | ||
<div className={props.wrapperClassName}> | ||
in the wrapper! | ||
<div className={props.className}>{props.children}</div> | ||
</div> | ||
) | ||
|
||
render( | ||
<ClassNames> | ||
{({ css, cx }) => ( | ||
<SomeComponent | ||
wrapperClassName={css({ color: 'green' })} | ||
className={css` | ||
color: hotpink; | ||
`} | ||
> | ||
from children!! | ||
</SomeComponent> | ||
)} | ||
</ClassNames> | ||
) | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
- with-props | ||
- theming | ||
- labels | ||
- instances | ||
- class-names | ||
- migrating-to-emotion-10 | ||
#- benchmarks | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,8 @@ | ||
--- | ||
title: "Attaching Props" | ||
title: 'Attaching Props' | ||
--- | ||
|
||
Sometimes it's useful to create components that already have props applied, like the example below with a password input. You use recompose's `withProps` higher-order component to do this. | ||
|
||
**[`withProps` documentation](https://github.com/acdlite/recompose/blob/master/docs/API.md#withprops)** | ||
|
||
```jsx | ||
// @live | ||
import styled from '@emotion/styled' | ||
import withProps from 'recompose/withProps' | ||
|
||
const RedPasswordInput = withProps({ | ||
type: 'password' | ||
})(styled('input')` | ||
background-color: red; | ||
`) | ||
|
||
render(<RedPasswordInput />) | ||
``` | ||
|
||
Alternatively, you can use the css prop and create a regular component like this. | ||
Some css-in-js libraries offer APIs to attach props to components, instead of having our own API to do that, we recommend creating a regular react component, using the css prop and attaching props like you would with any other React component. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. while this obviously should not require an example, maybe it's worth to add one, just so we can refer people to it when they start asking There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The example for it is below. |
||
|
||
```jsx | ||
// @live | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixes #655