import React, { ReactNode, FC, ElementType, HTMLAttributes } from 'react'; import { classNames } from '../../lib/classNames'; import { getClassName } from '../../helpers/getClassName'; import Tappable, { TappableProps } from '../Tappable/Tappable'; import { Icon24Chevron } from '@vkontakte/icons'; import { IOS } from '../../lib/platform'; import { usePlatform } from '../../hooks/usePlatform'; import { hasReactNode } from '../../lib/utils'; import { withAdaptivity, SizeType, AdaptivityProps } from '../../hoc/withAdaptivity'; import Title from '../Typography/Title/Title'; import Text from '../Typography/Text/Text'; import Caption from '../Typography/Caption/Caption'; interface SimpleCellTypographyProps extends HTMLAttributes, AdaptivityProps {} const SimpleCellTypography: FC = withAdaptivity((props: SimpleCellTypographyProps) => { const { sizeY, children, ...restProps } = props; if (sizeY === SizeType.COMPACT) { return {children}; } return {children}; }, { sizeY: true }); export interface SimpleCellOwnProps { /** * Иконка 28 или `` */ before?: ReactNode; /** * Иконка 12 или ``. Добавится справа от текста `children`. */ badge?: ReactNode; /** * Контейнер для текста справа от `children`. */ indicator?: ReactNode; /** * Иконка 24|28 или ``. Располагается справа от `indicator`. */ after?: ReactNode; /** * Контейнер для текста под `children`. */ description?: ReactNode; /** * Убирает анимацию нажатия */ disabled?: boolean; /** * В iOS добавляет chevron справа. Передавать `true`, если предполагается переход при клике по ячейке. */ expandable?: boolean; multiline?: boolean; Component?: ElementType; } export interface SimpleCellProps extends SimpleCellOwnProps, TappableProps {} const SimpleCell: FC = ({ badge, before, indicator, children, after, description, className, expandable, multiline, Component, onClick, sizeY, ...restProps }) => { const platform = usePlatform(); const hasAfter = hasReactNode(after) || expandable && platform === IOS; const RootComponent = restProps.disabled ? Component : Tappable; const props: SimpleCellProps = restProps; if (!restProps.disabled) { props.Component = restProps.href ? 'a' : Component; props.onClick = onClick; } return ( {before}
{children} {hasReactNode(badge) && {badge} }
{description && {description}}
{hasReactNode(indicator) && {indicator} } {hasAfter &&
{after} {expandable && platform === IOS && }
}
); }; SimpleCell.defaultProps = { Component: 'div', }; export default withAdaptivity(SimpleCell, { sizeY: true });