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

[Emotion] Memoize styles + opinionated clean up more components #8172

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,15 @@ exports[`EuiComment is rendered 1`] = `
class="emotion-euiTimelineItemIcon-center"
>
<div
class="emotion-euiTimelineItemIcon__content"
aria-label=""
class="euiAvatar euiAvatar--m euiAvatar--user euiCommentAvatar emotion-euiAvatar-user-m-uppercase-subdued"
role="img"
title=""
>
<div
aria-label=""
class="euiAvatar euiAvatar--m euiAvatar--user euiCommentAvatar emotion-euiAvatar-user-m-uppercase-subdued"
role="img"
title=""
>
<span
class="euiAvatar__icon"
data-euiicon-type="userAvatar"
/>
</div>
<span
class="euiAvatar__icon"
data-euiicon-type="userAvatar"
/>
</div>
</div>
<div
Expand All @@ -44,19 +40,15 @@ exports[`EuiComment props event is rendered 1`] = `
class="emotion-euiTimelineItemIcon-center"
>
<div
class="emotion-euiTimelineItemIcon__content"
aria-label=""
class="euiAvatar euiAvatar--m euiAvatar--user euiCommentAvatar emotion-euiAvatar-user-m-uppercase-subdued"
role="img"
title=""
>
<div
aria-label=""
class="euiAvatar euiAvatar--m euiAvatar--user euiCommentAvatar emotion-euiAvatar-user-m-uppercase-subdued"
role="img"
title=""
>
<span
class="euiAvatar__icon"
data-euiicon-type="userAvatar"
/>
</div>
<span
class="euiAvatar__icon"
data-euiicon-type="userAvatar"
/>
</div>
</div>
<div
Expand Down Expand Up @@ -105,19 +97,15 @@ exports[`EuiComment props timestamp is rendered 1`] = `
class="emotion-euiTimelineItemIcon-center"
>
<div
class="emotion-euiTimelineItemIcon__content"
aria-label=""
class="euiAvatar euiAvatar--m euiAvatar--user euiCommentAvatar emotion-euiAvatar-user-m-uppercase-subdued"
role="img"
title=""
>
<div
aria-label=""
class="euiAvatar euiAvatar--m euiAvatar--user euiCommentAvatar emotion-euiAvatar-user-m-uppercase-subdued"
role="img"
title=""
>
<span
class="euiAvatar__icon"
data-euiicon-type="userAvatar"
/>
</div>
<span
class="euiAvatar__icon"
data-euiicon-type="userAvatar"
/>
</div>
</div>
<div
Expand Down Expand Up @@ -168,19 +156,15 @@ exports[`EuiComment renders a body 1`] = `
class="emotion-euiTimelineItemIcon-top"
>
<div
class="emotion-euiTimelineItemIcon__content"
aria-label=""
class="euiAvatar euiAvatar--m euiAvatar--user euiCommentAvatar emotion-euiAvatar-user-m-uppercase-subdued"
role="img"
title=""
>
<div
aria-label=""
class="euiAvatar euiAvatar--m euiAvatar--user euiCommentAvatar emotion-euiAvatar-user-m-uppercase-subdued"
role="img"
title=""
>
<span
class="euiAvatar__icon"
data-euiicon-type="userAvatar"
/>
</div>
<span
class="euiAvatar__icon"
data-euiicon-type="userAvatar"
/>
</div>
</div>
<div
Expand Down Expand Up @@ -210,19 +194,15 @@ exports[`EuiComment renders a timeline icon 1`] = `
class="emotion-euiTimelineItemIcon-top"
>
<div
class="emotion-euiTimelineItemIcon__content"
aria-label=""
class="euiAvatar euiAvatar--m euiAvatar--user euiCommentAvatar emotion-euiAvatar-user-m-uppercase-subdued"
role="img"
title=""
>
<div
aria-label=""
class="euiAvatar euiAvatar--m euiAvatar--user euiCommentAvatar emotion-euiAvatar-user-m-uppercase-subdued"
role="img"
title=""
>
<span
class="euiAvatar__icon"
data-euiicon-type="dot"
/>
</div>
<span
class="euiAvatar__icon"
data-euiicon-type="dot"
/>
</div>
</div>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,15 @@ exports[`EuiCommentList is rendered 1`] = `
class="emotion-euiTimelineItemIcon-center"
>
<div
class="emotion-euiTimelineItemIcon__content"
aria-label=""
class="euiAvatar euiAvatar--m euiAvatar--user euiCommentAvatar emotion-euiAvatar-user-m-uppercase-subdued"
role="img"
title=""
>
<div
aria-label=""
class="euiAvatar euiAvatar--m euiAvatar--user euiCommentAvatar emotion-euiAvatar-user-m-uppercase-subdued"
role="img"
title=""
>
<span
class="euiAvatar__icon"
data-euiicon-type="userAvatar"
/>
</div>
<span
class="euiAvatar__icon"
data-euiicon-type="userAvatar"
/>
</div>
</div>
<div
Expand All @@ -53,19 +49,15 @@ exports[`EuiCommentList props gutterSize l is rendered 1`] = `
class="emotion-euiTimelineItemIcon-center"
>
<div
class="emotion-euiTimelineItemIcon__content"
aria-label=""
class="euiAvatar euiAvatar--m euiAvatar--user euiCommentAvatar emotion-euiAvatar-user-m-uppercase-subdued"
role="img"
title=""
>
<div
aria-label=""
class="euiAvatar euiAvatar--m euiAvatar--user euiCommentAvatar emotion-euiAvatar-user-m-uppercase-subdued"
role="img"
title=""
>
<span
class="euiAvatar__icon"
data-euiicon-type="userAvatar"
/>
</div>
<span
class="euiAvatar__icon"
data-euiicon-type="userAvatar"
/>
</div>
</div>
<div
Expand All @@ -92,19 +84,15 @@ exports[`EuiCommentList props gutterSize m is rendered 1`] = `
class="emotion-euiTimelineItemIcon-center"
>
<div
class="emotion-euiTimelineItemIcon__content"
aria-label=""
class="euiAvatar euiAvatar--m euiAvatar--user euiCommentAvatar emotion-euiAvatar-user-m-uppercase-subdued"
role="img"
title=""
>
<div
aria-label=""
class="euiAvatar euiAvatar--m euiAvatar--user euiCommentAvatar emotion-euiAvatar-user-m-uppercase-subdued"
role="img"
title=""
>
<span
class="euiAvatar__icon"
data-euiicon-type="userAvatar"
/>
</div>
<span
class="euiAvatar__icon"
data-euiicon-type="userAvatar"
/>
</div>
</div>
<div
Expand All @@ -131,19 +119,15 @@ exports[`EuiCommentList props gutterSize xl is rendered 1`] = `
class="emotion-euiTimelineItemIcon-center"
>
<div
class="emotion-euiTimelineItemIcon__content"
aria-label=""
class="euiAvatar euiAvatar--m euiAvatar--user euiCommentAvatar emotion-euiAvatar-user-m-uppercase-subdued"
role="img"
title=""
>
<div
aria-label=""
class="euiAvatar euiAvatar--m euiAvatar--user euiCommentAvatar emotion-euiAvatar-user-m-uppercase-subdued"
role="img"
title=""
>
<span
class="euiAvatar__icon"
data-euiicon-type="userAvatar"
/>
</div>
<span
class="euiAvatar__icon"
data-euiicon-type="userAvatar"
/>
</div>
</div>
<div
Expand Down
22 changes: 10 additions & 12 deletions packages/eui/src/components/expression/expression.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,16 @@ export const euiExpressionDescriptionStyles = ({ euiTheme }: UseEuiTheme) => {
};
};

export const euiExpressionValueStyles = ({}: UseEuiTheme) => {
return {
euiExpression__value: css``,
truncate: css`
${euiTextTruncate()}
display: inline-block;
vertical-align: bottom;
`,
columns: css`
flex-grow: 1;
`,
};
export const euiExpressionValueStyles = {
euiExpression__value: css``,
truncate: css`
${euiTextTruncate()}
display: inline-block;
vertical-align: bottom;
`,
columns: css`
flex-grow: 1;
`,
};

export const euiExpressionIconStyles = ({ euiTheme }: UseEuiTheme) => {
Expand Down
33 changes: 16 additions & 17 deletions packages/eui/src/components/expression/expression.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ import React, {
FunctionComponent,
} from 'react';
import classNames from 'classnames';

import { useEuiMemoizedStyles } from '../../services';
import { CommonProps, ExclusiveUnion } from '../common';
import { EuiIcon } from '../icon';
import { useEuiTheme } from '../../services';

import {
euiExpressionStyles,
euiExpressionDescriptionStyles,
euiExpressionValueStyles,
euiExpressionValueStyles as valueStyles,
euiExpressionIconStyles,
} from './expression.styles';

Expand Down Expand Up @@ -112,8 +113,7 @@ export const EuiExpression: FunctionComponent<
}) => {
const calculatedColor = isInvalid ? 'danger' : color;

const theme = useEuiTheme();
const styles = euiExpressionStyles(theme);
const styles = useEuiMemoizedStyles(euiExpressionStyles);
const cssStyles = [
styles.euiExpression,
onClick && styles.isClickable,
Expand All @@ -123,22 +123,23 @@ export const EuiExpression: FunctionComponent<
display === 'columns' && styles.columns,
textWrap === 'truncate' && styles.truncate,
];
const descriptionStyles = euiExpressionDescriptionStyles(theme);
const descriptionStyles = useEuiMemoizedStyles(
euiExpressionDescriptionStyles
);
const cssDescriptionStyles = [
descriptionStyles.euiExpression__description,
isInvalid ? descriptionStyles.danger : descriptionStyles[color],
uppercase && descriptionStyles.isUppercase,
textWrap === 'truncate' && descriptionStyles.truncate,
display === 'columns' && descriptionStyles.columns,
];
const valueStyles = euiExpressionValueStyles(theme);
const cssValueStyles = [
valueStyles.euiExpression__value,
textWrap === 'truncate' && valueStyles.truncate,
display === 'columns' && valueStyles.columns,
];

const iconStyles = euiExpressionIconStyles(theme);
const iconStyles = useEuiMemoizedStyles(euiExpressionIconStyles);
const cssIconStyles = [
iconStyles.euiExpression__icon,
display === 'columns' && iconStyles.columns,
Expand All @@ -153,15 +154,6 @@ export const EuiExpression: FunctionComponent<
? { flexBasis: descriptionWidth }
: undefined;

const invalidIcon = isInvalid ? (
<EuiIcon
className="euiExpression__icon"
type="warning"
css={cssIconStyles}
color={calculatedColor}
/>
) : undefined;

return (
<Component css={cssStyles} className={classes} onClick={onClick} {...rest}>
<span
Expand All @@ -184,7 +176,14 @@ export const EuiExpression: FunctionComponent<
{value}
</span>
)}
{invalidIcon}
{isInvalid && (
<EuiIcon
className="euiExpression__icon"
type="warning"
css={cssIconStyles}
color={calculatedColor}
/>
)}
</Component>
);
};
Loading
Loading