mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-07-19 11:20:04 +08:00
Initial implementation of progressbar tracking
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { Progress, Stack, Textarea, TextareaProps } from "@chakra-ui/react";
|
||||
|
||||
interface TrackedTextboxProps {
|
||||
text: string;
|
||||
thresholds: {
|
||||
low: number;
|
||||
medium: number;
|
||||
goal: number;
|
||||
};
|
||||
textareaProps?: TextareaProps;
|
||||
onTextChange: (event: React.ChangeEvent<HTMLTextAreaElement>) => void;
|
||||
}
|
||||
|
||||
export const TrackedTextarea = (props: TrackedTextboxProps) => {
|
||||
const wordCount = props.text.split(" ").length - 1;
|
||||
|
||||
let progressColor: string;
|
||||
switch (true) {
|
||||
case wordCount < props.thresholds.low:
|
||||
progressColor = "red";
|
||||
break;
|
||||
case wordCount < props.thresholds.medium:
|
||||
progressColor = "yellow";
|
||||
break;
|
||||
default:
|
||||
progressColor = "green";
|
||||
}
|
||||
|
||||
return (
|
||||
<Stack direction={"column"}>
|
||||
<Textarea data-cy="reply" value={props.text} onChange={props.onTextChange} {...props.textareaProps} onCapture />
|
||||
<Progress size={"md"} rounded={"md"} value={wordCount} colorScheme={progressColor} max={props.thresholds.goal} />
|
||||
</Stack>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user