2021-10-20 16:32:58 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { Text } from 'react-native';
|
|
|
|
import { Code as CodeProps } from '@rocket.chat/message-parser';
|
|
|
|
|
|
|
|
import styles from '../styles';
|
|
|
|
import { useTheme } from '../../../theme';
|
|
|
|
import CodeLine from './CodeLine';
|
|
|
|
|
|
|
|
interface ICodeProps {
|
|
|
|
value: CodeProps['value'];
|
|
|
|
}
|
|
|
|
|
2022-03-25 17:20:09 +00:00
|
|
|
const Code = ({ value }: ICodeProps) => {
|
2022-06-27 21:27:22 +00:00
|
|
|
const { colors } = useTheme();
|
2021-10-20 16:32:58 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Text
|
|
|
|
style={[
|
|
|
|
styles.codeBlock,
|
|
|
|
{
|
2022-06-27 21:27:22 +00:00
|
|
|
color: colors.bodyText,
|
|
|
|
backgroundColor: colors.bannerBackground,
|
|
|
|
borderColor: colors.borderColor
|
2021-10-20 16:32:58 +00:00
|
|
|
}
|
|
|
|
]}>
|
|
|
|
{value.map(block => {
|
|
|
|
switch (block.type) {
|
|
|
|
case 'CODE_LINE':
|
|
|
|
return <CodeLine value={block.value} />;
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
})}
|
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Code;
|