-
Notifications
You must be signed in to change notification settings - Fork 6.3k
/
Copy pathindex.stories.tsx
52 lines (41 loc) · 1.3 KB
/
index.stories.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import type { Meta as MetaObj, StoryObj } from '@storybook/react';
import { VFile } from 'vfile';
import { MDXRenderer } from '@/components/mdxRenderer';
import { compileMDX } from '@/next.mdx.compiler';
type Props = { children: string };
type Story = StoryObj<Props>;
type Meta = MetaObj<Props>;
export const Default: Story = {
args: {
children: `\`\`\`mjs
const { createHmac } = await import('node:crypto');
const secret = 'abcdefg';
const hash = createHmac('sha256', secret)
.update('I love cupcakes')
.digest('hex');
console.log(hash);
// Prints:
// c0fa1bc00531bd78ef38c628449c5102aeabd49b5dc3a2a516ea6ea959d6658e
\`\`\`
\`\`\`cjs displayName="CommonJS" showCopyButton="true"
const { createHmac } = require('node:crypto');
const secret = 'abcdefg';
const hash = createHmac('sha256', secret)
.update('I love cupcakes')
.digest('hex');
console.log(hash);
// Prints:
// c0fa1bc00531bd78ef38c628449c5102aeabd49b5dc3a2a516ea6ea959d6658e
\`\`\``,
},
};
export default {
title: 'MDX/CodeTabs',
render: (_, { loaded: { Content } }) => Content,
loaders: [
async ({ args }) => {
const { MDXContent } = await compileMDX(new VFile(args.children), 'mdx');
return { Content: <MDXRenderer Component={MDXContent} /> };
},
],
} as Meta;