Skip to content

Commit 285ed69

Browse files
committed
wip
1 parent 0d4ba5f commit 285ed69

File tree

9 files changed

+88
-44
lines changed

9 files changed

+88
-44
lines changed

apps/site/next.mdx.use.client.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
import Blockquote from '@node-core/ui-components/Common/Blockquote';
44
import MDXCodeTabs from '@node-core/ui-components/MDX/CodeTabs';
5+
import {
6+
MDXTooltip,
7+
MDXTooltipContent,
8+
MDXTooltipTrigger,
9+
} from '@node-core/ui-components/MDX/Tooltip';
510

611
import DownloadButton from './components/Downloads/DownloadButton';
712
import BlogPostLink from './components/Downloads/Release/BlogPostLink';
@@ -28,6 +33,10 @@ import { ReleaseProvider } from './providers/releaseProvider';
2833
export const clientMdxComponents = {
2934
// Renders MDX CodeTabs
3035
CodeTabs: MDXCodeTabs,
36+
// Renders Tooltips
37+
MDXTooltip,
38+
MDXTooltipContent,
39+
MDXTooltipTrigger,
3140
// Renders a Download Button
3241
DownloadButton,
3342
// Renders a stateless Release Select Component

apps/site/styles/index.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
*/
88

99
@import '@node-core/ui-components/styles/index.css';
10-
@import '@node-core/rehype-shiki/twoslash.css';
10+
@import '@node-core/rehype-shiki/index.css';
1111
@import './locales.css';

packages/rehype-shiki/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"type": "module",
55
"exports": {
66
".": "./src/index.mjs",
7-
"./twoslash.css": "./src/twoslash.css",
7+
"./index.css": "./src/index.css",
88
"./*": "./src/*.mjs"
99
},
1010
"repository": {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import './transformers/twoslash/index.css';

packages/rehype-shiki/src/index.mjs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,12 @@ async function getEngine({ wasm = false }) {
4646
* Configures and returns transformers based on options
4747
* @param {HighlighterOptions} options - Configuration options
4848
*/
49-
async function getTransformers({ twoslash = false }) {
49+
async function getTransformers({ twoslash: options = false }) {
5050
const transformers = [];
5151

52-
if (twoslash) {
53-
const { transformerTwoslash } = await import('@shikijs/twoslash');
54-
55-
transformers.push(
56-
transformerTwoslash({
57-
langs: ['ts', 'js', 'cjs', 'mjs'],
58-
rendererRich: { jsdoc: false },
59-
throws: false,
60-
...(typeof twoslash === 'object' ? twoslash : {}),
61-
})
62-
);
52+
if (options) {
53+
const { twoslash } = await import('./transformers/twoslash/index.mjs');
54+
transformers.push(twoslash(options));
6355
}
6456

6557
return transformers;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@import '@shikijs/twoslash/style-rich.css';
2+
3+
.twoslash-hover {
4+
cursor: text;
5+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { transformerTwoslash } from '@shikijs/twoslash';
2+
3+
const compose = ({ token, popup }) => [
4+
{
5+
type: 'element',
6+
tagName: 'MDXTooltipTrigger',
7+
children: [token],
8+
properties: { className: ['twoslash-hover'] },
9+
},
10+
popup,
11+
];
12+
13+
export const twoslash = options =>
14+
transformerTwoslash({
15+
langs: ['ts', 'js', 'cjs', 'mjs'],
16+
rendererRich: {
17+
jsdoc: false,
18+
hast: {
19+
hoverToken: { tagName: 'MDXTooltip' },
20+
hoverPopup: { tagName: 'MDXTooltipContent' },
21+
hoverCompose: compose,
22+
23+
queryToken: { tagName: 'MDXTooltip' },
24+
queryPopup: { tagName: 'MDXTooltipContent' },
25+
queryCompose: compose,
26+
27+
errorToken: { tagName: 'MDXTooltip' },
28+
errorPopup: { tagName: 'MDXTooltipContent' },
29+
errorCompose: compose,
30+
},
31+
},
32+
throws: false,
33+
...(typeof options === 'object' ? twoslash : {}),
34+
});

packages/rehype-shiki/src/twoslash.css

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as TooltipPrimitive from '@radix-ui/react-tooltip';
2+
import classNames from 'classnames';
3+
import type { FC, HTMLAttributes, PropsWithChildren } from 'react';
4+
5+
import styles from '../Common/Tooltip/index.module.css';
6+
7+
export const MDXTooltip: FC<PropsWithChildren> = ({ children, ...props }) => (
8+
<TooltipPrimitive.Provider delayDuration={100}>
9+
<TooltipPrimitive.Root {...props}>{children}</TooltipPrimitive.Root>
10+
</TooltipPrimitive.Provider>
11+
);
12+
13+
export const MDXTooltipTrigger: FC<PropsWithChildren> = ({
14+
children,
15+
...props
16+
}) => (
17+
<TooltipPrimitive.Trigger {...props}>{children}</TooltipPrimitive.Trigger>
18+
);
19+
20+
export const MDXTooltipContent: FC<
21+
PropsWithChildren<HTMLAttributes<HTMLElement>>
22+
> = ({ children, ...props }) => (
23+
<TooltipPrimitive.Portal>
24+
<TooltipPrimitive.Content
25+
side={'bottom'}
26+
sideOffset={4}
27+
{...props}
28+
className={classNames(props.className, styles.default, styles.content)}
29+
>
30+
{children}
31+
</TooltipPrimitive.Content>
32+
</TooltipPrimitive.Portal>
33+
);

0 commit comments

Comments
 (0)