-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCharacterCount.tsx
More file actions
51 lines (46 loc) · 1.33 KB
/
CharacterCount.tsx
File metadata and controls
51 lines (46 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import React, { TextareaHTMLAttributes } from "react";
import { Hint } from "../Hint";
import { Textarea } from "../Textarea";
import { CharacterCountProps } from "./CharacterCount.types";
const CharacterCount: React.FC<
CharacterCountProps & TextareaHTMLAttributes<HTMLTextAreaElement>
> = (props) => {
const {
id,
className,
maxlength,
threshold,
maxwords,
errorMessage,
countMessage,
...attributes
} = props;
const characterCountInfoId: string = `${id}-info`;
return (
<div
className="govuk-character-count"
data-module="govuk-character-count"
data-maxlength={maxlength}
data-threshold={threshold}
data-maxwords={maxwords}
>
<Textarea
id={id}
{...attributes}
errorMessage={errorMessage}
className={`govuk-js-character-count ${className || ""}${errorMessage ? " govuk-textarea--error" : ""}`}
aria-describedby={characterCountInfoId}
/>
<Hint
id={characterCountInfoId}
className={`govuk-hint govuk-character-count__message ${countMessage?.className || ""}`}
aria-live="polite"
>
You have {maxlength || maxwords} {maxwords ? "words" : "characters"}{" "}
remaining
</Hint>
</div>
);
};
CharacterCount.displayName = "CharacterCount";
export default CharacterCount;