diff --git a/.changelog/1287.bugfix.md b/.changelog/1287.bugfix.md new file mode 100644 index 000000000..7ac12493f --- /dev/null +++ b/.changelog/1287.bugfix.md @@ -0,0 +1 @@ +Show LongDataDisplay controls only when needed diff --git a/src/app/components/LongDataDisplay/index.tsx b/src/app/components/LongDataDisplay/index.tsx index 3f4ab14b0..37a2f65cf 100644 --- a/src/app/components/LongDataDisplay/index.tsx +++ b/src/app/components/LongDataDisplay/index.tsx @@ -1,47 +1,81 @@ -import Collapse from '@mui/material/Collapse' -import Link from '@mui/material/Link' -import { FC, useState } from 'react' +import { FC, useEffect, useRef, useState } from 'react' import { useTranslation } from 'react-i18next' +import Button from '@mui/material/Button' import Typography from '@mui/material/Typography' +import { styled } from '@mui/material/styles' +import { COLORS } from '../../../styles/theme/colors' -export const LongDataDisplay: FC<{ data: string; threshold: number; fontWeight?: number }> = ({ +const StyledButton = styled(Button)(({ theme }) => ({ + color: COLORS.brandDark, + fontWeight: 700, + minWidth: 'auto', + height: 'auto', + padding: 0, + [theme.breakpoints.down('sm')]: { + margin: theme.spacing(3, 0, 0, 0), + }, + [theme.breakpoints.up('sm')]: { + margin: theme.spacing(4, 0, 0, 0), + }, + '&&:hover, &&:active, &&:focus-visible': { + color: COLORS.brandDark, + textDecoration: 'none', + borderRadius: 0, + }, +})) + +const lineHeight = 22 + +export const LongDataDisplay: FC<{ data: string; fontWeight?: number; collapsedLinesNumber?: number }> = ({ data, - threshold, fontWeight = 700, + collapsedLinesNumber = 2, }) => { const { t } = useTranslation() - const [showData, setShowData] = useState(false) - const needsHiding = data.length > threshold - if (!needsHiding) { - return ( + const [isExpanded, setIsExpanded] = useState(false) + const [isOverflowing, setIsOverflowing] = useState(false) + const textRef = useRef(null) + const collapsedContainerMaxHeight = collapsedLinesNumber * lineHeight + + useEffect(() => { + const checkOverflow = () => { + if (textRef.current) { + const isOverflow = textRef.current.scrollHeight > textRef.current.clientHeight + setIsOverflowing(isOverflow) + } + } + + checkOverflow() + const handleResize = () => { + checkOverflow() + } + + window.addEventListener('resize', handleResize) + return () => window.removeEventListener('resize', handleResize) + }, [data]) + + return ( +
{data} - ) - } - return ( -
- setShowData(true)} collapsedSize="3em"> - - {data} - - - {data.length > threshold && ( - setShowData(!showData)}> - {showData ? t('common.hide') : t('common.show')} - + {(isOverflowing || isExpanded) && ( + setIsExpanded(!isExpanded)}> + {isExpanded ? t('common.hide') : t('common.show')} + )}
) diff --git a/src/app/components/RuntimeEvents/RuntimeEventDetails.tsx b/src/app/components/RuntimeEvents/RuntimeEventDetails.tsx index a52038de4..20fab3991 100644 --- a/src/app/components/RuntimeEvents/RuntimeEventDetails.tsx +++ b/src/app/components/RuntimeEvents/RuntimeEventDetails.tsx @@ -168,7 +168,6 @@ export const RuntimeEventDetails: FC<{
diff --git a/src/app/pages/RuntimeTransactionDetailPage/index.tsx b/src/app/pages/RuntimeTransactionDetailPage/index.tsx index 55cbeed5c..0ea100a08 100644 --- a/src/app/pages/RuntimeTransactionDetailPage/index.tsx +++ b/src/app/pages/RuntimeTransactionDetailPage/index.tsx @@ -359,7 +359,7 @@ export const RuntimeTransactionDetailView: FC<{ <>
{t('transaction.rawData')}
- +
)} @@ -392,7 +392,7 @@ export const RuntimeTransactionDetailView: FC<{ <>
{t('transactions.encryption.encryptedData')}
- +
)} @@ -412,11 +412,7 @@ export const RuntimeTransactionDetailView: FC<{ <>
{t('transactions.encryption.encryptedResult')}
- +
)}