UNPKG

@elastic/eui

Version:

Elastic UI Component Library

30 lines (28 loc) 1.67 kB
/* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0 and the Server Side Public License, v 1; you may not use this file except * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ import React from 'react'; import { EuiColorModeContext, EuiHighContrastModeContext } from '../../../services'; import { useWindowMediaMatcher } from './match_media_hook'; import { jsx as ___EmotionJSX } from "@emotion/react"; export var EuiSystemDefaultsProvider = function EuiSystemDefaultsProvider(_ref) { var children = _ref.children; // @see https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme var systemColorMode = useWindowMediaMatcher('(prefers-color-scheme: dark)') ? 'DARK' : 'LIGHT'; // There are different types of high contrast modes based on system/OS settings. @see: // - https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-contrast // - https://developer.mozilla.org/en-US/docs/Web/CSS/@media/forced-colors // - https://kilianvalkhof.com/2023/css-html/i-no-longer-understand-prefers-contrast/ var windowsHighContrast = useWindowMediaMatcher('(forced-colors: active)'); var macHighContrast = useWindowMediaMatcher('(prefers-contrast: more)'); var systemHighContrastMode = windowsHighContrast ? 'forced' : macHighContrast ? 'preferred' : false; return ___EmotionJSX(EuiColorModeContext.Provider, { value: systemColorMode }, ___EmotionJSX(EuiHighContrastModeContext.Provider, { value: systemHighContrastMode }, children)); };