-
Notifications
You must be signed in to change notification settings - Fork 859
[EuiProvider] Add globalStyles prop for customization
#5497
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
Changes from all commits
0b315d9
9c623be
a67c881
f8101c4
bc81ba8
a82f279
87bb5bf
11051bb
bb201f5
689182c
3cd86d0
8b4d7f8
275476c
fe99869
3c537b7
c389bb7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import React from 'react'; | ||
|
|
||
| import { EuiCodeBlock, useEuiTheme, isLegacyTheme } from '../../../../src'; | ||
|
|
||
| export default () => { | ||
| const { euiTheme, colorMode } = useEuiTheme(); | ||
| const isLegacy = isLegacyTheme(euiTheme.themeName); | ||
|
|
||
| return ( | ||
| <EuiCodeBlock language="tsx" fontSize="m" isCopyable> | ||
| {`import { EuiProvider } from '@elastic/eui'; | ||
|
|
||
| const MyApp = () => ( | ||
| <EuiProvider${isLegacy ? ' theme={null}' : ''}${ | ||
| colorMode === 'DARK' ? ' colorMode="dark"' : '' | ||
| }> | ||
| {/* Content */} | ||
| </EuiProvider> | ||
| );`} | ||
| </EuiCodeBlock> | ||
| ); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import React from 'react'; | ||
|
|
||
| import { | ||
| EuiCodeBlock, | ||
| EuiSpacer, | ||
| useEuiTheme, | ||
| isLegacyTheme, | ||
| } from '../../../../src'; | ||
|
|
||
| export default () => { | ||
| const { euiTheme, colorMode } = useEuiTheme(); | ||
| const isLegacy = isLegacyTheme(euiTheme.themeName); | ||
|
|
||
| return ( | ||
| <> | ||
| <EuiCodeBlock language="html" fontSize="m" isCopyable> | ||
| {!isLegacy | ||
| ? `<!-- index.html --> | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <title>My App</title> | ||
| <meta name="global-style-insert"> | ||
| </head> | ||
| <body> | ||
| <div id="root"></div> | ||
| </body> | ||
| </html>` | ||
| : `<!-- index.html --> | ||
| <!-- No template modifications necessary when using the Legacy theme -->`} | ||
| </EuiCodeBlock> | ||
|
|
||
| <EuiSpacer size="s" /> | ||
|
|
||
| <EuiCodeBlock language="jsx" fontSize="m" isCopyable> | ||
| {`// App.js | ||
| import { EuiProvider } from '@elastic/eui' | ||
| ${ | ||
| !isLegacy | ||
| ? `import createCache from '@emotion/cache'; | ||
|
|
||
| const cache = createCache({ | ||
| key: 'myApp', | ||
| container: document.querySelector('meta[name="global-style-insert"]'), | ||
| }); | ||
| ` | ||
| : '' | ||
| } | ||
| <EuiProvider${isLegacy ? ' theme={null}' : ''}${ | ||
| colorMode === 'DARK' ? ' colorMode="dark"' : '' | ||
| }${!isLegacy ? ' cache={cache}' : ''}> | ||
| {/* Content */} | ||
| </EuiProvider> | ||
| `} | ||
| </EuiCodeBlock> | ||
| </> | ||
| ); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,10 +9,7 @@ | |
| import React, { PropsWithChildren } from 'react'; | ||
| import { CacheProvider, EmotionCache } from '@emotion/react'; | ||
|
|
||
| import { | ||
| EuiGlobalStyles, | ||
| EuiGlobalStylesProps, | ||
| } from '../../global_styling/reset/global_styles'; | ||
| import { EuiGlobalStyles, EuiGlobalStylesProps } from '../../global_styling'; | ||
| import { | ||
| EuiThemeProvider, | ||
| EuiThemeProviderProps, | ||
|
|
@@ -28,24 +25,33 @@ export interface EuiProviderProps<T> | |
| * Pass `null` to remove all theming including global reset | ||
| */ | ||
| theme?: EuiThemeSystem | null; | ||
| /** | ||
| * Provide global styles via `@emotion/react` `Global` for your custom theme. | ||
| * Pass `false` to remove the default EUI global styles. | ||
| */ | ||
| globalStyles?: false | ((params: any) => JSX.Element | null); | ||
| /** | ||
| * Provide a cache configuration from `@emotion/cache` | ||
| */ | ||
| cache?: EmotionCache; | ||
| } | ||
|
|
||
| export const EuiProvider = <T extends {} = {}>({ | ||
| cache, | ||
| theme = EuiThemeAmsterdam, | ||
| globalStyles: GlobalStyles = EuiGlobalStyles, | ||
|
Contributor
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. Should the default be undefined instead? My guess is that most consumer's of multiple providers won't realize they need to remove the global styles. But likely, they'll notice they need to add it in order to fix the base styles. Or should we be recommending two different providers. For instance this is just the theme provider, so should Kibana's multiple instances just switch to using the theme provider?
Contributor
Author
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 summary might be overly concerned with multiple providers. The reasons for having default global styles but allowing for their removal are that:
Contributor
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.
This is specifically where I worry that Kibana engineers will not know that they need to remove the global styles, making them compound or override. What is your plan to educate those engineers about this workaround?
Contributor
Author
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. All instances of |
||
| colorMode, | ||
| modify, | ||
| children, | ||
| }: PropsWithChildren<EuiProviderProps<T>>) => { | ||
| return theme !== null ? ( | ||
| return theme !== null && GlobalStyles !== false ? ( | ||
| <EuiThemeProvider theme={theme} colorMode={colorMode} modify={modify}> | ||
| {cache ? ( | ||
| <CacheProvider value={cache}> | ||
| <EuiGlobalStyles /> | ||
| <GlobalStyles /> | ||
| </CacheProvider> | ||
| ) : ( | ||
| <EuiGlobalStyles /> | ||
| <GlobalStyles /> | ||
| )} | ||
| {children} | ||
| </EuiThemeProvider> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| export * from './reset/global_styles'; |
Uh oh!
There was an error while loading. Please reload this page.