-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: DRY things up a bit by swizzling (#2149)
Signed-off-by: Kent Rancourt <[email protected]>
- Loading branch information
Showing
15 changed files
with
134 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import React from 'react'; | ||
import Link from '@docusaurus/Link'; | ||
export default function MDXA(props) { | ||
return <Link {...props} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import React from 'react'; | ||
import CodeBlock from '@theme/CodeBlock'; | ||
export default function MDXCode(props) { | ||
const shouldBeInline = React.Children.toArray(props.children).every( | ||
(el) => typeof el === 'string' && !el.includes('\n'), | ||
); | ||
return shouldBeInline ? <code {...props} /> : <CodeBlock {...props} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
import Details from '@theme/Details'; | ||
export default function MDXDetails(props) { | ||
const items = React.Children.toArray(props.children); | ||
// Split summary item from the rest to pass it as a separate prop to the | ||
// Details theme component | ||
const summary = items.find( | ||
(item) => React.isValidElement(item) && item.type === 'summary', | ||
); | ||
const children = <>{items.filter((item) => item !== summary)}</>; | ||
return ( | ||
<Details {...props} summary={summary}> | ||
{children} | ||
</Details> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import React from 'react'; | ||
import Heading from '@theme/Heading'; | ||
export default function MDXHeading(props) { | ||
return <Heading {...props} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
import clsx from 'clsx'; | ||
import styles from './styles.module.css'; | ||
function transformImgClassName(className) { | ||
return clsx(className, styles.img); | ||
} | ||
export default function MDXImg(props) { | ||
return ( | ||
// eslint-disable-next-line jsx-a11y/alt-text | ||
<img | ||
loading="lazy" | ||
{...props} | ||
className={transformImgClassName(props.className)} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.img { | ||
height: auto; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import React from 'react'; | ||
export default function MDXPre(props) { | ||
// With MDX 2, this element is only used for fenced code blocks | ||
// It always receives a MDXComponents/Code as children | ||
return <>{props.children}</>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import clsx from 'clsx'; | ||
import styles from './styles.module.css'; | ||
function transformUlClassName(className) { | ||
// Fix https://github.com/facebook/docusaurus/issues/9098 | ||
if (typeof className === 'undefined') { | ||
return undefined; | ||
} | ||
return clsx( | ||
className, | ||
// This class is set globally by GitHub/MDX. We keep the global class, and | ||
// add another class to get a task list without the default ul styling | ||
// See https://github.com/syntax-tree/mdast-util-to-hast/issues/28 | ||
className?.includes('contains-task-list') && styles.containsTaskList, | ||
); | ||
} | ||
export default function MDXUl(props) { | ||
return <ul {...props} className={transformUlClassName(props.className)} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.containsTaskList { | ||
list-style: none; | ||
} | ||
|
||
:not(.containsTaskList > li) > .containsTaskList { | ||
padding-left: 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from 'react'; | ||
import Head from '@docusaurus/Head'; | ||
import MDXCode from '@theme/MDXComponents/Code'; | ||
import MDXA from '@theme/MDXComponents/A'; | ||
import MDXPre from '@theme/MDXComponents/Pre'; | ||
import MDXDetails from '@theme/MDXComponents/Details'; | ||
import MDXHeading from '@theme/MDXComponents/Heading'; | ||
import MDXUl from '@theme/MDXComponents/Ul'; | ||
import MDXImg from '@theme/MDXComponents/Img'; | ||
import Admonition from '@theme/Admonition'; | ||
import Mermaid from '@theme/Mermaid'; | ||
|
||
// We use these a lot. Let's make them available globally. | ||
import Tabs from '@theme/Tabs'; | ||
import TabItem from '@theme/TabItem'; | ||
|
||
// Custom highlight component | ||
import Highlight from '@site/src/components/Highlight'; | ||
|
||
const MDXComponents = { | ||
Head, | ||
details: MDXDetails, | ||
Details: MDXDetails, | ||
code: MDXCode, | ||
a: MDXA, | ||
pre: MDXPre, | ||
ul: MDXUl, | ||
img: MDXImg, | ||
h1: (props) => <MDXHeading as="h1" {...props} />, | ||
h2: (props) => <MDXHeading as="h2" {...props} />, | ||
h3: (props) => <MDXHeading as="h3" {...props} />, | ||
h4: (props) => <MDXHeading as="h4" {...props} />, | ||
h5: (props) => <MDXHeading as="h5" {...props} />, | ||
h6: (props) => <MDXHeading as="h6" {...props} />, | ||
admonition: Admonition, | ||
mermaid: Mermaid, | ||
|
||
// We use these a lot. Let's make them available globally. | ||
Tabs, | ||
TabItem, | ||
|
||
// Custom highlight component | ||
Hlt: Highlight, | ||
}; | ||
|
||
export default MDXComponents; |