optimized-react-component-library-xyz123 0.21.2 → 0.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -333,6 +333,11 @@ var InputTextarea = ({
333
333
  const aboutId = `about-${question.id}`;
334
334
  const errorId = `error-${question.id}`;
335
335
  const defaultMaxLength = 1e3;
336
+ const answerLength = (_b = (_a = question.answer) == null ? void 0 : _a.length) != null ? _b : 0;
337
+ const maxLength = (_d = (_c = question.questionExtraAttribute) == null ? void 0 : _c.answerMaxLength) != null ? _d : defaultMaxLength;
338
+ const isTooLong = answerLength > maxLength;
339
+ const counterText = activatedLanguage === "en" ? `${answerLength} of ${maxLength} characters` : `${answerLength} av ${maxLength} tecken`;
340
+ const maxLengthErrorText = activatedLanguage === "en" ? `The text must be ${maxLength} characters or less` : `Texten f\xE5r max vara ${maxLength} tecken`;
336
341
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
337
342
  !showPreview && question.visible && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
338
343
  "div",
@@ -364,29 +369,20 @@ var InputTextarea = ({
364
369
  required: question.isQuestionMandatory,
365
370
  "aria-required": question.isQuestionMandatory,
366
371
  "aria-invalid": question.hasValidationError,
367
- maxLength: ((_a = question.questionExtraAttribute) == null ? void 0 : _a.answerMaxLength) || defaultMaxLength,
368
372
  "aria-describedby": [question.aboutText ? aboutId : null, question.hasValidationError ? errorId : null].filter(Boolean).join(" ") || void 0,
369
373
  id: inputId
370
374
  }
371
375
  ),
372
376
  /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "pts-textarea-counter-error-container", children: [
373
- question.hasValidationError && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "pts-root-error", id: errorId, children: [
377
+ !isTooLong && question.hasValidationError && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "pts-root-error", id: errorId, children: [
374
378
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "aria-label": "Felmeddelande.", className: "errorDot", children: "!" }),
375
379
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "errorText", children: question.validationDefaultMessesege })
376
380
  ] }),
377
- !((_b = question.questionExtraAttribute) == null ? void 0 : _b.hideTextCounter) && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
378
- "div",
379
- {
380
- className: `pts-character-counter ${question.answer && (((_c = question.questionExtraAttribute) == null ? void 0 : _c.answerMaxLength) || defaultMaxLength) && question.answer.length > (((_d = question.questionExtraAttribute) == null ? void 0 : _d.answerMaxLength) || defaultMaxLength) ? "error" : ""}`,
381
- children: [
382
- question.answer ? question.answer.length : 0,
383
- " av",
384
- " ",
385
- ((_e = question.questionExtraAttribute) == null ? void 0 : _e.answerMaxLength) || defaultMaxLength,
386
- " tecken"
387
- ]
388
- }
389
- )
381
+ isTooLong && question.hasValidationError && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "pts-root-error", id: errorId, children: [
382
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "aria-label": "Felmeddelande.", className: "errorDot", children: "!" }),
383
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "errorText", children: maxLengthErrorText })
384
+ ] }),
385
+ !((_e = question.questionExtraAttribute) == null ? void 0 : _e.hideTextCounter) && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { "aria-live": "polite", className: `pts-character-counter`, children: counterText })
390
386
  ] })
391
387
  ]
392
388
  }
