@uva-glass/component-library
Version:
React components UvA
46 lines (45 loc) • 1.98 kB
JavaScript
import { jsxs as r, jsx as _ } from "react/jsx-runtime";
import { useRef as p, useState as d } from "react";
import { c as i } from "../../clsx-OuTLNxxd.js";
import '../../assets/TextArea.css';const e = {
"text-area__wrapper": "_text-area__wrapper_1kj5x_1",
"text-area__header": "_text-area__header_1kj5x_7",
"text-area__label-wrapper": "_text-area__label-wrapper_1kj5x_13",
"text-area__label": "_text-area__label_1kj5x_13",
"text-area__sub-label": "_text-area__sub-label_1kj5x_25",
"text-area__word-count": "_text-area__word-count_1kj5x_30",
"text-area__word-count--alert": "_text-area__word-count--alert_1kj5x_35",
"text-area": "_text-area_1kj5x_1"
};
function j({ onChange: c, label: l, subLabel: n, maxCharacters: a = 0, defaultValue: x = "" }) {
const t = p(null), [s, o] = d(x.length), u = () => {
t.current && (t.current.style.height = "auto", t.current.style.height = `${t.current.scrollHeight}px`, o(t.current.value.length), c(t.current.value.trim()));
};
return /* @__PURE__ */ r("div", { className: e["text-area__wrapper"], children: [
(l || a > 0) && /* @__PURE__ */ r("div", { className: e["text-area__header"], children: [
/* @__PURE__ */ r("span", { className: e["text-area__label-wrapper"], children: [
l && /* @__PURE__ */ _("span", { className: e["text-area__label"], children: l }),
n && /* @__PURE__ */ _("span", { className: e["text-area__sub-label"], children: n })
] }),
a > 0 && /* @__PURE__ */ r("div", { className: e["text-area__word-count"], children: [
/* @__PURE__ */ _("span", { className: i({ [e["text-area__word-count--alert"]]: s === a }), children: s }),
" / ",
a
] })
] }),
/* @__PURE__ */ _(
"textarea",
{
ref: t,
className: e["text-area"],
maxLength: a > 0 ? a : void 0,
onInput: u,
defaultValue: x
}
)
] });
}
export {
j as TextArea
};
//# sourceMappingURL=TextArea.js.map