Skip to content

Commit

Permalink
Merge pull request #492 from WestpacGEL/483-design-system-docs-props-…
Browse files Browse the repository at this point in the history
…anchor-link

fixes #483 props anchor
  • Loading branch information
jaortiz authored Dec 8, 2023
2 parents 2503b0f + 4565bc7 commit 1004354
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,26 @@ import { type CodeContentProps } from '.';

export function CodeContent({ codeSections = [], westpacUIInfo, componentProps, subComponentProps }: CodeContentProps) {
const sectionNames = useMemo(() => {
return codeSections?.filter(({ noTitle }) => !noTitle).map(({ title }) => ({ title })) || [];
const sections = codeSections?.filter(({ noTitle }) => !noTitle).map(({ title }) => ({ title }));
if (sections.length > 0) {
return [...sections, { title: 'Props' }];
}
return [];
}, [codeSections]);

const sectionHeadings = useMemo(() => {
return (
codeSections.reduce((acc, section) => {
return section.content?.reduce((acc, item: DocumentElement & { level?: number }) => {
if (item.type === 'heading' && item?.level && item.level <= 3) {
return [...acc, { title: item.children[0].text as string }];
}
return acc;
}, acc);
}, [] as { title: string }[]) || []
);
const sections = codeSections.reduce((acc, section) => {
return section.content?.reduce((acc, item: DocumentElement & { level?: number }) => {
if (item.type === 'heading' && item?.level && item.level <= 3) {
return [...acc, { title: item.children[0].text as string }];
}
return acc;
}, acc);
}, [] as { title: string }[]);
if (sections.length > 0) {
return [...sections, { title: 'Props' }];
}
return [];
}, [codeSections]);

return (
Expand Down
2 changes: 1 addition & 1 deletion apps/site/src/app/design-system/[...component]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default async function ComponentLayout({
<>
<Header title={content.name} />
<div className="flex flex-1 flex-col p-5">
<div className="-m-5 flex flex-1 flex-col">{children}</div>
<div className="-m-5 flex flex-1 flex-col bg-background">{children}</div>
</div>
</>
);
Expand Down

0 comments on commit 1004354

Please sign in to comment.