@digigov/react-modules 1.2.0-2177f152 → 1.2.0-2271444d
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/Faq/Results.d.ts +9 -0
- package/Faq/Results.js +34 -0
- package/Faq/hooks.d.ts +15 -0
- package/Faq/hooks.js +54 -0
- package/Faq/index.d.ts +43 -0
- package/Faq/index.js +197 -0
- package/Faq/slug.d.ts +1 -0
- package/Faq/slug.js +94 -0
- package/Faq/utils.d.ts +1 -0
- package/Faq/utils.js +3 -0
- package/FilteredResults/DataTable.js +12 -0
- package/FilteredResults/FilterChips.js +34 -0
- package/FilteredResults/FilterFields.js +13 -0
- package/FilteredResults/hooks.d.ts +1 -1
- package/FilteredResults/hooks.js +78 -0
- package/FilteredResults/index.js +96 -112
- package/index.d.ts +2 -1
- package/index.js +3 -3
- package/lazy.d.ts +13 -12
- package/lazy.js +28 -0
- package/package.json +32 -13
- package/registry.d.ts +6 -1
- package/registry.js +34 -0
- package/src/Faq/Faq.stories.js +7 -0
- package/src/Faq/Results.tsx +53 -0
- package/src/Faq/__stories__/Default.tsx +292 -0
- package/src/Faq/hooks.ts +89 -0
- package/src/Faq/index.test.tsx +24 -0
- package/src/Faq/index.tsx +286 -0
- package/src/Faq/slug.ts +140 -0
- package/src/Faq/splitted.test.tsx +19 -0
- package/src/Faq/utils.ts +5 -0
- package/src/FilteredResults/__stories__/Default.tsx +1 -1
- package/src/FilteredResults/index.test.tsx +14 -11
- package/src/FilteredResults/splitted.test.tsx +9 -5
- package/src/index.ts +1 -0
- package/src/lazy.ts +11 -0
- package/src/registry.ts +43 -0
- package/FilteredResults/DataTable/index.js +0 -18
- package/FilteredResults/DataTable/package.json +0 -6
- package/FilteredResults/DataTable.js.map +0 -7
- package/FilteredResults/FilterChips/index.js +0 -52
- package/FilteredResults/FilterChips/package.json +0 -6
- package/FilteredResults/FilterChips.js.map +0 -7
- package/FilteredResults/FilterFields/index.js +0 -11
- package/FilteredResults/FilterFields/package.json +0 -6
- package/FilteredResults/FilterFields.js.map +0 -7
- package/FilteredResults/FilteredResults.stories/index.js +0 -12
- package/FilteredResults/FilteredResults.stories/package.json +0 -6
- package/FilteredResults/FilteredResults.stories.d.ts +0 -8
- package/FilteredResults/FilteredResults.stories.js.map +0 -7
- package/FilteredResults/__stories__/Default/index.js +0 -220
- package/FilteredResults/__stories__/Default/package.json +0 -6
- package/FilteredResults/__stories__/Default.d.ts +0 -2
- package/FilteredResults/__stories__/Default.js.map +0 -7
- package/FilteredResults/hooks/index.js +0 -105
- package/FilteredResults/hooks/package.json +0 -6
- package/FilteredResults/hooks.js.map +0 -7
- package/FilteredResults/index.js.map +0 -7
- package/FilteredResults/index.test.d.ts +0 -1
- package/FilteredResults/package.json +0 -6
- package/FilteredResults/splitted.test.d.ts +0 -1
- package/ReactModules.stories/index.js +0 -7
- package/ReactModules.stories/package.json +0 -6
- package/ReactModules.stories.d.ts +0 -4
- package/ReactModules.stories.js.map +0 -7
- package/cjs/FilteredResults/DataTable/index.js +0 -42
- package/cjs/FilteredResults/DataTable.js.map +0 -7
- package/cjs/FilteredResults/FilterChips/index.js +0 -82
- package/cjs/FilteredResults/FilterChips.js.map +0 -7
- package/cjs/FilteredResults/FilterFields/index.js +0 -44
- package/cjs/FilteredResults/FilterFields.js.map +0 -7
- package/cjs/FilteredResults/FilteredResults.stories/index.js +0 -45
- package/cjs/FilteredResults/FilteredResults.stories.js.map +0 -7
- package/cjs/FilteredResults/__stories__/Default/index.js +0 -250
- package/cjs/FilteredResults/__stories__/Default.js.map +0 -7
- package/cjs/FilteredResults/hooks/index.js +0 -132
- package/cjs/FilteredResults/hooks.js.map +0 -7
- package/cjs/FilteredResults/index.js +0 -153
- package/cjs/FilteredResults/index.js.map +0 -7
- package/cjs/ReactModules.stories/index.js +0 -26
- package/cjs/ReactModules.stories.js.map +0 -7
- package/cjs/index.js +0 -22
- package/cjs/index.js.map +0 -7
- package/cjs/lazy/index.js +0 -71
- package/cjs/lazy.js.map +0 -7
- package/cjs/registry/index.js +0 -73
- package/cjs/registry.js.map +0 -7
- package/index.js.map +0 -7
- package/lazy/index.js +0 -42
- package/lazy/package.json +0 -6
- package/lazy.js.map +0 -7
- package/registry/index.js +0 -44
- package/registry/package.json +0 -6
- package/registry.js.map +0 -7
- package/src/lazy.js +0 -38
- package/src/registry.js +0 -41
package/Faq/Results.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface ResultsProps {
|
|
3
|
+
filteredSections: number;
|
|
4
|
+
primarySections: number;
|
|
5
|
+
Onclose: (v: string) => void;
|
|
6
|
+
activeQa: string;
|
|
7
|
+
}
|
|
8
|
+
declare const Results: React.ForwardRefExoticComponent<ResultsProps & React.RefAttributes<HTMLHeadingElement>>;
|
|
9
|
+
export default Results;
|
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
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { sectionsConfigType, SectionType } from './index.js';
|
|
2
|
+
export declare const useURLParamsSearch: (searchFunc: (params: Record<string, string | undefined>) => void, { navigate, filteredSections, }: {
|
|
3
|
+
navigate: (url: string) => void;
|
|
4
|
+
filteredSections: SectionType[];
|
|
5
|
+
}) => {
|
|
6
|
+
search: (params: Record<string, string>) => void;
|
|
7
|
+
values: {
|
|
8
|
+
text: string;
|
|
9
|
+
};
|
|
10
|
+
hashId: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const useFaqSearch: (questions: sectionsConfigType) => {
|
|
13
|
+
filteredSections: SectionType[];
|
|
14
|
+
search: (values: Record<string, string>) => void;
|
|
15
|
+
};
|
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.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface sectionsConfigType {
|
|
3
|
+
sections: SectionType[];
|
|
4
|
+
}
|
|
5
|
+
export interface QaType {
|
|
6
|
+
id?: string;
|
|
7
|
+
question: string;
|
|
8
|
+
answer: string;
|
|
9
|
+
}
|
|
10
|
+
export interface SectionType {
|
|
11
|
+
id: string;
|
|
12
|
+
title: string;
|
|
13
|
+
qa: QaType[];
|
|
14
|
+
}
|
|
15
|
+
export interface TocType {
|
|
16
|
+
title: string;
|
|
17
|
+
placement: 'top' | 'left' | 'right' | 'none';
|
|
18
|
+
}
|
|
19
|
+
export interface SearchFilterType {
|
|
20
|
+
title?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface ContentsType {
|
|
23
|
+
title: string;
|
|
24
|
+
toc: TocType;
|
|
25
|
+
search?: SearchFilterType;
|
|
26
|
+
}
|
|
27
|
+
export interface NavigationListProps {
|
|
28
|
+
title?: string;
|
|
29
|
+
sections: SectionType[];
|
|
30
|
+
}
|
|
31
|
+
export interface FaqProps {
|
|
32
|
+
contents: ContentsType;
|
|
33
|
+
sections: SectionType[];
|
|
34
|
+
initialSections: sectionsConfigType;
|
|
35
|
+
search: (values: Record<string, string>) => void;
|
|
36
|
+
submitValues: {
|
|
37
|
+
text: string;
|
|
38
|
+
};
|
|
39
|
+
activeQa: string;
|
|
40
|
+
onActiveQa: (v: string) => void;
|
|
41
|
+
}
|
|
42
|
+
export declare const Faq: React.ForwardRefExoticComponent<FaqProps & React.RefAttributes<HTMLDivElement>>;
|
|
43
|
+
export default Faq;
|
package/Faq/index.js
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
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);
|
|
44
|
+
};
|
|
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, {
|
|
146
|
+
type: "string",
|
|
147
|
+
key: "text",
|
|
148
|
+
name: "text",
|
|
149
|
+
placeholder: "Αναζητήστε σχετικά με την ερώτησή σας",
|
|
150
|
+
label: {
|
|
151
|
+
primary: contents.search.title
|
|
152
|
+
}
|
|
153
|
+
})), /*#__PURE__*/ react.createElement(SearchButton, {
|
|
154
|
+
type: "submit",
|
|
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
|
+
})));
|
|
195
|
+
});
|
|
196
|
+
const Faq = Faq_Faq;
|
|
197
|
+
export { Faq_Faq as Faq, Faq as default };
|
package/Faq/slug.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function slug(text: string, maxWidth?: number): string;
|
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.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createId: (id: string | undefined, text: string) => string;
|
package/Faq/utils.js
ADDED
|
@@ -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 '
|
|
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;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from "react";
|
|
2
|
+
function isBooleanString(str) {
|
|
3
|
+
return /^(true|false)$/i.test(str);
|
|
4
|
+
}
|
|
5
|
+
function normalizeText(text) {
|
|
6
|
+
return text.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
|
|
7
|
+
}
|
|
8
|
+
const getOptionLabelForSelectValue = (field, value)=>{
|
|
9
|
+
if (field.extra?.options) {
|
|
10
|
+
const matchedOption = field.extra.options.find((option)=>option.value.toString() === value?.toString());
|
|
11
|
+
if (matchedOption) return matchedOption.label.primary;
|
|
12
|
+
}
|
|
13
|
+
return value;
|
|
14
|
+
};
|
|
15
|
+
const useURLParamsSearch = (searchFunc, { navigate, fields })=>{
|
|
16
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
17
|
+
const currentParams = Object.fromEntries(urlParams.entries());
|
|
18
|
+
const values = fields.reduce((newValues, field)=>{
|
|
19
|
+
if (currentParams[field.key]) newValues[field.key] = currentParams[field.key];
|
|
20
|
+
return newValues;
|
|
21
|
+
}, {});
|
|
22
|
+
const search = (params)=>{
|
|
23
|
+
navigate('?' + new URLSearchParams(Object.entries({
|
|
24
|
+
...currentParams,
|
|
25
|
+
...params
|
|
26
|
+
}).filter(([, value])=>!!value)).toString());
|
|
27
|
+
return searchFunc(params);
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
search,
|
|
31
|
+
values
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
function useStaticSearch({ fields, data, initialFilters }) {
|
|
35
|
+
const [results, setResults] = useState(data);
|
|
36
|
+
useEffect(()=>{
|
|
37
|
+
search(initialFilters);
|
|
38
|
+
}, [
|
|
39
|
+
initialFilters
|
|
40
|
+
]);
|
|
41
|
+
const search = (filters)=>{
|
|
42
|
+
if (!filters || Object.keys(filters).every((key)=>'' === filters[key])) return void setResults(data);
|
|
43
|
+
const newResults = data.filter((row)=>{
|
|
44
|
+
const filterKeys = Object.keys(filters);
|
|
45
|
+
const enabledFilters = filterKeys.filter((filterKey)=>filters[filterKey]?.toString() && row[filterKey]?.toString());
|
|
46
|
+
const freeTextFilters = filterKeys.filter((filterKey)=>filters[filterKey]?.toString() && !row[filterKey]?.toString());
|
|
47
|
+
let filtersMatchingValue = false;
|
|
48
|
+
if (enabledFilters.length > 0) {
|
|
49
|
+
filtersMatchingValue = enabledFilters.every((filterKey)=>{
|
|
50
|
+
if (filters[filterKey]?.toString() !== row[filterKey]?.toString()) {
|
|
51
|
+
const field = fields.find((f)=>f.key === filterKey);
|
|
52
|
+
const optionsObj = field?.extra?.options.find((option)=>option?.label?.primary === row[filterKey]);
|
|
53
|
+
return optionsObj?.value.toString() === filters[filterKey]?.toString();
|
|
54
|
+
}
|
|
55
|
+
filtersMatchingValue = true;
|
|
56
|
+
return filtersMatchingValue;
|
|
57
|
+
});
|
|
58
|
+
if (!filtersMatchingValue) return false;
|
|
59
|
+
}
|
|
60
|
+
if (freeTextFilters.length > 0) return freeTextFilters.every((filterKey)=>Object.values(row).some((value)=>{
|
|
61
|
+
if ('string' != typeof value) return false;
|
|
62
|
+
const normalizedItemValue = normalizeText(value.toString().toLowerCase());
|
|
63
|
+
const normalizedFilterValue = normalizeText(filters[filterKey]?.toString().toLowerCase().trim() || '');
|
|
64
|
+
return normalizedItemValue.includes(normalizedFilterValue);
|
|
65
|
+
}));
|
|
66
|
+
return filtersMatchingValue;
|
|
67
|
+
});
|
|
68
|
+
setResults(newResults);
|
|
69
|
+
};
|
|
70
|
+
return useMemo(()=>({
|
|
71
|
+
search,
|
|
72
|
+
results
|
|
73
|
+
}), [
|
|
74
|
+
search,
|
|
75
|
+
results
|
|
76
|
+
]);
|
|
77
|
+
}
|
|
78
|
+
export { getOptionLabelForSelectValue, isBooleanString, normalizeText, useStaticSearch, useURLParamsSearch };
|