import { Stack } from '@mobily/stacks'; import React, { Children, FunctionComponentElement, PropsWithChildren } from 'react'; import { BODY_HZ_SPACING, BODY_PARAGRAPH_SPACING } from '../constants'; import { useColorRoles } from '../theme/colorSystem'; import BodyDividerAtom from './BodyDividerAtom'; import BodySectionMolecule, { BodySectionMoleculeProps } from './BodySectionMolecule'; import MaxWidthContainerAtom from './MaxWidthContainerAtom'; import BoxNucleon from './nucleons/BoxNucleon'; import TextRoleNucleon from './nucleons/TextRoleNucleon'; import { PropsWithStyle } from './nucleons/types'; import { useScroller } from './templates/ArticleTemplate/ScrollerProvider'; import { View } from 'react-native'; function isBodySectionElement( candidate: unknown ): candidate is FunctionComponentElement { return ( typeof candidate === 'object' && candidate != null && (candidate as any).type === BodySectionMolecule ); } function BodyHeader({ children, style, prefix }: PropsWithStyle>) { const { surface } = useColorRoles(); const color = surface.content; return ( Chapter {prefix} {children} ); } export type BodyChapterMoleculeProps = PropsWithChildren< PropsWithStyle<{ title: string; prefix?: string }> >; export default function BodyChapterMolecule({ title, style, prefix, children }: BodyChapterMoleculeProps) { const scrollIndex = useScroller(); return ( {title} {Children.map(children, (c) => { if (isBodySectionElement(c)) { return ( { scrollIndex.registerLayout(e, c.props.title!); }}> {c} ); } return c; })} ); }