Draft
Exploring Custom MDX Components
Posted on: Feb 18, 2022
7 mins read
Headings
Explore various heading styles to structure your content effectively.
Code:
md# This is a h1 Heading## This is a h2 Heading### This is a h3 Heading#### This is a h4 Heading#### This is a h5 Heading
Output:
This is a h1 Heading,
This is a h2 Heading,
This is a h3 Heading,
This is a h4 Heading,
This is a h5 Heading,
Texts
Add emphasis and style to your text using bold, italic, and strikethrough.
Code:
mdThis is a paragraph.**This is a bold sentence.**_This is an italic sentence._~~This is a strikethrough sentence.~~This is a <sparklyText>sparklyText</sparklyText> element.
Output:
This is a paragraph.
This is a bold sentence.
This is an italic sentence.
This is a strikethrough sentence.
This is a sparklyText element.
Links
Enhance your links with custom styling.
Code:
md[I am a link](https://example.com). I will open in a new tab.I am an <internalLink href="https://example.com">internal link</internalLink>. I will open in the same tab.
Output:
I am a link. I will open in a new tab.
I am an internal link. I will open in the same tab.
Media
Explore different media elements.
Image:
Code:
md![alt text](https://res.cloudinary.com/denkuysrh/image/upload/v1699795335/Cover%20Images/Articles/My_custom_components_1_xw0i15.png)<figcaption>The image caption</figcaption>
Output:
Youtube Video:
Code:
md<iframewidth="560"height="315"src="https://www.youtube.com/embed/7CqJlxBYj-M"title="YouTube video player"frameBorder="0"allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"allowFullScreen></iframe><figcaption>The video caption</figcaption>
Output:
Lists
Organize content with ordered, unordered, and nested lists.
Code:
md### Ordered list:1. Item 12. Item 23. Item 3### Unordered list:- Item 1- Item 2- Item 3### Nested list:1. Item 1- Item 1- Item 22. Item 21. Item 12. Item 2- Item 1- Item 1- Item 2- Item 21. Item 12. Item 2
Output:
Ordered list:
- Item 1
- Item 2
- Item 3
Unordered list:
- Item 1
- Item 2
- Item 3
Nested list:
- Item 1
- Item 1
- Item 2
- Item 2
- Item 1
- Item 2
- Item 1
- Item 1
- Item 2
- Item 2
- Item 1
- Item 2
Tables
Present data in an organized manner using tables.
Code:
mdx| Name | Age || ----- | --- || John | 20 || Peter | 30 |
Output:
Name | Age |
---|---|
John | 20 |
Peter | 30 |
Blockquotes
Highlight quotes with custom blockquote styling.
Code:
md> I am a blockquote
Output:
I am a blockquote
Horizontal Rule
Separate content with a horizontal rule.
Code:
md---This is a horizontal rule
Output:
This is a horizontal rule
Summary and Details
Create interactive content with summary and details.
Code:
md<details><summary>Click me</summary><p>Here is the details</p><p>I am an <faqCode>inline code</faqCode></p><faqCodeBlock>{`I am a code block::root {--variable-name: value;}`}</faqCodeBlock></details>
Output:
Click me
Here is the details
I am an inline code
I am a code block:
:root {
--variable-name: value;
}
Code Playgrounds
Include code snippets and playgrounds for interactive coding experiences.
Inline Code:
Code:
mdHere is an `inline code`.
Output:
Here is an inline code
.
Code Blocks:
html<div><h1>Hello World!</h1><!-- this is a comment --></div>
css/* accordion card */.accordion2-card {width: 280px;border: double goldenrod;background-color: white;}
jsximport React from "react";export default function App() {return (<div><h1>Hello World!</h1></div>);}
CodePen:
Code:
js<iframeheight="400"style={{ width: "100%", minHeight: "400px", height: "400px" }}scrolling="no"title="Pure HTML Accordion with CSS: Example 1 [T's Notes]"src="https://codepen.io/timonwa/embed/QWaWEoY?default-tab=html%2Cresult&editable=true&theme-id=dark"frameBorder="no"loading="lazy"allowTransparency="true"allowFullscreen="true">See the Pen{" "}<a href="https://codepen.io/timonwa/pen/QWaWEoY">Pure HTML Accordion with CSS: Example 1 [T's Notes]</a>{" "}by Timonwa (<a href="https://codepen.io/timonwa">@timonwa</a>) on{" "}<a href="https://codepen.io">CodePen</a>.</iframe>
Output:
Sandbox:
Code:
md<codePlaygroundtemplate="react"files={{"/App.js": `import React from 'react';import './index.css';\n\export default function App() {\n\const [count, setCount] = React.useState(0);console.warn("I am a warning!");\n\return (<div><h1>Hello World!</h1>{/* this is a comment */}<button onClick={() => setCount(count + 1)}>Count: {count}</button></div>);}`,"/index.css": `h1 {color: tomato;}`,}}/>
Output:
import React from 'react'; import './index.css'; export default function App() { const [count, setCount] = React.useState(0); console.warn("I am a warning!"); return ( <div> <h1>Hello World!</h1> {/* this is a comment */} <button onClick={() => setCount(count + 1)}> Count: {count} </button> </div> ); }
Info Cards
Display information in styled cards.
code:
md<infoCard title="Critical info/warnings" color="red">Use red color along with an exclamation mark icon (❗❗) to emphasize critical information or warnings.</infoCard><infoCard title="Less critical info/warnings" color="yellow">Apply yellow color and pair it with a warning icon (⚠️) to highlight less critical warnings or a light bulb icon (💡) to bring attention to insightful ideas and suggestions.</infoCard><infoCard title="Positive or successful outcomes" color="green">Utilize green color in conjunction with a checkmark icon (✅) to highlight positive or successful outcomes, achievements, or recommended practices.</infoCard><infoCard title="Tips, hints, ideas" color="blue">Opt for blue color and complement it with an information circle icon (🛈) to emphasize tips, hints, or important notes that provide additional insights or guidance.</infoCard><infoCard title="Announcement, general info" color="grey">When you want to make information stand out without indicating a specific level of importance, use a neutral color with an exclamation mark icon (📣).</infoCard>
Output:
Critical info/warnings:
Use red color along with an exclamation mark icon (❗❗) to emphasize critical information or warnings.
Less critical info/warnings:
Apply yellow color and pair it with a warning icon (⚠️) to highlight less critical warnings or a light bulb icon (💡) to bring attention to insightful ideas and suggestions.
Positive or successful outcomes:
Utilize green color in conjunction with a checkmark icon (✅) to highlight positive or successful outcomes, achievements, or recommended practices.
Tips, hints, ideas:
Opt for blue color and complement it with an information circle icon (🛈) to emphasize tips, hints, or important notes that provide additional insights or guidance.
Announcement, general info:
When you want to make information stand out without indicating a specific level of importance, use a neutral color with an exclamation mark icon (📣).
Advertisement Cards
Integrate stylish advertisement cards.
Code:
md<advertCard /><advertCard2 />
Output:
Get Free Notion Templates to Stay Organized and Productive! Whether you need a simple setup or a powerful dashboard, we have something for everyone.
Widgets
Add interactive widgets to your content.
Connect With Me Widget:
Code:
md<connectWithMe />
Output:
Connect With Me
Follow me on X(Twitter), and LinkedIn to stay updated with my latest content.
If you like my notes and want to support me, you can sponsor me on GitHub Sponsor, or you can buy me a virtual ice cream on ByMeACoffee or Selar. I would really appreciate it. 🙏
For other ways to support me, visit my Sponsorship page or Affiliate Links page.
Bye Bye Widget:
Code:
md<byeBye />
Output:
Image from
giphy.com
Subscribe Widget:
Code:
md<subscribe />
Output:
Enjoying this article?
Be the first to read new content, and more!
Occasional emails. No spam. Unsubscribe anytime.
Others
Explore additional custom components.
Share to Twitter Link in a Paragraph:
Code:
mdThis is a paragraph with a <twitterShareLink url="https://timonwa.com/blog/candid-journey-through-2023" title="Unfiltered Moments: A Candid Journey Through 2023 written by @timonwa\_" hashtags={[`UnfilteredMoments2023`, `UnfilteredMoments`]}>share to X(Twitter)</twitterShareLink> link.
Output:
This is a paragraph with a link.
Custom Code Snippet for Post Example:
Code:
md<starRatings />
Output:
Star Ratings: 5/5
Enjoy the versatility of custom MDX components in creating engaging and dynamic content on your blog.