Back to CodeBlock

Custom

View Source
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
import { getThemeColors } from 'mdxts'
import { CodeBlock, LineNumbers, Tokens, Toolbar } from 'mdxts/components'

export async function Custom() {
  const theme = await getThemeColors()

  return (
    <CodeBlock
      allowErrors="2307"
      filename="toolbar.tsx"
      source="./counter/Counter.tsx"
    >
      <div
        style={{
          fontSize: '1rem',
          color: theme.foreground,
          backgroundColor: theme.background,
          border: `1px solid ${theme.panel.border}`,
        }}
      >
        <Toolbar allowCopy style={{ padding: '0.5lh' }} />
        <pre
          style={{
            display: 'grid',
            gridTemplateColumns: 'min-content max-content',
            padding: '0.5lh 0',
            lineHeight: 1.4,
            whiteSpace: 'pre',
            wordWrap: 'break-word',
            overflow: 'auto',
          }}
        >
          <LineNumbers
            style={{ padding: '0 0.5lh', backgroundColor: theme.background }}
          />
          <code style={{ paddingRight: '0.5lh' }}>
            <Tokens />
          </code>
        </pre>
      </div>
    </CodeBlock>
  )
}
toolbar.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
'use client'
import React from 'react'
import { useCounter } from './useCounter'

export default function Counter({ initialCount }: { initialCount: number }) {
  const { count, decrement, increment } = useCounter(initialCount)
  return (
    <div>
      <button onClick={decrement}>-</button>
      <span>{count}</span>
      <button onClick={increment}>+</button>
    </div>
  )
}