@@ -423,18 +419,21 @@ var TextFieldStandard = ({
423
419
  showPreview = false,
424
420
  activatedLanguage
425
421
  }) => {
426
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
422
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
427
423
  const questionId = `question-${question.id}`;
428
424
  const inputId = `textField-${question.id}`;
429
425
  const aboutId = `about-${question.id}`;
430
426
  const errorId = `error-${question.id}`;
431
- const defaultMaxLength = 1e3;
427
+ const answerLength = (_b = (_a = question.answer) == null ? void 0 : _a.length) != null ? _b : 0;
428
+ const maxLength = 100;
429
+ const isTooLong = answerLength > maxLength;
430
+ const maxLengthErrorText = activatedLanguage === "en" ? `The text must be ${maxLength} characters or less` : `Texten f\xE5r max vara ${maxLength} tecken`;
432
431
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
433
432
  !showPreview && question.visible && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
434
433
  "div",
435
434
  {
436
435
  id: questionId,
437
- className: `pts-root-question pts-textField-container${((_a = question.questionExtraAttribute) == null ? void 0 : _a.disabled) ? " pts-textField-disabled" : ""}${question.aboutText ? " pts-question-hasAbout" : ""}`.trim(),
436
+ className: `pts-root-question pts-textField-container${((_c = question.questionExtraAttribute) == null ? void 0 : _c.disabled) ? " pts-textField-disabled" : ""}${question.aboutText ? " pts-question-hasAbout" : ""}`.trim(),
438
437
  children: [
439
438
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { htmlFor: inputId, children: [
440
439
  question.questionLabel,
@@ -454,29 +453,33 @@ var TextFieldStandard = ({
454
453
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
455
454
  "input",
456
455
  {
457
- type: (_c = (_b = question.questionExtraAttribute) == null ? void 0 : _b.inputType) != null ? _c : "text",
458
- autoComplete: (_e = (_d = question.questionExtraAttribute) == null ? void 0 : _d.autoComplete) != null ? _e : void 0,
459
- inputMode: (_g = (_f = question.questionExtraAttribute) == null ? void 0 : _f.inputMode) != null ? _g : void 0,
456
+ type: (_e = (_d = question.questionExtraAttribute) == null ? void 0 : _d.inputType) != null ? _e : "text",
457
+ autoComplete: (_g = (_f = question.questionExtraAttribute) == null ? void 0 : _f.autoComplete) != null ? _g : void 0,
458
+ inputMode: (_i = (_h = question.questionExtraAttribute) == null ? void 0 : _h.inputMode) != null ? _i : void 0,
460
459
  name: `question-name-${question.id}`,
461
460
  className: question.hasValidationError ? "pts-root-question-input-error-border" : void 0,
462
461
  onChange: (e) => handleQuestionInputChange(e, question),
463
462
  value: question.answer,
464
- maxLength: ((_h = question.questionExtraAttribute) == null ? void 0 : _h.answerMaxLength) || defaultMaxLength,
465
463
  id: inputId,
466
- disabled: (_i = question.questionExtraAttribute) == null ? void 0 : _i.disabled,
464
+ disabled: (_j = question.questionExtraAttribute) == null ? void 0 : _j.disabled,
467
465
  required: question.isQuestionMandatory,
468
466
  "aria-required": question.isQuestionMandatory,
469
467
  "aria-describedby": [question.aboutText ? aboutId : null].filter(Boolean).join(" ") || void 0,
470
468
  "aria-invalid": question.hasValidationError,
471
469
  "aria-errormessage": question.hasValidationError ? errorId : void 0,
472
- spellCheck: (_k = (_j = question.questionExtraAttribute) == null ? void 0 : _j.spellCheck) != null ? _k : void 0,
473
- autoCapitalize: (_m = (_l = question.questionExtraAttribute) == null ? void 0 : _l.autoCapitalize) != null ? _m : void 0
470
+ spellCheck: (_l = (_k = question.questionExtraAttribute) == null ? void 0 : _k.spellCheck) != null ? _l : void 0,
471
+ autoCapitalize: (_n = (_m = question.questionExtraAttribute) == null ? void 0 : _m.autoCapitalize) != null ? _n : void 0
474
472
  }
475
473
  ),
476
- question.hasValidationError && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "pts-root-error", id: errorId, children: [
474
+ !isTooLong && question.hasValidationError && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "pts-root-error", id: errorId, children: [
477
475
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { "aria-hidden": true, className: "errorDot", children: "!" }),
478
476
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "sr-only", children: "Valideringsfel" }),
479
477
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "errorText", children: question.validationDefaultMessesege })
478
+ ] }),
479
+ isTooLong && question.hasValidationError && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "pts-root-error", id: errorId, children: [
480
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { "aria-hidden": true, className: "errorDot", children: "!" }),
481
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "sr-only", children: "Valideringsfel" }),
482
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "errorText", children: maxLengthErrorText })
480
483
  ] })
481
484
  ]
482
485
  }
@@ -708,10 +711,6 @@ var SelectedFiles = ({
708
711
  isTouched(e, questionObject);
709
712
  removeFile(newCountOfFiles);
710
713
  };
711
- (0, import_react6.useEffect)(() => {
712
- var _a;
713
- numberOfFiles > 0 && ((_a = theDiv.current) == null ? void 0 : _a.scrollIntoView({ behavior: "smooth", block: "end" }));
714
- }, [numberOfFiles]);
715
714
  const useWindowWidth = () => {
716
715
  const [windowWidth2, setWindowWidth] = (0, import_react6.useState)(window.innerWidth);
717
716
  (0, import_react6.useEffect)(() => {
@@ -1199,7 +1198,7 @@ var PreviewSingleCheckbox = ({
1199
1198
  // src/helpers/hasQuestionValidationError/hasQuestionValidationError.tsx
1200
1199
  var import_date_fns = require("date-fns");
1201
1200
  var hasQuestionValidationError = (question, questions) => {
1202
- var _a, _b, _c, _d, _e;
1201
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1203
1202
  let error = false;
1204
1203
  if (question.isQuestionMandatory) {
1205
1204
  if (question.isTouched === false) {
@@ -1212,19 +1211,28 @@ var hasQuestionValidationError = (question, questions) => {
1212
1211
  error = true;
1213
1212
  }
1214
1213
  }
1215
- if (((_b = question.validationType) == null ? void 0 : _b.find((e) => e === "email")) && (question.isQuestionMandatory || question.answer !== "")) {
1214
+ const maxLength = (_c = (_b = question.questionExtraAttribute) == null ? void 0 : _b.answerMaxLength) != null ? _c : 1e3;
1215
+ if (((_d = question.validationType) == null ? void 0 : _d.includes("maxLength")) && question.answer.length > maxLength) {
1216
+ error = true;
1217
+ }
1218
+ if (question.questionType === "TextField") {
1219
+ if (question.answer.length > 100) {
1220
+ error = true;
1221
+ }
1222
+ }
1223
+ if (((_e = question.validationType) == null ? void 0 : _e.find((e) => e === "email")) && (question.isQuestionMandatory || question.answer !== "")) {
1216
1224
  const emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
1217
1225
  if (!emailRegex.test(question.answer)) {
1218
1226
  error = true;
1219
1227
  }
1220
1228
  }
1221
- if (((_c = question.validationType) == null ? void 0 : _c.find((e) => e === "fourNumbers")) && (question.isQuestionMandatory || question.answer !== "")) {
1229
+ if (((_f = question.validationType) == null ? void 0 : _f.find((e) => e === "fourNumbers")) && (question.isQuestionMandatory || question.answer !== "")) {
1222
1230
  const fourNumbersRegex = /^\d{4}$/.test(question.answer);
1223
1231
  if (!fourNumbersRegex) {
1224
1232
  error = true;
1225
1233
  }
1226
1234
  }
1227
- if (((_d = question.validationType) == null ? void 0 : _d.find((e) => e === "isDateFormatValid")) && question.answer !== "") {
1235
+ if (((_g = question.validationType) == null ? void 0 : _g.find((e) => e === "isDateFormatValid")) && question.answer !== "") {
1228
1236
  const regex = /^\d{4}-\d{2}-\d{2}$/;
1229
1237
  if (!regex.test(question.answer)) {
1230
1238
  error = true;
@@ -1238,16 +1246,18 @@ var hasQuestionValidationError = (question, questions) => {
1238
1246
  error = true;
1239
1247
  }
1240
1248
  }
1241
- const groupCheckError = (_e = question.validationType) == null ? void 0 : _e.find((e) => e.startsWith("groupCheck-"));
1249
+ const groupCheckError = (_h = question.validationType) == null ? void 0 : _h.find((e) => e.startsWith("groupCheck-"));
1242
1250
  if (groupCheckError) {
1243
1251
  const ids = groupCheckError.replace("groupCheck-", "").split("-");
1244
- const relatedAnswers = ids.map((id) => {
1245
- var _a2;
1246
- return (_a2 = questions.find((q) => {
1247
- var _a3;
1248
- return ((_a3 = q.id) == null ? void 0 : _a3.toString()) === id;
1249
- })) == null ? void 0 : _a2.answer;
1250
- });
1252
+ const relatedAnswers = ids.map(
1253
+ (id) => {
1254
+ var _a2;
1255
+ return (_a2 = questions.find((q) => {
1256
+ var _a3;
1257
+ return ((_a3 = q.id) == null ? void 0 : _a3.toString()) === id;
1258
+ })) == null ? void 0 : _a2.answer;
1259
+ }
1260
+ );
1251
1261
  const currentAnswer = question.answer;
1252
1262
  const allAnswers = [...relatedAnswers, currentAnswer];
1253
1263
  if (allAnswers.every((ans) => ans === "")) {
@@ -2116,7 +2126,7 @@ var CookieBanner = ({
2116
2126
  href: "https://pts.se/om-oss/om-pts.se/kakor-pa-webbplatsen/kakor-pa-pts-e-tjanster/",
2117
2127
  target: "_blank",
2118
2128
  rel: "noopener noreferrer",
2119
- children: "Kakor (cookies) p\xE5 pts.se (\xF6ppnas i nytt f\xF6nster)"
2129
+ children: "Kakor (cookies) p\xE5 pts.se (\xF6ppnas i ny flik)"
2120
2130
  }
2121
2131
  )
2122
2132
  ] }),
@@ -2228,7 +2238,7 @@ var LanguageIcon = () => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("svg", {
2228
2238
  fill: "#6E3282"
2229
2239
  }
2230
2240
  ) });
2231
- var Logo_sv = () => /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("svg", { width: "168.8", height: "46.67", viewBox: "0 0 168.8 46.67", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
2241
+ var Logo_sv = () => /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("svg", { width: "168.8", height: "40", viewBox: "0 0 168.8 40", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
2232
2242
  /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2233
2243
  "path",
2234
2244
  {
@@ -2374,7 +2384,7 @@ var Logo_sv = () => /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("svg", { widt
2374
2384
  ),
2375
2385
  /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("path", { d: "M82.2223 18.3335V37.2224", stroke: "currentColor", strokeWidth: "0.8", strokeMiterlimit: "10" })
2376
2386
  ] });
2377
- var Logo_en = () => /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("svg", { width: "189.0", height: "46.67", viewBox: "0 0 189 46.67", fill: "none", xmlns: "http://www.w3.org/2000/svg", role: "img", children: [
2387
+ var Logo_en = () => /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("svg", { width: "189.0", height: "40", viewBox: "0 0 189 40", fill: "none", xmlns: "http://www.w3.org/2000/svg", role: "img", children: [
2378
2388
  /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2379
2389
  "path",
2380
2390
  {