@digigov/react-modules 1.2.0-rc.32 → 2.0.0-16fbe090

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.
Files changed (89) hide show
  1. package/Faq/Results.js +34 -0
  2. package/Faq/hooks.d.ts +1 -1
  3. package/Faq/hooks.js +54 -0
  4. package/Faq/index.js +191 -163
  5. package/Faq/slug.js +94 -0
  6. package/Faq/utils.js +3 -0
  7. package/FilteredResults/DataTable.js +12 -0
  8. package/FilteredResults/FilterChips.js +34 -0
  9. package/FilteredResults/FilterFields.js +13 -0
  10. package/FilteredResults/hooks.d.ts +1 -1
  11. package/FilteredResults/hooks.js +78 -0
  12. package/FilteredResults/index.js +96 -112
  13. package/index.d.ts +2 -2
  14. package/index.js +3 -4
  15. package/lazy.d.ts +17 -0
  16. package/lazy.js +28 -0
  17. package/package.json +10 -10
  18. package/registry.d.ts +14 -0
  19. package/registry.js +34 -0
  20. package/Faq/Faq.stories.d.ts +0 -8
  21. package/Faq/Results/index.js +0 -29
  22. package/Faq/Results/package.json +0 -6
  23. package/Faq/Results.js.map +0 -7
  24. package/Faq/__stories__/Default.d.ts +0 -2
  25. package/Faq/hooks/index.js +0 -66
  26. package/Faq/hooks/package.json +0 -6
  27. package/Faq/hooks.js.map +0 -7
  28. package/Faq/index.js.map +0 -7
  29. package/Faq/index.test.d.ts +0 -1
  30. package/Faq/package.json +0 -6
  31. package/Faq/slug/index.js +0 -97
  32. package/Faq/slug/package.json +0 -6
  33. package/Faq/slug.js.map +0 -7
  34. package/Faq/splitted.test.d.ts +0 -1
  35. package/Faq/utils/index.js +0 -8
  36. package/Faq/utils/package.json +0 -6
  37. package/Faq/utils.js.map +0 -7
  38. package/FilteredResults/DataTable/index.js +0 -18
  39. package/FilteredResults/DataTable/package.json +0 -6
  40. package/FilteredResults/DataTable.js.map +0 -7
  41. package/FilteredResults/FilterChips/index.js +0 -52
  42. package/FilteredResults/FilterChips/package.json +0 -6
  43. package/FilteredResults/FilterChips.js.map +0 -7
  44. package/FilteredResults/FilterFields/index.js +0 -11
  45. package/FilteredResults/FilterFields/package.json +0 -6
  46. package/FilteredResults/FilterFields.js.map +0 -7
  47. package/FilteredResults/FilteredResults.stories.d.ts +0 -8
  48. package/FilteredResults/__stories__/Default.d.ts +0 -2
  49. package/FilteredResults/hooks/index.js +0 -105
  50. package/FilteredResults/hooks/package.json +0 -6
  51. package/FilteredResults/hooks.js.map +0 -7
  52. package/FilteredResults/index.js.map +0 -7
  53. package/FilteredResults/index.test.d.ts +0 -1
  54. package/FilteredResults/package.json +0 -6
  55. package/FilteredResults/splitted.test.d.ts +0 -1
  56. package/ReactModules.stories.d.ts +0 -4
  57. package/cjs/Faq/Results/index.js +0 -58
  58. package/cjs/Faq/Results.js.map +0 -7
  59. package/cjs/Faq/hooks/index.js +0 -90
  60. package/cjs/Faq/hooks.js.map +0 -7
  61. package/cjs/Faq/index.js +0 -194
  62. package/cjs/Faq/index.js.map +0 -7
  63. package/cjs/Faq/slug/index.js +0 -120
  64. package/cjs/Faq/slug.js.map +0 -7
  65. package/cjs/Faq/utils/index.js +0 -31
  66. package/cjs/Faq/utils.js.map +0 -7
  67. package/cjs/FilteredResults/DataTable/index.js +0 -42
  68. package/cjs/FilteredResults/DataTable.js.map +0 -7
  69. package/cjs/FilteredResults/FilterChips/index.js +0 -82
  70. package/cjs/FilteredResults/FilterChips.js.map +0 -7
  71. package/cjs/FilteredResults/FilterFields/index.js +0 -44
  72. package/cjs/FilteredResults/FilterFields.js.map +0 -7
  73. package/cjs/FilteredResults/hooks/index.js +0 -132
  74. package/cjs/FilteredResults/hooks.js.map +0 -7
  75. package/cjs/FilteredResults/index.js +0 -153
  76. package/cjs/FilteredResults/index.js.map +0 -7
  77. package/cjs/index.js +0 -24
  78. package/cjs/index.js.map +0 -7
  79. package/cjs/lazy.js +0 -44
  80. package/cjs/lazy.js.map +0 -7
  81. package/cjs/registry.js +0 -73
  82. package/cjs/registry.js.map +0 -7
  83. package/index.js.map +0 -7
  84. package/lazy/package.json +0 -6
  85. package/registry/package.json +0 -6
  86. package/src/lazy.js +0 -11
  87. package/src/registry.js +0 -43
  88. /package/{lazy/index.js → src/lazy.ts} +0 -0
  89. /package/{registry/index.js → src/registry.ts} +0 -0
