Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs-infra] Allow to link slots to their dedicated section #42503

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/pages/base-ui/api/button.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"name": "root",
"description": "The component that renders the root.",
"default": "props.href || props.to ? 'a' : 'button'",
"class": "base-Button-root"
"class": "base-Button-root",
"tutorial": "https://mui.com/sdlkfj/sdlkfjls"
}
],
"classes": [
Expand Down
14 changes: 13 additions & 1 deletion docs/src/modules/components/ApiPage/list/SlotsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useTranslate } from '@mui/docs/i18n';
import ExpandableApiItem, {
ApiItemContaier,
} from 'docs/src/modules/components/ApiPage/list/ExpandableApiItem';
import { Link } from '@mui/docs/Link';

const StyledApiItem = styled(ExpandableApiItem)(
({ theme }) => ({
Expand All @@ -25,6 +26,11 @@ const StyledApiItem = styled(ExpandableApiItem)(
fontFamily: theme.typography.fontFamilyCode,
fontWeight: theme.typography.fontWeightRegular,
},
'& .tutorial-slot-value': {
...theme.typography.caption,
fontFamily: theme.typography.fontFamilyCode,
fontWeight: theme.typography.fontWeightRegular,
},
'& .global-class-value': {
...theme.typography.caption,
fontFamily: theme.typography.fontFamilyCode,
Expand Down Expand Up @@ -53,6 +59,7 @@ export type SlotsFormatedParams = {
className: string;
componentName: string;
description?: string;
tutorial?: string;
name: string;
defaultValue?: string;
};
Expand All @@ -69,7 +76,7 @@ export default function SlotsList(props: SlotsListProps) {
return (
<ApiItemContaier className="MuiApi-slot-list">
{slots.map((params) => {
const { description, className, name, defaultValue, componentName } = params;
const { description, className, name, defaultValue, componentName, tutorial } = params;

const isExtendable = description || defaultValue || className;

Expand Down Expand Up @@ -105,6 +112,11 @@ export default function SlotsList(props: SlotsListProps) {
<code className="default-slot-value">{defaultValue}</code>
</p>
)}
{tutorial && (
<p className="slot-default-element">
{t('api-docs.tutorial-link.see')}<Link href={tutorial}>{t('api-docs.tutorial-link.docs-section')}</Link>
</p>
)}
</StyledApiItem>
);
})}
Expand Down
23 changes: 13 additions & 10 deletions docs/src/modules/components/ApiPage/sections/SlotsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SlotsList from 'docs/src/modules/components/ApiPage/list/SlotsList';
import SlotsTable from 'docs/src/modules/components/ApiPage/table/SlotsTable';

export type SlotsSectionProps = {
componentSlots: { class: string; name: string; default: string }[];
componentSlots: { class: string; name: string; default: string; tutorial?: string }[];
slotDescriptions: { [key: string]: string };
componentName: string;
title?: string;
Expand Down Expand Up @@ -42,15 +42,18 @@ export default function SlotsSection(props: SlotsSectionProps) {
return null;
}

const formatedSlots = componentSlots?.map(({ class: className, name, default: defaultValue }) => {
return {
description: slotDescriptions[name],
className,
name,
defaultValue,
componentName,
};
});
const formatedSlots = componentSlots?.map(
({ class: className, name, default: defaultValue, tutorial }) => {
return {
description: slotDescriptions[name],
tutorial,
className,
name,
defaultValue,
componentName,
};
},
);

return (
<React.Fragment>
Expand Down
12 changes: 11 additions & 1 deletion docs/src/modules/components/ApiPage/table/SlotsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
brandingDarkTheme as darkTheme,
brandingLightTheme as lightTheme,
} from '@mui/docs/branding';
import { Link } from '@mui/docs/Link';
import { SlotsFormatedParams, getHash } from 'docs/src/modules/components/ApiPage/list/SlotsList';
import StyledTableContainer from 'docs/src/modules/components/ApiPage/table/StyledTableContainer';

Expand Down Expand Up @@ -89,7 +90,7 @@ export default function SlotsTable(props: SlotsTableProps) {
</thead>
<tbody>
{slots.map((params) => {
const { description, className, name, defaultValue, componentName } = params;
const { description, className, name, defaultValue, componentName, tutorial } = params;

return (
<tr key={className} id={getHash({ componentName, className })}>
Expand All @@ -106,6 +107,15 @@ export default function SlotsTable(props: SlotsTableProps) {
__html: description || '',
}}
/>
{tutorial && (
<React.Fragment>
<br />
<span>
{t('api-docs.tutorial-link.see')}
<Link href={tutorial}>{t('api-docs.tutorial-link.docs-section')}</Link>
</span>
</React.Fragment>
)}
</td>
</tr>
);
Expand Down
2 changes: 2 additions & 0 deletions packages/api-docs-builder/utils/parseSlotsAndClasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface Slot {
name: string;
description: string;
default?: string;
tutorial?: string;
}

/**
Expand Down Expand Up @@ -223,6 +224,7 @@ function extractSlots(
description: getSymbolDescription(propertySymbol, project),
default: tags.default?.text?.[0].text,
class: slotClassDefinition?.className ?? null,
tutorial: tags.tutorial?.text?.[0].text,
};
});

Expand Down
1 change: 1 addition & 0 deletions packages/mui-base/src/Button/Button.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface ButtonSlots {
/**
* The component that renders the root.
* @default props.href || props.to ? 'a' : 'button'
* @tutorial https://mui.com/sdlkfj/sdlkfjls
*/
root?: React.ElementType;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/mui-docs/src/translations/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
"joy-size": "To learn how to add custom sizes to the component, check out <a href='/joy-ui/customization/themed-components/#extend-sizes'>Themed components—Extend sizes</a>.",
"joy-color": "To learn how to add your own colors, check out <a href='/joy-ui/customization/themed-components/#extend-colors'>Themed components—Extend colors</a>.",
"joy-variant": "To learn how to add your own variants, check out <a href='/joy-ui/customization/themed-components/#extend-variants'>Themed components—Extend variants</a>."
},
"tutorial-link": {
"see": "See ",
"docs-section": "dedicated demos"
}
},
"landingPageDescr": "A responsive landing page layout with common sections found in marketing pages.",
Expand Down
Loading