The padding of this box is passed as a raw unit translated to pixels
diff --git a/src-docs/src/views/theme/consuming_hoc.tsx b/src-docs/src/views/theme/consuming_hoc.tsx
index 67d4b608988..8ef66de8bdd 100644
--- a/src-docs/src/views/theme/consuming_hoc.tsx
+++ b/src-docs/src/views/theme/consuming_hoc.tsx
@@ -1,18 +1,18 @@
import React from 'react';
import { css } from '@emotion/react';
-import { withEuiTheme } from '../../../../src/services';
+import { withEuiTheme, WithEuiThemeProps } from '../../../../src/services';
import { EuiIcon } from '../../../../src/components/icon';
// eslint-disable-next-line react/prefer-stateless-function
-class Block extends React.Component {
+class Block extends React.Component {
render() {
const { theme } = this.props;
const divStyle = css`
- background: ${theme.theme.colors.euiColorLightShade};
+ background: ${theme.euiTheme.colors.euiColorLightShade};
// This way of providing sizing values doesn't output correctly
- padding: ${theme.theme.sizes.euiSizeXL};
- border-radius: ${theme.theme.borders.euiBorderRadius};
+ padding: ${theme.euiTheme.sizes.euiSizeXL};
+ border-radius: ${theme.euiTheme.borders.euiBorderRadius};
`;
return (
diff --git a/src-docs/src/views/theme/create_computed.tsx b/src-docs/src/views/theme/create_computed.tsx
index 32497587d5d..9bc013ffaab 100644
--- a/src-docs/src/views/theme/create_computed.tsx
+++ b/src-docs/src/views/theme/create_computed.tsx
@@ -9,24 +9,26 @@ import {
useEuiTheme,
} from '../../../../src/services';
+interface ThemeExtensions {
+ colors: {
+ customColorPrimary: string;
+ customColorPrimaryHighlight: string;
+ customColorPrimaryText: string;
+ };
+}
+
const Box: FunctionComponent<{ children: ReactNode }> = ({ children }) => {
- const [theme] = useEuiTheme();
+ const { euiTheme } = useEuiTheme();
return (
- {' '}
+ {' '}
{children}
diff --git a/src-docs/src/views/theme/inverse.tsx b/src-docs/src/views/theme/inverse.tsx
index cbdf8ceac79..3eec2b1b138 100644
--- a/src-docs/src/views/theme/inverse.tsx
+++ b/src-docs/src/views/theme/inverse.tsx
@@ -4,14 +4,14 @@ import { EuiSpacer } from '../../../../src/components/spacer';
import { EuiThemeProvider, useEuiTheme } from '../../../../src/services';
const Box: FunctionComponent<{ children: ReactNode }> = ({ children }) => {
- const [theme] = useEuiTheme();
+ const { euiTheme } = useEuiTheme();
return (
diff --git a/src-docs/src/views/theme/override_simple.tsx b/src-docs/src/views/theme/override_simple.tsx
index 2b8e394cac9..23b7b103118 100644
--- a/src-docs/src/views/theme/override_simple.tsx
+++ b/src-docs/src/views/theme/override_simple.tsx
@@ -3,13 +3,13 @@ import { EuiCode } from '../../../../src/components/code';
import { EuiThemeProvider, useEuiTheme } from '../../../../src/services';
const Box: FunctionComponent<{ children: ReactNode }> = ({ children }) => {
- const [theme] = useEuiTheme();
+ const { euiTheme } = useEuiTheme();
return (
diff --git a/src-docs/src/views/theme/theme_example.js b/src-docs/src/views/theme/theme_example.js
index dd76e441eb8..00adf63bca5 100644
--- a/src-docs/src/views/theme/theme_example.js
+++ b/src-docs/src/views/theme/theme_example.js
@@ -77,13 +77,31 @@ export const ThemeExample = {
<>
Using the react hook useEuiTheme() makes it very
- easy to consume the EUI static variables like colors and sizing. It
- will also automatically update based on the currently used theme.
+ easy to consume the EUI static and computed variables like colors
+ and sizing. It simply passes back an object of the current theme
+ which includes
+
+ -
+ euiTheme: EuiThemeComputed All
+ the calculated keys including any modifications
+
+ -
+ colorMode: EuiThemeColorMode{' '}
+ Simply {"'light'"} or {"'dark'"}
+
+ -
+
+ modifications: EuiThemeModifications
+ {' '}
+ Only the modification keys
+
+
- You'll want to pass these theme variables via the{' '}
- css property to take advantage of Emotion's
- compilation.
+ When consuming the theme's keys like{' '}
+ euiTheme.colors.primary, you'll want to pass
+ them via the css property to take advantage of
+ Emotion's compilation.
>
),
@@ -217,6 +235,9 @@ export const ThemeExample = {
specific theme variables. Instead, you should append custom keys to
the theme.
+
+ TODO: Indicate type support for custom keys.
+
>
),
demo:
,
diff --git a/src/services/index.ts b/src/services/index.ts
index 2c3cb251a66..bc5538365f9 100644
--- a/src/services/index.ts
+++ b/src/services/index.ts
@@ -129,6 +129,7 @@ export {
EuiColorModeContext,
useEuiTheme,
withEuiTheme,
+ WithEuiThemeProps,
EuiThemeProvider,
buildTheme,
computed,
diff --git a/src/services/theme/README.md b/src/services/theme/README.md
index 48e65de41f3..59aea98c0d0 100644
--- a/src/services/theme/README.md
+++ b/src/services/theme/README.md
@@ -93,10 +93,10 @@ All three props are optional. The default values for EUI will be used in the eve
A custom React hook that returns the computed theme. This hook is little more than a wrapper around the `useContext` hook, accessing three of the top-level providers: computed theme, color mode, and modifications.
```js
-const [theme, colorMode, modifications] = useEuiTheme();
+const {euiTheme, colorMode, modifications} = useEuiTheme();
```
-The `theme` variable has TypeScript support, which will result in IDE autocomplete availability.
+The `euiTheme` variable has TypeScript support, which will result in IDE autocomplete availability.
### WithEuiTheme
A higher-order-component that wraps `useEuiTheme` for React class components.
diff --git a/src/services/theme/hooks.tsx b/src/services/theme/hooks.tsx
index ee7e8065349..7a56137a6ab 100644
--- a/src/services/theme/hooks.tsx
+++ b/src/services/theme/hooks.tsx
@@ -30,43 +30,45 @@ import {
EuiThemeComputed,
} from './types';
-export const useEuiTheme =
(): [
- EuiThemeComputed,
- EuiThemeColorMode,
- EuiThemeModifications
-] => {
+export const useEuiTheme = (): {
+ euiTheme: EuiThemeComputed;
+ colorMode: EuiThemeColorMode;
+ modifications: EuiThemeModifications;
+} => {
const theme = useContext(EuiThemeContext);
- const modifications = useContext(EuiModificationsContext);
const colorMode = useContext(EuiColorModeContext);
+ const modifications = useContext(EuiModificationsContext);
- return [
- theme as EuiThemeComputed,
+ return {
+ euiTheme: theme as EuiThemeComputed,
colorMode,
- modifications as EuiThemeModifications,
- ];
+ modifications: modifications as EuiThemeModifications,
+ };
};
-export const withEuiTheme = (
- Component: React.ComponentType<
- T & {
- theme: {
- theme: EuiThemeComputed;
- colorMode: EuiThemeColorMode;
- };
- }
- >
+export interface WithEuiThemeProps {
+ theme: {
+ euiTheme: EuiThemeComputed
;
+ colorMode: EuiThemeColorMode;
+ };
+}
+export const withEuiTheme = (
+ Component: React.ComponentType>
) => {
const componentName = Component.displayName || Component.name || 'Component';
- const Render = (props: T, ref: React.Ref) => {
- const [theme, colorMode] = useEuiTheme();
+ const Render = (
+ props: Omit>,
+ ref: React.Ref>>
+ ) => {
+ const { euiTheme, colorMode } = useEuiTheme();
return (
);
};
diff --git a/src/services/theme/index.ts b/src/services/theme/index.ts
index 58ada6c9dc6..d7e299b0a43 100644
--- a/src/services/theme/index.ts
+++ b/src/services/theme/index.ts
@@ -23,7 +23,7 @@ export {
EuiModificationsContext,
EuiColorModeContext,
} from './context';
-export { useEuiTheme, withEuiTheme } from './hooks';
+export { useEuiTheme, withEuiTheme, WithEuiThemeProps } from './hooks';
export { EuiThemeProvider } from './provider';
export {
buildTheme,