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.mjs CHANGED
@@ -251,6 +251,11 @@ var InputTextarea = ({
251
251
  const aboutId = `about-${question.id}`;
252
252
  const errorId = `error-${question.id}`;
253
253
  const defaultMaxLength = 1e3;
254
+ const answerLength = (_b = (_a = question.answer) == null ? void 0 : _a.length) != null ? _b : 0;
255
+ const maxLength = (_d = (_c = question.questionExtraAttribute) == null ? void 0 : _c.answerMaxLength) != null ? _d : defaultMaxLength;
256
+ const isTooLong = answerLength > maxLength;
257
+ const counterText = activatedLanguage === "en" ? `${answerLength} of ${maxLength} characters` : `${answerLength} av ${maxLength} tecken`;
258
+ const maxLengthErrorText = activatedLanguage === "en" ? `The text must be ${maxLength} characters or less` : `Texten f\xE5r max vara ${maxLength} tecken`;
254
259
  return /* @__PURE__ */ jsxs4(Fragment4, { children: [
255
260
  !showPreview && question.visible && /* @__PURE__ */ jsxs4(
256
261
  "div",
@@ -282,29 +287,20 @@ var InputTextarea = ({
282
287
  required: question.isQuestionMandatory,
283
288
  "aria-required": question.isQuestionMandatory,
284
289
  "aria-invalid": question.hasValidationError,
285
- maxLength: ((_a = question.questionExtraAttribute) == null ? void 0 : _a.answerMaxLength) || defaultMaxLength,
286
290
  "aria-describedby": [question.aboutText ? aboutId : null, question.hasValidationError ? errorId : null].filter(Boolean).join(" ") || void 0,
287
291
  id: inputId
288
292
  }
289
293
  ),
290
294
  /* @__PURE__ */ jsxs4("div", { className: "pts-textarea-counter-error-container", children: [
291
- question.hasValidationError && /* @__PURE__ */ jsxs4("div", { className: "pts-root-error", id: errorId, children: [
295
+ !isTooLong && question.hasValidationError && /* @__PURE__ */ jsxs4("div", { className: "pts-root-error", id: errorId, children: [
292
296
  /* @__PURE__ */ jsx4("span", { "aria-label": "Felmeddelande.", className: "errorDot", children: "!" }),
293
297
  /* @__PURE__ */ jsx4("span", { className: "errorText", children: question.validationDefaultMessesege })
294
298
  ] }),
295
- !((_b = question.questionExtraAttribute) == null ? void 0 : _b.hideTextCounter) && /* @__PURE__ */ jsxs4(
296
- "div",
297
- {
298
- 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" : ""}`,
299
- children: [
300
- question.answer ? question.answer.length : 0,
301
- " av",
302
- " ",
303
- ((_e = question.questionExtraAttribute) == null ? void 0 : _e.answerMaxLength) || defaultMaxLength,
304
- " tecken"
305
- ]
306
- }
307
- )
299
+ isTooLong && question.hasValidationError && /* @__PURE__ */ jsxs4("div", { className: "pts-root-error", id: errorId, children: [
300
+ /* @__PURE__ */ jsx4("span", { "aria-label": "Felmeddelande.", className: "errorDot", children: "!" }),
301
+ /* @__PURE__ */ jsx4("span", { className: "errorText", children: maxLengthErrorText })
302
+ ] }),
303
+ !((_e = question.questionExtraAttribute) == null ? void 0 : _e.hideTextCounter) && /* @__PURE__ */ jsx4("div", { "aria-live": "polite", className: `pts-character-counter`, children: counterText })
308
304
  ] })
309
305
  ]
310
306
  }
@@ -341,18 +337,21 @@ var TextFieldStandard = ({
341
337
  showPreview = false,
342
338
  activatedLanguage
343
339
  }) => {
344
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
340
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
345
341
  const questionId = `question-${question.id}`;
346
342
  const inputId = `textField-${question.id}`;
347
343
  const aboutId = `about-${question.id}`;
348
344
  const errorId = `error-${question.id}`;
349
- const defaultMaxLength = 1e3;
345
+ const answerLength = (_b = (_a = question.answer) == null ? void 0 : _a.length) != null ? _b : 0;
346
+ const maxLength = 100;
347
+ const isTooLong = answerLength > maxLength;
348
+ const maxLengthErrorText = activatedLanguage === "en" ? `The text must be ${maxLength} characters or less` : `Texten f\xE5r max vara ${maxLength} tecken`;
350
349
  return /* @__PURE__ */ jsxs5(Fragment5, { children: [
351
350
  !showPreview && question.visible && /* @__PURE__ */ jsxs5(
352
351
  "div",
353
352
  {
354
353
  id: questionId,
355
- className: `pts-root-question pts-textField-container${((_a = question.questionExtraAttribute) == null ? void 0 : _a.disabled) ? " pts-textField-disabled" : ""}${question.aboutText ? " pts-question-hasAbout" : ""}`.trim(),
354
+ className: `pts-root-question pts-textField-container${((_c = question.questionExtraAttribute) == null ? void 0 : _c.disabled) ? " pts-textField-disabled" : ""}${question.aboutText ? " pts-question-hasAbout" : ""}`.trim(),
356
355
  children: [
357
356
  /* @__PURE__ */ jsxs5("label", { htmlFor: inputId, children: [
358
357
  question.questionLabel,
@@ -372,29 +371,33 @@ var TextFieldStandard = ({
372
371
  /* @__PURE__ */ jsx5(
373
372
  "input",
374
373
  {
375
- type: (_c = (_b = question.questionExtraAttribute) == null ? void 0 : _b.inputType) != null ? _c : "text",
376
- autoComplete: (_e = (_d = question.questionExtraAttribute) == null ? void 0 : _d.autoComplete) != null ? _e : void 0,
377
- inputMode: (_g = (_f = question.questionExtraAttribute) == null ? void 0 : _f.inputMode) != null ? _g : void 0,
374
+ type: (_e = (_d = question.questionExtraAttribute) == null ? void 0 : _d.inputType) != null ? _e : "text",
375
+ autoComplete: (_g = (_f = question.questionExtraAttribute) == null ? void 0 : _f.autoComplete) != null ? _g : void 0,
376
+ inputMode: (_i = (_h = question.questionExtraAttribute) == null ? void 0 : _h.inputMode) != null ? _i : void 0,
378
377
  name: `question-name-${question.id}`,
379
378
  className: question.hasValidationError ? "pts-root-question-input-error-border" : void 0,
380
379
  onChange: (e) => handleQuestionInputChange(e, question),
381
380
  value: question.answer,
382
- maxLength: ((_h = question.questionExtraAttribute) == null ? void 0 : _h.answerMaxLength) || defaultMaxLength,
383
381
  id: inputId,
384
- disabled: (_i = question.questionExtraAttribute) == null ? void 0 : _i.disabled,
382
+ disabled: (_j = question.questionExtraAttribute) == null ? void 0 : _j.disabled,
385
383
  required: question.isQuestionMandatory,
386
384
  "aria-required": question.isQuestionMandatory,
387
385
  "aria-describedby": [question.aboutText ? aboutId : null].filter(Boolean).join(" ") || void 0,
388
386
  "aria-invalid": question.hasValidationError,
389
387
  "aria-errormessage": question.hasValidationError ? errorId : void 0,
390
- spellCheck: (_k = (_j = question.questionExtraAttribute) == null ? void 0 : _j.spellCheck) != null ? _k : void 0,
391
- autoCapitalize: (_m = (_l = question.questionExtraAttribute) == null ? void 0 : _l.autoCapitalize) != null ? _m : void 0
388
+ spellCheck: (_l = (_k = question.questionExtraAttribute) == null ? void 0 : _k.spellCheck) != null ? _l : void 0,
389
+ autoCapitalize: (_n = (_m = question.questionExtraAttribute) == null ? void 0 : _m.autoCapitalize) != null ? _n : void 0
392
390
  }
393
391
  ),
394
- question.hasValidationError && /* @__PURE__ */ jsxs5("div", { className: "pts-root-error", id: errorId, children: [
392
+ !isTooLong && question.hasValidationError && /* @__PURE__ */ jsxs5("div", { className: "pts-root-error", id: errorId, children: [
395
393
  /* @__PURE__ */ jsx5("span", { "aria-hidden": true, className: "errorDot", children: "!" }),
396
394
  /* @__PURE__ */ jsx5("span", { className: "sr-only", children: "Valideringsfel" }),
397
395
  /* @__PURE__ */ jsx5("span", { className: "errorText", children: question.validationDefaultMessesege })
396
+ ] }),
397
+ isTooLong && question.hasValidationError && /* @__PURE__ */ jsxs5("div", { className: "pts-root-error", id: errorId, children: [
398
+ /* @__PURE__ */ jsx5("span", { "aria-hidden": true, className: "errorDot", children: "!" }),
399
+ /* @__PURE__ */ jsx5("span", { className: "sr-only", children: "Valideringsfel" }),
400
+ /* @__PURE__ */ jsx5("span", { className: "errorText", children: maxLengthErrorText })
398
401
  ] })
399
402
  ]
400
403
  }
@@ -626,10 +629,6 @@ var SelectedFiles = ({
626
629
  isTouched(e, questionObject);
627
630
  removeFile(newCountOfFiles);
628
631
  };
629
- useEffect4(() => {
630
- var _a;
631
- numberOfFiles > 0 && ((_a = theDiv.current) == null ? void 0 : _a.scrollIntoView({ behavior: "smooth", block: "end" }));
632
- }, [numberOfFiles]);
633
632
  const useWindowWidth = () => {
634
633
  const [windowWidth2, setWindowWidth] = useState4(window.innerWidth);
635
634
  useEffect4(() => {
@@ -1117,7 +1116,7 @@ var PreviewSingleCheckbox = ({
1117
1116
  // src/helpers/hasQuestionValidationError/hasQuestionValidationError.tsx
1118
1117
  import { isValid, parseISO } from "date-fns";
1119
1118
  var hasQuestionValidationError = (question, questions) => {
1120
- var _a, _b, _c, _d, _e;
1119
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1121
1120
  let error = false;
1122
1121
  if (question.isQuestionMandatory) {
1123
1122
  if (question.isTouched === false) {
@@ -1130,19 +1129,28 @@ var hasQuestionValidationError = (question, questions) => {
1130
1129
  error = true;
1131
1130
  }
1132
1131
  }
1133
- if (((_b = question.validationType) == null ? void 0 : _b.find((e) => e === "email")) && (question.isQuestionMandatory || question.answer !== "")) {
1132
+ const maxLength = (_c = (_b = question.questionExtraAttribute) == null ? void 0 : _b.answerMaxLength) != null ? _c : 1e3;
1133
+ if (((_d = question.validationType) == null ? void 0 : _d.includes("maxLength")) && question.answer.length > maxLength) {
1134
+ error = true;
1135
+ }
1136
+ if (question.questionType === "TextField") {
1137
+ if (question.answer.length > 100) {
1138
+ error = true;
1139
+ }
1140
+ }
1141
+ if (((_e = question.validationType) == null ? void 0 : _e.find((e) => e === "email")) && (question.isQuestionMandatory || question.answer !== "")) {
1134
1142
  const emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
1135
1143
  if (!emailRegex.test(question.answer)) {
1136
1144
  error = true;
1137
1145
  }
1138
1146
  }
1139
- if (((_c = question.validationType) == null ? void 0 : _c.find((e) => e === "fourNumbers")) && (question.isQuestionMandatory || question.answer !== "")) {
1147
+ if (((_f = question.validationType) == null ? void 0 : _f.find((e) => e === "fourNumbers")) && (question.isQuestionMandatory || question.answer !== "")) {
1140
1148
  const fourNumbersRegex = /^\d{4}$/.test(question.answer);
1141
1149
  if (!fourNumbersRegex) {
1142
1150
  error = true;
1143
1151
  }
1144
1152
  }
1145
- if (((_d = question.validationType) == null ? void 0 : _d.find((e) => e === "isDateFormatValid")) && question.answer !== "") {
1153
+ if (((_g = question.validationType) == null ? void 0 : _g.find((e) => e === "isDateFormatValid")) && question.answer !== "") {
1146
1154
  const regex = /^\d{4}-\d{2}-\d{2}$/;
1147
1155
  if (!regex.test(question.answer)) {
1148
1156
  error = true;
@@ -1156,16 +1164,18 @@ var hasQuestionValidationError = (question, questions) => {
1156
1164
  error = true;
1157
1165
  }
1158
1166
  }
1159
- const groupCheckError = (_e = question.validationType) == null ? void 0 : _e.find((e) => e.startsWith("groupCheck-"));
1167
+ const groupCheckError = (_h = question.validationType) == null ? void 0 : _h.find((e) => e.startsWith("groupCheck-"));
1160
1168
  if (groupCheckError) {
1161
1169
  const ids = groupCheckError.replace("groupCheck-", "").split("-");
1162
- const relatedAnswers = ids.map((id) => {
1163
- var _a2;
1164
- return (_a2 = questions.find((q) => {
1165
- var _a3;
1166
- return ((_a3 = q.id) == null ? void 0 : _a3.toString()) === id;
1167
- })) == null ? void 0 : _a2.answer;
1168
- });
1170
+ const relatedAnswers = ids.map(
1171
+ (id) => {
1172
+ var _a2;
1173
+ return (_a2 = questions.find((q) => {
1174
+ var _a3;
1175
+ return ((_a3 = q.id) == null ? void 0 : _a3.toString()) === id;
1176
+ })) == null ? void 0 : _a2.answer;
1177
+ }
1178
+ );
1169
1179
  const currentAnswer = question.answer;
1170
1180
  const allAnswers = [...relatedAnswers, currentAnswer];
1171
1181
  if (allAnswers.every((ans) => ans === "")) {
@@ -2037,7 +2047,7 @@ var CookieBanner = ({
2037
2047
  href: "https://pts.se/om-oss/om-pts.se/kakor-pa-webbplatsen/kakor-pa-pts-e-tjanster/",
2038
2048
  target: "_blank",
2039
2049
  rel: "noopener noreferrer",
2040
- children: "Kakor (cookies) p\xE5 pts.se (\xF6ppnas i nytt f\xF6nster)"
2050
+ children: "Kakor (cookies) p\xE5 pts.se (\xF6ppnas i ny flik)"
2041
2051
  }
2042
2052
  )
2043
2053
  ] }),
@@ -2149,7 +2159,7 @@ var LanguageIcon = () => /* @__PURE__ */ jsx17("svg", { width: "15", height: "15
2149
2159
  fill: "#6E3282"
2150
2160
  }
2151
2161
  ) });
2152
- var Logo_sv = () => /* @__PURE__ */ jsxs15("svg", { width: "168.8", height: "46.67", viewBox: "0 0 168.8 46.67", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
2162
+ var Logo_sv = () => /* @__PURE__ */ jsxs15("svg", { width: "168.8", height: "40", viewBox: "0 0 168.8 40", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
2153
2163
  /* @__PURE__ */ jsx17(
2154
2164
  "path",
2155
2165
  {
@@ -2295,7 +2305,7 @@ var Logo_sv = () => /* @__PURE__ */ jsxs15("svg", { width: "168.8", height: "46.
2295
2305
  ),
2296
2306
  /* @__PURE__ */ jsx17("path", { d: "M82.2223 18.3335V37.2224", stroke: "currentColor", strokeWidth: "0.8", strokeMiterlimit: "10" })
2297
2307
  ] });
2298
- var Logo_en = () => /* @__PURE__ */ jsxs15("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: [
2308
+ var Logo_en = () => /* @__PURE__ */ jsxs15("svg", { width: "189.0", height: "40", viewBox: "0 0 189 40", fill: "none", xmlns: "http://www.w3.org/2000/svg", role: "img", children: [
2299
2309
  /* @__PURE__ */ jsx17(
2300
2310
  "path",
2301
2311
  {