Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1f1de84
WIP Logicals
Apr 27, 2022
83e0a1f
Added padding utils
Apr 27, 2022
977d845
Added background color utils
Apr 27, 2022
e70d3f0
Increasing the logical properties
Apr 28, 2022
bc56cbf
Moved logical utils to Theming/Size
Apr 28, 2022
0804078
Moved padding utils to Theming/Size
Apr 28, 2022
9894542
Moved background color utils to Theming/Color
Apr 28, 2022
de889dd
Added separate `text-align` logical props and started updating some e…
Apr 28, 2022
e321d46
cl
Apr 28, 2022
3ef3975
Merge remote-tracking branch 'origin/main' into css-in-js/utils
Apr 28, 2022
c170cd1
Added tests for `padding` hook
Apr 28, 2022
8c7cd2c
Added tests for `logical` functions
Apr 28, 2022
ac5c03d
Added tests for `background-color` util
Apr 28, 2022
972d57e
Added test for `typography`
Apr 28, 2022
cc21b63
Fix order of font size measurements to have rem first
Apr 29, 2022
468ac79
Revert "Added test for `typography`"
May 2, 2022
87b964f
Added simplified `euiBackgroundColor` for calculating just the color
May 2, 2022
6b9fa3b
Merge remote-tracking branch 'origin/main' into css-in-js/utils
May 2, 2022
652ae22
Updated padding in the same way
May 2, 2022
c30eea4
Naming fix & CL
May 2, 2022
8bcd4a5
Fixed contrast badge tooltips 🤦‍♀️ and typos
May 2, 2022
3ec5af9
More types/tests for text-align
May 2, 2022
2f4ded4
Uniform styles
May 2, 2022
4a3a034
camelCase logicStyle object return
cee-chen May 2, 2022
ded07ab
Remove `logicalCSS()` in favor of `logicalStyle()`
May 2, 2022
29c6642
Update cl
May 2, 2022
162be46
Revert "Update cl"
May 3, 2022
c2d64ec
Revert "Remove `logicalCSS()` in favor of `logicalStyle()`"
May 3, 2022
921c6ae
Add `CSS` and `Style` version of text-align logical mixin
May 3, 2022
857ca4e
Renamed `useEuiBackgroundColorStyles` to `useEuiBackgroundColorCSS`
May 3, 2022
099f6bc
chore: Set permissions for GitHub actions (#5858)
naveensrinivasan May 3, 2022
d47f414
[Emotion] Convert `euiFocusRing()` mixin (#5855)
May 3, 2022
89c551a
Changed name of `useEuiBackgroundColorStyles` to `useEuiBackgroundCol…
May 3, 2022
5f08efa
Merge remote-tracking branch 'origin/main' into css-in-js/utils
May 3, 2022
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
98 changes: 97 additions & 1 deletion src-docs/src/views/theme/color/_color_js.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,18 @@ import { css } from '@emotion/react';
import { transparentize, useEuiTheme } from '../../../../../src/services';
import { getPropsFromComponent } from '../../../services/props/get_props';

import { EuiCode, EuiColorPickerSwatch } from '../../../../../src';
import {
useEuiBackgroundColorCSS,
EuiCode,
EuiColorPickerSwatch,
EuiSpacer,
EuiText,
useEuiBackgroundColor,
useEuiPaddingSize,
BACKGROUND_COLORS,
euiBackgroundColor,
useEuiPaddingCSS,
} from '../../../../../src';

import { EuiThemeColors, ThemeRowType } from '../_props';

Expand Down Expand Up @@ -215,3 +226,88 @@ export const SpecialJS: FunctionComponent<ThemeRowType> = ({ description }) => {
</>
);
};

export const UtilsJS = () => {
const euiTheme = useEuiTheme();

return (
<>
<EuiText grow={false}>
<h3>Background colors</h3>
<p>
To all but ensure proper contrast of text to background, we recommend
using our pre-defined shades of background colors based on the
EuiTheme brand colors. You can also use{' '}
<Link to="/layout/panel">
<strong>EuiPanel</strong>
</Link>{' '}
for the same effect plus more options like padding and rounded
corners.
</p>
</EuiText>

<EuiSpacer size="l" />

<ThemeExample
title={<code>{'useEuiBackgroundColorCSS()[color]'}</code>}
description={
<>
<p>
Returns an object of the available color keys containing the css
string of the computed background version for the given{' '}
<EuiCode language="sass">color</EuiCode>.
</p>
<p>
This is best used to map component prop styles to padding output.
</p>
</>
}
example={
<p css={[useEuiBackgroundColorCSS().accent, useEuiPaddingCSS().l]}>
<code>{useEuiBackgroundColorCSS().accent}</code>
</p>
}
snippetLanguage="tsx"
snippet={`const colorStyles = useEuiBackgroundColorCSS();
const cssStyles = [colorStyles['accent']];

<span css={cssStyles}>
/* Your content */
</span>`}
/>

<ThemeExample
title={<code>useEuiBackgroundColor(color)</code>}
description={
<p>
Returns just the computed background color for the given{' '}
<EuiCode language="sass">color</EuiCode>.
</p>
}
example={
<p
css={css`
background: ${useEuiBackgroundColor('subdued')};
padding: ${useEuiPaddingSize('l')};
`}
>
<code>{useEuiBackgroundColor('subdued')}</code>
</p>
}
snippetLanguage="emotion"
snippet={"background: ${useEuiBackgroundColor('subdued')};"}
/>

<ThemeValuesTable
items={BACKGROUND_COLORS.map((color) => {
return {
id: color,
token: `useEuiBackgroundColor('${color}')`,
value: euiBackgroundColor(color, euiTheme),
};
})}
render={(item) => <EuiColorPickerSwatch color={item.value} disabled />}
/>
</>
);
};
32 changes: 23 additions & 9 deletions src-docs/src/views/theme/color/_contrast_js.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ const textVariants = [...brandTextKeys, ...textColors];

type ColorSection = {
color: keyof _EuiThemeColorsMode;
colorValue?: string;
minimumContrast: string | number;
showTextVariants: boolean;
matchPanelColor?: boolean;
hookName?: string;
};

export const ColorSectionJS: FunctionComponent<ColorSection> = ({
color,
colorValue: _colorValue,
minimumContrast,
showTextVariants,
matchPanelColor,
hookName,
}) => {
const { euiTheme } = useEuiTheme();
const colorsForContrast = showTextVariants ? textVariants : allowedColors;
Expand All @@ -40,35 +44,38 @@ export const ColorSectionJS: FunctionComponent<ColorSection> = ({
return brandKeys.includes(color) || brandTextKeys.includes(color);
}

const colorValue = _colorValue || euiTheme.colors[color];

return (
<EuiPanel
color="transparent"
hasBorder={false}
paddingSize={matchPanelColor ? 'l' : 'none'}
style={{
background: matchPanelColor ? euiTheme.colors[color] : undefined,
background: matchPanelColor ? colorValue : undefined,
}}
>
<EuiText size="xs">
<EuiFlexGrid columns={2} direction="column" gutterSize="s">
{showTextVariants && colorIsCore(color) && (
{showTextVariants && colorIsCore(colorValue) && (
<ColorsContrastItem
foreground={`${color}Text`}
background={'body'}
minimumContrast={minimumContrast}
/>
)}
{colorsForContrast.map((color2) => {
if (colorIsCore(color) && colorIsCore(color2)) {
if (colorIsCore(colorValue) && colorIsCore(color2)) {
// i.e. don't render if both are core colors
return;
}
return (
<ColorsContrastItem
foreground={color2}
background={color}
background={_colorValue ? colorValue : color}
key={color2}
minimumContrast={minimumContrast}
styleString={hookName && `${hookName}('${color}')`}
/>
);
})}
Expand All @@ -82,18 +89,22 @@ type ColorsContrastItem = {
foreground: string;
background: string;
minimumContrast: string | number;
styleString?: string;
};

const ColorsContrastItem: FunctionComponent<ColorsContrastItem> = ({
foreground,
background,
minimumContrast,
styleString,
}) => {
const { euiTheme } = useEuiTheme();
const backgroundColor =
const backgroundColorIsToken =
euiTheme.colors[background as keyof _EuiThemeColorsMode];
const foregroundColor =
const backgroundColor = backgroundColorIsToken || background;
const foregroundColorIsToken =
euiTheme.colors[foreground as keyof _EuiThemeColorsMode];
const foregroundColor = foregroundColorIsToken || foreground;
const backgroundIsBody = background === 'body';

const contrast = chroma.contrast(backgroundColor, foregroundColor);
Expand All @@ -107,14 +118,17 @@ const ColorsContrastItem: FunctionComponent<ColorsContrastItem> = ({
foreground
);

const backgroundStyleString = styleString || `euiTheme.colors.${background}`;

const contrastIsAcceptableToCopy = contrast >= 3;
const textToCopy = backgroundIsBody
? `color: $\{euiTheme.colors.${foreground}};`
: `background-color: $\{euiTheme.colors.${background}};
: `background-color: $\{${backgroundStyleString}};
color: $\{euiTheme.colors.${foreground}};`;

const beforeMessage = contrastIsAcceptableToCopy ? (
<small>
<code>{`euiTheme.colors.${foreground} / euiTheme.colors.${background}`}</code>
<code>{`euiTheme.colors.${foreground} / ${backgroundStyleString}`}</code>
<EuiHorizontalRule margin="xs" />
<kbd>Click</kbd> to copy CSS-in-JS configuration
</small>
Expand All @@ -127,7 +141,7 @@ color: $\{euiTheme.colors.${foreground}};`;
return (
<EuiFlexItem className="eui-textCenter">
<EuiCopy
anchorClassName="eui-displayBlock"
display="block"
title={
<span>
{contrastRatingBadge} Contrast is {contrast.toFixed(1)}
Expand Down
26 changes: 21 additions & 5 deletions src-docs/src/views/theme/color/colors.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useContext, useMemo, useState } from 'react';

import { EuiCode, EuiSpacer, EuiText } from '../../../../../src';
import { EuiCallOut, EuiCode, EuiSpacer, EuiText } from '../../../../../src';

// @ts-ignore Importing from JS
import { GuidePage } from '../../../components/guide_page';
Expand All @@ -11,7 +11,7 @@ import { ThemeNotice } from '../_components/_theme_notice';
// @ts-ignore Importing JS
import ColorsContrast from './contrast';

import { BrandJS, ShadeJS, SpecialJS, TextJS } from './_color_js';
import { BrandJS, ShadeJS, SpecialJS, TextJS, UtilsJS } from './_color_js';
import { Link } from 'react-router-dom';
import { BrandSass, ShadeSass, SpecialSass, TextSass } from './_color_sass';

Expand All @@ -32,6 +32,7 @@ export const colorsSections = [
{ title: 'Text colors', id: 'text-colors' },
{ title: 'Shades', id: 'shades' },
{ title: 'Special colors', id: 'special-colors' },
{ title: 'Utilities', id: 'utilities' },
];

export default () => {
Expand Down Expand Up @@ -97,6 +98,12 @@ export default () => {
return <SpecialJS description={description} />;
}, [showSass]);

const utilsContent = useMemo(() => {
if (showSass)
return <EuiCallOut title="Utilities only available for Emotion." />;
return <UtilsJS />;
}, [showSass]);

return (
<GuidePage
isBeta={!showSass && !selectedTabId.includes('contrast')}
Expand Down Expand Up @@ -155,7 +162,6 @@ export default () => {
<EuiSpacer size="xl" />

<EuiText grow={false}>
{' '}
<h2
id={`${colorsSections[1].id}`}
>{`${colorsSections[1].title}`}</h2>
Expand All @@ -182,7 +188,6 @@ export default () => {
<EuiSpacer size="xl" />

<EuiText grow={false}>
{' '}
<h2
id={`${colorsSections[2].id}`}
>{`${colorsSections[2].title}`}</h2>
Expand All @@ -199,7 +204,6 @@ export default () => {
<EuiSpacer size="xl" />

<EuiText grow={false}>
{' '}
<h2
id={`${colorsSections[3].id}`}
>{`${colorsSections[3].title}`}</h2>
Expand All @@ -209,6 +213,18 @@ export default () => {
<EuiSpacer size="xl" />

{specialContent}

<EuiSpacer size="xl" />

<EuiText grow={false}>
<h2
id={`${colorsSections[4].id}`}
>{`${colorsSections[4].title}`}</h2>
</EuiText>

<EuiSpacer size="xl" />

{utilsContent}
</>
)}
</GuidePage>
Expand Down
48 changes: 47 additions & 1 deletion src-docs/src/views/theme/color/contrast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import {
EuiLink,
EuiTitle,
EuiPanel,
} from '../../../../../src/components';
EuiCallOut,
EuiCode,
} from '../../../../../src';

import {
ColorSectionSass,
Expand All @@ -21,6 +23,11 @@ import { brandKeys, shadeKeys } from './_color_js';
import { ContrastSlider } from './_contrast_slider';
import { ratingAA } from './_contrast_utilities';
import { _EuiThemeColorsMode } from '../../../../../src/global_styling/variables/colors';
import {
BACKGROUND_COLORS,
EuiBackgroundColor,
useEuiBackgroundColor,
} from '../../../../../src/global_styling';

export default () => {
const [showTextVariants, setShowTextVariants] = useState(true);
Expand Down Expand Up @@ -181,6 +188,45 @@ export default () => {
);
})}
</EuiPanel>

<EuiSpacer size="xxl" />

<EuiText grow={false}>
<h3>Background colors</h3>
<p>
These background colors are pre-defined shades of the brand colors.
They are recalled by using the hook{' '}
<EuiCode>useEuiBackgroundColor(color)</EuiCode>.
</p>
</EuiText>

<EuiSpacer />

<EuiPanel color="subdued">
{showSass ? (
<EuiCallOut title="Background colors only exist for CSS-in-JS styling." />
) : (
BACKGROUND_COLORS.map((color: string) => {
return (
color !== 'transparent' && (
<React.Fragment key={color}>
<ColorSectionJS
key={color}
color={color as keyof _EuiThemeColorsMode}
colorValue={useEuiBackgroundColor(
color as EuiBackgroundColor
)}
hookName="useEuiBackgroundColor"
minimumContrast={contrastValue}
showTextVariants={showTextVariants}
/>
<EuiSpacer />
</React.Fragment>
)
);
})
)}
</EuiPanel>
</div>
</>
);
Expand Down
Loading