blob: afc18a529e36a1fcd8c95a56207cc45a4b749a20 (
plain) (
blame)
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
|
'use client';
import React from 'react';
import { cn, withRef } from '@udecode/cn';
import { useCodeBlockElementState } from '@udecode/plate-code-block/react';
import { CodeBlockCombobox } from './code-block-combobox';
import { PlateElement } from './plate-element';
import './code-block-element.css';
export const CodeBlockElement = withRef<typeof PlateElement>(
({ children, className, ...props }, ref) => {
const { element } = props;
const state = useCodeBlockElementState({ element });
return (
<PlateElement
ref={ref}
className={cn('relative py-1', state.className, className)}
{...props}
>
<pre className="overflow-x-auto rounded-md bg-muted px-6 py-8 font-mono text-sm leading-[normal] [tab-size:2]">
<code>{children}</code>
</pre>
{state.syntax && (
<div
className="absolute right-2 top-2 z-10 select-none"
contentEditable={false}
>
<CodeBlockCombobox />
</div>
)}
</PlateElement>
);
}
);
|