import React from 'react';
import { Box, Grid, color, space, BoxProps } from '@stacks/ui';
import { slugify } from '@common/utils';
import { Text } from '@components/typography';
import { Link } from '@components/mdx';
import { useActiveHeading } from '@common/hooks/use-active-heading';
import NextLink from 'next/link';
import { getHeadingStyles } from '@components/mdx/typography';
const getLevelPadding = (level: number) => {
switch (level) {
case 2:
return space('base');
case 3:
return space('base-loose');
default:
return 0;
}
};
const Item = ({
slug,
label,
level,
limit,
}: {
slug: string;
label: string;
level: number;
limit?: boolean;
}) => {
const { isActive: _isActive, slugInView } = useActiveHeading(slug);
const isOnScreen = slugInView === slug;
const isActive = isOnScreen || _isActive;
const adjustedLevel = level - 2;
const shouldRender = limit ? adjustedLevel > 0 && adjustedLevel <= 1 : true;
return shouldRender ? (
) : null;
};
export const TableOfContents = ({
headings,
noLabel,
label = 'On this page',
columns = 1,
display,
limit,
...rest
}: {
headings?: {
content: string;
level: number;
}[];
noLabel?: boolean;
label?: string;
limit?: boolean;
columns?: number | number[];
} & BoxProps) => {
return (
{!noLabel && (
{label}
)}
`repeat(${value}, 1fr)`)
: `repeat(${columns}, 1fr)`
}
>
{headings?.map((heading, index) => {
return (
);
})}
);
};