Skip to content

Commit

Permalink
feat(HorizontalCell): add titleComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackySoul committed Nov 26, 2024
1 parent e89e14b commit 5cf983c
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions packages/vkui/src/components/HorizontalCell/HorizontalCell.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import * as React from 'react';
import { classNames, hasReactNode } from '@vkontakte/vkjs';
import { mergeStyle } from '../../helpers/mergeStyle';
import type {
CSSCustomProperties,
HasRef,
HasRootRef,
HTMLAttributesWithRootRef,
LiteralUnion,
} from '../../types';
import type { CSSCustomProperties, HasRef, HasRootRef, LiteralUnion } from '../../types';
import { Avatar } from '../Avatar/Avatar';
import { Tappable, type TappableProps } from '../Tappable/Tappable';
import { Caption } from '../Typography/Caption/Caption';
Expand All @@ -32,18 +26,6 @@ const textAlignClassNames = {

type HorizontalCellSizes = 's' | 'm' | 'l' | 'xl' | 'auto';

interface CellTypographyProps extends HTMLAttributesWithRootRef<HTMLDivElement> {
size: HorizontalCellProps['size'];
}

const CellTypography = ({ size, children, ...restProps }: CellTypographyProps) => {
return size === 's' ? (
<Caption {...restProps}>{children}</Caption>
) : (
<Subhead {...restProps}>{children}</Subhead>
);
};

export interface HorizontalCellProps
extends Omit<TappableProps, 'size' | 'getRootRef' | 'title' | 'borderRadiusMode'>,
HasRootRef<HTMLDivElement>,
Expand Down Expand Up @@ -78,6 +60,8 @@ export interface HorizontalCellProps
* Актуально для использования в многострочных списках
*/
noPadding?: boolean;
/* Позволяет поменять тег, используемый для `title` */
TitleComponent?: React.ElementType;
}

/**
Expand All @@ -95,6 +79,7 @@ export const HorizontalCell = ({
extraSubtitle,
textAlign = size === 's' ? 'center' : 'start',
noPadding = false,
TitleComponent = size === 's' ? Caption : Subhead,
...restProps
}: HorizontalCellProps): React.ReactNode => {
const hasTypography =
Expand Down Expand Up @@ -125,7 +110,7 @@ export const HorizontalCell = ({
textAlign !== 'start' && textAlignClassNames[textAlign],
)}
>
{hasReactNode(title) && <CellTypography size={size}>{title}</CellTypography>}
{hasReactNode(title) && <TitleComponent>{title}</TitleComponent>}
{hasReactNode(subtitle) && <Footnote className={styles.subtitle}>{subtitle}</Footnote>}
{hasReactNode(extraSubtitle) && (
<Footnote className={styles.subtitle}>{extraSubtitle}</Footnote>
Expand Down

0 comments on commit 5cf983c

Please sign in to comment.