'use client'; import * as React from 'react'; import { classNames, hasReactNode } from '@vkontakte/vkjs'; import { useAdaptivity } from '../../hooks/useAdaptivity'; import { usePlatform } from '../../hooks/usePlatform'; import type { HasChildren, HTMLAttributesWithRootRef } from '../../types'; import { RootComponent } from '../RootComponent/RootComponent'; import { Tappable } from '../Tappable/Tappable'; import { Footnote } from '../Typography/Footnote/Footnote'; import { Text } from '../Typography/Text/Text'; import styles from './PanelHeaderContent.module.css'; const platformClassNames = { ios: styles.ios, android: styles.android, vkcom: styles.vkcom, }; const sizeYClassNames = { none: styles.sizeYNone, compact: styles.sizeYCompact, }; export interface PanelHeaderContentProps extends HTMLAttributesWithRootRef { /** * Компонент отображаемый после содержимого. */ aside?: React.ReactNode; /** * Компонент отображаемый до содержимого. */ before?: React.ReactNode; /** * Подпись под основным текстом. */ subtitle?: React.ReactNode; } interface PanelHeaderChildrenProps extends HasChildren { /** * Есть ли подпись. */ hasSubtitle: boolean; /** * Есть ли `before`. */ hasBefore: boolean; } const PanelHeaderChildren = ({ hasSubtitle, hasBefore, children }: PanelHeaderChildrenProps) => { const platform = usePlatform(); return hasSubtitle || hasBefore ? ( {children} ) : (
{children}
); }; /** * @see https://vkui.io/components/panel-header#panel-header-content */ export const PanelHeaderContent = ({ aside, subtitle, before, children, onClick, ...restProps }: PanelHeaderContentProps): React.ReactNode => { const { sizeY = 'none' } = useAdaptivity(); const InComponent = onClick ? Tappable : 'div'; const rootProps = onClick ? {} : restProps; const platform = usePlatform(); const inProps = onClick ? { ...restProps, onClick, activeEffectDelay: 200, hasActive: platform === 'ios', activeMode: 'opacity', } : {}; return ( {hasReactNode(before) &&
{before}
} {hasReactNode(subtitle) && {subtitle}}
{children} {hasReactNode(aside) &&
{aside}
}
{hasReactNode(before) &&
} ); };