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

[DON NOT MERGE] Semantic color tokens testing branch #8083

Draft
wants to merge 43 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
9645c1f
fix: ensure getComputed resolves Computed objects correctly
mgadewoll Sep 18, 2024
30b13be
feat: setup new theme package
mgadewoll Sep 18, 2024
777f613
feat: add experimental flag
mgadewoll Sep 19, 2024
fcab2ec
feat: add theme switcher to Storybook
mgadewoll Sep 19, 2024
3aab917
feat: udpate theme switcher to eui docs
mgadewoll Sep 19, 2024
75d91cf
build: use workspace reference for EUI dependency
mgadewoll Sep 19, 2024
b2dfbd9
feat: add theme switcher to eui+ docs
mgadewoll Sep 19, 2024
70dfd30
build: add eui-common internal module package
mgadewoll Sep 22, 2024
7ad01e4
build: add eui-theme-base internal module package
mgadewoll Sep 22, 2024
bd6fd9c
refactor: use new module packages in eui package
mgadewoll Sep 22, 2024
8f8bcc7
refactor: use eui-theme-base package in eui-theme-berlin
mgadewoll Sep 22, 2024
33fc2e4
build: prevent generating i18ntokens.json when running build locally
mgadewoll Sep 22, 2024
c288542
build: add esm and cjs export for common module
mgadewoll Sep 23, 2024
96d21b3
build: add esm and cjs export for theme-base module
mgadewoll Sep 23, 2024
f53c887
build: add script for building workspace dependencies
mgadewoll Sep 23, 2024
0c89f09
refactor: update sass imports
mgadewoll Sep 23, 2024
3a22ecf
build: update dependencies
mgadewoll Sep 23, 2024
b46479e
build: update new_docs and release scripts
mgadewoll Sep 23, 2024
d394f47
refactor: rename script
mgadewoll Sep 26, 2024
1092c59
build: add build:workspaces script on pre-push hook
mgadewoll Sep 26, 2024
2d34eef
refactor: separate out scss files and resolve circular scss dependency
mgadewoll Sep 26, 2024
0d3ee58
build: ensure common scss is part of package
mgadewoll Sep 30, 2024
3305295
chore: rebase cleanup
mgadewoll Sep 30, 2024
710ee70
refactor: rename theme
mgadewoll Oct 2, 2024
4b3c631
add eui-theme-common package
mgadewoll Oct 8, 2024
f99ad77
-remove eui-common package
mgadewoll Oct 8, 2024
7513fff
chore: add min. README
mgadewoll Oct 8, 2024
1d6b352
build: add pre-push scripts
mgadewoll Oct 8, 2024
a6eba42
build: update workspaces script to ensure theme-common builds first
mgadewoll Oct 8, 2024
7b03a10
feat: add primitive and first level semantic color tokens
mgadewoll Oct 9, 2024
5ad9c24
feat: add background and border tokens
mgadewoll Oct 14, 2024
f532c9f
feat: add util for retrieving a token name based on a dynamic variant
mgadewoll Oct 14, 2024
24db4d5
refactor: update EUI background color usages
mgadewoll Oct 14, 2024
df53246
refactor: update EUI+ background token usages
mgadewoll Oct 14, 2024
8e1777d
refactor: update background color usage in EUI docs
mgadewoll Oct 14, 2024
11949ce
refactor: return tokens from mixins and add deprecations
mgadewoll Oct 16, 2024
ee2694d
refactor: update sass variables and add background sass vars
mgadewoll Oct 16, 2024
d79c40d
feat: add new base border value
mgadewoll Oct 16, 2024
1b49a84
refactor: update border mixin usages
mgadewoll Oct 16, 2024
49141ae
feat: update primitive token values
mgadewoll Oct 16, 2024
0164c95
reafactor: move button mixin file
mgadewoll Oct 17, 2024
069d97a
refactor: update paths
mgadewoll Oct 17, 2024
a739f69
refactor: update token mappings and usages
mgadewoll Oct 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .buildkite/scripts/pipelines/pipeline_deploy_new_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ analytics_vault="secret/ci/elastic-eui/analytics"
export DOCS_BASE_URL="/${bucket_directory}"
export DOCS_GOOGLE_TAG_MANAGER_ID="$(retry 5 vault read -field=google_tag_manager_id "${analytics_vault}")"

