forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Infra UI] Add and use typed styled-components theme provider (elasti…
…c#33607) This adds a specialization of the styled-components api, which is correctly typed according to the new theme variable type definitions included in EUI (elastic/eui#1750) and made available in Kibana via elastic#33873.
- Loading branch information
1 parent
ac896fb
commit ce7189d
Showing
45 changed files
with
224 additions
and
145 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
x-pack/common/eui_styled_components/eui_styled_components.tsx
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,43 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import * as styledComponents from 'styled-components'; | ||
import { ThemedStyledComponentsModule, ThemeProvider, ThemeProviderProps } from 'styled-components'; | ||
|
||
import euiDarkVars from '@elastic/eui/dist/eui_theme_dark.json'; | ||
import euiLightVars from '@elastic/eui/dist/eui_theme_light.json'; | ||
|
||
export interface EuiTheme { | ||
eui: typeof euiLightVars | typeof euiDarkVars; | ||
darkMode: boolean; | ||
} | ||
|
||
const EuiThemeProvider = <T extends any>({ | ||
darkMode = false, | ||
...otherProps | ||
}: ThemeProviderProps<T & EuiTheme> & { | ||
darkMode?: boolean; | ||
children?: React.ReactNode; | ||
}) => ( | ||
<ThemeProvider | ||
{...otherProps} | ||
theme={() => ({ | ||
eui: darkMode ? euiDarkVars : euiLightVars, | ||
darkMode, | ||
})} | ||
/> | ||
); | ||
|
||
const { | ||
default: euiStyled, | ||
css, | ||
injectGlobal, | ||
keyframes, | ||
withTheme, | ||
} = styledComponents as ThemedStyledComponentsModule<EuiTheme>; | ||
|
||
export { css, euiStyled, EuiThemeProvider, injectGlobal, keyframes, withTheme }; |
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,19 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { | ||
css, | ||
euiStyled, | ||
EuiTheme, | ||
EuiThemeProvider, | ||
injectGlobal, | ||
keyframes, | ||
withTheme, | ||
} from './eui_styled_components'; | ||
|
||
export { css, euiStyled, EuiTheme, EuiThemeProvider, injectGlobal, keyframes, withTheme }; | ||
// tslint:disable-next-line:no-default-export to mimick the styled-components module | ||
export default euiStyled; |
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
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
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
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
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
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
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
Oops, something went wrong.