'use client'; import * as React from 'react'; import { classNames } from '@vkontakte/vkjs'; import { useAdaptivity } from '../../hooks/useAdaptivity'; import { Tappable, type TappableOmitProps } from '../Tappable/Tappable'; import { Subhead } from '../Typography/Subhead/Subhead'; import { RichCellIcon } from './RichCellIcon/RichCellIcon'; import styles from './RichCell.module.css'; const sizeYClassNames = { none: styles.sizeYNone, compact: styles.sizeYCompact, }; const alignAfterClassNames = { start: styles.alignAfterStart, center: styles.alignAfterCenter, end: styles.alignAfterEnd, }; const alignBeforeClassNames = { start: styles.alignBeforeStart, center: styles.alignBeforeCenter, end: styles.alignBeforeEnd, }; const alignContentClassNames = { start: styles.contentAlignStart, center: styles.contentAlignCenter, end: styles.contentAlignEnd, }; type Align = 'start' | 'center' | 'end'; export interface RichCellProps extends TappableOmitProps { /** * Контейнер для текста над `children`. */ overTitle?: React.ReactNode; /** * Контейнер для текста под `children`. */ subtitle?: React.ReactNode; /** * Контейнер для текста под `subtitle`. */ extraSubtitle?: React.ReactNode; /** * Контейнер для контента под `caption`. Например ``. */ bottom?: React.ReactNode; /** * Кнопки-действия. Принимает [`Button`](https://vkui.io/components/button) с параметрами: * * - `mode="primary" size="s"` * - `mode="secondary" size="s"`. * * Для набора кнопок используйте [`ButtonGroup`](https://vkui.io/components/button-group) с параметрами: * * - `mode="horizontal" gap="s" stretched`. */ actions?: React.ReactNode; /** * ``. */ before?: React.ReactNode; /** * Иконка 28 или текст. */ after?: React.ReactNode; /** * Текст под `after`. */ afterCaption?: React.ReactNode; /** * Выравнивание before компонента по вертикали. */ beforeAlign?: Align; /** * Выравнивание центрального контента по вертикали. */ contentAlign?: Align; /** * Выравнивание after компонента по вертикали. */ afterAlign?: Align; /** * Блокировка взаимодействия с компонентом. Убирает анимацию нажатия. */ disabled?: boolean; /** * Включает многострочный режим для `subhead`, `children`, `text` и `caption`. */ multiline?: boolean; } /** * @see https://vkui.io/components/rich-cell */ export const RichCell: React.FC & { Icon: typeof RichCellIcon; } = ({ overTitle, children, subtitle, extraSubtitle, before, after, afterCaption, bottom, actions, multiline, beforeAlign = 'start', contentAlign = 'start', afterAlign = 'start', ...restProps }: RichCellProps) => { const { sizeY = 'none' } = useAdaptivity(); const withAfter = after || afterCaption; const afterRender = () => { if (!withAfter) { return; } return ( {after && {after}} {afterCaption && {afterCaption}} ); }; return ( {before && {before}} {overTitle && ( {overTitle} )} {children} {subtitle && {subtitle}} {extraSubtitle && ( {extraSubtitle} )} {afterAlign === 'start' && afterRender()} {bottom && {bottom}} {actions && {actions}} {afterAlign !== 'start' && afterRender()} ); }; RichCell.Icon = RichCellIcon;