yarn workspaces foreach -Rpt --from @elastic/eui-website run build
yarn workspace @elastic/eui-website run build:workspaces

echo "+++ Configuring environment for website deployment"

Expand Down
18 changes: 9 additions & 9 deletions .buildkite/scripts/pipelines/pipeline_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,53 +29,53 @@ COMMAND=""
case $TEST_TYPE in
lint)
echo "[TASK]: Running linters"
COMMAND="/opt/yarn*/bin/yarn --cwd packages/eui && yarn --cwd packages/eui lint"
COMMAND="/opt/yarn*/bin/yarn --cwd packages/eui && yarn --cwd packages/eui build:workspaces && yarn --cwd packages/eui lint"
;;

unit:ts)
echo "[TASK]: Running .ts and .js unit tests"
COMMAND="/opt/yarn*/bin/yarn --cwd packages/eui && yarn --cwd packages/eui test-unit --node-options=--max_old_space_size=2048 --testMatch=non-react"
COMMAND="/opt/yarn*/bin/yarn --cwd packages/eui && yarn --cwd packages/eui build:workspaces && yarn --cwd packages/eui test-unit --node-options=--max_old_space_size=2048 --testMatch=non-react"
;;

unit:tsx:16)
echo "[TASK]: Running Jest .tsx tests against React 16"
DOCKER_OPTIONS+=(--env BUILDKITE_ANALYTICS_TOKEN="$(retry 5 vault read -field=jest_token_react16 "${buildkite_analytics_vault}")")
COMMAND="/opt/yarn*/bin/yarn --cwd packages/eui && yarn --cwd packages/eui test-unit --node-options=--max_old_space_size=2048 --react-version=16 --testMatch=react"
COMMAND="/opt/yarn*/bin/yarn --cwd packages/eui && yarn --cwd packages/eui build:workspaces && yarn --cwd packages/eui test-unit --node-options=--max_old_space_size=2048 --react-version=16 --testMatch=react"
;;

unit:tsx:17)
echo "[TASK]: Running Jest .tsx tests against React 17"
DOCKER_OPTIONS+=(--env BUILDKITE_ANALYTICS_TOKEN="$(retry 5 vault read -field=jest_token_react17 "${buildkite_analytics_vault}")")
COMMAND="/opt/yarn*/bin/yarn --cwd packages/eui && yarn --cwd packages/eui test-unit --node-options=--max_old_space_size=2048 --react-version=17 --testMatch=react"
COMMAND="/opt/yarn*/bin/yarn --cwd packages/eui && yarn --cwd packages/eui build:workspaces && yarn --cwd packages/eui test-unit --node-options=--max_old_space_size=2048 --react-version=17 --testMatch=react"
;;

unit:tsx)
echo "[TASK]: Running Jest .tsx tests against React 18"
DOCKER_OPTIONS+=(--env BUILDKITE_ANALYTICS_TOKEN="$(retry 5 vault read -field=jest_token_react18 "${buildkite_analytics_vault}")")
COMMAND="/opt/yarn*/bin/yarn --cwd packages/eui && yarn --cwd packages/eui test-unit --node-options=--max_old_space_size=2048 --testMatch=react"
COMMAND="/opt/yarn*/bin/yarn --cwd packages/eui && yarn --cwd packages/eui build:workspaces && yarn --cwd packages/eui test-unit --node-options=--max_old_space_size=2048 --testMatch=react"
;;

