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 EuiSkeleton components #7562

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 2 additions & 3 deletions src/components/skeleton/skeleton_circle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import React, { FunctionComponent, HTMLAttributes } from 'react';
import classNames from 'classnames';

import { useEuiMemoizedStyles } from '../../services';
import { CommonProps } from '../common';
import { useEuiTheme } from '../../services';

import { EuiSkeletonLoading, _EuiSkeletonAriaProps } from './skeleton_loading';
import { euiSkeletonCircleStyles } from './skeleton_circle.styles';
Expand All @@ -36,8 +36,7 @@ export const EuiSkeletonCircle: FunctionComponent<EuiSkeletonCircleProps> = ({
children,
...rest
}) => {
const euiTheme = useEuiTheme();
const styles = euiSkeletonCircleStyles(euiTheme);
const styles = useEuiMemoizedStyles(euiSkeletonCircleStyles);
const cssStyles = [styles.euiSkeletonCircle, styles[size]];

return (
Expand Down
5 changes: 2 additions & 3 deletions src/components/skeleton/skeleton_rectangle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import React, { FunctionComponent, HTMLAttributes } from 'react';
import classNames from 'classnames';

import { useEuiMemoizedStyles } from '../../services';
import { CommonProps } from '../common';
import { useEuiTheme } from '../../services';
import { logicalStyles } from '../../global_styling';

import { EuiSkeletonLoading, _EuiSkeletonAriaProps } from './skeleton_loading';
Expand Down Expand Up @@ -44,8 +44,7 @@ export const EuiSkeletonRectangle: FunctionComponent<
children,
...rest
}) => {
const euiTheme = useEuiTheme();
const styles = euiSkeletonRectangleStyles(euiTheme);
const styles = useEuiMemoizedStyles(euiSkeletonRectangleStyles);
const cssStyles = [styles.euiSkeletonRectangle, styles[borderRadius]];

return (
Expand Down
23 changes: 14 additions & 9 deletions src/components/skeleton/skeleton_text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
* Side Public License, v 1.
*/

import React, { FunctionComponent, HTMLAttributes } from 'react';
import React, { FunctionComponent, HTMLAttributes, useMemo } from 'react';
import classNames from 'classnames';

import { useEuiMemoizedStyles } from '../../services';
import { CommonProps } from '../common';
import { useEuiTheme } from '../../services';
import { TextSize } from '../text/text';

import { EuiSkeletonLoading, _EuiSkeletonAriaProps } from './skeleton_loading';
Expand Down Expand Up @@ -45,14 +45,19 @@ export const EuiSkeletonText: FunctionComponent<EuiSkeletonTextProps> = ({
children,
...rest
}) => {
const euiTheme = useEuiTheme();
const styles = euiSkeletonTextStyles(euiTheme);
const lineCssStyles = [styles.euiSkeletonText, styles[size]];
const styles = useEuiMemoizedStyles(euiSkeletonTextStyles);
const cssStyles = useMemo(
() => [styles.euiSkeletonText, styles[size]],
[styles, size]
);

const lineElements = [];
for (let i = 0; i < lines; i++) {
lineElements.push(<span key={i} css={lineCssStyles} />);
}
const lineElements = useMemo(() => {
const lineElements = [];
for (let i = 0; i < lines; i++) {
lineElements.push(<span key={i} css={cssStyles} />);
}
return lineElements;
}, [lines, cssStyles]);

return (
<EuiSkeletonLoading
Expand Down
5 changes: 2 additions & 3 deletions src/components/skeleton/skeleton_title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import React, { FunctionComponent, HTMLAttributes } from 'react';
import classNames from 'classnames';

import { useEuiMemoizedStyles } from '../../services';
import { CommonProps } from '../common';
import { useEuiTheme } from '../../services';
import { EuiTitleSize } from '../title';

import { EuiSkeletonLoading, _EuiSkeletonAriaProps } from './skeleton_loading';
Expand All @@ -37,8 +37,7 @@ export const EuiSkeletonTitle: FunctionComponent<EuiSkeletonTitleProps> = ({
children,
...rest
}) => {
const euiTheme = useEuiTheme();
const styles = euiSkeletonTitleStyles(euiTheme);
const styles = useEuiMemoizedStyles(euiSkeletonTitleStyles);
const cssStyles = [styles.euiSkeletonTitle, styles[size]];

return (
Expand Down
Loading