From 7ef0b105b2b08893e64f56288292828b6c85dd1f Mon Sep 17 00:00:00 2001
From: Alexandre Fauquette <45398769+alexfauquette@users.noreply.github.com>
Date: Tue, 27 Aug 2024 10:27:53 +0200
Subject: [PATCH] [docs-infra] Add link to the source in API page if available
(#43387)
---
docs/src/modules/components/ApiPage.tsx | 17 +++++++++++++++--
.../ComponentLinkHeader/ComponentLinkHeader.tsx | 2 +-
.../mui-docs/src/translations/translations.json | 2 ++
3 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/docs/src/modules/components/ApiPage.tsx b/docs/src/modules/components/ApiPage.tsx
index d3aab5ed9d85ba..19ec201baa713d 100644
--- a/docs/src/modules/components/ApiPage.tsx
+++ b/docs/src/modules/components/ApiPage.tsx
@@ -47,7 +47,8 @@ type ApiHeaderKeys =
| 'inheritance'
| 'slots'
| 'classes'
- | 'css';
+ | 'css'
+ | 'source-code';
export function getTranslatedHeader(t: Translate, header: ApiHeaderKeys) {
const translations = {
@@ -59,6 +60,7 @@ export function getTranslatedHeader(t: Translate, header: ApiHeaderKeys) {
slots: t('api-docs.slots'),
classes: t('api-docs.classes'),
css: t('api-docs.css'),
+ 'source-code': t('api-docs.source-code'),
};
// TODO Drop runtime type-checking once we type-check this file
@@ -202,7 +204,8 @@ export default function ApiPage(props: ApiPageProps) {
getPropertiesToC({ properties: propertiesDef, hash: 'props', t }),
...(componentSlots?.length > 0 ? [createTocEntry('slots')] : []),
...getClassesToC({ classes: classesDef, t }),
- ].filter(Boolean);
+ pageContent.filename ? createTocEntry('source-code') : null,
+ ].filter((item): item is TableOfContentsParams => Boolean(item));
// The `ref` is forwarded to the root element.
let refHint = t('api-docs.refRootElement');
@@ -360,6 +363,16 @@ export default function ApiPage(props: ApiPageProps) {
layoutStorageKey={layoutStorageKey.classes}
displayClassKeys
/>
+
+