2021-10-20 16:32:58 +00:00
|
|
|
import React from 'react';
|
2022-07-20 21:02:18 +00:00
|
|
|
import { View } from 'react-native';
|
2021-10-20 16:32:58 +00:00
|
|
|
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-07-20 21:02:18 +00:00
|
|
|
const Code = ({ value }: ICodeProps): React.ReactElement => {
|
|
|
|
const { colors } = useTheme();
|
2021-10-20 16:32:58 +00:00
|
|
|
|
|
|
|
return (
|
2022-07-20 21:02:18 +00:00
|
|
|
<View
|
2021-10-20 16:32:58 +00:00
|
|
|
style={[
|
|
|
|
styles.codeBlock,
|
|
|
|
{
|
2022-07-20 21:02:18 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
})}
|
2022-07-20 21:02:18 +00:00
|
|
|
</View>
|
2021-10-20 16:32:58 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Code;
|