optimized-react-component-library-xyz123 0.1.7 → 0.1.9

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.d.mts CHANGED
@@ -86,6 +86,7 @@ interface IQuestionExtraAttribute {
86
86
  inputType?: string;
87
87
  showTextAreaCounter?: boolean;
88
88
  hideValidationMessage?: boolean;
89
+ hideTextCounter?: boolean;
89
90
  }
90
91
  interface IStepQuestionData {
91
92
  step: number;
@@ -289,16 +290,11 @@ interface TextHeadlineAndBodyProps {
289
290
 
290
291
  declare const TextHeadlineAndBody: FC<TextHeadlineAndBodyProps>;
291
292
 
292
- interface ValidationError {
293
- id: string;
294
- fieldName: string;
295
- }
296
293
  interface ValidationErrorSummaryListProps {
297
294
  formQuestions: any[];
298
295
  activatedLanguage: string;
299
296
  validationErrorsList: any[];
300
297
  summaryText?: string;
301
- onErrorClick?: (error: ValidationError) => void;
302
298
  }
303
299
 
304
300
  declare const ValidationErrorSummaryList: React.FC<ValidationErrorSummaryListProps>;
package/dist/index.d.ts CHANGED
@@ -86,6 +86,7 @@ interface IQuestionExtraAttribute {
86
86
  inputType?: string;
87
87
  showTextAreaCounter?: boolean;
88
88
  hideValidationMessage?: boolean;
89
+ hideTextCounter?: boolean;
89
90
  }
90
91
  interface IStepQuestionData {
91
92
  step: number;
@@ -289,16 +290,11 @@ interface TextHeadlineAndBodyProps {
289
290
 
290
291
  declare const TextHeadlineAndBody: FC<TextHeadlineAndBodyProps>;
291
292
 
292
- interface ValidationError {
293
- id: string;
294
- fieldName: string;
295
- }
296
293
  interface ValidationErrorSummaryListProps {
297
294
  formQuestions: any[];
298
295
  activatedLanguage: string;
299
296
  validationErrorsList: any[];
300
297
  summaryText?: string;
301
- onErrorClick?: (error: ValidationError) => void;
302
298
  }
303
299
 
304
300
  declare const ValidationErrorSummaryList: React.FC<ValidationErrorSummaryListProps>;
package/dist/index.js CHANGED
@@ -240,8 +240,13 @@ var PrevieMultipleCheckboxes = ({
240
240
  // src/NewInputComponentStandard/TextAreaStandard/TextAreaStandard.tsx
241
241
  var import_dompurify = __toESM(require("dompurify"));
242
242
  var import_jsx_runtime3 = require("react/jsx-runtime");
243
- var InputTextarea = ({ question, isTouched, showPreview = false, activatedLanguage }) => {
244
- var _a, _b, _c, _d;
243
+ var InputTextarea = ({
244
+ question,
245
+ isTouched,
246
+ showPreview = false,
247
+ activatedLanguage
248
+ }) => {
249
+ var _a, _b, _c, _d, _e;
245
250
  const questionId = `question-${question.id}`;
246
251
  const inputId = `textarea-${question.id}`;
247
252
  const aboutId = `about-${question.id}`;
@@ -287,15 +292,15 @@ var InputTextarea = ({ question, isTouched, showPreview = false, activatedLangua
287
292
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { "aria-label": "Felmeddelande.", className: "errorDot", children: "!" }),
288
293
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "errorText", children: question.validationDefaultMessesege })
289
294
  ] }),
290
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
295
+ !((_b = question.questionExtraAttribute) == null ? void 0 : _b.hideTextCounter) && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
291
296
  "div",
292
297
  {
293
- className: `pts-character-counter ${question.answer && (((_b = question.questionExtraAttribute) == null ? void 0 : _b.answerMaxLength) || defaultMaxLength) && question.answer.length > (((_c = question.questionExtraAttribute) == null ? void 0 : _c.answerMaxLength) || defaultMaxLength) ? "error" : ""}`,
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" : ""}`,
294
299
  children: [
295
300
  question.answer ? question.answer.length : 0,
296
301
  " av",
297
302
  " ",
298
- ((_d = question.questionExtraAttribute) == null ? void 0 : _d.answerMaxLength) || defaultMaxLength,
303
+ ((_e = question.questionExtraAttribute) == null ? void 0 : _e.answerMaxLength) || defaultMaxLength,
299
304
  " tecken"
300
305
  ]
301
306
  }
@@ -1960,78 +1965,53 @@ var Stepper = ({ arraySteps = [], activeStep = 1 }) => {
1960
1965
  var StepperStandard_default = Stepper;
1961
1966
 
1962
1967
  // src/NewTextComponentStandard/ValidationErrorSummaryList/ValidationErrorSummaryList.tsx
1963
- var import_react6 = require("react");
1964
1968
  var import_jsx_runtime20 = require("react/jsx-runtime");
1965
1969
  var ValidationErrorSummaryList = ({
1966
1970
  validationErrorsList,
1967
1971
  formQuestions,
1968
1972
  activatedLanguage,
1969
- summaryText = "Du beh\xF6ver \xE5tg\xE4rda {count} {plural}",
1970
- onErrorClick
1973
+ summaryText = "Du beh\xF6ver \xE5tg\xE4rda {count} {plural}"
1971
1974
  }) => {
1972
- const [validationErrors, setValidationErrors] = (0, import_react6.useState)([]);
1973
- const getFieldName = (errorId) => {
1974
- const questionId = errorId.replace("error-", "");
1975
- const selectors = [
1976
- `#label-${questionId}`,
1977
- `label[for*="${questionId}"]`,
1978
- `legend[id*="${questionId}"]`
1979
- ];
1980
- for (const selector of selectors) {
1981
- const element = document.querySelector(selector);
1982
- if (element == null ? void 0 : element.textContent) return element.textContent.trim().replace("*", "").trim();
1983
- }
1984
- return "Ok\xE4nt f\xE4lt";
1985
- };
1986
- const detectValidationErrors = () => {
1987
- const errors = [];
1988
- document.querySelectorAll("#pts-form-id .pts-root-error").forEach((container) => {
1989
- var _a, _b;
1990
- if (!container.offsetParent) return;
1991
- const errorText = (_b = (_a = container.querySelector(".errorText")) == null ? void 0 : _a.textContent) == null ? void 0 : _b.trim();
1992
- if (!errorText) return;
1993
- const errorId = container.id || `error-${Date.now()}`;
1994
- errors.push({ id: errorId, fieldName: getFieldName(errorId) });
1995
- });
1996
- setValidationErrors(errors);
1997
- };
1998
- (0, import_react6.useEffect)(detectValidationErrors, [validationErrorsList]);
1999
- const handleErrorClick = (error, e) => {
2000
- e.preventDefault();
2001
- if (onErrorClick) onErrorClick(error);
2002
- const questionId = error.id.replace("error-", "");
2003
- const selectors = [
2004
- `#radio-group-${questionId}`,
2005
- `input[name*="${questionId}"]`,
2006
- `#${questionId}`
2007
- ];
2008
- for (const selector of selectors) {
2009
- const element = document.querySelector(selector);
2010
- if (element) {
2011
- element.scrollIntoView();
2012
- try {
2013
- element.focus();
2014
- } catch {
1975
+ console.log(formQuestions);
1976
+ console.log(validationErrorsList);
1977
+ function scrollToQuestion(questionId) {
1978
+ const container = document.getElementById(`question-${questionId}`);
1979
+ if (container) {
1980
+ container.scrollIntoView({ behavior: "smooth", block: "center" });
1981
+ setTimeout(() => {
1982
+ const input = container.querySelector("input, textarea, select");
1983
+ if (input) {
1984
+ input.focus();
2015
1985
  }
2016
- break;
2017
- }
1986
+ }, 300);
2018
1987
  }
2019
- };
2020
- if (!validationErrors.length) return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_jsx_runtime20.Fragment, {});
2021
- const count = validationErrors.length;
1988
+ }
1989
+ if (!validationErrorsList.length) return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_jsx_runtime20.Fragment, {});
1990
+ const count = validationErrorsList.length;
2022
1991
  const title = summaryText.replace("{count}", count.toString()).replace("{plural}", count === 1 ? "sak" : "saker");
1992
+ function getQuestionLabelById(id) {
1993
+ const found = formQuestions.find((item) => item.id === id);
1994
+ return found == null ? void 0 : found.questionLabel;
1995
+ }
2023
1996
  return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(
2024
1997
  "div",
2025
1998
  {
2026
1999
  id: "pts-form-id-error-summary",
2027
- role: "alert",
2028
2000
  className: "pts-errorSummary-container pts-root-error",
2029
2001
  tabIndex: -1,
2030
2002
  children: [
2031
2003
  /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("span", { "aria-hidden": "true", className: "errorDot", children: "!" }),
2032
2004
  /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "errorSummary-content", children: [
2033
2005
  /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("h2", { children: title }),
2034
- /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("ul", { children: validationErrors.map((error, i) => /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("a", { href: "#", onClick: (e) => handleErrorClick(error, e), className: "errorSummary-text", children: error.fieldName }) }, error.id || i)) })
2006
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("ul", { children: validationErrorsList.map((questionId, i) => /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2007
+ "a",
2008
+ {
2009
+ href: "#",
2010
+ onClick: (e) => scrollToQuestion(questionId),
2011
+ className: "errorSummary-text",
2012
+ children: getQuestionLabelById(questionId)
2013
+ }
2014
+ ) }, questionId || i)) })
2035
2015
  ] })
2036
2016
  ]
2037
2017
  }
