verdnatura-chat/app/containers/markdown/MessageBody/Code.js

47 lines
907 B
JavaScript
Raw Normal View History

/* eslint-disable react/no-array-index-key */
import React from 'react';
2021-08-12 21:05:18 +00:00
import { Text } from 'react-native';
import PropTypes from 'prop-types';
import CodeLine from './CodeLine';
import styles from '../styles';
import { themes } from '../../../constants/colors';
import { useTheme } from '../../../theme';
const Code = ({
value, style
}) => {
const { theme } = useTheme();
return (
<Text
style={[
{
...styles.codeBlock,
color: themes[theme].bodyText,
backgroundColor: themes[theme].bannerBackground,
2021-08-20 16:25:30 +00:00
borderColor: themes[theme].borderColor
},
...style
]}
>
{value.map((block, index) => {
switch (block.type) {
case 'CODE_LINE':
return <CodeLine key={index} value={block.value} />;
default:
return null;
}
})}
</Text>
);
};
Code.propTypes = {
value: PropTypes.array,
style: PropTypes.object
};
export default Code;