cypress:16)
echo "[TASK]: Running Cypress tests against React 16"
DOCKER_OPTIONS+=(--env BUILDKITE_ANALYTICS_TOKEN="$(retry 5 vault read -field=cypress_token_react16 "${buildkite_analytics_vault}")")
COMMAND="/opt/yarn*/bin/yarn --cwd packages/eui && yarn --cwd packages/eui cypress install && yarn --cwd packages/eui test-cypress --node-options=--max_old_space_size=2048 --react-version=16"
COMMAND="/opt/yarn*/bin/yarn --cwd packages/eui && yarn --cwd packages/eui build:workspaces && yarn --cwd packages/eui cypress install && yarn --cwd packages/eui test-cypress --node-options=--max_old_space_size=2048 --react-version=16"
;;

cypress:17)
echo "[TASK]: Running Cypress tests against React 17"
DOCKER_OPTIONS+=(--env BUILDKITE_ANALYTICS_TOKEN="$(retry 5 vault read -field=cypress_token_react17 "${buildkite_analytics_vault}")")
COMMAND="/opt/yarn*/bin/yarn --cwd packages/eui && yarn --cwd packages/eui cypress install && yarn --cwd packages/eui test-cypress --node-options=--max_old_space_size=2048 --react-version=17"
COMMAND="/opt/yarn*/bin/yarn --cwd packages/eui && yarn --cwd packages/eui build:workspaces && yarn --cwd packages/eui cypress install && yarn --cwd packages/eui test-cypress --node-options=--max_old_space_size=2048 --react-version=17"
;;

cypress:18)
echo "[TASK]: Running Cypress tests against React 18"
DOCKER_OPTIONS+=(--env BUILDKITE_ANALYTICS_TOKEN="$(retry 5 vault read -field=cypress_token_react18 "${buildkite_analytics_vault}")")
COMMAND="/opt/yarn*/bin/yarn --cwd packages/eui && yarn --cwd packages/eui cypress install && yarn --cwd packages/eui test-cypress --node-options=--max_old_space_size=2048"
COMMAND="/opt/yarn*/bin/yarn --cwd packages/eui && yarn --cwd packages/eui build:workspaces && yarn --cwd packages/eui cypress install && yarn --cwd packages/eui test-cypress --node-options=--max_old_space_size=2048"
;;

cypress:a11y)
echo "[TASK]: Running Cypress accessibility tests against React 18"
COMMAND="/opt/yarn*/bin/yarn --cwd packages/eui && yarn --cwd packages/eui cypress install && yarn --cwd packages/eui run test-cypress-a11y --node-options=--max_old_space_size=2048"
COMMAND="/opt/yarn*/bin/yarn --cwd packages/eui && yarn --cwd packages/eui build:workspaces && yarn --cwd packages/eui cypress install && yarn --cwd packages/eui run test-cypress-a11y --node-options=--max_old_space_size=2048"
;;

*)
Expand Down
1 change: 1 addition & 0 deletions .buildkite/scripts/release/step_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ echo "+++ :yarn: Installing dependencies"
yarn

echo "+++ :yarn: Building @elastic/eui"
yarn build:workspaces
yarn build