package/dist/index.mjs CHANGED
@@ -177,8 +177,13 @@ var PrevieMultipleCheckboxes = ({
177
177
  // src/NewInputComponentStandard/TextAreaStandard/TextAreaStandard.tsx
178
178
  import DOMPurify from "dompurify";
179
179
  import { Fragment as Fragment3, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
180
- var InputTextarea = ({ question, isTouched, showPreview = false, activatedLanguage }) => {
181
- var _a, _b, _c, _d;
180
+ var InputTextarea = ({
181
+ question,
182
+ isTouched,
183
+ showPreview = false,
184
+ activatedLanguage
185
+ }) => {
186
+ var _a, _b, _c, _d, _e;
182
187
  const questionId = `question-${question.id}`;
183
188
  const inputId = `textarea-${question.id}`;
184
189
  const aboutId = `about-${question.id}`;
@@ -224,15 +229,15 @@ var InputTextarea = ({ question, isTouched, showPreview = false, activatedLangua
224
229
  /* @__PURE__ */ jsx3("span", { "aria-label": "Felmeddelande.", className: "errorDot", children: "!" }),
225
230
  /* @__PURE__ */ jsx3("span", { className: "errorText", children: question.validationDefaultMessesege })
226
231
  ] }),
227
- /* @__PURE__ */ jsxs3(
232
+ !((_b = question.questionExtraAttribute) == null ? void 0 : _b.hideTextCounter) && /* @__PURE__ */ jsxs3(
228
233
  "div",
229
234
  {
230
- className: `pts-character-counter ${question.answer && (((_b = question.questionExtraAttribute) == null ? void 0 : _b.answerMaxLength) || defaultMaxLength) && question.answer.length > (((_c = question.questionExtraAttribute) == null ? void 0 : _c.answerMaxLength) || defaultMaxLength) ? "error" : ""}`,
235
+ 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" : ""}`,
231
236
  children: [
232
237
  question.answer ? question.answer.length : 0,
233
238
  " av",
234
239
  " ",
235
- ((_d = question.questionExtraAttribute) == null ? void 0 : _d.answerMaxLength) || defaultMaxLength,
240
+ ((_e = question.questionExtraAttribute) == null ? void 0 : _e.answerMaxLength) || defaultMaxLength,
236
241
  " tecken"
237
242
  ]
238
243
  }
@@ -1897,78 +1902,53 @@ var Stepper = ({ arraySteps = [], activeStep = 1 }) => {
1897
1902
  var StepperStandard_default = Stepper;
1898
1903
 
1899
1904
  // src/NewTextComponentStandard/ValidationErrorSummaryList/ValidationErrorSummaryList.tsx
1900
- import { useState as useState4, useEffect as useEffect4 } from "react";
1901
1905
  import { Fragment as Fragment9, jsx as jsx20, jsxs as jsxs18 } from "react/jsx-runtime";
1902
1906
  var ValidationErrorSummaryList = ({
1903
1907
  validationErrorsList,
1904
1908
  formQuestions,
1905
1909
  activatedLanguage,
1906
- summaryText = "Du beh\xF6ver \xE5tg\xE4rda {count} {plural}",
1907
- onErrorClick
1910
+ summaryText = "Du beh\xF6ver \xE5tg\xE4rda {count} {plural}"
1908
1911
  }) => {
1909
- const [validationErrors, setValidationErrors] = useState4([]);
1910
- const getFieldName = (errorId) => {
1911
- const questionId = errorId.replace("error-", "");
1912
- const selectors = [
1913
- `#label-${questionId}`,
1914
- `label[for*="${questionId}"]`,
1915
- `legend[id*="${questionId}"]`
1916
- ];
1917
- for (const selector of selectors) {
1918
- const element = document.querySelector(selector);
1919
- if (element == null ? void 0 : element.textContent) return element.textContent.trim().replace("*", "").trim();
1920
- }
1921
- return "Ok\xE4nt f\xE4lt";
1922
- };
1923
- const detectValidationErrors = () => {
1924
- const errors = [];
1925
- document.querySelectorAll("#pts-form-id .pts-root-error").forEach((container) => {
1926
- var _a, _b;
1927
- if (!container.offsetParent) return;
1928
- const errorText = (_b = (_a = container.querySelector(".errorText")) == null ? void 0 : _a.textContent) == null ? void 0 : _b.trim();
1929
- if (!errorText) return;
1930
- const errorId = container.id || `error-${Date.now()}`;
1931
- errors.push({ id: errorId, fieldName: getFieldName(errorId) });
1932
- });
1933
- setValidationErrors(errors);
1934
- };
1935
- useEffect4(detectValidationErrors, [validationErrorsList]);
1936
- const handleErrorClick = (error, e) => {
1937
- e.preventDefault();
1938
- if (onErrorClick) onErrorClick(error);
1939
- const questionId = error.id.replace("error-", "");
1940
- const selectors = [
1941
- `#radio-group-${questionId}`,
1942
- `input[name*="${questionId}"]`,
1943
- `#${questionId}`
1944
- ];
1945
- for (const selector of selectors) {
1946
- const element = document.querySelector(selector);
1947
- if (element) {
1948
- element.scrollIntoView();
1949
- try {
1950
- element.focus();
1951
- } catch {
1912
+ console.log(formQuestions);
1913
+ console.log(validationErrorsList);
1914
+ function scrollToQuestion(questionId) {
1915
+ const container = document.getElementById(`question-${questionId}`);
1916
+ if (container) {
1917
+ container.scrollIntoView({ behavior: "smooth", block: "center" });
1918
+ setTimeout(() => {
1919
+ const input = container.querySelector("input, textarea, select");
1920
+ if (input) {
1921
+ input.focus();
1952
1922
  }
1953
- break;
1954
- }
1923
+ }, 300);
1955
1924
  }
1956
- };
1957
- if (!validationErrors.length) return /* @__PURE__ */ jsx20(Fragment9, {});
1958
- const count = validationErrors.length;
1925
+ }
1926
+ if (!validationErrorsList.length) return /* @__PURE__ */ jsx20(Fragment9, {});
1927
+ const count = validationErrorsList.length;
1959
1928
  const title = summaryText.replace("{count}", count.toString()).replace("{plural}", count === 1 ? "sak" : "saker");
1929
+ function getQuestionLabelById(id) {
1930
+ const found = formQuestions.find((item) => item.id === id);
1931
+ return found == null ? void 0 : found.questionLabel;
1932
+ }
1960
1933
  return /* @__PURE__ */ jsxs18(
1961
1934
  "div",
1962
1935
  {
1963
1936
  id: "pts-form-id-error-summary",
1964
- role: "alert",
1965
1937
  className: "pts-errorSummary-container pts-root-error",
1966
1938
  tabIndex: -1,
1967
1939
  children: [
1968
1940
  /* @__PURE__ */ jsx20("span", { "aria-hidden": "true", className: "errorDot", children: "!" }),
1969
1941
  /* @__PURE__ */ jsxs18("div", { className: "errorSummary-content", children: [
1970
1942
  /* @__PURE__ */ jsx20("h2", { children: title }),
1971
- /* @__PURE__ */ jsx20("ul", { children: validationErrors.map((error, i) => /* @__PURE__ */ jsx20("li", { children: /* @__PURE__ */ jsx20("a", { href: "#", onClick: (e) => handleErrorClick(error, e), className: "errorSummary-text", children: error.fieldName }) }, error.id || i)) })
1943
+ /* @__PURE__ */ jsx20("ul", { children: validationErrorsList.map((questionId, i) => /* @__PURE__ */ jsx20("li", { children: /* @__PURE__ */ jsx20(
1944
+ "a",
1945
+ {
1946
+ href: "#",
1947
+ onClick: (e) => scrollToQuestion(questionId),
1948
+ className: "errorSummary-text",
1949
+ children: getQuestionLabelById(questionId)
1950
+ }
1951
+ ) }, questionId || i)) })
1972
1952
  ] })
1973
1953
  ]
1974
1954
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "optimized-react-component-library-xyz123",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "A modern React component library using TypeScript.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",