From 0139fd5e3cf06e4ea3fe1d66aa03bc784a005338 Mon Sep 17 00:00:00 2001 From: thibautbremand Date: Mon, 14 Aug 2023 14:33:31 +0200 Subject: [PATCH] Refactor TruncatedText component --- .../TruncatedMultiLinesText.tsx | 32 ----------------- .../atoms/TruncatedMultiLinesText/index.ts | 1 - .../atoms/TruncatedText/TruncatedText.tsx | 36 ++++++++++++++++--- .../extension/src/components/atoms/index.ts | 1 - .../components/molecules/NFTCard/NFTCard.tsx | 5 +-- 5 files changed, 34 insertions(+), 41 deletions(-) delete mode 100644 packages/extension/src/components/atoms/TruncatedMultiLinesText/TruncatedMultiLinesText.tsx delete mode 100644 packages/extension/src/components/atoms/TruncatedMultiLinesText/index.ts diff --git a/packages/extension/src/components/atoms/TruncatedMultiLinesText/TruncatedMultiLinesText.tsx b/packages/extension/src/components/atoms/TruncatedMultiLinesText/TruncatedMultiLinesText.tsx deleted file mode 100644 index ac4d2b8ae..000000000 --- a/packages/extension/src/components/atoms/TruncatedMultiLinesText/TruncatedMultiLinesText.tsx +++ /dev/null @@ -1,32 +0,0 @@ -import { ComponentProps } from 'react'; - -import Typography from '@mui/material/Typography'; - -type TruncatedMultiLinesTextProps = ComponentProps & { - text?: string; - maxLines?: string; -}; - -export const TruncatedMultiLinesText = ({ - text = '', - maxLines = '4', // defaults to 4 max lines - sx, - ...rest -}: TruncatedMultiLinesTextProps) => { - return ( - - {text} - - ); -}; diff --git a/packages/extension/src/components/atoms/TruncatedMultiLinesText/index.ts b/packages/extension/src/components/atoms/TruncatedMultiLinesText/index.ts deleted file mode 100644 index b159c2074..000000000 --- a/packages/extension/src/components/atoms/TruncatedMultiLinesText/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './TruncatedMultiLinesText'; diff --git a/packages/extension/src/components/atoms/TruncatedText/TruncatedText.tsx b/packages/extension/src/components/atoms/TruncatedText/TruncatedText.tsx index 7b6cfd847..aec71a307 100644 --- a/packages/extension/src/components/atoms/TruncatedText/TruncatedText.tsx +++ b/packages/extension/src/components/atoms/TruncatedText/TruncatedText.tsx @@ -4,16 +4,42 @@ import { Typography } from '@mui/material'; type TruncatedTextProps = ComponentProps & { text?: string; + isMultiline?: boolean; + maxLines?: string; }; -export const TruncatedText = ({ text = '', sx, ...rest }: TruncatedTextProps) => { +export const TruncatedText = ({ + text = '', + isMultiline = false, + maxLines = '4', // defaults to 4 max lines + sx, + ...rest +}: TruncatedTextProps) => { + let styleProps: {}; + + if (isMultiline) { + styleProps = { + overflow: 'hidden', + display: '-webkit-box', + width: '100%', // if the string is very long without spaces, it will not overflow the view + '-webkit-box-orient': 'vertical', + '-webkit-line-clamp': maxLines, // start showing ellipsis when X line is reached + 'white-space': 'pre-wrap' // let the text wrap preserving spaces + }; + } else { + // mode is 'width' + styleProps = { + display: 'block', + overflow: 'hidden', + textOverflow: 'ellipsis', + width: '100%' + }; + } + return ( = ({ NFT }) => { sx={{ fontSize: '16px', color: 'white', marginTop: '10px' }} data-testid="nft_name" /> -