echo "+++ :yarn: Built @elastic/eui"
3 changes: 2 additions & 1 deletion packages/docusaurus-theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
"@docusaurus/theme-common": "^3.5.2",
"@docusaurus/utils-validation": "^3.5.2",
"@elastic/datemath": "^5.0.3",
"@elastic/eui": "94.5.0",
"@elastic/eui": "workspace:^",
"@elastic/eui-docgen": "workspace:^",
"@elastic/eui-theme-borealis": "workspace:^",
"@emotion/css": "^11.11.2",
"@emotion/react": "^11.11.4",
"@types/react-window": "^1.8.8",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,24 @@ const getDemoActionsBarStyles = (euiTheme: UseEuiTheme) => {
&:last-child {
// border radius should be 1px smaller to work nicely
// with the wrapper border width of 1px
border-radius: 0 0 calc(var(--docs-demo-border-radius) - 1px) calc(var(--docs-demo-border-radius) - 1px);
border-radius: 0 0 calc(var(--docs-demo-border-radius) - 1px)
calc(var(--docs-demo-border-radius) - 1px);
}
`,
button: css`
background: var(--eui-background-color-primary-opaque);
background: var(--eui-background-color-primary);
border: 1px solid var(--eui-border-color-primary);
margin-right: auto;
`,
};
}
};

export const DemoActionsBar = ({
isSourceOpen,
setSourceOpen,
onClickOpenInCodeSandbox,
onClickReloadExample,
onClickCopyToClipboard
onClickCopyToClipboard,
}: DemoActionsBarProps) => {
const styles = useEuiMemoizedStyles(getDemoActionsBarStyles);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ export const NavbarItem = (props: Props) => {
} = props;

const isBrowser = useIsBrowser();
const { theme } = useContext(AppThemeContext);
const { colorMode } = useContext(AppThemeContext);

const isDarkMode = theme === 'dark';
const isDarkMode = colorMode === 'dark';

const styles = useEuiMemoizedStyles(getStyles);
const cssStyles = [
Expand Down
58 changes: 47 additions & 11 deletions packages/docusaurus-theme/src/components/theme_context/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,39 @@ import {
useState,
} from 'react';
import useIsBrowser from '@docusaurus/useIsBrowser';
import { EUI_THEMES, EuiProvider, EuiThemeColorMode } from '@elastic/eui';
import {
EuiProvider,
EuiThemeAmsterdam,
EuiThemeColorMode,
} from '@elastic/eui';
import { EuiThemeBorealis } from '@elastic/eui-theme-borealis';

import { EuiThemeOverrides } from './theme_overrides';

const EUI_THEME_NAMES = EUI_THEMES.map(
({ value }) => value
) as EuiThemeColorMode[];
const EXPERIMENTAL_THEMES = [
{
text: 'Borealis',
value: EuiThemeBorealis.key,
provider: EuiThemeBorealis,
},
];

export const AVAILABLE_THEMES = [
{
text: 'Amsterdam',
value: EuiThemeAmsterdam.key,
provider: EuiThemeAmsterdam,
},
...EXPERIMENTAL_THEMES,
];

const EUI_COLOR_MODES = ['light', 'dark'] as EuiThemeColorMode[];

const defaultState = {
theme: EUI_THEME_NAMES[0] as EuiThemeColorMode,
changeTheme: (themeValue: EuiThemeColorMode) => {},
colorMode: EUI_COLOR_MODES[0] as EuiThemeColorMode,
changeColorMode: (colorMode: EuiThemeColorMode) => {},
theme: AVAILABLE_THEMES[0]!,
changeTheme: (themeValue: string) => {},
};

export const AppThemeContext = createContext(defaultState);
Expand All @@ -24,25 +46,39 @@ export const AppThemeProvider: FunctionComponent<PropsWithChildren> = ({
children,
}) => {
const isBrowser = useIsBrowser();
const [theme, setTheme] = useState<EuiThemeColorMode>(() => {
const [colorMode, setColorMode] = useState<EuiThemeColorMode>(() => {
if (isBrowser) {
return localStorage.getItem('theme') as EuiThemeColorMode ?? defaultState.theme;
return (
(localStorage.getItem('theme') as EuiThemeColorMode) ??
defaultState.colorMode
);
}

return defaultState.theme;
return defaultState.colorMode;
});

const [theme, setTheme] = useState(defaultState.theme);

const handleChangeTheme = (themeValue: string) => {
const themeObj = AVAILABLE_THEMES.find((t) => t.value === themeValue);

setTheme((currentTheme) => themeObj ?? currentTheme);
};

return (
<AppThemeContext.Provider
value={{
colorMode,
theme,
changeTheme: setTheme,
changeColorMode: setColorMode,
changeTheme: handleChangeTheme,
}}
>
<EuiProvider
globalStyles={false}
modify={EuiThemeOverrides}
colorMode={theme}
colorMode={colorMode}
theme={theme.provider}
>
{children}
</EuiProvider>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { useContext, useEffect, useState } from 'react';
import { css } from '@emotion/react';
import {
EuiAvatar,
EuiButtonEmpty,
euiFocusRing,
EuiListGroup,
EuiListGroupItem,
EuiPopover,
useEuiMemoizedStyles,
useEuiTheme,
UseEuiTheme,
} from '@elastic/eui';

import { AppThemeContext, AVAILABLE_THEMES } from '../theme_context';

const getStyles = (euiThemeContext: UseEuiTheme) => {
const { euiTheme } = euiThemeContext;

return {
button: css`
padding: 0;
`,
listItem: css`
.euiListGroupItem__button:focus-visible {
// overriding the global "outset" style to ensure the focus style is not cut off
${euiFocusRing(euiThemeContext, 'inset', {
color: euiTheme.colors.primary,
})};
}
`,
};
};

export const ThemeSwitcher = () => {
const { euiTheme } = useEuiTheme();
const [currentTheme, setCurrentTheme] = useState(
AVAILABLE_THEMES[0]?.value ?? ''
);
const [isPopoverOpen, setPopoverOpen] = useState(false);
const { theme, changeTheme } = useContext(AppThemeContext);

useEffect(() => {
changeTheme(currentTheme);
}, [currentTheme]);

const styles = useEuiMemoizedStyles(getStyles);

const button = (
<EuiButtonEmpty
size="s"
color="text"
css={styles.button}
onClick={() => setPopoverOpen((isOpen) => !isOpen)}
aria-label={`${theme.text} theme`}
>
<EuiAvatar name={theme.text} size="s" color={euiTheme.colors.primary} />
</EuiButtonEmpty>
);

return (
<EuiPopover
isOpen={isPopoverOpen}
closePopover={() => setPopoverOpen(false)}
button={button}
panelPaddingSize="xs"
repositionOnScroll
aria-label="EUI theme list"
>
<EuiListGroup>
{AVAILABLE_THEMES &&
AVAILABLE_THEMES.map((theme) => {
const isCurrentTheme = currentTheme === theme.value;

const handleOnClick = () => {
setCurrentTheme(theme.value);
};

return (
<EuiListGroupItem
key={theme.value}
css={styles.listItem}
label={theme.text}
size="xs"
isActive={isCurrentTheme}
color={isCurrentTheme ? 'primary' : 'text'}
onClick={handleOnClick}
/>
);
})}
</EuiListGroup>
</EuiPopover>
);
};
12 changes: 6 additions & 6 deletions packages/docusaurus-theme/src/theme/ColorModeToggle/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ function ColorModeToggle({
onChange,
...rest
}: WrappedProps): JSX.Element {
const { theme, changeTheme } = useContext(AppThemeContext);
const { colorMode, changeColorMode } = useContext(AppThemeContext);

useEffect(() => {
changeTheme(value);
changeColorMode(value);
}, []);

const handleOnChange = (themeName: EuiThemeColorMode) => {
changeTheme(themeName);
onChange?.(themeName);
const handleOnChange = (colorMode: EuiThemeColorMode) => {
changeColorMode(colorMode);
onChange?.(colorMode);
};

return (
<OriginalColorModeToggle
value={theme}
value={colorMode}
onChange={handleOnChange}
{...rest}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Props } from '@theme-original/EditThisPage';
import { EuiButton, useEuiMemoizedStyles, UseEuiTheme } from '@elastic/eui';
// @ts-ignore - eui only has module declarations for '@elastic/eui/src/themes/amsterdam/global_styling/mixins/button'
// but importing from /src results in "Module not found" error
import { euiButtonColor } from '@elastic/eui/lib/themes/amsterdam/global_styling/mixins/button';
import { euiButtonColor } from '@elastic/eui/lib/global_styling/mixins/_button';

const getStyles = (theme: UseEuiTheme) => {
const { euiTheme } = theme;
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-theme/src/theme/Logo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ function LogoThemedImage({
alt: string;
imageClassName?: string;
}) {
const { theme } = useContext(AppThemeContext);
const isDarkMode = theme === 'dark';
const { colorMode } = useContext(AppThemeContext);
const isDarkMode = colorMode === 'dark';

const styles = useEuiMemoizedStyles(getStyles);

Expand Down
Loading
Loading