Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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: 2 additions & 0 deletions packages/eui-theme-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
},
"dependencies": {
"@types/lodash": "^4.14.202",
"chroma-js": "^2.4.2",
"lodash": "^4.17.21"
},
"devDependencies": {
Expand All @@ -32,6 +33,7 @@
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.21.5",
"@emotion/react": "^11.11.0",
"@types/chroma-js": "^2.4.0",
"@types/jest": "^29.5.12",
"@types/prettier": "2.7.3",
"@types/react": "^16.9 || ^17.0 || ^18.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@

export * from './size';
export * from './math';
export * from './shadows';
26 changes: 26 additions & 0 deletions packages/eui-theme-common/src/global_styling/functions/shadows.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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 chroma from 'chroma-js';
import {
COLOR_MODES_STANDARD,
EuiThemeColorModeStandard,
} from '../../services/theme/types';

// Create a CSS color value using whose opacity is determined based
// on either a light or dark theme. We use a multiplier
// of 1 for light themes and 2.5 for dark themes
export const getShadowColor = (
color: string,
opacity: number,
colorMode: EuiThemeColorModeStandard
) => {
const themeOpacity =
colorMode === COLOR_MODES_STANDARD.dark ? opacity * 3.5 : opacity * 1;
return chroma(color).alpha(themeOpacity).css();
};
3 changes: 2 additions & 1 deletion packages/eui-theme-common/src/global_styling/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Side Public License, v 1.
*/

export * from './types';
export * from '../services/theme/types';
export * from './functions';
export * from './variables';
export * from './mixins';
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
* Side Public License, v 1.
*/

export { colorVis } from '../../themes/amsterdam/global_styling/variables/_colors_vis';
export * from './shadow';
170 changes: 170 additions & 0 deletions packages/eui-theme-common/src/global_styling/mixins/shadow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
/*
* 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 type { UseEuiTheme } from '../../services/theme/types';
import { getShadowColor } from '../functions';
import {
_EuiThemeShadowSize,
_EuiThemeShadowCustomColor,
} from '../variables/shadow';

export interface EuiShadowCustomColor {
color?: string;
}

/**
* euiSlightShadow
*/
export const euiShadowXSmall = (
{ euiTheme, colorMode }: UseEuiTheme,
{ color: _color }: _EuiThemeShadowCustomColor = {}
) => {
const color = _color || euiTheme.colors.shadow;
return `
box-shadow:
0 .8px .8px ${getShadowColor(color, 0.04, colorMode)},
0 2.3px 2px ${getShadowColor(color, 0.03, colorMode)};
`;
};

/**
* bottomShadowSmall
*/
export const euiShadowSmall = (
{ euiTheme, colorMode }: UseEuiTheme,
{ color: _color }: _EuiThemeShadowCustomColor = {}
) => {
const color = _color || euiTheme.colors.shadow;
return `
box-shadow:
0 .7px 1.4px ${getShadowColor(color, 0.07, colorMode)},
0 1.9px 4px ${getShadowColor(color, 0.05, colorMode)},
0 4.5px 10px ${getShadowColor(color, 0.05, colorMode)};
`;
};

/**
* bottomShadowMedium
*/
export const euiShadowMedium = (
{ euiTheme, colorMode }: UseEuiTheme,
{ color: _color, property }: _EuiThemeShadowCustomColor = {}
) => {
const color = _color || euiTheme.colors.shadow;

if (property === 'filter') {
// Using only one drop-shadow filter instead of multiple is more performant & prevents Safari bugs
return `filter: drop-shadow(0 5.7px 9px ${getShadowColor(
color,
0.2,
colorMode
)});`;
} else {
return `box-shadow:
0 .9px 4px ${getShadowColor(color, 0.08, colorMode)},
0 2.6px 8px ${getShadowColor(color, 0.06, colorMode)},
0 5.7px 12px ${getShadowColor(color, 0.05, colorMode)},
0 15px 15px ${getShadowColor(color, 0.04, colorMode)};`;
}
};

/**
* bottomShadow
*/
export const euiShadowLarge = (
{ euiTheme, colorMode }: UseEuiTheme,
{ color: _color }: _EuiThemeShadowCustomColor = {}
) => {
const color = _color || euiTheme.colors.shadow;
return `
box-shadow:
0 1px 5px ${getShadowColor(color, 0.1, colorMode)},
0 3.6px 13px ${getShadowColor(color, 0.07, colorMode)},
0 8.4px 23px ${getShadowColor(color, 0.06, colorMode)},
0 23px 35px ${getShadowColor(color, 0.05, colorMode)};
`;
};

/**
* bottomShadowLarge
*/
export interface EuiShadowXLarge extends _EuiThemeShadowCustomColor {
reverse?: boolean;
}
export const euiShadowXLarge = (
{ euiTheme, colorMode }: UseEuiTheme,
{ color: _color, reverse }: EuiShadowXLarge = {}
) => {
const color = _color || euiTheme.colors.shadow;
return `
box-shadow:
0 ${reverse ? '-' : ''}2.7px 9px ${getShadowColor(color, 0.13, colorMode)},
0 ${reverse ? '-' : ''}9.4px 24px ${getShadowColor(color, 0.09, colorMode)},
0 ${reverse ? '-' : ''}21.8px 43px ${getShadowColor(color, 0.08, colorMode)};
`;
};

/**
* slightShadowHover
*/
export const euiSlightShadowHover = (
{ euiTheme, colorMode }: UseEuiTheme,
{ color: _color }: _EuiThemeShadowCustomColor = {}
) => {
const color = _color || euiTheme.colors.shadow;
return `
box-shadow:
0 1px 5px ${getShadowColor(color, 0.1, colorMode)},
0 3.6px 13px ${getShadowColor(color, 0.07, colorMode)},
0 8.4px 23px ${getShadowColor(color, 0.06, colorMode)},
0 23px 35px ${getShadowColor(color, 0.05, colorMode)};
`;
};

/**
* bottomShadowFlat
*
* Similar to shadow medium but without the bottom depth.
* Useful for popovers that drop UP rather than DOWN.
*/
export const euiShadowFlat = (
{ euiTheme, colorMode }: UseEuiTheme,
{ color: _color }: _EuiThemeShadowCustomColor = {}
) => {
const color = _color || euiTheme.colors.shadow;
return `
box-shadow:
0 0 .8px ${getShadowColor(color, 0.06, colorMode)},
0 0 2px ${getShadowColor(color, 0.04, colorMode)},
0 0 5px ${getShadowColor(color, 0.04, colorMode)},
0 0 17px ${getShadowColor(color, 0.03, colorMode)};
`;
};

export const euiShadow = (
euiThemeContext: UseEuiTheme,
size: _EuiThemeShadowSize = 'l',
{ color }: _EuiThemeShadowCustomColor = {}
) => {
switch (size) {
case 'xs':
return euiShadowXSmall(euiThemeContext, { color });
case 's':
return euiShadowSmall(euiThemeContext, { color });
case 'm':
return euiShadowMedium(euiThemeContext, { color });
case 'l':
return euiShadowLarge(euiThemeContext, { color });
case 'xl':
return euiShadowXLarge(euiThemeContext, { color });

default:
console.warn('Please provide a valid size option to useEuiShadow');
return '';
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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 { _EuiThemeBreakpoints } from './breakpoint';

export const breakpoint: _EuiThemeBreakpoints = {
xl: 1200,
l: 992,
m: 768,
s: 575,
xs: 0,
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { CSSProperties } from 'react';
import { ColorModeSwitch } from '../types';
import { ColorModeSwitch } from '../../services/theme/types';

export interface _EuiThemeBorderWidthValues {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
* Side Public License, v 1.
*/

import { ColorModeSwitch, StrictColorModeSwitch } from '../types';
import {
ColorModeSwitch,
StrictColorModeSwitch,
} from '../../services/theme/types';

export type _EuiThemeButtonColors = {
backgroundPrimary: ColorModeSwitch;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
* Side Public License, v 1.
*/

import { ColorModeSwitch, StrictColorModeSwitch } from '../types';
import {
ColorModeSwitch,
StrictColorModeSwitch,
} from '../../services/theme/types';

/**
* Top 5 colors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
* Side Public License, v 1.
*/

import { ColorModeSwitch, StrictColorModeSwitch } from '../types';
import {
ColorModeSwitch,
StrictColorModeSwitch,
} from '../../services/theme/types';
import { _EuiThemeButtonColors } from './buttons';
import { _EuiThemeForm, _EuiThemeFormColors } from './forms';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { ColorModeSwitch } from '../types';
import { ColorModeSwitch } from '../../services/theme/types';

export type _EuiThemeForm = {
maxWidth: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
export * from './animations';
export * from './borders';
export * from './breakpoint';
export * from './_breakpoint';
export * from './breakpoint';
export * from './colors';
export * from './levels';
export * from './size';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { CSSProperties } from 'react';
import { ColorModeSwitch } from '../types';
import { ColorModeSwitch } from '../../services/theme/types';

export interface _EuiThemeFocus {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@

import type { CSSObject } from '@emotion/react';

import type { RecursivePartial, ValueOf } from '../types';
import type { RecursivePartial, ValueOf } from '../../types';

import { _EuiThemeAnimation } from './variables/animations';
import { _EuiThemeBreakpoints } from './variables/breakpoint';
import { _EuiThemeBorder } from './variables/borders';
import { _EuiThemeColors } from './variables/colors';
import { _EuiThemeBase, _EuiThemeSizes } from './variables/size';
import { _EuiThemeFont } from './variables/typography';
import { _EuiThemeFocus } from './variables/states';
import { _EuiThemeLevels } from './variables/levels';
import { _EuiThemeComponents } from './variables/components';
import { _EuiThemeFlags } from './variables';
import { _EuiThemeAnimation } from '../../global_styling/variables/animations';
import { _EuiThemeBreakpoints } from '../../global_styling/variables/breakpoint';
import { _EuiThemeBorder } from '../../global_styling/variables/borders';
import { _EuiThemeColors } from '../../global_styling/variables/colors';
import {
_EuiThemeBase,
_EuiThemeSizes,
} from '../../global_styling/variables/size';
import { _EuiThemeFont } from '../../global_styling/variables/typography';
import { _EuiThemeFocus } from '../../global_styling/variables/states';
import { _EuiThemeLevels } from '../../global_styling/variables/levels';
import { _EuiThemeComponents } from '../../global_styling/variables/components';
import { _EuiThemeFlags } from '../../global_styling/variables';

export const COLOR_MODES_STANDARD = {
light: 'LIGHT',
Expand Down Expand Up @@ -108,3 +111,9 @@ export type EuiThemeNested = {
setNearestThemeCSSVariables: Function;
themeCSSVariables?: CSSObject;
};

export interface UseEuiTheme<T extends {} = {}> {
euiTheme: EuiThemeComputed<T>;
colorMode: EuiThemeColorModeStandard;
modifications: EuiThemeModifications<T>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
keysOf,
} from '../../../../../src';

import { breakpoint as breakpoints } from '../../../../../src/themes/amsterdam/global_styling/variables/_breakpoint';
import { breakpoint as breakpoints } from '@elastic/eui-theme-common';
const breakpointKeys = keysOf(breakpoints);

import { GuideSection } from '../../../components/guide_section/guide_section';
Expand Down
3 changes: 2 additions & 1 deletion packages/eui/src/components/bottom_bar/bottom_bar.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
*/

import { css, keyframes } from '@emotion/react';
import { euiShadowFlat } from '@elastic/eui-theme-common';

import { euiCanAnimate } from '../../global_styling';
import { UseEuiTheme } from '../../services';
import { euiShadowFlat } from '../../themes/amsterdam/global_styling/mixins';

const euiBottomBarAppear = keyframes`
0% {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
_EuiButtonColor,
euiButtonEmptyColor,
euiButtonSizeMap,
} from '../../../themes/amsterdam/global_styling/mixins/button';
} from '../../../global_styling/mixins/_button';

import { euiButtonBaseCSS } from '../button_display/_button_display.styles';

Expand Down
Loading