2021-10-28 17:48:53 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { Text } from 'react-native';
|
|
|
|
import { Code as CodeProps } from '@rocket.chat/message-parser';
|
|
|
|
|
|
|
|
import styles from '../styles';
|
2022-04-28 18:45:00 +00:00
|
|
|
import { themes } from '../../../lib/constants';
|
2021-10-28 17:48:53 +00:00
|
|
|
import { useTheme } from '../../../theme';
|
|
|
|
import CodeLine from './CodeLine';
|
|
|
|
|
|
|
|
interface ICodeProps {
|
|
|
|
value: CodeProps['value'];
|
|
|
|
}
|
|
|
|
|
2022-03-29 18:53:10 +00:00
|
|
|
const Code = ({ value }: ICodeProps) => {
|
2021-10-28 17:48:53 +00:00
|
|
|
const { theme } = useTheme();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Text
|
|
|
|
style={[
|
|
|
|
styles.codeBlock,
|
|
|
|
{
|
2022-03-29 18:53:10 +00:00
|
|
|
color: themes[theme].bodyText,
|
|
|
|
backgroundColor: themes[theme].bannerBackground,
|
|
|
|
borderColor: themes[theme].borderColor
|
2021-10-28 17:48:53 +00:00
|
|
|
}
|
|
|
|
]}>
|
|
|
|
{value.map(block => {
|
|
|
|
switch (block.type) {
|
|
|
|
case 'CODE_LINE':
|
|
|
|
return <CodeLine value={block.value} />;
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
})}
|
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Code;
|