-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Made long notes, history, and description fields collapsible (#503)
Signed-off-by: Johannes Groß <[email protected]>
- Loading branch information
Showing
3 changed files
with
103 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react'; | ||
|
||
interface ExpandableTextProps { | ||
text: string; | ||
} | ||
|
||
export interface ExpandableTextHandle { | ||
recalculateClamp: () => void; | ||
} | ||
|
||
const ExpandableText = forwardRef<ExpandableTextHandle, ExpandableTextProps>(({ text }, ref) => { | ||
const textRef = useRef<HTMLDivElement | null>(null); // Typisiert als HTMLDivElement | ||
const [isClamped, setIsClamped] = useState(false); | ||
|
||
const checkClamp = () => { | ||
if (textRef.current) { | ||
setIsClamped(textRef.current.scrollHeight > textRef.current.clientHeight); | ||
} | ||
}; | ||
|
||
useImperativeHandle(ref, () => ({ | ||
recalculateClamp: checkClamp, | ||
})); | ||
|
||
useEffect(() => { | ||
checkClamp(); | ||
}, [text]); | ||
|
||
return ( | ||
<details className="group"> | ||
<summary className={`${isClamped ? 'cursor-pointer' : ''} flex w-full list-none flex-col`}> | ||
<div ref={textRef} className="long-text-format line-clamp-3 group-open:line-clamp-none"> | ||
{text} | ||
</div> | ||
{isClamped && ( | ||
<> | ||
<div className="w-full p-1 text-center underline group-open:hidden">mehr anzeigen</div> | ||
<div className="hidden p-1 text-center underline group-open:inline">weniger anzeigen</div> | ||
</> | ||
)} | ||
</summary> | ||
</details> | ||
); | ||
}); | ||
|
||
ExpandableText.displayName = 'ExpandableText'; | ||
|
||
export default ExpandableText; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters