-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[storybook][eui] Add EUIThemeProvider to kbn-storybook (#122094)
- Loading branch information
1 parent
99cdba3
commit 8890384
Showing
3 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { EuiProvider } from '@elastic/eui'; | ||
import createCache from '@emotion/cache'; | ||
import type { DecoratorFn } from '@storybook/react'; | ||
|
||
/** | ||
* Storybook decorator using the EUI provider. Uses the value from | ||
* `globals` provided by the Storybook theme switcher. | ||
*/ | ||
const EuiProviderDecorator: DecoratorFn = (storyFn, { globals }) => { | ||
const colorMode = globals.euiTheme === 'v8.dark' ? 'dark' : 'light'; | ||
const emotionCache = createCache({ | ||
key: 'eui-styles', | ||
container: document.querySelector(`meta[name="eui-styles-global"]`) as HTMLElement, | ||
}); | ||
|
||
return ( | ||
<EuiProvider colorMode={colorMode} cache={emotionCache}> | ||
{storyFn()} | ||
</EuiProvider> | ||
); | ||
}; | ||
|
||
export const decorators = [EuiProviderDecorator]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters