UNPKG

@fremtind/jkl-feedback-react

Version:
46 lines (45 loc) 2.03 kB
import { TextArea } from "@fremtind/jkl-text-input-react"; import React, { useEffect, useState } from "react"; import { useFeedbackContext } from "../feedbackContext"; import { useMainQuestionContext } from "../main-question/mainQuestionContext"; const AddonQuestion = ({ helpLabel = "Ikke skriv personlige opplysninger. Tilbakemeldinger som kommer inn her blir ikke besvart, men brukt i videre arbeid med \xE5 forbedre tjenestene v\xE5re.", label }) => { const { counter } = useFeedbackContext(); const context = useMainQuestionContext(); const [dynamicLabel, setDynamicLabel] = useState(); useEffect(() => { var _a, _b, _c; const labelFromValue = Array.isArray(context == null ? void 0 : context.currentValue) ? (_a = context == null ? void 0 : context.currentValue[0].textAreaLabel) == null ? void 0 : _a.toString() : (_c = (_b = context == null ? void 0 : context.currentValue) == null ? void 0 : _b.textAreaLabel) == null ? void 0 : _c.toString(); setDynamicLabel(labelFromValue || label); }, [context == null ? void 0 : context.currentValue, label]); if (!context) { console.error( "Addon question must be used inside a MainQuestion context provider" ); return null; } const { message, setMessage } = context; const handleChange = (e) => setMessage(e.target.value); return /* @__PURE__ */ React.createElement(React.Fragment, null, context.currentValue !== void 0 && /* @__PURE__ */ React.createElement("div", { className: "jkl-sr-only", "aria-live": "polite" }, dynamicLabel, " ", helpLabel), /* @__PURE__ */ React.createElement( TextArea, { startOpen: true, rows: 4, "data-testid": "jkl-feedback__open-question", className: "jkl-spacing-xl--bottom jkl-spacing-xl--top", label: dynamicLabel, labelProps: { srOnly: true }, placeholder: dynamicLabel, helpLabel, value: message || "", onChange: handleChange, counter } )); }; export { AddonQuestion }; //# sourceMappingURL=AddonQuestion.js.map