Provider
EuiProvider contains all necessary context providers required for full functionality and styling of EUI. A single instance of EuiProvider should exist at the top level of your app, where functionality will flow down the component tree.
Basic setup
For EUI to work correctly, set up EuiProvider at the root of your application:
jsx code block:import { EuiProvider } from '@elastic/eui'; const MyApp = () => ( <EuiProvider> {/* Content */} </EuiProvider> );
EuiProvider includes global reset and utilities styles and other app-wide contexts, functionality, and configuration options. It should only be instantiated once. This requirement is enforced internally - if another nested instance of EuiProvider is detected, that instance will return early without further processing, and will
warn if configured to do so. Nested instances of EuiThemeProvider, however, are valid.Theming and global styles
To customize the global theme of your app, use the
theme
, colorMode
, and modify
props (documented in EuiThemeProvider). For instance, it's likely that you will want to implement color mode switching at the top level:
jsx code block:<EuiProvider colorMode={isDark ? 'dark' : 'light'} />
If you do not wish your app to include EUI's default global reset CSS or utility CSS classes, this is configurable via the globalStyles
or utilityClasses
props. You can either pass in your own as a React component returning an Emotion Global, or remove them completely by setting the props to false
:
jsx code block:<EuiProvider globalStyles={false} utilityClasses={false} />
@emotion/cache
customization
The @emotion/cache library provides extra configuration options for EUI's CSS-in-JS behavior:
Browser prefixing: By default, EUI uses CSS browser prefixes based on our supported browsers matrix (latest evergreen only). Should you need to customize this, you can pass in your own prefix plugin via the
stylisPlugins
option.Injection location: In the case that your app has its own static stylesheet, Emotion's styles may not be injected into the correct location in the
<head>
, causing unintentional overrides or unapplied styles. You can use thecontainer
option and<meta>
tags to achieve this.
html code block:<!-- index.html --> <!DOCTYPE html> <html lang="en"> <head> <title>My App</title> <meta name="eui-style-insert"> <link name="compiled-css-here" /> </head> <body> <div id="root"></div> </body> </html>
jsx code block: