Skip to content

Commit

Permalink
[docs-infra] Fix anchor links in API pages (#40450)
Browse files Browse the repository at this point in the history
Co-authored-by: alexandre <[email protected]>
  • Loading branch information
oliviertassinari and alexfauquette authored Jan 8, 2024
1 parent c7788e9 commit f8e820a
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 29 deletions.
2 changes: 1 addition & 1 deletion docs/src/modules/components/ApiPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export default function ApiPage(props) {
<PropertiesSection
properties={componentProps}
propertiesDescriptions={propDescriptions}
targetName={pageContent.name}
componentName={pageContent.name}
spreadHint={spreadHint}
/>
{cssComponent && (
Expand Down
12 changes: 7 additions & 5 deletions docs/src/modules/components/ApiPage/list/ClassesList.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable react/no-danger */
import * as React from 'react';
import { styled } from '@mui/material/styles';
import kebabCase from 'lodash/kebabCase';
import { ComponentClassDefinition } from '@mui-internal/docs-utilities';
import { useTranslate } from 'docs/src/modules/utils/i18n';
import ExpandableApiItem, {
Expand Down Expand Up @@ -34,17 +35,18 @@ const StyledApiItem = styled(ExpandableApiItem)(
}),
);

type HashParams = { componentName: string; className: string };

export function getHash({ componentName, className }: HashParams) {
return `${kebabCase(componentName)}-classes-${className}`;
}

type ClassesListProps = {
componentName: string;
classes: ComponentClassDefinition[];
displayOption: 'collapsed' | 'expanded';
displayClassKeys?: boolean;
};
type HashParams = { componentName?: string; className: string };

export function getHash({ componentName, className }: HashParams) {
return `${componentName ? `${componentName}-` : ''}classes-${className}`;
}

export default function ClassesList(props: ClassesListProps) {
const { classes, displayOption, componentName, displayClassKeys } = props;
Expand Down
13 changes: 7 additions & 6 deletions docs/src/modules/components/ApiPage/list/PropertiesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as React from 'react';
import { styled } from '@mui/material/styles';
import Alert from '@mui/material/Alert';
import WarningRoundedIcon from '@mui/icons-material/WarningRounded';
import kebabCase from 'lodash/kebabCase';
import { useTranslate } from 'docs/src/modules/utils/i18n';
import {
brandingDarkTheme as darkTheme,
Expand Down Expand Up @@ -99,12 +100,12 @@ function PropDescription(props: { description: string }) {
}

export function getHash({
targetName,
componentName,
propName,
hooksParameters,
hooksReturnValue,
}: {
targetName: string;
componentName: string;
propName: string;
hooksParameters?: boolean;
hooksReturnValue?: boolean;
Expand All @@ -115,11 +116,11 @@ export function getHash({
} else if (hooksReturnValue) {
sectionName = 'return-value';
}
return `${targetName ? `${targetName}-` : ''}${sectionName}-${propName}`;
return `${kebabCase(componentName)}-${sectionName}-${propName}`;
}

export interface PropDescriptionParams {
targetName: string;
componentName: string;
propName: string;
description?: string;
requiresRef?: string;
Expand Down Expand Up @@ -149,7 +150,7 @@ export default function PropertiesList(props: PropertiesListProps) {
<ApiItemContaier>
{properties.map((params) => {
const {
targetName,
componentName,
propName,
description,
requiresRef,
Expand All @@ -169,7 +170,7 @@ export default function PropertiesList(props: PropertiesListProps) {
return (
<StyledApiItem
key={propName}
id={getHash({ targetName, propName, hooksParameters, hooksReturnValue })}
id={getHash({ componentName, propName, hooksParameters, hooksReturnValue })}
title={propName}
note={(isOptional && 'Optional') || (isRequired && 'Required') || ''}
type="props"
Expand Down
14 changes: 7 additions & 7 deletions docs/src/modules/components/ApiPage/list/SlotsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ const StyledApiItem = styled(ExpandableApiItem)(
}),
);

type HashParams = { componentName: string; className: string };

export function getHash({ componentName, className }: HashParams) {
return `${componentName}-css-${className}`;
}

export type SlotsFormatedParams = {
className: string;
componentName?: string;
componentName: string;
description?: string;
name: string;
defaultValue?: string;
};

type HashParams = { componentName?: string; className: string };

export function getHash({ componentName, className }: HashParams) {
return `${componentName ? `${componentName}-` : ''}css-${className}`;
}

interface SlotsListProps {
slots: SlotsFormatedParams[];
displayOption: 'collapsed' | 'expanded';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function getPropsToC({
.filter(([, propData]) => propData.description !== '@ignore')
.map(([propName]) => ({
text: propName,
hash: getHash({ propName, targetName: componentName }),
hash: getHash({ propName, componentName }),
children: [],
})),
...(inheritance
Expand All @@ -43,7 +43,7 @@ export default function PropertiesSection(props) {
const {
properties,
propertiesDescriptions,
targetName = '',
componentName = '',
showOptionalAbbr = false,
title = 'api-docs.props',
titleHash = 'props',
Expand Down Expand Up @@ -87,7 +87,7 @@ export default function PropertiesSection(props) {
propertiesDescriptions[propName].typeDescriptions[propData.signature.returned];

return {
targetName,
componentName,
propName,
description: propDescription?.description,
requiresRef: propDescription?.requiresRef,
Expand Down Expand Up @@ -135,14 +135,14 @@ export default function PropertiesSection(props) {
}

PropertiesSection.propTypes = {
componentName: PropTypes.string,
hooksParameters: PropTypes.bool,
hooksReturnValue: PropTypes.bool,
level: PropTypes.string,
properties: PropTypes.object.isRequired,
propertiesDescriptions: PropTypes.object.isRequired,
showOptionalAbbr: PropTypes.bool,
spreadHint: PropTypes.string,
targetName: PropTypes.string,
title: PropTypes.string,
titleHash: PropTypes.string,
};
5 changes: 2 additions & 3 deletions docs/src/modules/components/ApiPage/sections/SlotsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import SlotsTable from 'docs/src/modules/components/ApiPage/table/SlotsTable';
export type SlotsSectionProps = {
componentSlots: { class: string; name: string; default: string }[];
slotDescriptions: { [key: string]: string };
componentName?: string;
componentName: string;
title?: string;
titleHash?: string;
level?: 'h2' | 'h3' | 'h4';
Expand All @@ -38,9 +38,8 @@ export default function SlotsSection(props: SlotsSectionProps) {
}

const formatedSlots = componentSlots?.map(({ class: className, name, default: defaultValue }) => {
const description = slotDescriptions[name];
return {
description,
description: slotDescriptions[name],
className,
name,
defaultValue,
Expand Down
4 changes: 2 additions & 2 deletions docs/src/modules/components/ApiPage/table/PropertiesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export default function PropertiesTable(props: PropertiesTableProps) {
<tbody>
{properties.map((params) => {
const {
targetName,
componentName,
propName,
description,
requiresRef,
Expand All @@ -201,7 +201,7 @@ export default function PropertiesTable(props: PropertiesTableProps) {
return (
<tr
key={propName}
id={getHash({ targetName, propName, hooksParameters, hooksReturnValue })}
id={getHash({ componentName, propName, hooksParameters, hooksReturnValue })}
>
<td className="MuiApi-table-item-title">
{propName}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/modules/components/ComponentsApiContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export default function ComponentsApiContent(props) {
<PropertiesSection
properties={componentProps}
propertiesDescriptions={propDescriptions}
targetName={componentNameKebabCase}
componentName={componentName}
spreadHint={spreadHint}
level="h3"
titleHash={`${componentNameKebabCase}-props`}
Expand Down

0 comments on commit f8e820a

Please sign in to comment.