feat: list properties and method in table of content

This commit is contained in:
iCrawl
2022-08-22 14:30:15 +02:00
parent 9f18036078
commit e5678f4656
4 changed files with 30 additions and 8 deletions

View File

@@ -36,7 +36,7 @@ export function CodeListing({
inheritanceData?: InheritanceData | null; inheritanceData?: InheritanceData | null;
}) { }) {
return ( return (
<Stack spacing="xs" key={name}> <Stack id={name} className="scroll-mt-30" spacing="xs">
<Group> <Group>
{deprecation ? ( {deprecation ? (
<Badge variant="filled" color="red"> <Badge variant="filled" color="red">

View File

@@ -6,7 +6,7 @@ import { PrismAsyncLight as SyntaxHighlighter } from 'react-syntax-highlighter';
import { vscDarkPlus } from 'react-syntax-highlighter/dist/cjs/styles/prism'; import { vscDarkPlus } from 'react-syntax-highlighter/dist/cjs/styles/prism';
import { HyperlinkedText } from './HyperlinkedText'; import { HyperlinkedText } from './HyperlinkedText';
import { Section } from './Section'; import { Section } from './Section';
import { TableOfContentsItems } from './TableOfContentsItems'; import { TableOfContentItems } from './TableOfContentItems';
import { TypeParamTable } from './TypeParamTable'; import { TypeParamTable } from './TypeParamTable';
import { TSDoc } from './tsdoc/TSDoc'; import { TSDoc } from './tsdoc/TSDoc';
import type { ApiClassJSON, ApiItemJSON } from '~/DocModel/ApiNodeJSONEncoder'; import type { ApiClassJSON, ApiItemJSON } from '~/DocModel/ApiNodeJSONEncoder';
@@ -26,6 +26,7 @@ export interface DocContainerProps {
typeParams?: TypeParameterData[]; typeParams?: TypeParameterData[];
comment?: AnyDocNodeJSON | null; comment?: AnyDocNodeJSON | null;
methods?: ApiClassJSON['methods'] | null; methods?: ApiClassJSON['methods'] | null;
properties?: ApiClassJSON['properties'] | null;
} }
export function DocContainer({ export function DocContainer({
@@ -38,6 +39,7 @@ export function DocContainer({
extendsTokens, extendsTokens,
implementsTokens, implementsTokens,
methods, methods,
properties,
}: DocContainerProps) { }: DocContainerProps) {
const matches = useMediaQuery('(max-width: 768px)', true, { getInitialValueInEffect: false }); const matches = useMediaQuery('(max-width: 768px)', true, { getInitialValueInEffect: false });
@@ -102,7 +104,7 @@ export function DocContainer({
<Stack>{children}</Stack> <Stack>{children}</Stack>
</Stack> </Stack>
</Stack> </Stack>
{kind === 'Class' && methods ? ( {kind === 'Class' && methods && properties ? (
<MediaQuery smallerThan="md" styles={{ display: 'none' }}> <MediaQuery smallerThan="md" styles={{ display: 'none' }}>
<Aside <Aside
sx={{ backgroundColor: 'transparent' }} sx={{ backgroundColor: 'transparent' }}
@@ -111,7 +113,7 @@ export function DocContainer({
withBorder={false} withBorder={false}
> >
<ScrollArea p="xs"> <ScrollArea p="xs">
<TableOfContentsItems members={methods}></TableOfContentsItems> <TableOfContentItems properties={properties} methods={methods}></TableOfContentItems>
</ScrollArea> </ScrollArea>
</Aside> </Aside>
</MediaQuery> </MediaQuery>

View File

@@ -24,10 +24,26 @@ const useStyles = createStyles((theme) => ({
}, },
})); }));
export function TableOfContentsItems({ members }: { members: ApiClassJSON['methods'] | ApiInterfaceJSON['methods'] }) { export function TableOfContentItems({
methods,
properties,
}: {
methods: ApiClassJSON['methods'] | ApiInterfaceJSON['methods'];
properties: ApiClassJSON['properties'] | ApiInterfaceJSON['properties'];
}) {
const { classes } = useStyles(); const { classes } = useStyles();
const items = members.map((member) => { const propertyItems = properties.map((prop) => (
<Box<'a'> key={prop.name} href={`#${prop.name}`} component="a" className={classes.link}>
<Group>
<Text sx={{ textOverflow: 'ellipsis', overflow: 'hidden' }} className="line-clamp-1">
{prop.name}
</Text>
</Group>
</Box>
));
const methodItems = methods.map((member) => {
const key = `${member.name}${member.overloadIndex && member.overloadIndex > 1 ? `:${member.overloadIndex}` : ''}`; const key = `${member.name}${member.overloadIndex && member.overloadIndex > 1 ? `:${member.overloadIndex}` : ''}`;
return ( return (
@@ -50,9 +66,12 @@ export function TableOfContentsItems({ members }: { members: ApiClassJSON['metho
<Box> <Box>
<Group mb="md"> <Group mb="md">
<VscListSelection size={20} /> <VscListSelection size={20} />
<Text>Table of contents</Text> <Text>Table of content</Text>
</Group> </Group>
{items} <Text>Properties</Text>
{propertyItems}
<Text>Methods</Text>
{methodItems}
</Box> </Box>
); );
} }

View File

@@ -14,6 +14,7 @@ export function Class({ data }: { data: ApiClassJSON }) {
implementsTokens={data.implementsTokens} implementsTokens={data.implementsTokens}
comment={data.comment} comment={data.comment}
methods={data.methods} methods={data.methods}
properties={data.properties}
> >
{data.constructor ? <ConstructorSection data={data.constructor} /> : null} {data.constructor ? <ConstructorSection data={data.constructor} /> : null}
<PropertiesSection data={data.properties} /> <PropertiesSection data={data.properties} />