Skip to content

Commit

Permalink
Add short docs for css prop + TS
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist committed Jul 30, 2020
1 parent 3a7fc3d commit ad1a84d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .changeset/moody-ravens-deny.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
'@emotion/react': patch
---

The way in which we provide TypeScript support for `css` prop has changed. Based on usage of our JSX pragma we are able to add support for `css` prop only for components that support `className` prop (as our `jsx` factory function takes provided `css` prop, resolves it and pass the generated `className` to the rendered component). This has been implemented using technique described [here](https://www.typescriptlang.org/docs/handbook/jsx.html#factory-functions). What is important - we no longer extend any global interfaces, so people shouldn't bump anymore into type conflicts for the `css` prop when using different libraries with the `css` prop support, such as `styled-components`.
The way in which we provide TypeScript support for `css` prop has changed. Based on usage of our jsx pragma we are able to add support for `css` prop only for components that support `className` prop (as our `jsx` factory function takes provided `css` prop, resolves it and pass the generated `className` to the rendered component). This has been implemented using technique described [here](https://www.typescriptlang.org/docs/handbook/jsx.html#factory-functions). What is important - we no longer extend any global interfaces, so people shouldn't bump anymore into type conflicts for the `css` prop when using different libraries with the `css` prop support, such as `styled-components`.

However, it's not possible to leverage `css` prop support being added conditionally based on a type of rendered component when one is not using our JSX pragma. For those cases when people use our pragma implicitly (for example when using our `@emotion/babel-preset-css-prop`) we have added special file that can be imported once to add support for the `css` prop globally, for all components. Use it like this:
However, it's not possible to leverage `css` prop support being added conditionally based on a type of rendered component when one is not using our jsx pragma. For those cases when people use our pragma implicitly (for example when using our `@emotion/babel-preset-css-prop`) we have added special file that can be imported once to add support for the `css` prop globally, for all components. Use it like this:

```ts
import {} from '@emotion/react/types/css-prop'
Expand Down
10 changes: 10 additions & 0 deletions docs/typescript.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ import { css } from '@emotion'
<div className={css({ background: 'black' })} />
```

### `css` prop

When using our jsx pragma the support for `css` prop is being added only for components that accepts `className` prop, as our `jsx` factory function takes provided `css` prop, resolves it and pass the generated `className` to the rendered component.

However, it's not possible to leverage `css` prop support being added conditionally based on a type of rendered component when one is not using our jsx pragma. For those cases when people use our pragma implicitly (for example when using our `@emotion/babel-preset-css-prop`) we have a special file that can be imported once to add support for the `css` prop globally, for all components. Use it like this:

```ts
import {} from '@emotion/react/types/css-prop'
```

## @emotion/styled

### HTML/SVG elements
Expand Down

0 comments on commit ad1a84d

Please sign in to comment.