/* Dependencies */ import React, { Fragment, useState } from 'react' import { StyleSheet, Text, View } from 'react-native' /* Libraries */ import * as Clipboard from 'expo-clipboard' import { Snackbar, Surface, useTheme } from 'react-native-paper' /* Types */ interface Info { description: string title: string onPress?: ( item: Info ) => void } type Props = { title: string data: Info[] onPress?: ( item: Info ) => void } const BlockInfo = ({ title, data, onPress }: Props) => { /* Styles */ const { colors } = useTheme() const styles = StyleSheet.create({ container: { backgroundColor: colors.background, borderRadius: 15, display: 'flex', elevation: 4, marginBottom: 20, padding: 10 }, data: { color: colors.text, flex: 1, textAlign: 'right', fontWeight: 'bold' }, dataContainer: { display: 'flex', flex: 1, flexDirection: 'row', padding: 3 }, dataTitle: { color: colors.text, marginRight: 15 }, separator: { backgroundColor: colors.text, height: 1, marginBottom: 10, marginTop: 10 }, snackbar: { backgroundColor: colors.primary, bottom: 0, position: 'absolute', right: 0, width: 175 }, snackbarMessage: { color: colors.accent }, title: { color: colors.text, fontSize: 16, fontWeight: 'bold', marginTop: 10 } }) /* States */ const [visible, setVisible] = useState(false) return ( {title} {data.map((item, index) => ( {item.title} { if (item.onPress) { item.onPress(item) } else if (onPress) { onPress(item) } else { if (item.description) { Clipboard.setString(item.description) setVisible(true) } } }} style={styles.data}> {item.description?.includes('undefined') ? undefined : item.description} ))} setVisible(false)} style={styles.snackbar} visible={visible}> {'Campo Copiado!'} ) } BlockInfo.displayName = 'Block.Info' export default BlockInfo