Skip to content

Commit

Permalink
Add documentation for typing the theme with emotion (#1739)
Browse files Browse the repository at this point in the history
* Add documentation for typing the theme with emotion

* Add example TS error
  • Loading branch information
Robin Métral authored Sep 7, 2022
1 parent edc760b commit 88f6b22
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions docs/introduction/getting-started.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,31 @@ export default function App() {
}
```

#### Typing the theme

If you're using TypeScript, you might run into type conflicts when using the `theme` prop:

```
Type 'Theme' is not assignable to type 'ThemeArgs'.ts(2322)
```

Type the theme by extending the `@emotion/react` module declaration, for example in a new `types/emotion.d.ts` file (make sure the file is included in `typeRoots` in your `tsconfig.json`):

```ts
// types/emotion.d.ts
import { Theme as CircuitTheme } from '@sumup/design-tokens';
import {} from '@emotion/react/types/css-prop'; // See https://github.com/emotion-js/emotion/pull/1941

declare module '@emotion/react' {
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface Theme extends CircuitTheme {}
}
```

This will also enable Intellisense for the theme object.

For more information, refer to [Emotion's TypeScript documentation](https://emotion.sh/docs/typescript#define-a-theme).

### Configuring the viewport

Finally, make sure that the viewport meta tag includes `viewport-fit=cover`, and that your app has the right padding to render inside [CSS safe areas](<https://developer.mozilla.org/en-US/docs/Web/CSS/env()>):
Expand Down

1 comment on commit 88f6b22

@vercel
Copy link

@vercel vercel bot commented on 88f6b22 Sep 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.