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] Add a feature list "component" #41484

Merged
merged 11 commits into from
Mar 15, 2024
1 change: 1 addition & 0 deletions docs/data/docs-infra/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const pages: readonly MuiPage[] = [
children: [
{ pathname: '/experiments/docs/callouts' },
{ pathname: '/experiments/docs/codeblock' },
{ pathname: '/experiments/docs/custom-components' },
{ pathname: '/experiments/docs/demos' },
{ pathname: '/experiments/docs/data-grid-premium', title: 'API DataGridPremium' },
],
Expand Down
7 changes: 7 additions & 0 deletions docs/pages/experiments/docs/custom-components.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as React from 'react';
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';
import * as pageProps from './custom-components.md?muiMarkdown';

export default function Page() {
return <MarkdownDocs {...pageProps} />;
}
19 changes: 19 additions & 0 deletions docs/pages/experiments/docs/custom-components.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Callouts

<p class="description">Type of callouts.</p>

## Header chips

{{"component": "modules/components/ComponentLinkHeader.js"}}

## Feature list

Available through the custom `<featureList>` tag.

<featureList>
- Manages modal stacking when one-at-a-time just isn't enough.
- Creates a backdrop, for disabling interaction below the modal.est
- It disables scrolling of the page content while open.
- It properly manages focus; moving to the modal content, and keeping it there until the modal is closed.
- Adds the appropriate ARIA roles automatically.
</featureList>
22 changes: 22 additions & 0 deletions docs/src/modules/components/MarkdownElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,21 @@ const Root = styled('div')(
marginBottom: theme.spacing(1),
},
},
'& .feature-list': {
padding: 0,
listStyle: 'none',
'& li': {
marginBottom: 6,
display: 'flex',
alignItems: 'center',
gap: 12,
'::before': {
content: `url('/static/branding/pricing/yes-light.svg')`,
width: '18px',
height: '18px',
},
},
},
}),
({ theme }) => ({
[`:where(${theme.vars ? '[data-mui-color-scheme="dark"]' : '.mode-dark'}) &`]: {
Expand Down Expand Up @@ -747,6 +762,13 @@ const Root = styled('div')(
backgroundColor: `var(--muidocs-palette-primaryDark-800, ${darkTheme.palette.primaryDark[800]})`,
},
},
'& .feature-list': {
'& li': {
'::before': {
content: `url('/static/branding/pricing/yes-dark.svg')`,
},
},
},
},
}),
);
Expand Down
46 changes: 31 additions & 15 deletions packages/markdown/parseMarkdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ function getContents(markdown) {
.replace(headerRegExp, '') // Remove header information
.split(/^{{("(?:demo|component)":.*)}}$/gm) // Split markdown into an array, separating demos
.flatMap((text) => text.split(/^(<codeblock.*?<\/codeblock>)$/gmsu))
.flatMap((text) => text.split(/^(<featureList.*?<\/featureList>)$/gmsu))
.filter((content) => !emptyRegExp.test(content)); // Remove empty lines
return rep;
}
Expand All @@ -212,23 +213,37 @@ function getDescription(markdown) {
}

function getCodeblock(content) {
if (content.startsWith('<codeblock')) {
const storageKey = content.match(/^<codeblock [^>]*storageKey=["|'](\S*)["|'].*>/m)?.[1];
const blocks = [...content.matchAll(/^```(\S*) (\S*)\n(.*?)\n```/gmsu)].map(
([, language, tab, code]) => ({ language, tab, code }),
);

const blocksData = blocks.filter(
(block) => block.tab !== undefined && !emptyRegExp.test(block.code),
);
if (!content.startsWith('<codeblock')) {
return undefined;
}
const storageKey = content.match(/^<codeblock [^>]*storageKey=["|'](\S*)["|'].*>/m)?.[1];
const blocks = [...content.matchAll(/^```(\S*) (\S*)\n(.*?)\n```/gmsu)].map(
([, language, tab, code]) => ({ language, tab, code }),
);

const blocksData = blocks.filter(
(block) => block.tab !== undefined && !emptyRegExp.test(block.code),
);

return {
type: 'codeblock',
data: blocksData,
storageKey,
};
}

return {
type: 'codeblock',
data: blocksData,
storageKey,
};
function getFeatureList(content) {
if (!content.startsWith('<featureList')) {
return undefined;
}
return undefined;
const lines = content
.split('\n')
.filter((line) => line.startsWith('- '))
.map((line) => line.slice(2));

return ['<ul class="feature-list">', ...lines.map((line) => `<li>${line}</li>`), '</ul>'].join(
'',
);
}

/**
Expand Down Expand Up @@ -475,6 +490,7 @@ module.exports = {
getContents,
getDescription,
getCodeblock,
getFeatureList,
getHeaders,
getTitle,
renderMarkdown,
Expand Down
8 changes: 7 additions & 1 deletion packages/markdown/prepareMarkdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
getContents,
getDescription,
getCodeblock,
getFeatureList,
getHeaders,
getTitle,
} = require('./parseMarkdown');
Expand Down Expand Up @@ -155,13 +156,18 @@ ${headers.hooks
return null;
}
}

const codeblock = getCodeblock(content);

if (codeblock) {
return codeblock;
}

const featureList = getFeatureList(content);

if (featureList) {
return featureList;
}

return render(content);
});

Expand Down
Loading