2021-09-13 20:41:05 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { StyleSheet, Text, View } from 'react-native';
|
|
|
|
import { BLOCK_CONTEXT } from '@rocket.chat/ui-kit';
|
|
|
|
|
|
|
|
import { themes } from '../../constants/colors';
|
2022-03-16 19:07:49 +00:00
|
|
|
import { IAccessoryComponent, IFields, ISection } from './interfaces';
|
2021-09-13 20:41:05 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
content: {
|
|
|
|
marginBottom: 8
|
|
|
|
},
|
|
|
|
row: {
|
|
|
|
flexDirection: 'row'
|
|
|
|
},
|
|
|
|
column: {
|
|
|
|
justifyContent: 'center'
|
|
|
|
},
|
|
|
|
text: {
|
|
|
|
flex: 1,
|
|
|
|
padding: 4
|
|
|
|
},
|
|
|
|
field: {
|
|
|
|
marginVertical: 6
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-03-16 19:07:49 +00:00
|
|
|
const Accessory = ({ element, parser }: IAccessoryComponent) =>
|
|
|
|
parser.renderAccessories({ ...element }, BLOCK_CONTEXT.SECTION, parser);
|
2021-09-13 20:41:05 +00:00
|
|
|
|
2022-03-16 19:07:49 +00:00
|
|
|
const Fields = ({ fields, parser, theme }: IFields) => (
|
|
|
|
<>
|
|
|
|
{fields.map(field => (
|
|
|
|
<Text style={[styles.text, styles.field, { color: themes[theme].bodyText }]}>{parser.text(field)}</Text>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
);
|
2021-09-13 20:41:05 +00:00
|
|
|
|
|
|
|
const accessoriesRight = ['image', 'overflow'];
|
|
|
|
|
|
|
|
export const Section = ({ blockId, appId, text, fields, accessory, parser, theme }: ISection) => (
|
|
|
|
<View style={[styles.content, accessory && accessoriesRight.includes(accessory.type) ? styles.row : styles.column]}>
|
|
|
|
{text ? <View style={styles.text}>{parser.text(text)}</View> : null}
|
|
|
|
{fields ? <Fields fields={fields} theme={theme} parser={parser} /> : null}
|
|
|
|
{accessory ? <Accessory element={{ blockId, appId, ...accessory }} parser={parser} /> : null}
|
|
|
|
</View>
|
|
|
|
);
|