|
1 | 1 | import * as React from "react"; |
2 | 2 | import { classNames } from "../../lib/classNames"; |
3 | | -import { getClassName } from "../../helpers/getClassName"; |
4 | | -import { usePlatform } from "../../hooks/usePlatform"; |
5 | 3 | import { Caption } from "../Typography/Caption/Caption"; |
6 | | -import { Text } from "../Typography/Text/Text"; |
7 | | -import { VKCOM } from "../../lib/platform"; |
| 4 | +import { Headline } from "../Typography/Headline/Headline"; |
8 | 5 | import { hasReactNode } from "../../lib/utils"; |
9 | | -import { HasComponent, HasPlatform } from "../../types"; |
10 | 6 | import "./Counter.css"; |
11 | 7 |
|
12 | 8 | export interface CounterProps extends React.HTMLAttributes<HTMLSpanElement> { |
13 | 9 | /** |
14 | 10 | * Тип счетчика. При использовании компонента в качестве значения свойства `after` у `Button` эти значения игнорируются |
15 | 11 | */ |
16 | | - mode?: "secondary" | "primary" | "prominent"; |
| 12 | + mode?: "secondary" | "primary" | "prominent" | "contrast"; |
17 | 13 | size?: "s" | "m"; |
18 | 14 | } |
19 | 15 |
|
20 | | -type CounterTypographyProps = Pick<CounterProps, "size"> & |
21 | | - HasPlatform & |
22 | | - HasComponent; |
23 | | - |
24 | | -const CounterTypography: React.FC<CounterTypographyProps> = ({ |
25 | | - size, |
26 | | - platform, |
27 | | - ...restProps |
28 | | -}) => { |
29 | | - return size === "s" ? ( |
30 | | - <Caption |
31 | | - level="2" |
32 | | - weight={platform === VKCOM ? "1" : undefined} |
33 | | - {...restProps} |
34 | | - /> |
35 | | - ) : ( |
36 | | - <Text weight="2" {...restProps} /> |
37 | | - ); |
38 | | -}; |
39 | | - |
40 | 16 | /** |
41 | 17 | * @see https://vkcom.github.io/VKUI/#/Counter |
42 | 18 | */ |
43 | | -const Counter: React.FC<CounterProps> = (props: CounterProps) => { |
44 | | - const { mode, size, children, ...restProps } = props; |
45 | | - const platform = usePlatform(); |
46 | | - |
| 19 | +export const Counter = ({ |
| 20 | + mode = "secondary", |
| 21 | + size = "m", |
| 22 | + children, |
| 23 | + ...restProps |
| 24 | +}: CounterProps) => { |
47 | 25 | if (React.Children.count(children) === 0) { |
48 | 26 | return null; |
49 | 27 | } |
50 | 28 |
|
| 29 | + const CounterTypography = size === "s" ? Caption : Headline; |
| 30 | + |
51 | 31 | return ( |
52 | 32 | <span |
53 | 33 | {...restProps} |
54 | 34 | vkuiClass={classNames( |
55 | | - getClassName("Counter", platform), |
| 35 | + "Counter", |
56 | 36 | `Counter--${mode}`, |
57 | 37 | `Counter--s-${size}` |
58 | 38 | )} |
59 | 39 | > |
60 | 40 | {hasReactNode(children) && ( |
61 | | - <CounterTypography |
62 | | - platform={platform} |
63 | | - size={size} |
64 | | - vkuiClass="Counter__in" |
65 | | - > |
| 41 | + <CounterTypography Component="span" vkuiClass="Counter__in" level="2"> |
66 | 42 | {children} |
67 | 43 | </CounterTypography> |
68 | 44 | )} |
69 | 45 | </span> |
70 | 46 | ); |
71 | 47 | }; |
72 | | - |
73 | | -Counter.defaultProps = { |
74 | | - mode: "secondary", |
75 | | - size: "m", |
76 | | -}; |
77 | | - |
78 | | -// eslint-disable-next-line import/no-default-export |
79 | | -export default React.memo(Counter); |
0 commit comments