Skip to content

Commit

Permalink
Functionality to manually expand text
Browse files Browse the repository at this point in the history
  • Loading branch information
LuizFNJ committed Jan 18, 2025
1 parent d343716 commit 17b522d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
3 changes: 2 additions & 1 deletion public/locales/en/verificationRequest.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@
"topicsFilterOption": "Topics",
"contentFilterOption": "Content",
"filterByContentLabel": "Filter by Content",
"applyButtonLabel": "Apply"
"applyButtonLabel": "Apply",
"showText": "Show"
}
3 changes: 2 additions & 1 deletion public/locales/pt/verificationRequest.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@
"topicsFilterOption": "Tópicos",
"contentFilterOption": "Conteudo",
"filterByContentLabel": "Filtrar por Conteudo",
"applyButtonLabel": "Aplicar"
"applyButtonLabel": "Aplicar",
"showText": "Mostrar"
}
36 changes: 34 additions & 2 deletions src/components/VerificationRequest/VerificationRequestCard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Grid, Chip, Typography } from "@mui/material";
import React from "react";
import { Grid, Chip, Typography, Button } from "@mui/material";
import React, { useEffect, useRef, useState } from "react";
import styled from "styled-components";
import CardBase from "../CardBase";
import Link from "next/link";
Expand Down Expand Up @@ -62,9 +62,25 @@ const truncateUrl = (url) => {
const VerificationRequestCard = ({
verificationRequest,
actions = [],
expandable = true,
t,
style = {},
}) => {
const [visible, setVisible] = useState(false);
const [isOverflowing, setIsOverflowing] = useState(false);
const textRef = useRef(null);

const handleToggle = () => {
setVisible(true);
};

useEffect(() => {
if (textRef.current) {
const isOverflow = textRef.current.scrollHeight > textRef.current.clientHeight;
setIsOverflowing(isOverflow);
}
}, [verificationRequest.content]);

const getTags = (verificationRequest) => {
const tags = [];
if (verificationRequest.publicationDate) {
Expand Down Expand Up @@ -156,15 +172,31 @@ const VerificationRequestCard = ({
<CardBase style={{ padding: 32, ...style }}>
<ContentWrapper>
<Typography
ref={textRef}
variant="body1"
style={{
color: colors.black,
margin: 0,
lineHeight: 1.6,
display: "-webkit-box",
WebkitBoxOrient: "vertical",
overflow: "hidden",
textOverflow: "ellipsis",
WebkitLineClamp: visible ? "none" : 3,
}}

>
{verificationRequest.content}
</Typography>
{expandable && !visible && isOverflowing && (
<Button
variant="text"
style={{ marginLeft: "auto", color: colors.lightPrimary, textDecoration: 'underline', padding: 0 }}
onClick={handleToggle}
>
{t("verificationRequest:showText")}
</Button>
)}
<TagContainer>{getTags(verificationRequest)}</TagContainer>
</ContentWrapper>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const VerificationRequestResultList = ({ results }) => {
>
<VerificationRequestCard
verificationRequest={verificationRequest}
expandable={false}
t={t}
style={{ minHeight: "100%" }}
actions={[
Expand Down

0 comments on commit 17b522d

Please sign in to comment.