From e6ccac87490d625be94e5af9452c1eca2898415e Mon Sep 17 00:00:00 2001
From: Cee Chen <549407+cee-chen@users.noreply.github.com>
Date: Fri, 20 Sep 2024 14:06:27 -0700
Subject: [PATCH] [Docs] Update references to Sass/Emotion migration (#8029)
---
README.md | 7 +-
packages/eui/README.md | 70 +----
.../src/components/codesandbox/link.js | 37 +--
.../guide_tabbed_page/guide_tabbed_page.tsx | 21 +-
.../guidelines/getting_started/_app_setup.tsx | 71 ++---
.../getting_started/_customizing.tsx | 105 --------
.../guidelines/getting_started/_tokens.tsx | 101 -------
.../getting_started/getting_started.js | 167 +++++++-----
.../views/theme/_components/_theme_notice.tsx | 53 ++--
.../src/views/theme/borders/borders.tsx | 1 -
.../src-docs/src/views/theme/consuming.tsx | 4 +-
.../src/views/theme/customizing/_sass.tsx | 25 +-
.../src/views/theme/customizing/values.tsx | 1 -
.../src-docs/src/views/theme/other/other.tsx | 1 -
.../docs/01_guidelines/getting_started.mdx | 249 +++++++-----------
wiki/consuming-eui/README.md | 26 +-
16 files changed, 298 insertions(+), 641 deletions(-)
delete mode 100644 packages/eui/src-docs/src/views/guidelines/getting_started/_customizing.tsx
delete mode 100644 packages/eui/src-docs/src/views/guidelines/getting_started/_tokens.tsx
diff --git a/README.md b/README.md
index 694c966f993..54db578deb3 100644
--- a/README.md
+++ b/README.md
@@ -45,12 +45,9 @@ This activity counter can be soft reset by commenting on the issue directly, but
The EUI team, like everyone else, has a finite amount of time and resources, and it is not humanly possible for us to implement every task or feature requested of us. However, that's where the beauty of open source comes in - if your request is important to you, we strongly encourage you to [contribute code directly to EUI](wiki/contributing-to-eui/) that addresses your issue or request!
-
-### What is the status of EUI's theming?
+### I have more questions!
-The EUI library was previously built upon Sass and is in the process of migrating to CSS-in-JS (specifically [Emotion](https://emotion.sh)). While this work is in progress, we ask for your patience with our in-between state in areas such as documentation and setup.
-
-If you're a Kibana developer with questions around CSS-in-JS usage in Kibana, please check out our [FAQ discussion](https://github.com/elastic/eui/discussions/6828)!
+The EUI team has ongoing FAQs for more transient or component-specific questions. [Please see the FAQ section in our GitHub discussions here](https://github.com/elastic/eui/discussions/categories/faq).
## Wiki
diff --git a/packages/eui/README.md b/packages/eui/README.md
index 694c966f993..7012e6ff7d0 100644
--- a/packages/eui/README.md
+++ b/packages/eui/README.md
@@ -1,69 +1 @@
-
-
-# Elastic UI Framework
-
-**The Elastic UI Framework is a collection of React UI components for quickly building user interfaces at Elastic.**
-
-Check out our [full documentation site][docs] which contains many examples of components in the EUI framework aesthetic, and how to use them in your products. Our FAQ below covers common usage questions — for other general questions regarding EUI, check out the [Discussions tab](https://github.com/elastic/eui/discussions).
-
-> [!NOTE]
-> We're in the process of migrating this repository to a monorepo structure. You can find `@elastic/eui` files in the [packages/eui](https://github.com/elastic/eui/tree/main/packages/eui) directory.
-
-## Frequently Asked Questions
-
-### What is the Elastic UI Framework?
-
-The Elastic UI Framework (EUI) is a design library in use at Elastic to build React applications that need to share our branding and aesthetics. It distributes typed UI React components and static assets for use in building web layouts. Alongside the React components, we ship theme & style utilities that can be used independently on their own.
-
-The primary goal of this library is to provide reusable UI components that can be used throughout Elastic's web products. As React components, they remove CSS from the process of building UIs. As a single source of truth, the framework allows our designers to make changes to our aesthetic directly in the code. And unit test coverage for the UI components allows us to deliver a stable "API for user interfaces".
-
-### Can I use EUI?
-
-Please see Elastic's licensing FAQ: [I’m using EUI or Elastic Charts in my application outside of Kibana, how does this affect me?][licensing-faq]
-
-### Why is EUI open source?
-
-Many of Elastic's products are open source and rely upon this library to function. The Elastic UI Framework began as a folder of code in Kibana and we decided it could be used beyond that codebase. It exists as an independent library so that patterns can be shared across teams and design standards can be scaled across our organization. Since most of our products are open source, we treat this one similarly as far as public publishing and conversation even if its usage tends to focus more inward towards Elastic itself.
-
-### What is the versioning, release, and upgrade strategy?
-
-We use [semver](https://semver.org/) for versioning and use that to denote breaking changes in EUI upgrades. Traditionally we consider API changes in our prop names or existing component functionality to be a reason for a breaking change, but do not track the renaming of CSS selectors, mixins or other style changes under this same rigor.
-
-Traditionally releases are made weekly against whatever is in the `main` branch and you can upgrade from NPM as you see fit.
-
-### Can I contribute to EUI?
-
-Yes! We welcome community-contributed PRs, especially around feature requests that the EUI team may not have bandwidth to carry out alone. You can find documentation around creating and submitting new components in [our wiki](wiki/contributing-to-eui/).
-
-### What about reporting bugs and feature requests?
-
-Bug reports and feature requests are most welcome, but our roadmap and prioritization are driven primarily by [internal Elastic usage](wiki/contributing-to-eui#how-we-assign-work-and-define-our-roadmap).
-
-Please note that in order to keep our backlog manageable and focused on tasks we intend to complete, feature requests & tech debt issues that are inactive for a year will be auto-closed (bugs will remain open if determined to be reproducible and valid).
-
-This activity counter can be soft reset by commenting on the issue directly, but please do so mindfully. We would ask that you proactively let the EUI team know why this request matters to you or how it impacts you or your users, in order to help us prioritize accordingly.
-
-The EUI team, like everyone else, has a finite amount of time and resources, and it is not humanly possible for us to implement every task or feature requested of us. However, that's where the beauty of open source comes in - if your request is important to you, we strongly encourage you to [contribute code directly to EUI](wiki/contributing-to-eui/) that addresses your issue or request!
-
-
-### What is the status of EUI's theming?
-
-The EUI library was previously built upon Sass and is in the process of migrating to CSS-in-JS (specifically [Emotion](https://emotion.sh)). While this work is in progress, we ask for your patience with our in-between state in areas such as documentation and setup.
-
-If you're a Kibana developer with questions around CSS-in-JS usage in Kibana, please check out our [FAQ discussion](https://github.com/elastic/eui/discussions/6828)!
-
-## Wiki
-
-Our wiki docs contain instructions and guidelines on multiple areas of EUI usage and development that are too detailed for an initial README. For more information, see:
-
-- [Consuming EUI](wiki/consuming-eui)
-- [Contributing to EUI](wiki/contributing-to-eui/)
-- [Running EUI locally](wiki/contributing-to-eui/running-eui-locally.md)
-
-## License
-
-[Dual-licensed under Elastic v2 and Server Side Public License, v1][license]. See Elastic's [licensing FAQ][licensing-faq] for details.
-
-[license]: LICENSE.txt
-[licensing-faq]: https://www.elastic.co/pricing/faq/licensing#im-using-eui-or-elastic-charts-in-my-application-outside-of-kibana-how-does-this-affect-me
-[docs]: https://elastic.github.io/eui/
+## See [the top-level repo README](../../#readme) and [wiki](../../wiki) for more information on consuming and contributing to EUI.
diff --git a/packages/eui/src-docs/src/components/codesandbox/link.js b/packages/eui/src-docs/src/components/codesandbox/link.js
index 214a8aae8de..4ed303ea954 100644
--- a/packages/eui/src-docs/src/components/codesandbox/link.js
+++ b/packages/eui/src-docs/src/components/codesandbox/link.js
@@ -1,13 +1,12 @@
import React from 'react';
import { getParameters } from 'codesandbox/lib/api/define';
+import { useEuiTheme } from '../../../../src/services';
import {
cleanEuiImports,
hasDisplayToggles,
listExtraDeps,
} from '../../services';
-import { ThemeContext } from '../with_theme';
-
const pkg = require('../../../../package.json');
const getVersion = (packageName) => {
@@ -33,39 +32,14 @@ const getVersion = (packageName) => {
const displayTogglesRawCode =
require('!!raw-loader!../../views/form_controls/display_toggles').default;
-export const CodeSandboxLink = ({ ...rest }) => {
- return (
-
- {(context) => }
-
- );
-};
-
/* 1 */
-export const CodeSandboxLinkComponent = ({
+export const CodeSandboxLink = ({
children,
className,
content,
type = 'js',
- context,
}) => {
- const isDarkMode = context.theme.includes('dark');
- const colorMode = isDarkMode ? 'dark' : 'light';
-
- const cssFile = `@elastic/eui/dist/eui_theme_${colorMode}.css`;
-
- const providerPropsObject = {};
- // Only add configuration if it isn't the default
- if (isDarkMode) {
- providerPropsObject.colorMode = 'dark';
- }
- // Can't spread an object inside of a string literal
- const providerProps = Object.keys(providerPropsObject)
- .map((prop) => {
- const value = providerPropsObject[prop];
- return value !== null ? `${prop}="${value}"` : `${prop}={${value}}`;
- })
- .join(' ');
+ const { colorMode } = useEuiTheme();
let demoContent;
@@ -165,8 +139,7 @@ import '@elastic/charts/dist/theme_only_${colorMode}.css';`
content: demoContent,
},
'index.js': {
- content: `import '${cssFile}';
-import React from 'react';
+ content: `import React from 'react';
import { createRoot } from 'react-dom/client';
import createCache from '@emotion/cache';
import { EuiProvider, euiStylisPrefixer } from '@elastic/eui';
@@ -182,7 +155,7 @@ cache.compat = true;
const root = createRoot(document.getElementById('root'));
root.render(
-
+
);`,
diff --git a/packages/eui/src-docs/src/components/guide_tabbed_page/guide_tabbed_page.tsx b/packages/eui/src-docs/src/components/guide_tabbed_page/guide_tabbed_page.tsx
index 576de96f5dd..78116df1354 100644
--- a/packages/eui/src-docs/src/components/guide_tabbed_page/guide_tabbed_page.tsx
+++ b/packages/eui/src-docs/src/components/guide_tabbed_page/guide_tabbed_page.tsx
@@ -62,16 +62,15 @@ export const GuideTabbedPage: FunctionComponent = ({
const currentLanguage = themeContext.themeLanguage;
const showSass = currentLanguage.includes('sass');
- const headerBadge =
- isBeta || (showThemeLanguageToggle && !showSass) ? (
-
- ) : isNew ? (
-
- ) : undefined;
+ const headerBadge = isBeta ? (
+
+ ) : isNew ? (
+
+ ) : undefined;
let tabs:
| Array<{
@@ -190,7 +189,7 @@ export const GuideTabbedPage: FunctionComponent = ({
};
const renderNotice = () => {
- if (!showSass && notice) {
+ if (showSass && notice) {
return (
+ EUI uses CSS-in-JS (specifically{' '}
+
+ Emotion
+
+ ) for its styles and theming. As such, we require an{' '}
+ {''} wrapper around your application
+ in order for various theme-related UI & UX (such as dark/light mode
+ switching) to work as expected.
+
- While EUI is in the process of converting from a Sass based theme to
- CSS-in-JS via Emotion. We require that both the{' '}
-
- EuiProvider
- {' '}
- and the compiled CSS (or raw Sass) files be imported
- during this transition.
-
-
-
-
-
-
-
- EUI provides a general context provider to handle global aspects like
- light and dark theme. You can import these default themes through
- their respective compiled CSS files. Use the{' '}
- .min.css file extension for the minified version.
-
-
-
-
- {appSetup}
+
- For the dark theme, you can swap the words light{' '}
- for dark.
For more configuration options of the provider, see the{' '}
- EuiProvider documentation.
+
+ EuiProvider documentation
+
+ .
-
- Keep an eye out for this language selector that will allow you
- to view the syntax for either the Sass or CSS-in-JS (Emotion)
- theming mechanisms.
-
-
-
-
-
-
-
-
-
-
- {showSass ? (
- <>
-
-
-
- This will require style, css, postcss, and sass loaders and a
- full re-compile of all EUI component styles.
-
-
-
-
-
-
- >
- ) : (
- <>
-
-
-
- You can pass along a full or partial list of global{' '}
- overrides to the{' '}
-
- EuiProvider
- {' '}
- which will update the EUI components that are currently using
- the Emotion method of theming.
-
-
- Keep an eye out for this language selector that will allow you
- to view the syntax for either the Sass or CSS-in-JS (Emotion)
- theming mechanisms.
-
-
-
-
-
-
-
-
-
-
- {showSass ? (
- <>
-
-
-
This will require style, css, postcss, and sass loaders.
-
-
-
-
-
- >
- ) : (
- <>
-
-
-
- As long as you have wrapped your application with{' '}
-
- EuiProvider
-
- , you have access to the JS theme tokens via{' '}
- useEuiTheme() and Emotion's{' '}
- css prop.
-
- To build your custom components using EUI theme variables,
- functions, and mixins, you will need to consume them through one
- of the Sass,{' '}
- Emotion, or{' '}
-
- JSON import
- {' '}
- methods.
+ You can build custom components using EUI's theme tokens, consumed
+ via useEuiTheme(). The below example uses
+ Emotion's css prop, but any CSS-in-JS library
+ should be able to interpolate the JS variables.
+
+
+ For more ways to consume EUI's theme, see the{' '}
+
+ EuiThemeProvider documentation
+
+ .
-
+
+
+
-
Customizing the style tokens
+
Customizing with classes
- EUI can be slightly customized to fit your branding needs by
- altering the base tokens like color and typography. Simply declare
- your token overrides before importing the whole EUI theme. This
- will re-compile all of the EUI components with your colors.
+ For consumers using vanilla or preprocessed CSS, all components
+ allow you to pass a custom className prop,
+ which will be appended onto the component.
+
+ Avoid overwriting .eui class names
+ >
+ }
+ >
+ EUI's class names are not a guaranteed API and are prone to
+ change, which will risk breaking your theme. Target your custom
+ classNames instead.
+
+
- For a full list of global tokens visit{' '}
- Customizing theme.
+ While EUI's styles are generally low in{' '}
+
+ specificity
+ {' '}
+ due to our usage of CSS-in-JS, you may need to ensure that your
+ CSS is defined after ours in your {''}.{' '}
+ See{' '}
+
+ EuiProvider's cache customization
+ {' '}
+ for more style injection options.
If you provide both, it will duplicate the imported styles.
-
Touch the least amount of variables possible.
+
Customizing the style tokens
- By nature EUI is very rigid. You shouldn't need much to make
+ EUI can be slightly customized to fit your branding needs by
+ altering the base tokens like color and typography. You can pass a
+ full or partial list of override tokens to the{' '}
+ EuiProvider's modify prop.
+
+
+ By nature, EUI is very rigid. You shouldn't need much to make
drastic changes to color. Most themes are less then a dozen
variable overwrites in total.
-
-
- Do not overwrite individual component variables or{' '}
- .eui class names.
-
+
+
- Although this may be possible, components are much more prone to
- change and you'll risk breaking your theme. All EUI
- components accept custom a className which you
- can use to append your custom styles.
+ For a full list of global tokens, visit{' '}
+ Customizing themes.
+ For more examples of the modify prop, see the{' '}
+
+ EuiThemeProvider docs
+
+ .
- We do not recommend customizing EUI components by applying styles
- directly to EUI classes, eg. .euiButton. All
- components allow you to pass a custom className{' '}
- prop directly to the component which will then append this to the
- class list. Utilizing the cascade feature of CSS, you can then
- customize by overriding styles so long as your styles are imported{' '}
- after the EUI import.
-
- EUI is transitioning to a CSS-in-JS solution for theming and requires
- consuming/customizing global variables in{' '}
- both the Sass and CSS-in-JS methods. To track this
- effort, subscribe to the{' '}
-
- Meta ticket
-
- .
-
+ EUI is transitioning to a CSS-in-JS solution for theming, and will
+ eventually deprecate all exported Sass variables and mixins. We strongly
+ recommend moving your usages of Sass to{' '}
+
+ Emotion
+ {' '}
+ or other CSS-in-JS solutions. To track this migration, subscribe to the{' '}
+
+ Meta ticket
+
+ .
+
+
+);
diff --git a/packages/eui/src-docs/src/views/theme/borders/borders.tsx b/packages/eui/src-docs/src/views/theme/borders/borders.tsx
index 70866f0fbde..cf0ccca8e82 100644
--- a/packages/eui/src-docs/src/views/theme/borders/borders.tsx
+++ b/packages/eui/src-docs/src/views/theme/borders/borders.tsx
@@ -90,7 +90,6 @@ export default () => {
return (
}
description="The border tokens contain both individual border property values and full shorthand border properties."
showThemeLanguageToggle
diff --git a/packages/eui/src-docs/src/views/theme/consuming.tsx b/packages/eui/src-docs/src/views/theme/consuming.tsx
index 44bb1cd7971..82e3e440ab3 100644
--- a/packages/eui/src-docs/src/views/theme/consuming.tsx
+++ b/packages/eui/src-docs/src/views/theme/consuming.tsx
@@ -22,8 +22,8 @@ export default () => {
`}
>
The padding of this box is created using calc(){' '}
- because EUI's theme sizes are string pixel values that are
- calculated off the theme's base
+ because EUI's theme sizes are string pixel values that are calculated
+ off the theme's base
);
diff --git a/packages/eui/src-docs/src/views/theme/customizing/_sass.tsx b/packages/eui/src-docs/src/views/theme/customizing/_sass.tsx
index 16000573b1a..0f37fa70558 100644
--- a/packages/eui/src-docs/src/views/theme/customizing/_sass.tsx
+++ b/packages/eui/src-docs/src/views/theme/customizing/_sass.tsx
@@ -1,9 +1,13 @@
import React from 'react';
-import { EuiSpacer, EuiText } from '../../../../../src';
-
-import { CustomizeTokens } from '../../guidelines/getting_started/_customizing';
+import {
+ EuiSpacer,
+ EuiText,
+ EuiCodeBlock,
+ useEuiTheme,
+} from '../../../../../src';
export default () => {
+ const { colorMode } = useEuiTheme();
return (
<>
@@ -20,7 +24,20 @@ export default () => {
-
+
+
+ {`// mytheme.scss
+$euiColorPrimary: #7B61FF;
+
+// The following rebuilds the entire EUI component styles
+${
+ colorMode === 'DARK'
+ ? "@import '@elastic/eui/src/themes/amsterdam/theme_dark';"
+ : "@import '@elastic/eui/src/themes/amsterdam/theme_light';"
+}
+
+@import 'your/custom/styles';`}
+
>
);
};
diff --git a/packages/eui/src-docs/src/views/theme/customizing/values.tsx b/packages/eui/src-docs/src/views/theme/customizing/values.tsx
index e9980cd6d28..dacec14139b 100644
--- a/packages/eui/src-docs/src/views/theme/customizing/values.tsx
+++ b/packages/eui/src-docs/src/views/theme/customizing/values.tsx
@@ -81,7 +81,6 @@ export default () => {
return (
}
showThemeLanguageToggle
diff --git a/packages/eui/src-docs/src/views/theme/other/other.tsx b/packages/eui/src-docs/src/views/theme/other/other.tsx
index 9dfe253df29..68202c35c23 100644
--- a/packages/eui/src-docs/src/views/theme/other/other.tsx
+++ b/packages/eui/src-docs/src/views/theme/other/other.tsx
@@ -121,7 +121,6 @@ export default () => {
return (
}
showThemeLanguageToggle
description="Here are a few more global theme tokens for styles we use throughout EUI."
diff --git a/packages/website/docs/01_guidelines/getting_started.mdx b/packages/website/docs/01_guidelines/getting_started.mdx
index 75caebef0d6..6175877fd4e 100644
--- a/packages/website/docs/01_guidelines/getting_started.mdx
+++ b/packages/website/docs/01_guidelines/getting_started.mdx
@@ -44,24 +44,15 @@ You can read more about other ways to consume EUI in our wiki.
## Setting up your application
-:::warning
-While EUI is in the process of converting from a Sass based theme to CSS-in-JS via Emotion. We require that both
-the [EuiProvider](https://eui.elastic.co/#/utilities/provider) **and** the compiled CSS (or raw Sass) files be imported
-during this transition.
-:::
-
-
-EUI provides a general context provider to handle global aspects like light and dark theme. You can import these
-default themes through their respective compiled CSS files. Use the `.min.css` file extension for the minified version.
+EUI uses CSS-in-JS (specifically [Emotion](https://emotion.sh)) for its styles and theming. As such, we require an `` wrapper around your application in order for various theme-related UI & UX (such as dark/light mode switching) to work as expected.
```jsx
import React from 'react';
-import '@elastic/eui/dist/eui_theme_light.css';
import { EuiProvider, EuiText } from '@elastic/eui';
const MyApp = () => (
-
+
Hello World!
);
@@ -69,142 +60,123 @@ const MyApp = () => (
export default MyApp;
```
-For the dark theme, you can swap the words `light` for `dark`.
For more configuration options of the provider, see the
-[EuiProvider documentation](https://eui.elastic.co/#/utilities/provider).
+[**EuiProvider** documentation](https://eui.elastic.co/#/utilities/provider).
## Styling your application
-To build your custom components using EUI theme variables, functions, and mixins, you will need to consume them
-through one of the [Sass](https://eui.elastic.co/#/theming/sass),
-[Emotion](https://eui.elastic.co/#/theming/theme-provider),
-or [JSON import](https://github.com/elastic/eui/blob/main/wiki/consuming-eui/README.md#a-not-recommended-legacy-method-to-consume-theming-variables-from-sass) methods.
-
-
-
- ```scss title="This will require style, css, postcss, and sass loaders."
- // index.scss
- @import '@elastic/eui/src/themes/amsterdam/colors_light';
- @import '@elastic/eui/src/themes/amsterdam/globals';
+You can build custom components using EUI's theme tokens, consumed via `useEuiTheme()`. The below example uses Emotion's `css` prop, but any CSS-in-JS library should be able to interpolate the JS variables.
- @import 'your/custom/styles';
- ```
-
-
- ```jsx title="As long as you have wrapped your application with EuiProvider, you have access to the JS theme tokens via useEuiTheme() and Emotion's css prop."
- import React from 'react';
- import { EuiIcon, EuiCode, EuiText, useEuiTheme } from '@elastic/eui';
- import { css } from '@emotion/react';
-
- export default () => {
- const { euiTheme } = useEuiTheme();
- return (
-
-
- {' '}
- This primary color will adjust based on the light or dark theme value
-
-
-
- The padding of this box is created using calc(){' '}
- because EUI's theme sizes are string pixel values that are
- calculated off the theme's base
-
-
- );
- };
- ```
-
-
+For more ways to consume EUI's theme, see the [**EuiThemeProvider** documentation](https://eui.elastic.co/#/theming/theme-provider#consuming-with-the-react-hook).
-### Customizing the style tokens
+```jsx
+import React from 'react';
+import { EuiIcon, EuiCode, EuiText, useEuiTheme } from '@elastic/eui';
+import { css } from '@emotion/react';
+
+export default () => {
+ const { euiTheme } = useEuiTheme();
+ return (
+
+
+ {' '}
+ This primary color will adjust based on the light or dark theme value
+
+
+
+ The padding of this box is created using calc(){' '}
+ because EUI's theme sizes are string pixel values that are
+ calculated off the theme's base
+
+
+ );
+};
+```
-EUI can be slightly customized to fit your branding needs by altering the base tokens like color and typography.
-Simply declare your token overrides before importing the whole EUI theme. This will re-compile
-all of the EUI components with your colors.
+### Customizing with classes
-For a full list of global tokens visit Customizing theme.
+For consumers using vanilla or preprocessed CSS, all components allow you to pass a custom `className` prop, which will be appended onto the component.
-:::warning Partial component support
-EUI is transitioning to a CSS-in-JS solution for theming and requires consuming/customizing global variables
-in **both the Sass and CSS-in-JS** methods. To track this effort,
-subscribe to the [Meta ticket](https://github.com/elastic/eui/issues/3912).
+:::warning Avoid overwriting `.eui` class names
+EUI's class names are not a guaranteed API and are prone to change, which will risk breaking your theme. Target your custom classNames instead.
:::
-
-
- ```scss title="This will require style, css, postcss, and sass loaders and a full re-compile of all EUI component styles."
- $euiColorPrimary: #7B61FF;
-
- // The following rebuilds the entire EUI component styles
- @import '@elastic/eui/src/themes/amsterdam/theme_light';
-
- @import 'your/custom/styles';
- ```
-
-
- ```jsx title="You can pass along a full or partial list of global overrides to the EuiProvider which will update the EUI components that are currently using the Emotion method of theming."
- import React, { FunctionComponent, ReactNode } from 'react';
- import { EuiCode, EuiText, EuiThemeProvider, useEuiTheme } from '@elastic/eui';
-
- const Box: FunctionComponent<{ children: ReactNode }> = ({ children }) => {
- const { euiTheme } = useEuiTheme();
-
- return (
-
-
-
-
- The background of this box is using the locally overridden value of{' '}
- euiTheme.colors.lightShade
-
-
-
- );
- };
- ```
-
-
+While EUI's styles are generally low in [specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity) due to our usage of CSS-in-JS, you may need to ensure that your CSS is defined after ours in your ``. See [EuiProvider's cache customization](https://eui.elastic.co/#/utilities/provider#cache-customization) for more style injection options.
-#### Do not use in conjunction with the compiled CSS.
+```jsx
+import React from 'react';
+import { EuiButton } from '@elastic/eui';
+
+const myCustomCSS = `
+ .myCustomButton {
+ background-color: pink;
+ }
+`;
+
+export default () => (
+ <>
+
+ Hello world!
+ >
+);
+```
-If you provide both, it will duplicate the imported styles.
+### Customizing the style tokens
-#### Touch the least amount of variables possible.
+EUI can be slightly customized to fit your branding needs by altering the base tokens like color and typography. You can pass a full or partial list of override tokens to the **EuiProvider**'s `modify` prop.
-By nature EUI is very rigid. You shouldn't need much to make drastic changes to color. Most themes are less then a dozen variable overwrites in total.
+:::warning Touch the least amount of variables possible
+By nature, EUI is very rigid. You shouldn't need much to make drastic changes to color. Most themes are less then a dozen variable overwrites in total.
+:::
-#### Do not overwrite individual component variables or .eui class names.
+For a full list of global tokens visit [Customizing themes](https://eui.elastic.co/#/theming/customizing-themes). For more examples of the modify prop, see the [**EuiThemeProvider** docs](https://eui.elastic.co/#/theming/theme-provider#simple-instance-overrides).
-Although this may be possible, components are much more prone to change and you'll risk breaking your theme. All EUI components accept custom a className which you can use to append your custom styles.
+```jsx
+import React, { FunctionComponent, ReactNode } from 'react';
+import { EuiCode, EuiText, EuiThemeProvider, useEuiTheme } from '@elastic/eui';
+
+const Box: FunctionComponent<{ children: ReactNode }> = ({ children }) => {
+ const { euiTheme } = useEuiTheme();
+
+ return (
+
+
{children}
+
+ );
+};
+
+export default () => {
+ const overrides = {
+ colors: {
+ LIGHT: { lightShade: '#d3e6df' },
+ DARK: { lightShade: '#394c4b' },
+ },
+ };
+
+ return (
+
+
+ The background of this box is using the locally overridden value of{' '}
+ euiTheme.colors.lightShade
+
+
+ );
+};
+```
## Fonts
@@ -273,23 +245,6 @@ import { findTestSubject } from '@elastic/eui/lib/test'; // Enzyme
import { findByTestSubject, render, screen } from '@elastic/eui/lib/test/rtl'; // React Testing Library
```
-## Customizing with classes
-
-We do not recommend customizing EUI components by applying styles directly to EUI classes, eg. `.euiButton`.
-All components allow you to pass a custom `className` prop directly to the component which will then append this
-to the class list. Utilizing the cascade feature of CSS, you can then customize by overriding styles
-so long as your styles are imported `after` the EUI import.
-
-```jsx
-
-```
-
-Renders as:
-
-```jsx
-
-```
-
## Customizing component defaults
While all props can be individually customized via props, some components can have their default props customized
diff --git a/wiki/consuming-eui/README.md b/wiki/consuming-eui/README.md
index 9e0e275a97d..a9322741e24 100644
--- a/wiki/consuming-eui/README.md
+++ b/wiki/consuming-eui/README.md
@@ -51,16 +51,15 @@ import { findByTestSubject, render, screen } from '@elastic/eui/lib/test/rtl'; /
### Theming
-As of April 2022 EUI is in the process of [migrating to Emotion JS for the CSS and theming layer](https://github.com/elastic/eui/issues/3912). While EUI is in the process of this conversion, we require that both the EuiProvider and the compiled CSS (or raw Sass) files be imported during this transition.
+EUI uses CSS-in-JS (specifically [Emotion](https://emotion.sh)) for its styles and theming. As such, we require an `` wrapper around your application in order for various theme-related UI & UX (such as dark/light mode switching) to work as expected.
```jsx
import React from 'react';
-import '@elastic/eui/dist/eui_theme_light.css';
import { EuiProvider, EuiText } from '@elastic/eui';
const MyApp = () => (
-
+
Hello World!
);
@@ -68,7 +67,7 @@ const MyApp = () => (
export default MyApp;
```
-#### The recommended method to consume theming variables using Emotion
+#### Consuming theme tokens
Using EUI's theme layer with Emotion is [documented in our docs](https://elastic.github.io/eui/#/theming/theme-provider) and should cover the majority of your theming needs.
@@ -88,25 +87,6 @@ export default () => {
);
};
```
-#### A not-recommended, legacy method to consume theming variables from Sass
-
-Until the conversion is complete, the components you consume may still contain soon-to-be-removed Sass styling. EUI's distribution also provides both a light and dark JSON token file that exposes these Sass variables (through an automatic process derived from the Sass) to make tokens from the individual Sass components available to consume if you need them. As components continue to convert to Emotion, these Sass-to-JS tokens in these files will degrade, eventually disappearing altogether. We therefore recommend not relying on the JSON dist of these tokens, and instead using the above recommended Emotion approach.
-
-The following is provided as an example of the soon-to-be-deprecated Sass theme variables, to aid consumers in converting legacy usage.
-
-```jsx
-import * as euiVars from '@elastic/eui/dist/eui_theme_light.json';
-
-const styles = {
- color: euiVars.euiColorPrimary,
- border: euiVars.euiBorderThin
- padding: euiVars.euiPanelPaddingModifiers.paddingSmall
-};
-
-export default () => (
-
-)
-```
### "Module build failed" or "Module parse failed: Unexpected token" error