forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender-element.tsx
More file actions
44 lines (41 loc) · 1.13 KB
/
Copy pathrender-element.tsx
File metadata and controls
44 lines (41 loc) · 1.13 KB
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 { RenderElementProps } from "slate-react";
import React from "react";
export type RenderElementFunction = (
props: RenderElementProps,
) => React.JSX.Element;
export function makeRenderElementFunction(
suggestionsStyle: React.CSSProperties,
): RenderElementFunction {
return (props: RenderElementProps) => {
switch (props.element.type) {
case "paragraph":
return <DefaultElement {...props} />;
case "suggestion":
return (
<SuggestionElement {...props} suggestionsStyle={suggestionsStyle} />
);
}
};
}
const DefaultElement = (props: RenderElementProps) => {
return <div {...props.attributes}>{props.children}</div>;
};
const SuggestionElement = (
props: RenderElementProps & {
suggestionsStyle: React.CSSProperties;
},
) => {
return (
<span
{...props.attributes}
style={{
...props.suggestionsStyle,
}}
data-testid="suggestion"
contentEditable={false}
>
{props.children /* https://github.com/ianstormtaylor/slate/issues/3930 */}
{props.element.type === "suggestion" && props.element.content}
</span>
);
};