import * as React from 'react'; import { classNames } from '@vkontakte/vkjs'; import { mergeStyle } from '../../helpers/mergeStyle'; import type { CSSCustomProperties, HTMLAttributesWithRootRef } from '../../types'; import { Caption } from '../Typography/Caption/Caption'; import { Headline } from '../Typography/Headline/Headline'; import styles from './Counter.module.css'; import panelHeaderButtonStylesGlobal from '../PanelHeaderButton/PanelHeaderButton.global.module.css'; import tabbarStylesGlobal from '../TabbarItem/TabbarItem.global.module.css'; const modeClassNames = { primary: styles.modePrimary, contrast: styles.modeContrast, tertiary: styles.modeTertiary, inherit: styles.modeInherit, }; const appearanceClassNames: Record = { 'custom': styles.appearanceCustom, 'accent': styles.appearanceAccent, 'neutral': styles.appearanceNeutral, 'accent-green': styles.appearanceAccentGreen, 'accent-red': styles.appearanceAccentRed, }; const sizeClassNames = { s: styles.sizeS, m: styles.sizeM, }; export interface CounterProps extends HTMLAttributesWithRootRef { /** * Режим отображения счетчика. */ mode?: 'primary' | 'contrast' | 'tertiary' | 'inherit' | undefined; /** * Внешний вид счетчика. */ appearance?: 'accent' | 'neutral' | 'accent-green' | 'accent-red' | 'custom' | undefined; /** * Пользовательский цвет (работает только при appearance="custom") * - При mode="primary" - изменяет фон * - При mode="contrast" - изменяет цвет текста * - При mode="tertiary" - изменяет цвет текста * - При mode="inherit" - не работает. */ color?: string | undefined; /** * Размер счетчика. */ size?: 's' | 'm' | undefined; } /** * @see https://vkui.io/components/counter */ export const Counter = ({ mode = 'inherit', appearance: appearanceProp, color, size = 'm', children, className, style: styleProp, ...restProps }: CounterProps): React.ReactNode => { const appearance = mode === 'inherit' ? undefined : appearanceProp || 'accent'; let style: (React.CSSProperties & CSSCustomProperties) | undefined; if (mode !== 'inherit' && appearance === 'custom' && color) { style = mode === 'primary' ? { '--vkui_internal--counter_background': color } : { '--vkui_internal--counter_foreground': color }; } if (React.Children.count(children) === 0) { return null; } const CounterTypography = size === 's' ? Caption : Headline; const counterLevel = size === 's' ? '1' : '2'; return ( {children} ); };