From 0a92caa2ff21dc142b3544ed6f2643f3f24b6854 Mon Sep 17 00:00:00 2001 From: Mark Trepanier Date: Sun, 25 Feb 2024 12:00:46 -0500 Subject: [PATCH 1/4] replaces js truncated textArea with webkit line clamp --- .../LibrarySearch/LibraryCard/LibraryCard.jsx | 4 +- .../LibraryCard/LibraryCard.scss | 25 ++++++-- src/components/UI/Inputs/ContentTextarea.jsx | 60 +------------------ 3 files changed, 22 insertions(+), 67 deletions(-) diff --git a/src/components/Library/LibrarySearch/LibraryCard/LibraryCard.jsx b/src/components/Library/LibrarySearch/LibraryCard/LibraryCard.jsx index b0e3f84..bf5456f 100644 --- a/src/components/Library/LibrarySearch/LibraryCard/LibraryCard.jsx +++ b/src/components/Library/LibrarySearch/LibraryCard/LibraryCard.jsx @@ -132,9 +132,7 @@ const LibraryCard = (props) => { style={contentContainerStyle} > dispatch(actions.updCardText(cardId, v))} setEditingParent={setEditingCard} diff --git a/src/components/Library/LibrarySearch/LibraryCard/LibraryCard.scss b/src/components/Library/LibrarySearch/LibraryCard/LibraryCard.scss index 0f949c3..4fba4c0 100644 --- a/src/components/Library/LibrarySearch/LibraryCard/LibraryCard.scss +++ b/src/components/Library/LibrarySearch/LibraryCard/LibraryCard.scss @@ -53,23 +53,29 @@ $round-radius: 12px; display: flex; flex-flow: column nowrap; + textarea { + cursor: auto; + } .library-card-textarea { - flex: 1 1 auto; - box-sizing: border-box; - width: 100%; + display: block; /* Fallback for non-webkit */ + display: -webkit-box; + + max-width: 100%; + -webkit-line-clamp: 3; + -webkit-box-orient: vertical; + overflow: hidden; margin: 0; - padding: 15px 0px 15px 15px; + padding: 15px 8px 15px 15px; border: 0; border-radius: $round-radius; - overflow-y: auto; resize: none; background-color: white; font-family: "Roboto"; - &::-webkit-scrollbar { + sc &::-webkit-scrollbar { width: 19px; } &::-webkit-scrollbar-track { @@ -82,6 +88,13 @@ $round-radius: 12px; border-radius: $round-radius; } } + + .library-card-textarea.selected { + flex: 1 1 auto; + overflow-y: auto; + -webkit-line-clamp: inherit; + background-color: pink; + } } @keyframes library-card-blink { diff --git a/src/components/UI/Inputs/ContentTextarea.jsx b/src/components/UI/Inputs/ContentTextarea.jsx index c3f4ebb..822c729 100644 --- a/src/components/UI/Inputs/ContentTextarea.jsx +++ b/src/components/UI/Inputs/ContentTextarea.jsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect, useRef } from "react"; +import React, { useState, useEffect } from "react"; import { CARD_FONT_SIZE } from "../../../shared/constants/fontSize"; @@ -9,16 +9,12 @@ import { CARD_FONT_SIZE } from "../../../shared/constants/fontSize"; const ContentTextarea = ({ className, styles, - isSelected, - lib = false, value, saveValue, setEditingParent, }) => { const [textareaValue, setTextareaValue] = useState(""); const [editing, setEditing] = useState(false); - const [textSlice, setSlice] = useState(textareaValue); - const textareaRef = useRef(null); useEffect(() => { setTextareaValue(value); @@ -60,60 +56,8 @@ const ContentTextarea = ({ } }; - //slice content - //if text content is greater than 300 char - //slice + ... - let maxLines = lib && !isSelected ? 4 : 1000; - - useEffect(() => { - if (textareaRef.current) { - // const lineHeight = parseFloat( - // window.getComputedStyle(textareaRef.current).lineHeight - // ); - const lineHeight = 20; - const maxHeight = lineHeight * maxLines; - - // Split the text into words - const words = textareaValue.split(" "); - - // Estimate line breaks based on word wrapping - let currentLine = []; - const lines = [currentLine]; - let currentLineHeight = 20; - - for (const word of words) { - const wordWidth = word.length * lineHeight; // Estimate word width based on characters - if (currentLineHeight + wordWidth <= maxHeight) { - currentLine.push(word); - currentLineHeight += wordWidth; - } else { - currentLine = [word]; - lines.push(currentLine); - currentLineHeight = wordWidth; - } - } - - // Truncate text if it exceeds the maximum height - if (lines.length > maxLines) { - lines.splice(maxLines); - } - - const truncatedText = - lines.map((line) => line.join(" ")).join(" ") + - (lib && !isSelected ? "..." : ""); - - setSlice(truncatedText); - } - }, [textareaValue, maxLines]); - - const slice = - textareaValue.length > 300 && lib - ? textareaValue.slice(0, 300) + "..." - : textareaValue; - return (