fix: update formatted text to work with status

This commit is contained in:
RadoslavDimchev 2023-08-11 10:17:27 +03:00
parent 9d7cd4c2c5
commit e9b4946c73

View File

@ -1,35 +1,27 @@
import { Text } from 'tamagui' import { Text } from '@status-im/components'
export type TextElement = { export type TextElement = {
text: string text: string
bold?: boolean bold?: boolean
italic?: boolean italic?: boolean
weight?: 'regular' | 'medium' | 'bold'
} }
type FormattedTextProps = { type FormattedTextProps = {
textElements: TextElement[] textElements: TextElement[]
color?: string color?: string
fontSize?: string size: 27 | 19 | 15 | 13 | 11
} }
const FormattedText = ({ textElements, color, fontSize }: FormattedTextProps) => { const FormattedText = ({ textElements, color, size }: FormattedTextProps) => {
const calculateStyle = (textElement: TextElement) => {
const isBold = textElement.bold ?? false
const isItalic = textElement.italic ?? false
return { fontWeight: isBold ? 'bold' : '', fontStyle: isItalic ? 'italic' : '' }
}
return ( return (
<Text color={color} fontSize={fontSize}> <>
{textElements.map((textElement, index) => { {textElements.map((textElement, index) => (
return ( <Text key={index} size={size} color={color} weight={textElement.weight}>
<span style={calculateStyle(textElement)} key={index}>
{textElement.text} {textElement.text}
</span>
)
})}
</Text> </Text>
))}
</>
) )
} }