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][EuiThemeProvider] highContrastMode set up and documentation #8142

Merged
merged 13 commits into from
Nov 21, 2024

Conversation

cee-chen
Copy link
Member

@cee-chen cee-chen commented Nov 14, 2024

Summary

Note

This PR merges into a feature branch. As this PR contains some heavy docs changes, I recommend following along by commit.

This PR sets up the initial architecture for a highContrastMode prop/return in <EuiThemeProvider> and useEuiTheme(). By default, this setting will inherit from the user's system settings with one of 3 possible options:

  • "forced" (Windows high contrast mode and some browser forced colors extensions)
  • "preferred" (MacOS high contrast mode)
  • false (high contrast mode not on)

The provider prop takes a simple true/false (aka preferred or false - forced is something that can only be set externally by the user/system and not by the consumer/application), whereas the internal state returned by our hooks returns more the granular enum for help with styling and other considerations.

What this PR does not do, and will be handled in future PRs:

  • Address components with shadows that should receive a full border around them instead just a bottom border
  • Do anything with forced contrast mode styles
  • Perform component-specific audits on custom colors or box shadows that need to be tweaked

QA

  • Go to https://eui.elastic.co/pr_8142/#/theming/high-contrast-mode
  • Confirm that while the rest of the page displays normally (shadows, etc.) the first example's table's borders are fully black (or white if in dark mode)
  • [MacOS] Go to Display > Increase contrast and check the toggle
  • Confirm that all shadows on the page disappear, and that all borders become fully black (or white if in dark mode)
  • Scroll down to the last example on the page and confirm the border around the text is 2px thick
  • Click the theme toggle in the top right corner of the sticky header
  • Manually toggle high contrast mode off/on, and confirm it overrides MacOS's system settings

General checklist

  • Browser QA
    • Checked in both light and dark modes
    • Checked in both MacOS and Windows high contrast modes
    • Checked in Chrome, Safari, Edge, and Firefox
      - [ ] Checked in mobile
      - [ ] Checked for accessibility including keyboard-only and screenreader modes
  • Docs site QA - N/A
  • Code quality checklist
  • Release checklist
    • A changelog entry exists and is marked appropriately.
      - [ ] If applicable, added the breaking change issue label (and filled out the breaking change checklist)
  • Designer checklist - N/A

@cee-chen cee-chen force-pushed the high-contrast-mode-1 branch 3 times, most recently from 153328b to 4e8406e Compare November 19, 2024 02:22
… high contrast mode detection

+ remove need for the render prop by fixing the global theme logic to check against defaults instead of the parent theme, which allows us to simply add a provider wrapper
- Prefer `modify` over computing at theme time, so that consumer modifications are also overridden and high contrast tokens are always enforced
- and set a border-bottom instead via box-shadow

+ code style cleanup - use optional chaining syntax instead of destructuring and correctly pass all options
+ update all provider snapshots (minor font tweaks)

+ remove snapshots for a story with no meaningful visuals
- note that EUI+ docs have been added by parity but will not actually work, since EUI+ points at a static EUI version/release instead of at the local workspace

- update some older doc copy while here as well
+ massive cleanup/refactor of src-docs theme context, prefer toggle for light/dark mode

+ remove defunct tour on language selector
… ThemeContext

- might as well since we're already handling localStorage things there, saves us from waterfalling props unnecessarily
@cee-chen cee-chen changed the title High contrast mode 1 [EuiProvider][EuiThemeProvider] highContrastMode set up and documentation Nov 19, 2024
@cee-chen cee-chen marked this pull request as ready for review November 19, 2024 02:56
@cee-chen cee-chen requested a review from a team as a code owner November 19, 2024 02:56
Copy link
Contributor

@mgadewoll mgadewoll left a comment

Choose a reason for hiding this comment

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

Awesome work on this! 🎉 🔥
I tested:
✅ macOS increased contrast setting
✅ Windows high contrast themes
✅ emulated contrast theme on macOS in Chrome browser

Overall the code looks good to me. I left only small comments and a general question about how we might want to support testing via the theme switcher.

const modificationsWithHighContrast = useMemo(() => {
if (!highContrastMode) return modifications;

const borderColor = system.root.colors[colorMode].fullShade;
Copy link
Contributor

Choose a reason for hiding this comment

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

🗒️ Note to self: Here we'll need to account for the new tokens in Borealis when merging to the feature branch.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll probably end up moving all those tokens to a separate file/hook util once that happens, since there will be a lot more overrides and I don't want to add that much context to the main provider file.

Actually, let me just go ahead and do that now while I'm here 🧠

Copy link
Member Author

Choose a reason for hiding this comment

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

Seperate hook util added in 1e79385

This feels much cleaner already! Hooray for sweeping my excessively long code spaghet comments into a corner where no one will see them 🤣

Copy link
Member Author

Choose a reason for hiding this comment

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

Although, hm, now I'm wondering if I should have moved the hook to utils.ts instead of creating a brand new file. utils.ts already feels plenty long and scary though... any preference?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's nice to have a dedicated file for the high contrast overrides. It ensures a clear scope and prevents additional file bloat, utils.ts is already quite long and scary indeed 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good! Thanks for sanity checking me as always Lene! ✨

packages/eui/src-docs/src/views/theme/theme_example.js Outdated Show resolved Hide resolved
selectedLocale: string;
context?: any;
};

export const GuideThemeSelector: React.FunctionComponent<
Copy link
Contributor

Choose a reason for hiding this comment

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

🗒️ General note: This will cause some merge/rebase conflicts when merging to the Borealis feature branch as this was implemented there too.

packages/eui/.storybook/decorator.tsx Show resolved Hide resolved
.github/pull_request_template.md Show resolved Hide resolved
+ generally improve story DX for EuiProvider
…anticipation of new theme tokens

- there'll be a lot more, so let's pull it out to its own file and keep the main provider fairly high level in terms of high contrast mode logic
@kibanamachine
Copy link

Preview staging links for this PR:

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

Copy link
Contributor

@mgadewoll mgadewoll left a comment

Choose a reason for hiding this comment

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

🚢 🐈‍⬛ Thanks for the additional updates!
I left one more non-blocking comment. Feel free to ignore if you think it's fine as is.

@cee-chen cee-chen merged commit 837ad1c into elastic:high-contrast-mode Nov 21, 2024
4 checks passed
@cee-chen cee-chen deleted the high-contrast-mode-1 branch November 21, 2024 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants