Skip to content
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

[EuiProvider] Detect OS/system light vs darkmode as a default #8026

Merged
merged 10 commits into from
Sep 23, 2024
13 changes: 3 additions & 10 deletions packages/eui/src-docs/src/views/avatar/avatar_icon.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import React, { useContext } from 'react';
import { ThemeContext } from '../../components';

import { EuiAvatar, EuiSpacer, EuiTitle } from '../../../../src/components';
import React from 'react';
import { EuiAvatar, EuiSpacer, EuiTitle, useEuiTheme } from '../../../../src';

export default () => {
const themeContext = useContext(ThemeContext);

/**
* Setup theme based on current light/dark theme
*/
const isDarkTheme = themeContext.theme.includes('dark');
const isDarkTheme = useEuiTheme().colorMode === 'DARK';

return (
<div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect, useContext } from 'react';
import React, { useState, useEffect } from 'react';
import reactElementToJSXString from 'react-element-to-jsx-string';
import classNames from 'classnames';
import {
Expand All @@ -20,8 +20,8 @@ import {
EuiDescriptionListDescription,
EuiLoadingSpinner,
useIsWithinBreakpoints,
useEuiTheme,
} from '../../../../src';
import { ThemeContext } from '../../components/with_theme';
import { typesOfPanelColors } from './_types_of_panel_colors';
// @ts-ignore Importing from JS file
import { typesOfUseCases } from './_types_of_use_cases';
Expand All @@ -43,12 +43,7 @@ import singleSvg from '../../images/single.svg';
import contentCenterSvg from '../../images/content_center.svg';

export default () => {
const themeContext = useContext(ThemeContext);

/**
* Setup theme based on current light/dark theme
*/
const isDarkTheme = themeContext.theme.includes('dark');
const isDarkTheme = useEuiTheme().colorMode === 'DARK';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay for being able to reuse things! 👏


const useCasesOptions: EuiRadioGroupOption[] = Object.values(
typesOfUseCases
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import React, { useContext } from 'react';
import React from 'react';
import {
EuiEmptyPrompt,
EuiImage,
EuiButton,
EuiButtonEmpty,
} from '../../../../../src/components';
import { ThemeContext } from '../../../components/with_theme';
useEuiTheme,
} from '../../../../../src';
import pageNotFoundLight from '../../../images/empty-prompt/accessDenied--light.png';
import pageNotFoundDark from '../../../images/empty-prompt/accessDenied--dark.png';

export default () => {
const themeContext = useContext(ThemeContext);
const isDarkTheme = themeContext.theme.includes('dark');
const isDarkTheme = useEuiTheme().colorMode === 'DARK';

const iconImg: string = isDarkTheme ? pageNotFoundDark : pageNotFoundLight;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import React, { useContext } from 'react';
import React from 'react';
import {
EuiEmptyPrompt,
EuiImage,
EuiButton,
EuiButtonEmpty,
} from '../../../../../src/components';
import { ThemeContext } from '../../../components/with_theme';
useEuiTheme,
} from '../../../../../src';

import pageNotFoundDark from '../../../images/empty-prompt/pageNotFound--dark.png';
import pageNotFoundLight from '../../../images/empty-prompt/pageNotFound--light.png';
import pageNotFoundDark2x from '../../../images/empty-prompt/pageNotFound--dark@2x.png';
import pageNotFoundLight2x from '../../../images/empty-prompt/pageNotFound--light@2x.png';

export default () => {
const themeContext = useContext(ThemeContext);
const isDarkTheme = themeContext.theme.includes('dark');
const isDarkTheme = useEuiTheme().colorMode === 'DARK';

const pageNotFound = isDarkTheme ? pageNotFoundDark : pageNotFoundLight;
const pageNotFound2x = isDarkTheme ? pageNotFoundDark2x : pageNotFoundLight2x;
Expand Down
18 changes: 9 additions & 9 deletions packages/eui/src-docs/src/views/home/home_illustration.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import React, { useContext } from 'react';
import { ThemeContext } from '../../components/with_theme';
import React from 'react';
import illustrationDarkMode from '../../images/illustration-eui-hero-500-darkmode-shadow.svg';
import illustrationLightMode from '../../images/illustration-eui-hero-500-shadow.svg';
import { EuiImage } from '../../../../src/components/image';
import { EuiImage, useEuiTheme } from '../../../../src';

function Icon() {
const themeContext: any = useContext(ThemeContext);
const { colorMode } = useEuiTheme();

const illustration = themeContext.theme.includes('dark') ? (
<EuiImage alt="Elastic UI" url={illustrationDarkMode} />
) : (
<EuiImage alt="Elastic UI" url={illustrationLightMode} />
);
const illustration =
colorMode === 'DARK' ? (
<EuiImage alt="Elastic UI" url={illustrationDarkMode} />
) : (
<EuiImage alt="Elastic UI" url={illustrationLightMode} />
);

return (
<div className="guideHomePage__illustration">
Expand Down