import React, { FunctionComponent, HTMLAttributes, ReactNode, Fragment } from 'react'; import { getClassName } from '../../helpers/getClassName'; import { classNames } from '../../lib/classNames'; import { usePlatform } from '../../hooks/usePlatform'; import { HasPlatform, HasRootRef } from '../../types'; import { hasReactNode, isPrimitiveReactNode } from '../../lib/utils'; import { Platform, PlatformType } from '../../lib/platform'; import Headline from '../Typography/Headline/Headline'; import Caption from '../Typography/Caption/Caption'; import Title from '../Typography/Title/Title'; import Text from '../Typography/Text/Text'; import Subhead from '../Typography/Subhead/Subhead'; export interface HeaderProps extends HTMLAttributes, HasRootRef { mode?: 'primary' | 'secondary' | 'tertiary'; subtitle?: ReactNode; /** * Допускаются иконки, текст, Link */ aside?: ReactNode; /** * Допускаются текст, Indicator */ indicator?: ReactNode; multiline?: boolean; } function renderChildren({ children, platform, mode }: Pick & HasPlatform) { switch (platform) { case Platform.ANDROID: switch (mode) { case 'primary': return {children}; case 'secondary': return {children}; case 'tertiary': return {children}; } break; case Platform.IOS: switch (mode) { case 'primary': case 'tertiary': return {children}; case 'secondary': return {children}; } break; case Platform.VKCOM: switch (mode) { case 'primary': return {children}; case 'secondary': case 'tertiary': return {children}; } } } function renderAside({ aside, platform }: { aside: HeaderProps['aside']; platform: PlatformType }) { if (platform === Platform.VKCOM) { return {aside}; } return {aside}; } const Header: FunctionComponent = ({ className, mode, children, subtitle, indicator, aside, getRootRef, multiline, ...restProps }: HeaderProps) => { const platform = usePlatform(); const baseClassNames = getClassName('Header', platform); return (
{renderChildren({ children: (
{children}
{hasReactNode(indicator) && {indicator}}
), platform, mode, })} {hasReactNode(subtitle) && {subtitle}}
{hasReactNode(aside) && renderAside({ aside, platform })}
); }; Header.defaultProps = { mode: 'primary', }; export default Header;