-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathCodeContent.tsx
More file actions
44 lines (36 loc) · 1.4 KB
/
CodeContent.tsx
File metadata and controls
44 lines (36 loc) · 1.4 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 { reactNode, validateProps } from '@msinternal/botframework-webchat-react-valibot';
import { useStyles } from '@msinternal/botframework-webchat-styles/react';
import cx from 'classnames';
import React, { Fragment, memo } from 'react';
import { object, optional, pipe, readonly, string, type InferInput } from 'valibot';
import useCodeBlockTag from '../../../providers/CustomElements/useCodeBlockTagName';
import styles from './ViewCodeDialog.module.css';
const codeContentPropsSchema = pipe(
object({
children: optional(reactNode()),
className: optional(string()),
code: string(),
language: string(),
title: string()
}),
readonly()
);
type CodeContentProps = InferInput<typeof codeContentPropsSchema>;
function CodeContent(props: CodeContentProps) {
const { children, className, code, language, title } = validateProps(codeContentPropsSchema, props);
const [, CodeBlock] = useCodeBlockTag();
const classNames = useStyles(styles);
return (
<Fragment>
<div className={classNames['view-code-dialog__header']}>
<h2 className={classNames['view-code-dialog__title']}>{title}</h2>
</div>
<CodeBlock className={cx(classNames['view-code-dialog__body'], className)} language={language}>
<code>{code}</code>
</CodeBlock>
{children}
</Fragment>
);
}
export default memo(CodeContent);
export { codeContentPropsSchema, type CodeContentProps };