package/Faq/Results.js ADDED
@@ -0,0 +1,34 @@
1
+ import react, { useCallback } from "react";
2
+ import { useFormContext } from "@digigov/form/FormBuilder/index.js";
3
+ import Button from "@digigov/ui/form/Button/index.js";
4
+ import { Heading } from "@digigov/ui/typography/Heading/index.js";
5
+ const Results_Results = /*#__PURE__*/ react.forwardRef(function({ filteredSections, Onclose, activeQa, primarySections }, ref) {
6
+ const { resetField, submit } = useFormContext();
7
+ const handleReset = useCallback((e)=>{
8
+ e.preventDefault();
9
+ const urlParams = new URLSearchParams(window.location.search);
10
+ urlParams.delete('text');
11
+ urlParams.delete('activeQa');
12
+ window.history.replaceState({}, '', '?' + urlParams.toString());
13
+ resetField('text', {
14
+ defaultValue: ''
15
+ });
16
+ Onclose(activeQa);
17
+ submit();
18
+ }, [
19
+ resetField,
20
+ Onclose,
21
+ submit,
22
+ activeQa
23
+ ]);
24
+ return /*#__PURE__*/ react.createElement(Heading, {
25
+ ref: ref,
26
+ size: "sm",
27
+ marginTop: 4
28
+ }, "Αποτελέσματα: ", filteredSections, " από ", primarySections, ".", ' ', /*#__PURE__*/ react.createElement(Button, {
29
+ variant: "link",
30
+ onClick: (e)=>handleReset(e)
31
+ }, "Επαναφορά αναζήτησης"));
32
+ });
33
+ const Faq_Results = Results_Results;
34
+ export { Faq_Results as default };
package/Faq/hooks.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { sectionsConfigType, SectionType } from '@digigov/react-modules/Faq';
1
+ import { sectionsConfigType, SectionType } from './index.js';
2
2
  export declare const useURLParamsSearch: (searchFunc: (params: Record<string, string | undefined>) => void, { navigate, filteredSections, }: {
3
3
  navigate: (url: string) => void;
4
4
  filteredSections: SectionType[];
package/Faq/hooks.js ADDED
@@ -0,0 +1,54 @@
1
+ import { useState } from "react";
2
+ import { slug } from "./slug.js";
3
+ const removeAccents = (text)=>text.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
4
+ const useURLParamsSearch = (searchFunc, { navigate, filteredSections })=>{
5
+ const urlParams = new URLSearchParams(window.location.search);
6
+ const currentParams = Object.fromEntries(urlParams.entries());
7
+ const hashId = window.location.hash ? window.location.hash.slice(1) : '';
8
+ const hashExistsInFilteredSections = filteredSections.some((section)=>section.qa.some(({ id, question })=>id === hashId || slug(question) === hashId));
9
+ const search = (params)=>{
10
+ const updatedParams = Object.entries({
11
+ ...currentParams,
12
+ ...params
13
+ }).filter(([, value])=>Boolean(value)).reduce((acc, [key, value])=>{
14
+ acc[key] = value;
15
+ return acc;
16
+ }, {});
17
+ const newUrl = Object.keys(updatedParams).length ? '?' + new URLSearchParams(updatedParams).toString() : window.location.pathname;
18
+ const finalURL = hashExistsInFilteredSections ? newUrl + `#${hashId}` : newUrl;
19
+ navigate(finalURL);
20
+ return searchFunc(params);
21
+ };
22
+ return {
23
+ search,
24
+ values: {
25
+ text: currentParams.text
26
+ },
27
+ hashId
28
+ };
29
+ };
30
+ const useFaqSearch = (questions)=>{
31
+ const [filteredSections, setFilteredSections] = useState(questions.sections);
32
+ const search = (values)=>{
33
+ if (!values || !values.text?.trim()) return void setFilteredSections(questions.sections);
34
+ const searchValue = values.text.trim();
35
+ const normalizedSearchWord = removeAccents(searchValue.toLowerCase());
36
+ const filteredSections = questions.sections.map((section)=>{
37
+ const filteredQa = section.qa.filter(({ question, answer })=>{
38
+ const normalizedQuestion = removeAccents(question?.toLowerCase() || '');
39
+ const normalizedAnswer = removeAccents(answer?.toLowerCase() || '');
40
+ return normalizedQuestion.includes(normalizedSearchWord) || normalizedAnswer.includes(normalizedSearchWord);
41
+ });
42
+ return {
43
+ ...section,
44
+ qa: filteredQa
45
+ };
46
+ }).filter((section)=>section.qa.length > 0);
47
+ setFilteredSections(filteredSections);
48
+ };
49
+ return {
50
+ filteredSections,
51
+ search
52
+ };
53
+ };
54
+ export { useFaqSearch, useURLParamsSearch };
package/Faq/index.js CHANGED
@@ -1,169 +1,197 @@
1
- import React, { useEffect, useContext } from "react";
2
- import { Field } from "@digigov/form/Field";
3
- import FormBuilder from "@digigov/form/FormBuilder";
4
- import { FormContext } from "@digigov/form/FormContext";
5
- import Results from "@digigov/react-modules/Faq/Results";
6
- import { createId } from "@digigov/react-modules/Faq/utils";
7
- import PageTitleContainer, {
8
- PageTitleHeading
9
- } from "@digigov/ui/app/PageTitleContainer";
10
- import {
11
- Accordion,
12
- AccordionSection,
13
- AccordionSectionContent,
14
- AccordionSectionSummary,
15
- AccordionSectionSummaryHeading
16
- } from "@digigov/ui/content/Accordion";
17
- import { useAccordion } from "@digigov/ui/content/Accordion/hooks";
18
- import Markdown from "@digigov/ui/content/Markdown";
19
- import { SearchButton } from "@digigov/ui/form/SearchContainer";
20
- import { Stack } from "@digigov/ui/layouts";
21
- import { Aside } from "@digigov/ui/layouts/Basic/Aside";
22
- import { Container } from "@digigov/ui/layouts/Basic/Container";
23
- import { Main } from "@digigov/ui/layouts/Basic/Main";
24
- import Grid from "@digigov/ui/layouts/Grid";
25
- import SectionBreak from "@digigov/ui/layouts/SectionBreak";
26
- import { BackToTop } from "@digigov/ui/navigation/BackToTopLink";
27
- import NavList, { NavListItemAction } from "@digigov/ui/navigation/NavList";
28
- import { Heading } from "@digigov/ui/typography/Heading";
29
- import Hint from "@digigov/ui/typography/Hint";
30
- const FormBuilderSyncValues = ({ values, autoSubmit }) => {
31
- const form = useContext(FormContext);
32
- const previousValues = form.getValues();
33
- useEffect(() => {
34
- const mergedObject = { ...values, ...previousValues };
35
- let shouldSubmit = false;
36
- for (const key in mergedObject) {
37
- if (values[key] !== void 0 && previousValues[key] !== values[key]) {
38
- shouldSubmit = true;
39
- previousValues[key] = values[key];
40
- form.setValue(key, values[key]);
41
- }
42
- }
43
- if (autoSubmit && shouldSubmit) {
44
- form.submit();
45
- }
46
- }, [autoSubmit, form, previousValues, values]);
47
- return /* @__PURE__ */ React.createElement(React.Fragment, null);
1
+ import react, { useContext, useEffect } from "react";
2
+ import { Field } from "@digigov/form/Field/index.js";
3
+ import FormBuilder from "@digigov/form/FormBuilder/index.js";
4
+ import { FormContext } from "@digigov/form/FormContext.js";
5
+ import Results from "./Results.js";
6
+ import { createId } from "./utils.js";
7
+ import PageTitleContainer, { PageTitleHeading } from "@digigov/ui/app/PageTitleContainer/index.js";
8
+ import { Accordion, AccordionSection, AccordionSectionContent, AccordionSectionSummary, AccordionSectionSummaryHeading } from "@digigov/ui/content/Accordion/index.js";
9
+ import { useAccordion } from "@digigov/ui/content/Accordion/hooks.js";
10
+ import Markdown from "@digigov/ui/content/Markdown/index.js";
11
+ import { SearchButton } from "@digigov/ui/form/SearchContainer/index.js";
12
+ import { Stack } from "@digigov/ui/layouts/index.js";
13
+ import { Aside } from "@digigov/ui/layouts/Basic/Aside/index.js";
14
+ import { Container } from "@digigov/ui/layouts/Basic/Container/index.js";
15
+ import { Main } from "@digigov/ui/layouts/Basic/Main/index.js";
16
+ import Grid from "@digigov/ui/layouts/Grid/index.js";
17
+ import SectionBreak from "@digigov/ui/layouts/SectionBreak/index.js";
18
+ import { BackToTop } from "@digigov/ui/navigation/BackToTopLink/index.js";
19
+ import NavList, { NavListItemAction } from "@digigov/ui/navigation/NavList/index.js";
20
+ import { Heading } from "@digigov/ui/typography/Heading/index.js";
21
+ import Hint from "@digigov/ui/typography/Hint/index.js";
22
+ const FormBuilderSyncValues = ({ values, autoSubmit })=>{
23
+ const form = useContext(FormContext);
24
+ const previousValues = form.getValues();
25
+ useEffect(()=>{
26
+ const mergedObject = {
27
+ ...values,
28
+ ...previousValues
29
+ };
30
+ let shouldSubmit = false;
31
+ for(const key in mergedObject)if (void 0 !== values[key] && previousValues[key] !== values[key]) {
32
+ shouldSubmit = true;
33
+ previousValues[key] = values[key];
34
+ form.setValue(key, values[key]);
35
+ }
36
+ if (autoSubmit && shouldSubmit) form.submit();
37
+ }, [
38
+ autoSubmit,
39
+ form,
40
+ previousValues,
41
+ values
42
+ ]);
43
+ return /*#__PURE__*/ react.createElement(react.Fragment, null);
48
44
  };
49
- const NavigationList = React.forwardRef(
50
- function NavigationList2({ title, sections }, ref) {
51
- return /* @__PURE__ */ React.createElement(NavList, { ref, layout: "vertical", marginBottom: 10 }, title && /* @__PURE__ */ React.createElement(Heading, { size: "md", id: "contents", marginBottom: 4 }, title), sections && sections.length > 0 && sections.map(({ id, title: title2 }, index) => /* @__PURE__ */ React.createElement(NavListItemAction, { key: index, href: `#${createId(id, title2)}` }, title2)));
52
- }
53
- );
54
- const Faq = React.forwardRef(function FAQ({
55
- contents,
56
- sections,
57
- initialSections,
58
- submitValues,
59
- activeQa,
60
- onActiveQa,
61
- search
62
- }, ref) {
63
- const { section, currentOpen, onOpen, close } = useAccordion({
64
- singleOpen: true,
65
- defaultOpen: 0
66
- });
67
- const placement = contents.toc?.placement || "none";
68
- const filteredSections = sections.reduce(
69
- (acc, section2) => acc + (section2.qa.length || 0),
70
- 0
71
- );
72
- const primarySections = initialSections.sections.reduce(
73
- (acc, section2) => acc + (section2.qa.length || 0),
74
- 0
75
- );
76
- const hash = window.location.hash.slice(1);
77
- const currentId = activeQa ? activeQa : hash;
78
- useEffect(() => {
79
- if (onActiveQa) {
80
- if (currentOpen && activeQa !== currentOpen) {
81
- onActiveQa(currentOpen);
82
- }
83
- }
84
- }, [activeQa, currentOpen, onActiveQa]);
85
- useEffect(() => {
86
- if (activeQa && activeQa !== currentOpen) {
87
- onOpen(activeQa);
88
- }
89
- }, [activeQa, currentOpen, onOpen]);
90
- useEffect(() => {
91
- if (currentId) {
92
- const element = document.getElementById(currentId);
93
- if (element) {
94
- element.scrollIntoView({ behavior: "smooth", block: "start" });
95
- }
96
- }
97
- }, [activeQa, currentId, hash]);
98
- const Onclose = (activeQa2) => {
99
- const urlParams = new URLSearchParams(window.location.search);
100
- urlParams.delete("text");
101
- urlParams.delete("activeQa");
102
- window.history.pushState({}, "", "?" + urlParams.toString());
103
- onActiveQa("");
104
- close(activeQa2);
105
- };
106
- const handleSubmit = (data) => {
107
- search(data);
108
- onActiveQa("");
109
- close(activeQa);
110
- const urlParams = new URLSearchParams(window.location.search);
111
- urlParams.delete("activeQa");
112
- window.history.replaceState({}, "", "?" + urlParams.toString());
113
- };
114
- return /* @__PURE__ */ React.createElement(Container, { ref }, placement !== "none" && placement === "left" && /* @__PURE__ */ React.createElement(Aside, { sticky: false }, /* @__PURE__ */ React.createElement(NavigationList, { title: contents.toc?.title, sections })), /* @__PURE__ */ React.createElement(Main, null, /* @__PURE__ */ React.createElement(PageTitleContainer, null, /* @__PURE__ */ React.createElement(PageTitleHeading, { size: "xl", id: "faq" }, contents?.title)), placement !== "none" && placement === "top" && /* @__PURE__ */ React.createElement(NavigationList, { title: contents?.toc?.title, sections }), contents.search && /* @__PURE__ */ React.createElement(FormBuilder, { onSubmit: handleSubmit, initial: { text: "" } }, submitValues && /* @__PURE__ */ React.createElement(FormBuilderSyncValues, { values: submitValues, autoSubmit: true }), /* @__PURE__ */ React.createElement(
115
- Stack,
116
- {
117
- direction: "row",
118
- flexWrap: "nowrap",
119
- alignItems: "flex-end",
120
- spacing: 4
121
- },
122
- /* @__PURE__ */ React.createElement(Grid, { container: true, style: { width: "100%" } }, /* @__PURE__ */ React.createElement(
123
- Field,
124
- {
45
+ const Faq_NavigationList = /*#__PURE__*/ react.forwardRef(function({ title, sections }, ref) {
46
+ return /*#__PURE__*/ react.createElement(NavList, {
47
+ ref: ref,
48
+ layout: "vertical",
49
+ marginBottom: 10
50
+ }, title && /*#__PURE__*/ react.createElement(Heading, {
51
+ size: "md",
52
+ id: "contents",
53
+ marginBottom: 4
54
+ }, title), sections && sections.length > 0 && sections.map(({ id, title }, index)=>/*#__PURE__*/ react.createElement(NavListItemAction, {
55
+ key: index,
56
+ href: `#${createId(id, title)}`
57
+ }, title)));
58
+ });
59
+ const Faq_Faq = /*#__PURE__*/ react.forwardRef(function({ contents, sections, initialSections, submitValues, activeQa, onActiveQa, search }, ref) {
60
+ const { section, currentOpen, onOpen, close } = useAccordion({
61
+ singleOpen: true,
62
+ defaultOpen: 0
63
+ });
64
+ const placement = contents.toc?.placement || 'none';
65
+ const filteredSections = sections.reduce((acc, section)=>acc + (section.qa.length || 0), 0);
66
+ const primarySections = initialSections.sections.reduce((acc, section)=>acc + (section.qa.length || 0), 0);
67
+ const hash = window.location.hash.slice(1);
68
+ const currentId = activeQa ? activeQa : hash;
69
+ useEffect(()=>{
70
+ if (onActiveQa) {
71
+ if (currentOpen && activeQa !== currentOpen) onActiveQa(currentOpen);
72
+ }
73
+ }, [
74
+ activeQa,
75
+ currentOpen,
76
+ onActiveQa
77
+ ]);
78
+ useEffect(()=>{
79
+ if (activeQa && activeQa !== currentOpen) onOpen(activeQa);
80
+ }, [
81
+ activeQa,
82
+ currentOpen,
83
+ onOpen
84
+ ]);
85
+ useEffect(()=>{
86
+ if (currentId) {
87
+ const element = document.getElementById(currentId);
88
+ if (element) element.scrollIntoView({
89
+ behavior: 'smooth',
90
+ block: 'start'
91
+ });
92
+ }
93
+ }, [
94
+ activeQa,
95
+ currentId,
96
+ hash
97
+ ]);
98
+ const Onclose = (activeQa)=>{
99
+ const urlParams = new URLSearchParams(window.location.search);
100
+ urlParams.delete('text');
101
+ urlParams.delete('activeQa');
102
+ window.history.pushState({}, '', '?' + urlParams.toString());
103
+ onActiveQa('');
104
+ close(activeQa);
105
+ };
106
+ const handleSubmit = (data)=>{
107
+ search(data);
108
+ onActiveQa('');
109
+ close(activeQa);
110
+ const urlParams = new URLSearchParams(window.location.search);
111
+ urlParams.delete('activeQa');
112
+ window.history.replaceState({}, '', '?' + urlParams.toString());
113
+ };
114
+ return /*#__PURE__*/ react.createElement(Container, {
115
+ ref: ref
116
+ }, 'none' !== placement && 'left' === placement && /*#__PURE__*/ react.createElement(Aside, {
117
+ sticky: false
118
+ }, /*#__PURE__*/ react.createElement(Faq_NavigationList, {
119
+ title: contents.toc?.title,
120
+ sections: sections
121
+ })), /*#__PURE__*/ react.createElement(Main, null, /*#__PURE__*/ react.createElement(PageTitleContainer, null, /*#__PURE__*/ react.createElement(PageTitleHeading, {
122
+ size: "xl",
123
+ id: "faq"
124
+ }, contents?.title)), 'none' !== placement && 'top' === placement && /*#__PURE__*/ react.createElement(Faq_NavigationList, {
125
+ title: contents?.toc?.title,
126
+ sections: sections
127
+ }), contents.search && /*#__PURE__*/ react.createElement(FormBuilder, {
128
+ onSubmit: handleSubmit,
129
+ initial: {
130
+ text: ''
131
+ }
132
+ }, submitValues && /*#__PURE__*/ react.createElement(FormBuilderSyncValues, {
133
+ values: submitValues,
134
+ autoSubmit: true
135
+ }), /*#__PURE__*/ react.createElement(Stack, {
136
+ direction: "row",
137
+ flexWrap: "nowrap",
138
+ alignItems: "flex-end",
139
+ spacing: 4
140
+ }, /*#__PURE__*/ react.createElement(Grid, {
141
+ container: true,
142
+ style: {
143
+ width: '100%'
144
+ }
145
+ }, /*#__PURE__*/ react.createElement(Field, {
125
146
  type: "string",
126
147
  key: "text",
127
148
  name: "text",
128
- placeholder: "\u0391\u03BD\u03B1\u03B6\u03B7\u03C4\u03AE\u03C3\u03C4\u03B5 \u03C3\u03C7\u03B5\u03C4\u03B9\u03BA\u03AC \u03BC\u03B5 \u03C4\u03B7\u03BD \u03B5\u03C1\u03CE\u03C4\u03B7\u03C3\u03AE \u03C3\u03B1\u03C2",
129
- label: { primary: contents.search.title }
130
- }
131
- )),
132
- /* @__PURE__ */ React.createElement(
133
- SearchButton,
134
- {
149
+ placeholder: "Αναζητήστε σχετικά με την ερώτησή σας",
150
+ label: {
151
+ primary: contents.search.title
152
+ }
153
+ })), /*#__PURE__*/ react.createElement(SearchButton, {
135
154
  type: "submit",
136
- mb: { md: 10 },
137
- style: { minHeight: "2.75rem" }
138
- }
139
- )
140
- ), filteredSections !== primarySections && /* @__PURE__ */ React.createElement(
141
- Results,
142
- {
143
- filteredSections,
144
- primarySections,
145
- Onclose,
146
- activeQa
147
- }
148
- )), /* @__PURE__ */ React.createElement(Grid, null, sections && sections.length > 0 ? sections.map(({ id: sectionId, title, qa }, index) => /* @__PURE__ */ React.createElement(React.Fragment, { key: index }, /* @__PURE__ */ React.createElement(Heading, { id: createId(sectionId, title), size: "lg" }, title), /* @__PURE__ */ React.createElement(Accordion, { marginBottom: qa && qa.length > 0 ? 12 : 0 }, qa?.map(({ id, question, answer }, indx) => /* @__PURE__ */ React.createElement(
149
- AccordionSection,
150
- {
151
- key: indx,
152
- ...section(createId(id, question))
153
- },
154
- /* @__PURE__ */ React.createElement(AccordionSectionSummary, null, /* @__PURE__ */ React.createElement(
155
- AccordionSectionSummaryHeading,
156
- {
157
- "aria-controls": createId(id, question)
158
- },
159
- question
160
- )),
161
- /* @__PURE__ */ React.createElement(AccordionSectionContent, { id: createId(id, question) }, /* @__PURE__ */ React.createElement(Markdown, { content: answer }))
162
- ))), /* @__PURE__ */ React.createElement(SectionBreak, { visible: false }))) : /* @__PURE__ */ React.createElement(Hint, { marginBottom: 10 }, "\u0394\u03B5\u03BD \u03B2\u03C1\u03AD\u03B8\u03B7\u03BA\u03B1\u03BD \u03B1\u03C0\u03BF\u03C4\u03B5\u03BB\u03AD\u03C3\u03BC\u03B1\u03C4\u03B1.")), /* @__PURE__ */ React.createElement(BackToTop, { topLimitId: "contents", id: "back-to-top" }, "\u0395\u03C0\u03B9\u03C3\u03C4\u03C1\u03BF\u03C6\u03AE \u03C3\u03C4\u03B1 \u03A0\u03B5\u03C1\u03B9\u03B5\u03C7\u03CC\u03BC\u03B5\u03BD\u03B1")), placement !== "none" && placement === "right" && /* @__PURE__ */ React.createElement(Aside, { sticky: false }, /* @__PURE__ */ React.createElement(NavigationList, { title: contents?.toc?.title, sections })));
155
+ mb: {
156
+ md: 10
157
+ },
158
+ style: {
159
+ minHeight: '2.75rem'
160
+ }
161
+ })), filteredSections !== primarySections && /*#__PURE__*/ react.createElement(Results, {
162
+ filteredSections: filteredSections,
163
+ primarySections: primarySections,
164
+ Onclose: Onclose,
165
+ activeQa: activeQa
166
+ })), /*#__PURE__*/ react.createElement(Grid, null, sections && sections.length > 0 ? sections.map(({ id: sectionId, title, qa }, index)=>/*#__PURE__*/ react.createElement(react.Fragment, {
167
+ key: index
168
+ }, /*#__PURE__*/ react.createElement(Heading, {
169
+ id: createId(sectionId, title),
170
+ size: "lg"
171
+ }, title), /*#__PURE__*/ react.createElement(Accordion, {
172
+ marginBottom: qa && qa.length > 0 ? 12 : 0
173
+ }, qa?.map(({ id, question, answer }, indx)=>/*#__PURE__*/ react.createElement(AccordionSection, {
174
+ key: indx,
175
+ ...section(createId(id, question))
176
+ }, /*#__PURE__*/ react.createElement(AccordionSectionSummary, null, /*#__PURE__*/ react.createElement(AccordionSectionSummaryHeading, {
177
+ "aria-controls": createId(id, question)
178
+ }, question)), /*#__PURE__*/ react.createElement(AccordionSectionContent, {
179
+ id: createId(id, question)
180
+ }, /*#__PURE__*/ react.createElement(Markdown, {
181
+ content: answer
182
+ }))))), /*#__PURE__*/ react.createElement(SectionBreak, {
183
+ visible: false
184
+ }))) : /*#__PURE__*/ react.createElement(Hint, {
185
+ marginBottom: 10
186
+ }, "Δεν βρέθηκαν αποτελέσματα.")), /*#__PURE__*/ react.createElement(BackToTop, {
187
+ topLimitId: "contents",
188
+ id: "back-to-top"
189
+ }, "Επιστροφή στα Περιεχόμενα")), 'none' !== placement && 'right' === placement && /*#__PURE__*/ react.createElement(Aside, {
190
+ sticky: false
191
+ }, /*#__PURE__*/ react.createElement(Faq_NavigationList, {
192
+ title: contents?.toc?.title,
193
+ sections: sections
194
+ })));
163
195
  });
164
- var Faq_default = Faq;
165
- export {
166
- Faq,
167
- Faq_default as default
168
- };
169
- //# sourceMappingURL=index.js.map
196
+ const Faq = Faq_Faq;
197
+ export { Faq_Faq as Faq, Faq as default };
package/Faq/slug.js ADDED
@@ -0,0 +1,94 @@
1
+ function slug(text, maxWidth = 50) {
2
+ const greekToLatinMap = {
3
+ α: 'a',
4
+ β: 'b',
5
+ γ: 'g',
6
+ δ: 'd',
7
+ ε: 'e',
8
+ ζ: 'z',
9
+ η: 'i',
10
+ θ: 'th',
11
+ ι: 'i',
12
+ κ: 'k',
13
+ λ: 'l',
14
+ μ: 'm',
15
+ ν: 'n',
16
+ ξ: 'x',
17
+ ο: 'o',
18
+ π: 'p',
19
+ ρ: 'r',
20
+ σ: 's',
21
+ τ: 't',
22
+ υ: 'y',
23
+ φ: 'f',
24
+ χ: 'ch',
25
+ ψ: 'ps',
26
+ ω: 'o',
27
+ ά: 'a',
28
+ έ: 'e',
29
+ ί: 'i',
30
+ ό: 'o',
31
+ ύ: 'y',
32
+ ή: 'i',
33
+ ώ: 'o',
34
+ ς: 's',
35
+ ϊ: 'i',
36
+ ΰ: 'y',
37
+ ϋ: 'y',
38
+ ΐ: 'i',
39
+ Α: 'A',
40
+ Β: 'B',
41
+ Γ: 'G',
42
+ Δ: 'D',
43
+ Ε: 'E',
44
+ Ζ: 'Z',
45
+ Η: 'I',
46
+ Θ: 'TH',
47
+ Ι: 'I',
48
+ Κ: 'K',
49
+ Λ: 'L',
50
+ Μ: 'M',
51
+ Ν: 'N',
52
+ Ξ: 'X',
53
+ Ο: 'O',
54
+ Π: 'P',
55
+ Ρ: 'R',
56
+ Σ: 'S',
57
+ Τ: 'T',
58
+ Υ: 'Y',
59
+ Φ: 'F',
60
+ Χ: 'CH',
61
+ Ψ: 'PS',
62
+ Ω: 'O',
63
+ Ά: 'A',
64
+ Έ: 'E',
65
+ Ί: 'I',
66
+ Ό: 'O',
67
+ Ύ: 'Y',
68
+ Ή: 'I',
69
+ Ώ: 'O',
70
+ Ϊ: 'I',
71
+ Ϋ: 'Y'
72
+ };
73
+ const latinText = text.split('').map((char)=>greekToLatinMap[char] || char).join('');
74
+ const processedText = latinText.toLowerCase().replace(/\s+/g, '-').replace(/[^\w-]+/g, '').replace(/--+/g, '-').replace(/^-+/, '').replace(/-+$/, '');
75
+ let slug1 = processedText.substring(0, maxWidth);
76
+ const remainingText = processedText.substring(maxWidth);
77
+ slug1 = slug1.replace(/-+$/, '');
78
+ const id = generateIDFromText(remainingText);
79
+ return `${slug1}${id && '-'}${id}`;
80
+ }
81
+ function generateIDFromText(text) {
82
+ if (!text) return '';
83
+ let processedText = text.replace(/-/g, '').replace(/[^a-z0-9]/g, '');
84
+ if (!processedText) processedText = 'default';
85
+ let hash = 0;
86
+ for(let i = 0; i < processedText.length; i++){
87
+ const char = processedText.charCodeAt(i);
88
+ hash = (hash << 5) - hash + char;
89
+ hash &= hash;
90
+ }
91
+ const id = Math.abs(hash).toString(36);
92
+ return id;
93
+ }
94
+ export { slug };
package/Faq/utils.js ADDED
@@ -0,0 +1,3 @@
1
+ import { slug } from "./slug.js";
2
+ const createId = (id, text)=>id ? id : slug(text);
3
+ export { createId };
@@ -0,0 +1,12 @@
1
+ import react from "react";
2
+ import { Table, TableBody, TableContainer, TableDataCell, TableHead, TableHeadCell, TableNoDataRow, TableRow } from "@digigov/ui/content/Table/index.js";
3
+ function DataTable({ dataConfig, data }) {
4
+ return /*#__PURE__*/ react.createElement(TableContainer, null, /*#__PURE__*/ react.createElement(Table, null, /*#__PURE__*/ react.createElement(TableHead, null, /*#__PURE__*/ react.createElement(TableRow, null, dataConfig.map((itenConfig)=>/*#__PURE__*/ react.createElement(TableHeadCell, {
5
+ key: itenConfig.key
6
+ }, itenConfig.title)))), /*#__PURE__*/ react.createElement(TableBody, null, data.length > 0 ? data.map((item, index)=>/*#__PURE__*/ react.createElement(TableRow, {
7
+ key: index
8
+ }, dataConfig.map((itemConfig, idx)=>/*#__PURE__*/ react.createElement(TableDataCell, {
9
+ key: idx
10
+ }, itemConfig.displayComponent ? itemConfig.displayComponent(item[itemConfig.key]) : item[itemConfig.key])))) : /*#__PURE__*/ react.createElement(TableNoDataRow, null, "Δεν υπάρχουν αποτελέσματα"))));
11
+ }
12
+ export { DataTable };
@@ -0,0 +1,34 @@
1
+ import react from "react";
2
+ import { useFormContext, useFormValues } from "@digigov/form/FormBuilder/index.js";
3
+ import { getOptionLabelForSelectValue } from "./hooks.js";
4
+ import { FilterSelectedHeading, FilterSelectedSection } from "@digigov/ui/app/FilterContainer/index.js";
5
+ import { Chip, ChipContainer } from "@digigov/ui/content/Chip/index.js";
6
+ import { Button } from "@digigov/ui/form/Button/index.js";
7
+ const FilterChips = ()=>{
8
+ const { fieldsMap, reset, resetField, submit } = useFormContext();
9
+ const values = useFormValues();
10
+ const enabledFilters = Object.keys(values).filter((v)=>values[v]);
11
+ if (0 === enabledFilters.length) return null;
12
+ return /*#__PURE__*/ react.createElement(FilterSelectedSection, {
13
+ m: 0,
14
+ mb: 6
15
+ }, /*#__PURE__*/ react.createElement(FilterSelectedHeading, {
16
+ mb: 0
17
+ }, /*#__PURE__*/ react.createElement(ChipContainer, null, enabledFilters.map((filterKey)=>/*#__PURE__*/ react.createElement(Chip, {
18
+ mb: 0,
19
+ key: filterKey,
20
+ onDelete: ()=>{
21
+ resetField(filterKey);
22
+ submit();
23
+ }
24
+ }, /*#__PURE__*/ react.createElement("b", null, fieldsMap[filterKey].label?.primary), " ", ': ', getOptionLabelForSelectValue(fieldsMap[filterKey], values[filterKey])))), /*#__PURE__*/ react.createElement(Button, {
25
+ onClick: (e)=>{
26
+ e.preventDefault();
27
+ reset();
28
+ submit();
29
+ },
30
+ variant: "link"
31
+ }, "Επαναφορά Επιλογών")));
32
+ };
33
+ const FilteredResults_FilterChips = FilterChips;
34
+ export { FilterChips, FilteredResults_FilterChips as default };
@@ -0,0 +1,13 @@
1
+ import react from "react";
2
+ import Field from "@digigov/form/Field/index.js";
3
+ import { FilterOptionsSection } from "@digigov/ui/app/FilterContainer/index.js";
4
+ import { Button } from "@digigov/ui/form/Button/index.js";
5
+ const FilterFields = ({ fields, horizontal })=>/*#__PURE__*/ react.createElement(FilterOptionsSection, {
6
+ horizontal: horizontal
7
+ }, fields.map((field)=>/*#__PURE__*/ react.createElement(Field, {
8
+ key: field.key,
9
+ name: field.key
10
+ })), /*#__PURE__*/ react.createElement(Button, {
11
+ type: "submit"
12
+ }, "Αναζήτηση"));
13
+ export { FilterFields };
@@ -1,5 +1,5 @@
1
1
  import { FieldSpec } from '@digigov/form/types';
2
- import { ScalarType } from '@digigov/react-modules/FilteredResults';
2
+ import { ScalarType } from './index.js';
3
3
  export declare function isBooleanString(str: string): boolean;
4
4
  export declare function normalizeText(text: string): string;
5
5
  export declare const getOptionLabelForSelectValue: (field: any, value: any) => any;