'use client'; import * as React from 'react'; import { classNames } from '@vkontakte/vkjs'; import { getNavId, type NavIdProps } from '../../lib/getNavId'; import { warnOnce } from '../../lib/warnOnce'; import type { HTMLAttributesWithRootRef } from '../../types'; import { RootComponent } from '../RootComponent/RootComponent'; import { ScrollSaver } from './ScrollSaver'; import styles from './Epic.module.css'; export interface EpicProps extends HTMLAttributesWithRootRef { /** * Компонент Tabbar, который будет отображаться снизу. */ tabbar?: React.ReactNode | undefined; /** * `id` активного окна. */ activeStory: string; /** * Внутри `Epic` может находиться либо коллекция `Root`, * либо коллекция `View`. У каждого элемента коллекции должен быть уникальный `id`. */ children: React.ReactElement | Iterable; } const warn = warnOnce('Epic'); /** * @see https://vkui.io/components/epic */ export const Epic = ({ activeStory, tabbar, children, ...restProps }: EpicProps): React.ReactNode => { const [scroll] = React.useState(() => new Map()); const story = (React.Children.toArray(children).find( (story) => React.isValidElement(story) && getNavId((story as React.ReactElement).props, warn) === activeStory, ) as Array> | undefined) ?? null; return ( { scroll.set(activeStory, value); }} > {story} {tabbar} ); };