-
Notifications
You must be signed in to change notification settings - Fork 0
feat: MDX component styling and UI improvements #16
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
bef131d
fix: add shiki syntax highlighting color support for code blocks
rsbh 1e33d28
feat: add styled MDX components for details, paragraph, and inline code
rsbh 06f8e87
fix: revert unused text directives to plain text to prevent URL mangling
rsbh 25de8ee
fix: improve content spacing and use unist-util-visit for directive p…
rsbh 8fa5f68
feat: add mermaid diagram support
rsbh 03457a4
feat: sticky sidebar, folder ordering, navbar API link, and callout fix
rsbh 45f1117
fix: match navbar button heights for search and API links
rsbh 64a38e0
fix: preserve sidebar scroll position across navigations
rsbh 9d16ac6
fix: default index page order to 0 for sidebar sorting
rsbh 918fa53
fix: address PR review comments
rsbh ac73b50
fix: prevent hydration error when block elements are inside paragraphs
rsbh a45f0ec
refactor: use useId hook for mermaid render ID
rsbh 268bbbe
fix: disable scroll-to-top on sidebar link navigation
rsbh a4ae8c7
chore: remove unused ref from mermaid component
rsbh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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,15 @@ | ||
| import { loadConfig } from '@/lib/config' | ||
| import { buildPageTree } from '@/lib/source' | ||
| import { getTheme } from '@/themes/registry' | ||
|
|
||
| export default function DocsLayout({ children }: { children: React.ReactNode }) { | ||
| const config = loadConfig() | ||
| const tree = buildPageTree() | ||
| const { Layout, className } = getTheme(config.theme?.name) | ||
|
|
||
| return ( | ||
| <Layout config={config} tree={tree} classNames={{ layout: className }}> | ||
| {children} | ||
| </Layout> | ||
| ) | ||
| } |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| .callout { | ||
| margin: var(--rs-space-5) 0; | ||
| } | ||
|
|
||
| .callout p:last-child { | ||
| margin-bottom: 0; | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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,37 @@ | ||
| .details { | ||
| border: 1px solid var(--rs-color-border-base-primary); | ||
| border-radius: var(--rs-radius-2); | ||
| margin: var(--rs-space-5) 0; | ||
| } | ||
|
|
||
| .summary { | ||
| padding: var(--rs-space-4) var(--rs-space-5); | ||
| cursor: pointer; | ||
| font-weight: 500; | ||
| font-size: var(--rs-font-size-small); | ||
| color: var(--rs-color-text-base-primary); | ||
| background: var(--rs-color-background-base-secondary); | ||
| list-style: none; | ||
| display: flex; | ||
| align-items: center; | ||
| gap: var(--rs-space-3); | ||
| } | ||
|
|
||
| .summary::-webkit-details-marker { | ||
| display: none; | ||
| } | ||
|
|
||
| .summary::before { | ||
| content: '▶'; | ||
| font-size: 10px; | ||
| transition: transform 0.2s ease; | ||
| color: var(--rs-color-text-base-secondary); | ||
| } | ||
|
|
||
| .details[open] > .summary::before { | ||
| transform: rotate(90deg); | ||
| } | ||
|
|
||
| .content { | ||
| padding: var(--rs-space-4) var(--rs-space-5); | ||
| } |
This file contains hidden or 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,18 @@ | ||
| import type { ComponentProps } from 'react' | ||
| import styles from './details.module.css' | ||
|
|
||
| export function MdxDetails({ children, className, ...props }: ComponentProps<'details'>) { | ||
| return ( | ||
| <details className={`${styles.details} ${className ?? ''}`} {...props}> | ||
| {children} | ||
| </details> | ||
| ) | ||
| } | ||
|
|
||
| export function MdxSummary({ children, className, ...props }: ComponentProps<'summary'>) { | ||
| return ( | ||
| <summary className={`${styles.summary} ${className ?? ''}`} {...props}> | ||
| {children} | ||
| </summary> | ||
| ) | ||
| } |
This file contains hidden or 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 hidden or 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,9 @@ | ||
| .mermaid { | ||
| margin: var(--rs-space-5) 0; | ||
| overflow-x: auto; | ||
| } | ||
|
|
||
| .mermaid svg { | ||
| max-width: 100%; | ||
| height: auto; | ||
| } |
This file contains hidden or 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,37 @@ | ||
| 'use client' | ||
|
|
||
| import { useEffect, useId, useState } from 'react' | ||
| import styles from './mermaid.module.css' | ||
|
|
||
| interface MermaidProps { | ||
| chart: string | ||
| } | ||
|
|
||
| export function Mermaid({ chart }: MermaidProps) { | ||
| const mermaidId = useId().replace(/:/g, '-') | ||
| const [svg, setSvg] = useState<string>('') | ||
|
|
||
| useEffect(() => { | ||
| let cancelled = false | ||
|
|
||
| async function render() { | ||
| const { default: mermaid } = await import('mermaid') | ||
| mermaid.initialize({ startOnLoad: false, theme: 'default' }) | ||
| const { svg: rendered } = await mermaid.render( | ||
| mermaidId, | ||
| chart | ||
| ) | ||
| if (!cancelled) setSvg(rendered) | ||
| } | ||
|
|
||
| render() | ||
| return () => { cancelled = true } | ||
| }, [chart]) | ||
|
|
||
| return ( | ||
| <div | ||
| className={styles.mermaid} | ||
| dangerouslySetInnerHTML={{ __html: svg }} | ||
| /> | ||
| ) | ||
| } |
This file contains hidden or 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 @@ | ||
| .paragraph { | ||
| font-size: var(--rs-font-size-regular); | ||
| margin-bottom: var(--rs-space-5); | ||
| } | ||
|
|
||
| .paragraph :global(a) { | ||
| font-size: inherit; | ||
| } |
This file contains hidden or 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 { Children, isValidElement, type ComponentProps } from 'react' | ||
| import styles from './paragraph.module.css' | ||
|
|
||
| const BLOCK_ELEMENTS = new Set(['summary', 'details', 'div', 'table', 'ul', 'ol']) | ||
|
|
||
| function hasBlockChild(children: React.ReactNode): boolean { | ||
| return Children.toArray(children).some( | ||
| (child) => isValidElement(child) && typeof child.type === 'string' && BLOCK_ELEMENTS.has(child.type) | ||
| ) | ||
| } | ||
|
|
||
| export function MdxParagraph({ children, className, ...props }: ComponentProps<'p'>) { | ||
| const Tag = hasBlockChild(children) ? 'div' : 'p' | ||
| return ( | ||
| <Tag className={`${styles.paragraph} ${className ?? ''}`} {...props}> | ||
| {children} | ||
| </Tag> | ||
| ) | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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,31 @@ | ||
| import { visit } from 'unist-util-visit' | ||
| import type { Plugin } from 'unified' | ||
| import type { Node } from 'unist' | ||
|
|
||
| interface DirectiveNode extends Node { | ||
| name?: string | ||
| attributes?: Record<string, string> | ||
| children?: Node[] | ||
| data?: unknown | ||
| [key: string]: unknown | ||
| } | ||
|
|
||
| const remarkUnusedDirectives: Plugin = () => { | ||
| return (tree) => { | ||
| visit(tree, ['textDirective'], (node: DirectiveNode) => { | ||
| if (!node.data) { | ||
| const hasAttributes = node.attributes && Object.keys(node.attributes).length > 0 | ||
| const hasChildren = node.children && node.children.length > 0 | ||
| if (!hasAttributes && !hasChildren) { | ||
| const name = node.name | ||
| if (!name) return | ||
| Object.keys(node).forEach((key) => delete node[key]) | ||
| node.type = 'text' | ||
| node.value = `:${name}` | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| export default remarkUnusedDirectives | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.