Skip to content

Commit b6e544a

Browse files
authored
Merge pull request #41 from jhiemstrawisc/docs-push
Add Example callout and stylized Terminal block for writing user docs
2 parents 60d090f + 7afa05e commit b6e544a

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

components/Callout.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Wrapper around Nextra Callout to add "example" type for user documentation
2+
import { Callout as NextraCallout } from 'nextra/components'
3+
4+
type CalloutProps = React.ComponentProps<typeof NextraCallout> & {
5+
type?: 'default' | 'info' | 'warning' | 'error' | 'success' | 'example'
6+
}
7+
8+
export function Callout({ type, children, ...props }: CalloutProps) {
9+
if (type === 'example') {
10+
return (
11+
<NextraCallout type="info" {...props}>
12+
<strong>Example:</strong> {children}
13+
</NextraCallout>
14+
)
15+
}
16+
return <NextraCallout type={type as any} {...props}>{children}</NextraCallout>
17+
}

components/Terminal.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Module to help create terminal-like code blocks in user documentation.
2+
import React from "react";
3+
4+
// It'd be cool if we colored lines beginning with $ differently, but I wasn't
5+
// able to figure that out.
6+
export function Terminal({ children }) {
7+
return (
8+
<pre
9+
style={{
10+
background: "#222",
11+
color: "#eee",
12+
padding: "1em",
13+
borderRadius: "6px",
14+
fontSize: "1em",
15+
overflowX: "auto",
16+
margin: "1em 0",
17+
// Not sure how to altogether avoid rendering links (example links in Terminal blocks are probably never
18+
// real links), but this makes them non-clickable
19+
pointerEvents: "none",
20+
}}
21+
>
22+
<code style={{ whiteSpace: "pre-wrap" }}>{children}</code>
23+
</pre>
24+
);
25+
}

0 commit comments

Comments
 (0)