2023-11-16 17:32:39 +01:00
|
|
|
import Handlebars from "handlebars";
|
2024-11-22 17:11:51 +01:00
|
|
|
import I18n from "I18n";
|
2023-11-16 17:32:39 +01:00
|
|
|
|
|
|
|
export default function wizardCharCounter(body, maxLength) {
|
|
|
|
let bodyLength = body ? body.length : 0;
|
|
|
|
let finalString;
|
|
|
|
|
|
|
|
if (maxLength) {
|
|
|
|
let isOverMax = bodyLength > maxLength ? "true" : "false";
|
|
|
|
finalString = `<div class="body-length" data-length=${bodyLength} data-over-max=${isOverMax}>${bodyLength} / ${I18n.t(
|
|
|
|
"wizard.x_characters",
|
|
|
|
{ count: parseInt(maxLength, 10) }
|
|
|
|
)}</div>`;
|
|
|
|
} else {
|
|
|
|
finalString = `<div class="body-length">${I18n.t("wizard.x_characters", {
|
|
|
|
count: parseInt(bodyLength, 10),
|
|
|
|
})}</div>`;
|
|
|
|
}
|
|
|
|
|
2023-11-16 17:35:54 +01:00
|
|
|
return new Handlebars.SafeString(finalString);
|
|
|
|
}
|