diff --git a/src/card/card.tsx b/src/card/card.tsx index 38c1136a63..859d2715fa 100644 --- a/src/card/card.tsx +++ b/src/card/card.tsx @@ -1,10 +1,8 @@ /* Copyright (c) Uber Technologies, Inc. - This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree. */ - import * as React from 'react'; import { getOverride, getOverrideProps } from '../helpers/overrides'; import { LevelContext } from '../heading'; @@ -17,22 +15,23 @@ import { Thumbnail as StyledThumbnail, Title as StyledTitle, } from './styled-components'; - import type { CardProps } from './types'; export function hasThumbnail(props: { readonly thumbnail?: string }) { return !!props.thumbnail; } +// Hoisted out of SemanticTitle so this array literal is allocated once at +// module load instead of on every render of every Card's title. +const HEADING_LEVELS = ['', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6']; + // @ts-ignore const SemanticTitle = ({ children, ...restProps }) => { - const levels = ['', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6']; - return ( {(level) => ( // @ts-expect-error - + {children} )} @@ -51,7 +50,6 @@ function Card(props: CardProps) { overrides, ...restProps } = props; - const { Action: ActionOverride, Body: BodyOverride, @@ -61,7 +59,6 @@ function Card(props: CardProps) { Thumbnail: ThumbnailOverride, Title: TitleOverride, } = overrides; - const Action = getOverride(ActionOverride) || StyledAction; const Body = getOverride(BodyOverride) || StyledBody; const Contents = getOverride(ContentsOverride) || StyledContents; @@ -69,9 +66,7 @@ function Card(props: CardProps) { const Root = getOverride(RootOverride) || StyledRoot; const Thumbnail = getOverride(ThumbnailOverride) || StyledThumbnail; const Title = getOverride(TitleOverride) || SemanticTitle; - const headerImageProps = typeof headerImage === 'string' ? { src: headerImage } : headerImage; - // @ts-ignore const $hasThumbnail = hasThumbnail(props); return (