'use client'; import type * as React from 'react'; import { classNames } from '@vkontakte/vkjs'; import { mergeStyle } from '../../helpers/mergeStyle'; import { useRootRef } from '../../hooks/useExternRef'; import type { HasComponent, HasRender, HasRootRef } from '../../types'; import styles from './RootComponent.module.css'; export type RootComponentProps = React.AllHTMLAttributes & HasRootRef & HasComponent & HasRender; export interface RootComponentExtendProps { /** * Базовый класс. */ baseClassName?: string | false | undefined; /** * Базовые стили. */ baseStyle?: React.CSSProperties | undefined; } export interface RootComponentInternalProps extends RootComponentProps, RootComponentExtendProps {} interface RenderRootComponentProps extends Omit, 'render' | 'ref'> { /** * Функция кастомного рендера. См. `RootComponentProps['render']`. */ render: NonNullable['render']>; } const RenderRootComponent = ({ render, getRootRef, ...restProps }: RenderRootComponentProps): React.ReactNode => render({ ...restProps, getRootRef }); /** * Базовый корневой компонент. */ export const RootComponent = ({ Component = 'div', baseClassName, className, baseStyle, style, getRootRef: getRootRefProp, ref: refProp, render, ...restProps }: RootComponentInternalProps): React.ReactNode => { const getRootRef = useRootRef(getRootRefProp, refProp); const resolvedProps = { className: classNames( className, baseClassName, styles.host, restProps.hidden === true && styles.hidden, ), style: mergeStyle(baseStyle, style), ...restProps, }; if (render) { return ( ); } return ; };