ldc-ovoteam/resources/ts/back/Components/WordCounter.tsx

44 lines
1.1 KiB
TypeScript
Raw Permalink Normal View History

2026-03-30 14:17:31 +02:00
// * Other
import type { MinMax } from "@/hooks/use-laravel-validation";
import trans from "@/hooks/use-translations";
2026-03-30 14:17:31 +02:00
export default function WordCounter({
value,
limits,
}: Readonly<{
value: string;
limits?: MinMax;
}>) {
2026-03-30 14:17:31 +02:00
const characters = value.length;
const words = characters ? value.split(" ").length : 0;
const renderLimit = () => {
if (!limits) return null;
const { min, max } = limits;
if (min !== undefined && max !== undefined) {
return ` / ${max} (min. ${min})`;
}
if (max !== undefined) {
return ` / ${max}`;
}
if (min !== undefined) {
return ` (min. ${min})`;
}
return null;
};
2026-03-30 14:17:31 +02:00
return (
<section className="flex justify-around w-full gap-1.5 bg-secondary rounded-md py-1">
<p className="text-sm text-muted-foreground mx-auto w-fit">
{trans("uwil-backend::back.characters")}
2026-03-30 14:17:31 +02:00
<span>{characters}</span>
{renderLimit()}
2026-03-30 14:17:31 +02:00
</p>
<p className="text-sm text-muted-foreground mx-auto w-fit">
{trans("uwil-backend::back.words")}
2026-03-30 14:17:31 +02:00
<span>{words}</span>
</p>
</section>
);
}