import React, { HTMLAttributes, FC, Children } from 'react'; import { classNames } from '../../lib/classNames'; import { getClassName } from '../../helpers/getClassName'; import { usePlatform } from '../../hooks/usePlatform'; import Caption from '../Typography/Caption/Caption'; import Text from '../Typography/Text/Text'; import { VKCOM } from '../../lib/platform'; import { hasReactNode } from '../../lib/utils'; interface CounterTypographyProps extends HTMLAttributes { size: CounterProps['size']; } const CounterTypography: FC = ({ size, children, ...restProps }: CounterTypographyProps) => { const platform = usePlatform(); if (size === 's') { const weight = platform === VKCOM ? 'medium' : 'regular'; return {children}; } return {children}; }; export interface CounterProps extends HTMLAttributes { /** * Тип счетчика. При использовании компонента в качестве значения свойства `after` у `Button` эти значения игнорируются */ mode?: 'secondary' | 'primary' | 'prominent'; size?: 's' | 'm'; } const Counter: FC = (props: CounterProps) => { const { mode, size, children, className, ...restProps } = props; const platform = usePlatform(); if (Children.count(children) === 0) { return null; } return (
{hasReactNode(children) && {children}}
); }; Counter.defaultProps = { mode: 'secondary', size: 'm', }; export default React.memo(Counter);