<commit_before>/**
 *  Copyright (C) 2020 3D Repo Ltd
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
import { FunctionComponent, useState, useEffect, useCallback, useRef } from 'react';
import { GhostElement } from '../../../../../components/screenshotDialog/components/editableText/editableText.styles';
import { TextField } from '../../../../../components/textField/textField.component';
import { ExpandAction } from '../riskDetails/riskDetails.styles';

interface IProps {
	value: string;
	disableExpandable: boolean;
}

export const ExpandableTextField: FunctionComponent<IProps> = ({ value, disableExpandable = true, ...props }) => {
	const textareaRef = useRef<HTMLTextAreaElement>(null);
	const ghostElementRef = useRef<HTMLPreElement>(null);
	const [isExpanded, setIsExpanded] = useState<boolean>(false);
	const [isLongContent, setIsLongContent] = useState<boolean>(false);

	useEffect(() => {
		if (textareaRef && ghostElementRef) {
			const height = ghostElementRef.current.offsetHeight;

			if (height > 48 && !isLongContent) {
				setIsLongContent(true);
			} else if (height <= 48 && isLongContent) {
				setIsLongContent(false);
			}
		}
	}, [value]);

	const isExpandable = isLongContent && !disableExpandable;

	const handleOnExpand = () => setIsExpanded(!isExpanded);
<commit_msg>ISSUE #3175 - address feedback<commit_after>/**
 *  Copyright (C) 2020 3D Repo Ltd
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
import { FunctionComponent, useState, useEffect, useCallback, useRef } from 'react';
import { GhostElement } from '../../../../../components/screenshotDialog/components/editableText/editableText.styles';
import { TextField } from '../../../../../components/textField/textField.component';
import { ExpandAction } from './../../../../../components/textField/textField.styles';

interface IProps {
	value: string;
	disableExpandable: boolean;
}

export const ExpandableTextField: FunctionComponent<IProps> = ({ value, disableExpandable = true, ...props }) => {
	const textareaRef = useRef<HTMLTextAreaElement>(null);
	const ghostElementRef = useRef<HTMLPreElement>(null);
	const [isExpanded, setIsExpanded] = useState<boolean>(false);
	const [isLongContent, setIsLongContent] = useState<boolean>(false);

	useEffect(() => {
		if (textareaRef && ghostElementRef) {
			const height = ghostElementRef.current.offsetHeight;

			if (height > 48 && !isLongContent) {
				setIsLongContent(true);
			} else if (height <= 48 && isLongContent) {
				setIsLongContent(false);
			}
		}
	}, [value]);

	const isExpandable = isLongContent && !disableExpandable;

	const handleOnExpand = () => setIsExpanded(!isExpanded);

{'fraction_non_alphanumeric': 0.11955965181771633, 'fraction_numerical': 0.006144393241167435, 'mean_word_length': 4.16116248348745, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5401622', 'n_tokens_mistral': 1152, 'n_tokens_neox': 1084, 'n_words': 369}