-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathCodeBlockContent.tsx
More file actions
42 lines (35 loc) · 1.39 KB
/
CodeBlockContent.tsx
File metadata and controls
42 lines (35 loc) · 1.39 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
import { useStyles } from 'botframework-webchat-styles/react';
import { validateProps } from 'botframework-webchat-react-valibot';
import cx from 'classnames';
import React, { memo } from 'react';
import { object, optional, pipe, readonly, string, type InferInput } from 'valibot';
import useCodeBlockTag from '../providers/CustomElements/useCodeBlockTagName';
import styles from './CodeBlockContent.module.css';
const codeBlockContentPropsSchema = pipe(
object({
code: string(),
language: optional(string()),
title: optional(string())
}),
readonly()
);
type CodeBlockContentProps = InferInput<typeof codeBlockContentPropsSchema>;
function CodeBlockContent(props: CodeBlockContentProps) {
const { code, language, title } = validateProps(codeBlockContentPropsSchema, props);
const classNames = useStyles(styles);
const [, CodeBlock] = useCodeBlockTag();
return (
<div className={classNames['code-block-content']}>
{title && (
<div className={cx(classNames['code-block-content__header'])}>
<div className={cx(classNames['code-block-content__title'])}>{title}</div>
</div>
)}
<CodeBlock className={cx(classNames['code-block-content__code-block'])} language={language}>
<code>{code}</code>
</CodeBlock>
</div>
);
}
export default memo(CodeBlockContent);
export { codeBlockContentPropsSchema, type CodeBlockContentProps };