From 4cae5c67a19dfd79f55ff2e1e19c36bbd07f00da Mon Sep 17 00:00:00 2001 From: RadoslavDimchev Date: Mon, 7 Aug 2023 14:20:54 +0300 Subject: [PATCH] refactor: add types and clean FormattedText --- .../FormattedText/FormattedText.jsx | 27 -------------- .../FormattedText/FormattedText.tsx | 36 +++++++++++++++++++ .../FormattedText/{index.jsx => index.tsx} | 0 3 files changed, 36 insertions(+), 27 deletions(-) delete mode 100644 src/components/FormattedText/FormattedText.jsx create mode 100644 src/components/FormattedText/FormattedText.tsx rename src/components/FormattedText/{index.jsx => index.tsx} (100%) diff --git a/src/components/FormattedText/FormattedText.jsx b/src/components/FormattedText/FormattedText.jsx deleted file mode 100644 index c3463616..00000000 --- a/src/components/FormattedText/FormattedText.jsx +++ /dev/null @@ -1,27 +0,0 @@ -import { Text } from "tamagui"; - -const FormattedText = ({ textElements, color, fontSize }) => { - return ( - - {textElements.map((textElement, index) => { - if (textElement.bold) { - return ( - - {textElement.bold} - - ); - } - if (textElement.italic) { - return ( - - {textElement.italic} - - ); - } - return {textElement.text}; - })} - - ); -}; - -export { FormattedText }; diff --git a/src/components/FormattedText/FormattedText.tsx b/src/components/FormattedText/FormattedText.tsx new file mode 100644 index 00000000..e43c5d8f --- /dev/null +++ b/src/components/FormattedText/FormattedText.tsx @@ -0,0 +1,36 @@ +import { Text } from 'tamagui' + +type TextElement = { + text: string + bold?: boolean + italic?: boolean +} + +type FormattedTextProps = { + textElements: TextElement[] + color?: string + fontSize?: string +} + +const FormattedText = ({ textElements, color, fontSize }: FormattedTextProps) => { + const calculateStyle = (textElement: TextElement) => { + const isBold = textElement.bold ?? false + const isItalic = textElement.italic ?? false + + return { fontWeight: isBold ? 'bold' : '', fontStyle: isItalic ? 'italic' : '' } + } + + return ( + + {textElements.map((textElement, index) => { + return ( + + {textElement.text} + + ) + })} + + ) +} + +export { FormattedText } diff --git a/src/components/FormattedText/index.jsx b/src/components/FormattedText/index.tsx similarity index 100% rename from src/components/FormattedText/index.jsx rename to src/components/FormattedText/index.tsx