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

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,11 +251,6 @@ 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`;
259
254
  return /* @__PURE__ */ jsxs4(Fragment4, { children: [
260
255
  !showPreview && question.visible && /* @__PURE__ */ jsxs4(
261
256
  "div",
@@ -287,20 +282,29 @@ var InputTextarea = ({
287
282
  required: question.isQuestionMandatory,
288
283
  "aria-required": question.isQuestionMandatory,
289
284
  "aria-invalid": question.hasValidationError,
285
+ maxLength: ((_a = question.questionExtraAttribute) == null ? void 0 : _a.answerMaxLength) || defaultMaxLength,
290
286
  "aria-describedby": [question.aboutText ? aboutId : null, question.hasValidationError ? errorId : null].filter(Boolean).join(" ") || void 0,
291
287
  id: inputId
292
288
  }
293
289
  ),
294
290
  /* @__PURE__ */ jsxs4("div", { className: "pts-textarea-counter-error-container", children: [
295
- !isTooLong && question.hasValidationError && /* @__PURE__ */ jsxs4("div", { className: "pts-root-error", id: errorId, children: [
291
+ question.hasValidationError && /* @__PURE__ */ jsxs4("div", { className: "pts-root-error", id: errorId, children: [
296
292
  /* @__PURE__ */ jsx4("span", { "aria-label": "Felmeddelande.", className: "errorDot", children: "!" }),
297
293
  /* @__PURE__ */ jsx4("span", { className: "errorText", children: question.validationDefaultMessesege })
298
294
  ] }),
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 })
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
+ )
304
308
  ] })
305
309
  ]
306
310
  }
@@ -337,21 +341,18 @@ var TextFieldStandard = ({
337
341
  showPreview = false,
338
342
  activatedLanguage
339
343
  }) => {
340
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
344
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
341
345
  const questionId = `question-${question.id}`;
342
346
  const inputId = `textField-${question.id}`;
343
347
  const aboutId = `about-${question.id}`;
344
348
  const errorId = `error-${question.id}`;
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`;
349
+ const defaultMaxLength = 1e3;
349
350
  return /* @__PURE__ */ jsxs5(Fragment5, { children: [
350
351
  !showPreview && question.visible && /* @__PURE__ */ jsxs5(
351
352
  "div",
352
353
  {
353
354
  id: questionId,
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(),
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(),
355
356
  children: [
356
357
  /* @__PURE__ */ jsxs5("label", { htmlFor: inputId, children: [
357
358
  question.questionLabel,
@@ -371,33 +372,29 @@ var TextFieldStandard = ({
371
372
  /* @__PURE__ */ jsx5(
372
373
  "input",
373
374
  {
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,
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,
377
378
  name: `question-name-${question.id}`,
378
379
  className: question.hasValidationError ? "pts-root-question-input-error-border" : void 0,
379
380
  onChange: (e) => handleQuestionInputChange(e, question),
380
381
  value: question.answer,
382
+ maxLength: ((_h = question.questionExtraAttribute) == null ? void 0 : _h.answerMaxLength) || defaultMaxLength,
381
383
  id: inputId,
382
- disabled: (_j = question.questionExtraAttribute) == null ? void 0 : _j.disabled,
384
+ disabled: (_i = question.questionExtraAttribute) == null ? void 0 : _i.disabled,
383
385
  required: question.isQuestionMandatory,
384
386
  "aria-required": question.isQuestionMandatory,
385
387
  "aria-describedby": [question.aboutText ? aboutId : null].filter(Boolean).join(" ") || void 0,
386
388
  "aria-invalid": question.hasValidationError,
387
389
  "aria-errormessage": question.hasValidationError ? errorId : 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
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
390
392
  }
391
393
  ),
392
- !isTooLong && question.hasValidationError && /* @__PURE__ */ jsxs5("div", { className: "pts-root-error", id: errorId, children: [
394
+ question.hasValidationError && /* @__PURE__ */ jsxs5("div", { className: "pts-root-error", id: errorId, children: [
393
395
  /* @__PURE__ */ jsx5("span", { "aria-hidden": true, className: "errorDot", children: "!" }),
394
396
  /* @__PURE__ */ jsx5("span", { className: "sr-only", children: "Valideringsfel" }),
395
397
  /* @__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 })
401
398
  ] })
402
399
  ]
403
400
  }
@@ -623,10 +620,16 @@ var SelectedFiles = ({
623
620
  let newFiles = questionObject.files.filter((f) => f !== file);
624
621
  const newCountOfFiles = newFiles.length;
625
622
  setNumberOfFiles(newCountOfFiles);
626
- const e = { target: { value: `${newCountOfFiles} files`, files: newFiles } };
623
+ let e = { target: { value: `${newCountOfFiles} files`, files: newFiles } };
624
+ const targetValue = e.target.value === "0 files" ? "" : e.target.value;
625
+ e = { ...e, target: { ...e.target, value: targetValue } };
627
626
  isTouched(e, questionObject);
628
627
  removeFile(newCountOfFiles);
629
628
  };
629
+ useEffect4(() => {
630
+ var _a;
631
+ numberOfFiles > 0 && ((_a = theDiv.current) == null ? void 0 : _a.scrollIntoView({ behavior: "smooth", block: "end" }));
632
+ }, [numberOfFiles]);
630
633
  const useWindowWidth = () => {
631
634
  const [windowWidth2, setWindowWidth] = useState4(window.innerWidth);
632
635
  useEffect4(() => {
@@ -909,7 +912,7 @@ var AddFiles = ({
909
912
  const currentFiles = questionObject.files ? questionObject.files : [];
910
913
  const e = {
911
914
  target: {
912
- value: `${currentFiles.length + newFiles.length} files`,
915
+ value: currentFiles.length + newFiles.length > 0 ? `${currentFiles.length + newFiles.length} files` : "",
913
916
  files: [...currentFiles, ...newFiles]
914
917
  }
915
918
  };
@@ -932,68 +935,75 @@ var AddFiles = ({
932
935
  setErrorMessageAddingFile([]);
933
936
  };
934
937
  return /* @__PURE__ */ jsxs9(Fragment11, { children: [
935
- !showPreview && visible && /* @__PURE__ */ jsx11("div", { className: "root-question addFile-question-container", id: `question-${questionObject.id}`, children: /* @__PURE__ */ jsxs9("div", { role: "group", children: [
936
- questionObject.aboutText && /* @__PURE__ */ jsxs9(
937
- "p",
938
- {
939
- id: aboutId,
940
- className: clsx3(
941
- "addFilesMandatory",
942
- questionObject.hasValidationError ? " error" : ""
938
+ !showPreview && visible && /* @__PURE__ */ jsx11(
939
+ "div",
940
+ {
941
+ className: "root-question addFile-question-container",
942
+ id: `question-${questionObject.id}`,
943
+ children: /* @__PURE__ */ jsxs9("div", { role: "group", children: [
944
+ questionObject.aboutText && /* @__PURE__ */ jsxs9(
945
+ "p",
946
+ {
947
+ id: aboutId,
948
+ className: clsx3(
949
+ "addFilesMandatory",
950
+ questionObject.hasValidationError ? " error" : ""
951
+ ),
952
+ children: [
953
+ questionObject.aboutText,
954
+ questionObject.isQuestionMandatory && /* @__PURE__ */ jsxs9("span", { className: "pts-root-mandatoryAsterisk", "aria-label": "Obligatorisk fr\xE5ga", children: [
955
+ " ",
956
+ "*"
957
+ ] })
958
+ ]
959
+ }
943
960
  ),
944
- children: [
945
- questionObject.aboutText,
946
- questionObject.isQuestionMandatory && /* @__PURE__ */ jsxs9("span", { className: "pts-root-mandatoryAsterisk", "aria-label": "Obligatorisk fr\xE5ga", children: [
947
- " ",
948
- "*"
949
- ] })
950
- ]
951
- }
952
- ),
953
- questionObject.hasValidationError && /* @__PURE__ */ jsxs9("div", { className: "pts-root-error error addfileserror", id: errorId, children: [
954
- /* @__PURE__ */ jsx11("span", { "aria-hidden": true, className: "errorDot", children: "!" }),
955
- /* @__PURE__ */ jsx11("span", { className: "sr-only", children: "Valideringsfel" }),
956
- /* @__PURE__ */ jsx11("span", { className: "errorText", children: questionObject.validationDefaultMessesege })
957
- ] }),
958
- /* @__PURE__ */ jsx11(
959
- ExploreFilesStandard_default,
960
- {
961
- FilesSelected: onDrop,
962
- numberOfFiles,
963
- allowedNumberOfFiles,
964
- activatedLanguage,
965
- inputId,
966
- labelId,
967
- aboutId,
968
- errorId,
969
- questionObject,
970
- errorMessageAddingFile,
971
- removeUploadErrors: handleRemoveErrors
972
- }
973
- ),
974
- /* @__PURE__ */ jsx11(
975
- DropFilesStandard_default,
976
- {
977
- FilesSelected: onDrop,
978
- DropFilesText: dropFilesText,
979
- language: activatedLanguage
980
- }
981
- ),
982
- /* @__PURE__ */ jsx11(
983
- SelectedFilesStandard_default,
984
- {
985
- questionObject,
986
- isTouched: handleQuestionInputChange,
987
- removeFile: removeFileFromNumberOfFiles,
988
- removeError,
989
- errorMessageAddingFile,
990
- activatedLanguage,
991
- numberOfFiles,
992
- setNumberOfFiles,
993
- removeUploadErrors: handleRemoveErrors
994
- }
995
- )
996
- ] }) }),
961
+ questionObject.hasValidationError && /* @__PURE__ */ jsxs9("div", { className: "pts-root-error error addfileserror", id: errorId, children: [
962
+ /* @__PURE__ */ jsx11("span", { "aria-hidden": true, className: "errorDot", children: "!" }),
963
+ /* @__PURE__ */ jsx11("span", { className: "sr-only", children: "Valideringsfel" }),
964
+ /* @__PURE__ */ jsx11("span", { className: "errorText", children: questionObject.validationDefaultMessesege })
965
+ ] }),
966
+ /* @__PURE__ */ jsx11(
967
+ ExploreFilesStandard_default,
968
+ {
969
+ FilesSelected: onDrop,
970
+ numberOfFiles,
971
+ allowedNumberOfFiles,
972
+ activatedLanguage,
973
+ inputId,
974
+ labelId,
975
+ aboutId,
976
+ errorId,
977
+ questionObject,
978
+ errorMessageAddingFile,
979
+ removeUploadErrors: handleRemoveErrors
980
+ }
981
+ ),
982
+ /* @__PURE__ */ jsx11(
983
+ DropFilesStandard_default,
984
+ {
985
+ FilesSelected: onDrop,
986
+ DropFilesText: dropFilesText,
987
+ language: activatedLanguage
988
+ }
989
+ ),
990
+ /* @__PURE__ */ jsx11(
991
+ SelectedFilesStandard_default,
992
+ {
993
+ questionObject,
994
+ isTouched: handleQuestionInputChange,
995
+ removeFile: removeFileFromNumberOfFiles,
996
+ removeError,
997
+ errorMessageAddingFile,
998
+ activatedLanguage,
999
+ numberOfFiles,
1000
+ setNumberOfFiles,
1001
+ removeUploadErrors: handleRemoveErrors
1002
+ }
1003
+ )
1004
+ ] })
1005
+ }
1006
+ ),
997
1007
  showPreview && /* @__PURE__ */ jsx11(PreviewAddFiles, { activatedLanguage, questionObject })
998
1008
  ] });
999
1009
  };
@@ -1107,7 +1117,7 @@ var PreviewSingleCheckbox = ({
1107
1117
  // src/helpers/hasQuestionValidationError/hasQuestionValidationError.tsx
1108
1118
  import { isValid, parseISO } from "date-fns";
1109
1119
  var hasQuestionValidationError = (question, questions) => {
1110
- var _a, _b, _c, _d, _e, _f, _g, _h;
1120
+ var _a, _b, _c, _d, _e;
1111
1121
  let error = false;
1112
1122
  if (question.isQuestionMandatory) {
1113
1123
  if (question.isTouched === false) {
@@ -1120,28 +1130,19 @@ var hasQuestionValidationError = (question, questions) => {
1120
1130
  error = true;
1121
1131
  }
1122
1132
  }
1123
- const maxLength = (_c = (_b = question.questionExtraAttribute) == null ? void 0 : _b.answerMaxLength) != null ? _c : 1e3;
1124
- if (((_d = question.validationType) == null ? void 0 : _d.includes("maxLength")) && question.answer.length > maxLength) {
1125
- error = true;
1126
- }
1127
- if (question.questionType === "TextField") {
1128
- if (question.answer.length > 100) {
1129
- error = true;
1130
- }
1131
- }
1132
- if (((_e = question.validationType) == null ? void 0 : _e.find((e) => e === "email")) && (question.isQuestionMandatory || question.answer !== "")) {
1133
+ if (((_b = question.validationType) == null ? void 0 : _b.find((e) => e === "email")) && (question.isQuestionMandatory || question.answer !== "")) {
1133
1134
  const emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
1134
1135
  if (!emailRegex.test(question.answer)) {
1135
1136
  error = true;
1136
1137
  }
1137
1138
  }
1138
- if (((_f = question.validationType) == null ? void 0 : _f.find((e) => e === "fourNumbers")) && (question.isQuestionMandatory || question.answer !== "")) {
1139
+ if (((_c = question.validationType) == null ? void 0 : _c.find((e) => e === "fourNumbers")) && (question.isQuestionMandatory || question.answer !== "")) {
1139
1140
  const fourNumbersRegex = /^\d{4}$/.test(question.answer);
1140
1141
  if (!fourNumbersRegex) {
1141
1142
  error = true;
1142
1143
  }
1143
1144
  }
1144
- if (((_g = question.validationType) == null ? void 0 : _g.find((e) => e === "isDateFormatValid")) && question.answer !== "") {
1145
+ if (((_d = question.validationType) == null ? void 0 : _d.find((e) => e === "isDateFormatValid")) && question.answer !== "") {
1145
1146
  const regex = /^\d{4}-\d{2}-\d{2}$/;
1146
1147
  if (!regex.test(question.answer)) {
1147
1148
  error = true;
@@ -1155,18 +1156,16 @@ var hasQuestionValidationError = (question, questions) => {
1155
1156
  error = true;
1156
1157
  }
1157
1158
  }
1158
- const groupCheckError = (_h = question.validationType) == null ? void 0 : _h.find((e) => e.startsWith("groupCheck-"));
1159
+ const groupCheckError = (_e = question.validationType) == null ? void 0 : _e.find((e) => e.startsWith("groupCheck-"));
1159
1160
  if (groupCheckError) {
1160
1161
  const ids = groupCheckError.replace("groupCheck-", "").split("-");
1161
- const relatedAnswers = ids.map(
1162
- (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
- }
1169
- );
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
1169
  const currentAnswer = question.answer;
1171
1170
  const allAnswers = [...relatedAnswers, currentAnswer];
1172
1171
  if (allAnswers.every((ans) => ans === "")) {
@@ -2038,7 +2037,7 @@ var CookieBanner = ({
2038
2037
  href: "https://pts.se/om-oss/om-pts.se/kakor-pa-webbplatsen/kakor-pa-pts-e-tjanster/",
2039
2038
  target: "_blank",
2040
2039
  rel: "noopener noreferrer",
2041
- children: "Kakor (cookies) p\xE5 pts.se (\xF6ppnas i ny flik)"
2040
+ children: "Kakor (cookies) p\xE5 pts.se (\xF6ppnas i nytt f\xF6nster)"
2042
2041
  }
2043
2042
  )
2044
2043
  ] }),
@@ -2150,7 +2149,7 @@ var LanguageIcon = () => /* @__PURE__ */ jsx17("svg", { width: "15", height: "15
2150
2149
  fill: "#6E3282"
2151
2150
  }
2152
2151
  ) });
2153
- 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: [
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: [
2154
2153
  /* @__PURE__ */ jsx17(
2155
2154
  "path",
2156
2155
  {
@@ -2296,7 +2295,7 @@ var Logo_sv = () => /* @__PURE__ */ jsxs15("svg", { width: "168.8", height: "40"
2296
2295
  ),
2297
2296
  /* @__PURE__ */ jsx17("path", { d: "M82.2223 18.3335V37.2224", stroke: "currentColor", strokeWidth: "0.8", strokeMiterlimit: "10" })
2298
2297
  ] });
2299
- 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: [
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: [
2300
2299
  /* @__PURE__ */ jsx17(
2301
2300
  "path",
2302
2301
  {