23 lines
630 B
TypeScript
23 lines
630 B
TypeScript
import type React from "react";
|
|
import { charCountClass } from "../utils/charCount.ts";
|
|
|
|
interface CountedInputProps
|
|
extends
|
|
Omit<React.InputHTMLAttributes<HTMLInputElement>, "maxLength" | "value"> {
|
|
value: string;
|
|
maxLength: number;
|
|
}
|
|
|
|
export function CountedInput({ value, maxLength, ...rest }: CountedInputProps) {
|
|
const countClass = charCountClass(value.length, maxLength);
|
|
|
|
return (
|
|
<div className="input-with-count">
|
|
<input value={value} maxLength={maxLength} {...rest} />
|
|
<span className={`text-editor-count${countClass}`}>
|
|
{value.length} / {maxLength}
|
|
</span>
|
|
</div>
|
|
);
|
|
}
|