[Emotion](https://emotion.sh/docs/introduction) is our default-to-be approach to styling React components. It provides a way for styles to be a consequence of properties and state of a component.
### Usage
## Usage
#### Basic styling
### Basic styling
For styling components use Emotion's `css` function
For styling components, use [Emotion's `css` function](https://emotion.sh/docs/emotion#css).
```tsx
import { css } from 'emotion';
const ComponentA = () => {
return (
<divclassName={css`background:red;`}>
As red as you can ge
</div>
);
}
import React from 'react';
import { css } from 'emotion';
const ComponentA = () => (
<div
className={css`
background: red;
`}
>
As red as you can get
</div>
);
```
#### Styling complex components
### Styling complex components
In more complex cases, especially when you need to style multiple DOM elements in one component or when your styles that depend on properties and/or state, you should create a helper function that returns an object with desired stylesheet. This function should also be wrapped in `stylesFactory` helper function that will provide basic memoization.
In more complex cases, especially when you need to style multiple DOM elements in one component, or when using styles that depend on properties and/or state, you should create a helper function that returns an object of styles. This function should also be wrapped in the `stylesFactory` helper function, which will provide basic memoization.
Let's say you need to style a component that has different background depending on the theme:
Let's say you need to style a component that has a different background depending on the theme:
```tsx
import { css, cx } from 'emotion';
import { GrafanaTheme, useTheme, selectThemeVariant, stylesFactory } from '@grafana/ui';
import React from 'react';
import { css } from 'emotion';
import { GrafanaTheme } from '@grafana/data';
import { selectThemeVariant, stylesFactory, useTheme } from '@grafana/ui';