@digigov/react-modules 1.2.0-rc.29 → 1.2.0-rc.31

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 (116) hide show
  1. package/Faq/Faq.stories.d.ts +8 -0
  2. package/Faq/Results/index.js +29 -0
  3. package/Faq/Results/package.json +6 -0
  4. package/Faq/Results.d.ts +9 -0
  5. package/Faq/Results.js.map +7 -0
  6. package/Faq/__stories__/Default.d.ts +2 -0
  7. package/Faq/hooks/index.js +66 -0
  8. package/Faq/hooks/package.json +6 -0
  9. package/Faq/hooks.d.ts +15 -0
  10. package/Faq/hooks.js.map +7 -0
  11. package/Faq/index.d.ts +43 -0
  12. package/Faq/index.js +169 -0
  13. package/Faq/index.js.map +7 -0
  14. package/Faq/index.test.d.ts +1 -0
  15. package/Faq/package.json +6 -0
  16. package/Faq/slug/index.js +97 -0
  17. package/Faq/slug/package.json +6 -0
  18. package/Faq/slug.d.ts +1 -0
  19. package/Faq/slug.js.map +7 -0
  20. package/Faq/splitted.test.d.ts +1 -0
  21. package/Faq/utils/index.js +8 -0
  22. package/Faq/utils/package.json +6 -0
  23. package/Faq/utils.d.ts +1 -0
  24. package/Faq/utils.js.map +7 -0
  25. package/FilteredResults/DataTable/index.js +18 -0
  26. package/FilteredResults/DataTable/package.json +6 -0
  27. package/FilteredResults/DataTable.d.ts +5 -0
  28. package/FilteredResults/DataTable.js.map +7 -0
  29. package/FilteredResults/FilterChips/index.js +52 -0
  30. package/FilteredResults/FilterChips/package.json +6 -0
  31. package/FilteredResults/FilterChips.d.ts +3 -0
  32. package/FilteredResults/FilterChips.js.map +7 -0
  33. package/FilteredResults/FilterFields/index.js +11 -0
  34. package/FilteredResults/FilterFields/package.json +6 -0
  35. package/FilteredResults/FilterFields.d.ts +5 -0
  36. package/FilteredResults/FilterFields.js.map +7 -0
  37. package/FilteredResults/FilteredResults.stories.d.ts +8 -0
  38. package/FilteredResults/__stories__/Default.d.ts +2 -0
  39. package/FilteredResults/hooks/index.js +105 -0
  40. package/FilteredResults/hooks/package.json +6 -0
  41. package/FilteredResults/hooks.d.ts +22 -0
  42. package/FilteredResults/hooks.js.map +7 -0
  43. package/FilteredResults/index.d.ts +25 -0
  44. package/FilteredResults/index.js +120 -0
  45. package/FilteredResults/index.js.map +7 -0
  46. package/FilteredResults/index.test.d.ts +1 -0
  47. package/FilteredResults/package.json +6 -0
  48. package/FilteredResults/splitted.test.d.ts +1 -0
  49. package/LICENSE +0 -0
  50. package/ReactModules.stories.d.ts +4 -0
  51. package/cjs/Faq/Results/index.js +58 -0
  52. package/cjs/Faq/Results.js.map +7 -0
  53. package/cjs/Faq/hooks/index.js +90 -0
  54. package/cjs/Faq/hooks.js.map +7 -0
  55. package/cjs/Faq/index.js +194 -0
  56. package/cjs/Faq/index.js.map +7 -0
  57. package/cjs/Faq/slug/index.js +120 -0
  58. package/cjs/Faq/slug.js.map +7 -0
  59. package/cjs/Faq/utils/index.js +31 -0
  60. package/cjs/Faq/utils.js.map +7 -0
  61. package/cjs/FilteredResults/DataTable/index.js +42 -0
  62. package/cjs/FilteredResults/DataTable.js.map +7 -0
  63. package/cjs/FilteredResults/FilterChips/index.js +82 -0
  64. package/cjs/FilteredResults/FilterChips.js.map +7 -0
  65. package/cjs/FilteredResults/FilterFields/index.js +44 -0
  66. package/cjs/FilteredResults/FilterFields.js.map +7 -0
  67. package/cjs/FilteredResults/hooks/index.js +132 -0
  68. package/cjs/FilteredResults/hooks.js.map +7 -0
  69. package/cjs/FilteredResults/index.js +153 -0
  70. package/cjs/FilteredResults/index.js.map +7 -0
  71. package/cjs/index.js +24 -0
  72. package/cjs/index.js.map +7 -0
  73. package/cjs/lazy/index.js +44 -0
  74. package/cjs/lazy.js.map +7 -0
  75. package/cjs/registry/index.js +73 -0
  76. package/cjs/registry.js.map +7 -0
  77. package/index.d.ts +2 -0
  78. package/index.js +8 -0
  79. package/index.js.map +7 -0
  80. package/lazy/index.js +11 -0
  81. package/lazy/package.json +6 -0
  82. package/package.json +12 -35
  83. package/registry/index.js +43 -0
  84. package/registry/package.json +6 -0
  85. package/src/Faq/Faq.stories.js +7 -0
  86. package/src/Faq/Results.tsx +53 -0
  87. package/src/Faq/__stories__/Default.tsx +292 -0
  88. package/src/Faq/hooks.ts +89 -0
  89. package/src/Faq/index.test.tsx +24 -0
  90. package/src/Faq/index.tsx +286 -0
  91. package/src/Faq/slug.ts +140 -0
  92. package/src/Faq/splitted.test.tsx +19 -0
  93. package/src/Faq/utils.ts +5 -0
  94. package/src/FilteredResults/__stories__/Default.tsx +1 -1
  95. package/src/FilteredResults/index.test.tsx +4 -0
  96. package/src/FilteredResults/splitted.test.tsx +4 -0
  97. package/src/index.ts +1 -0
  98. package/src/lazy.js +11 -0
  99. package/src/registry.js +43 -0
  100. package/.prettierrc.js +0 -1
  101. package/.rush/temp/chunked-rush-logs/react-modules.build.chunks.jsonl +0 -8
  102. package/.rush/temp/chunked-rush-logs/react-modules.lint.chunks.jsonl +0 -19
  103. package/.rush/temp/chunked-rush-logs/react-modules.publint.chunks.jsonl +0 -20
  104. package/.rush/temp/package-deps_build.json +0 -27
  105. package/.rush/temp/package-deps_lint.json +0 -27
  106. package/.rush/temp/package-deps_publint.json +0 -29
  107. package/.rush/temp/shrinkwrap-deps.json +0 -19
  108. package/eslint.config.mjs +0 -8
  109. package/playwright-ct.config.ts +0 -3
  110. package/react-modules.build.log +0 -9
  111. package/rush-logs/react-modules.build.log +0 -8
  112. package/rush-logs/react-modules.lint.log +0 -19
  113. package/rush-logs/react-modules.publint.log +0 -20
  114. package/tailwind.config.js +0 -17
  115. package/tsconfig.json +0 -27
  116. package/tsconfig.production.json +0 -29
@@ -0,0 +1,89 @@
1
+ import { useState } from 'react';
2
+ import { sectionsConfigType, SectionType } from '@digigov/react-modules/Faq';
3
+ import { slug } from '@digigov/react-modules/Faq/slug';
4
+ const removeAccents = (text: string) => {
5
+ return text.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
6
+ };
7
+
8
+ export const useURLParamsSearch = (
9
+ searchFunc: (params: Record<string, string | undefined>) => void,
10
+ {
11
+ navigate,
12
+ filteredSections,
13
+ }: { navigate: (url: string) => void; filteredSections: SectionType[] }
14
+ ) => {
15
+ const urlParams = new URLSearchParams(window.location.search);
16
+ const currentParams = Object.fromEntries(urlParams.entries());
17
+ const hashId = window.location.hash ? window.location.hash.slice(1) : '';
18
+
19
+ // When filtered sections change, check if hash should be preserved
20
+ const hashExistsInFilteredSections = filteredSections.some((section) =>
21
+ section.qa.some(
22
+ ({ id, question }) => id === hashId || slug(question) === hashId
23
+ )
24
+ );
25
+
26
+ const search = (params: Record<string, string>) => {
27
+ const updatedParams = Object.entries({
28
+ ...currentParams,
29
+ ...params,
30
+ })
31
+ .filter(([, value]) => Boolean(value)) // Ensure value is not empty
32
+ .reduce(
33
+ (acc, [key, value]) => {
34
+ acc[key] = value as string; // Explicitly cast to string
35
+ return acc;
36
+ },
37
+ {} as Record<string, string>
38
+ ); // Ensure correct type
39
+
40
+ const newUrl = Object.keys(updatedParams).length
41
+ ? '?' + new URLSearchParams(updatedParams).toString()
42
+ : window.location.pathname; // Reset to base URL if no params
43
+
44
+ const finalURL = hashExistsInFilteredSections
45
+ ? newUrl + `#${hashId}`
46
+ : newUrl;
47
+ navigate(finalURL);
48
+ return searchFunc(params);
49
+ };
50
+ return { search, values: { text: currentParams.text }, hashId };
51
+ };
52
+
53
+ export const useFaqSearch = (questions: sectionsConfigType) => {
54
+ const [filteredSections, setFilteredSections] = useState(questions.sections);
55
+
56
+ const search = (values: Record<string, string>) => {
57
+ if (!values || !values.text?.trim()) {
58
+ setFilteredSections(questions.sections);
59
+ return;
60
+ }
61
+
62
+ const searchValue: string = values.text.trim(); // Ensure no spaces-only search
63
+ const normalizedSearchWord = removeAccents(searchValue.toLowerCase());
64
+
65
+ const filteredSections = questions.sections
66
+ .map((section: SectionType) => {
67
+ const filteredQa = section.qa.filter(({ question, answer }: any) => {
68
+ const normalizedQuestion = removeAccents(
69
+ question?.toLowerCase() || ''
70
+ );
71
+ const normalizedAnswer = removeAccents(answer?.toLowerCase() || '');
72
+ return (
73
+ normalizedQuestion.includes(normalizedSearchWord) ||
74
+ normalizedAnswer.includes(normalizedSearchWord)
75
+ );
76
+ });
77
+
78
+ return { ...section, qa: filteredQa };
79
+ })
80
+ .filter((section: SectionType) => section.qa.length > 0);
81
+
82
+ setFilteredSections(filteredSections);
83
+ };
84
+
85
+ return {
86
+ filteredSections,
87
+ search,
88
+ };
89
+ };
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ import { test, expect } from '@playwright/experimental-ct-react';
3
+ import TestVariant from '@digigov/ui/utils/TestVariant'
4
+ import { Default } from '@digigov/react-modules/Faq/__stories__/Default';
5
+
6
+ test('renders the All Faq variants', async ({ mount, page }) => {
7
+ await mount(
8
+
9
+ <div>
10
+ <TestVariant title="Default">
11
+ <Default />
12
+ </TestVariant>
13
+ </div>
14
+ )
15
+ await page.evaluate(() => document.fonts.ready);
16
+
17
+ // Move the mouse to the top-left corner to avoid random hover issues
18
+ await page.mouse.move(0, 0);
19
+
20
+
21
+ const screenshot = await page.screenshot({ fullPage: true, animations: 'disabled' });
22
+ expect(screenshot).toMatchSnapshot();
23
+ });
24
+
@@ -0,0 +1,286 @@
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
+
31
+ export interface sectionsConfigType {
32
+ sections: SectionType[];
33
+ }
34
+
35
+ export interface QaType {
36
+ id?: string;
37
+ question: string;
38
+ answer: string;
39
+ }
40
+
41
+ export interface SectionType {
42
+ id: string;
43
+ title: string;
44
+ qa: QaType[];
45
+ }
46
+
47
+ export interface TocType {
48
+ title: string;
49
+ placement: 'top' | 'left' | 'right' | 'none';
50
+ }
51
+
52
+ export interface SearchFilterType {
53
+ title?: string;
54
+ }
55
+
56
+ export interface ContentsType {
57
+ title: string;
58
+ toc: TocType;
59
+ search?: SearchFilterType;
60
+ }
61
+
62
+ export interface NavigationListProps {
63
+ title?: string;
64
+ sections: SectionType[];
65
+ }
66
+
67
+ export interface FaqProps {
68
+ contents: ContentsType;
69
+ sections: SectionType[];
70
+ initialSections: sectionsConfigType;
71
+ search: (values: Record<string, string>) => void;
72
+ submitValues: { text: string };
73
+ activeQa: string;
74
+ onActiveQa: (v: string) => void;
75
+ }
76
+
77
+ const FormBuilderSyncValues = ({ values, autoSubmit }) => {
78
+ const form = useContext(FormContext);
79
+ const previousValues = form.getValues();
80
+ useEffect(() => {
81
+ const mergedObject = { ...values, ...previousValues };
82
+ let shouldSubmit = false;
83
+ for (const key in mergedObject) {
84
+ // catching the filters that have been parsed from url & avoid continuous submitting
85
+ if (values[key] !== undefined && previousValues[key] !== values[key]) {
86
+ shouldSubmit = true;
87
+ previousValues[key] = values[key];
88
+ form.setValue(key, values[key]);
89
+ }
90
+ }
91
+ if (autoSubmit && shouldSubmit) {
92
+ form.submit();
93
+ }
94
+ }, [autoSubmit, form, previousValues, values]);
95
+ return <></>;
96
+ };
97
+
98
+ const NavigationList = React.forwardRef<HTMLUListElement, NavigationListProps>(
99
+ function NavigationList({ title, sections }, ref) {
100
+ return (
101
+ <NavList ref={ref} layout="vertical" marginBottom={10}>
102
+ {title && (
103
+ <Heading size="md" id="contents" marginBottom={4}>
104
+ {title}
105
+ </Heading>
106
+ )}
107
+ {sections &&
108
+ sections.length > 0 &&
109
+ sections.map(({ id, title }, index) => (
110
+ <NavListItemAction key={index} href={`#${createId(id, title)}`}>
111
+ {title}
112
+ </NavListItemAction>
113
+ ))}
114
+ </NavList>
115
+ );
116
+ }
117
+ );
118
+
119
+ export const Faq = React.forwardRef<HTMLDivElement, FaqProps>(function FAQ(
120
+ {
121
+ contents,
122
+ sections,
123
+ initialSections,
124
+ submitValues,
125
+ activeQa,
126
+ onActiveQa,
127
+ search,
128
+ },
129
+ ref
130
+ ) {
131
+ const { section, currentOpen, onOpen, close } = useAccordion({
132
+ singleOpen: true,
133
+ defaultOpen: 0,
134
+ });
135
+ const placement = contents.toc?.placement || 'none';
136
+ const filteredSections = sections.reduce(
137
+ (acc, section) => acc + (section.qa.length || 0),
138
+ 0
139
+ );
140
+ const primarySections = initialSections.sections.reduce(
141
+ (acc, section) => acc + (section.qa.length || 0),
142
+ 0
143
+ );
144
+ const hash = window.location.hash.slice(1);
145
+ const currentId = activeQa ? activeQa : hash;
146
+
147
+ useEffect(() => {
148
+ if (onActiveQa) {
149
+ if (currentOpen && activeQa !== currentOpen) {
150
+ onActiveQa(currentOpen as string);
151
+ }
152
+ }
153
+ }, [activeQa, currentOpen, onActiveQa]);
154
+
155
+ useEffect(() => {
156
+ if (activeQa && activeQa !== currentOpen) {
157
+ onOpen(activeQa);
158
+ }
159
+ }, [activeQa, currentOpen, onOpen]);
160
+
161
+ useEffect(() => {
162
+ // Scroll to the target element if it exists
163
+ if (currentId) {
164
+ const element = document.getElementById(currentId);
165
+ if (element) {
166
+ element.scrollIntoView({ behavior: 'smooth', block: 'start' });
167
+ }
168
+ }
169
+ }, [activeQa, currentId, hash]);
170
+
171
+ const Onclose = (activeQa) => {
172
+ const urlParams = new URLSearchParams(window.location.search);
173
+ urlParams.delete('text');
174
+ urlParams.delete('activeQa');
175
+ window.history.pushState({}, '', '?' + urlParams.toString());
176
+ onActiveQa('');
177
+ close(activeQa);
178
+ };
179
+ const handleSubmit = (data) => {
180
+ search(data);
181
+ onActiveQa('');
182
+ close(activeQa);
183
+ const urlParams = new URLSearchParams(window.location.search);
184
+ urlParams.delete('activeQa');
185
+ window.history.replaceState({}, '', '?' + urlParams.toString());
186
+ };
187
+
188
+ return (
189
+ <Container ref={ref}>
190
+ {placement !== 'none' && placement === 'left' && (
191
+ <Aside sticky={false}>
192
+ <NavigationList title={contents.toc?.title} sections={sections} />
193
+ </Aside>
194
+ )}
195
+ <Main>
196
+ <PageTitleContainer>
197
+ <PageTitleHeading size="xl" id="faq">
198
+ {contents?.title}
199
+ </PageTitleHeading>
200
+ </PageTitleContainer>
201
+ {placement !== 'none' && placement === 'top' && (
202
+ <NavigationList title={contents?.toc?.title} sections={sections} />
203
+ )}
204
+
205
+ {contents.search && (
206
+ <FormBuilder onSubmit={handleSubmit} initial={{ text: '' }}>
207
+ {submitValues && (
208
+ <FormBuilderSyncValues values={submitValues} autoSubmit={true} />
209
+ )}
210
+ <Stack
211
+ direction="row"
212
+ flexWrap="nowrap"
213
+ alignItems="flex-end"
214
+ spacing={4}
215
+ >
216
+ <Grid container style={{ width: '100%' }}>
217
+ <Field
218
+ type="string"
219
+ key="text"
220
+ name="text"
221
+ placeholder="Αναζητήστε σχετικά με την ερώτησή σας"
222
+ label={{ primary: contents.search.title }}
223
+ />
224
+ </Grid>
225
+ <SearchButton
226
+ type="submit"
227
+ mb={{ md: 10 }}
228
+ style={{ minHeight: '2.75rem' }}
229
+ />
230
+ </Stack>
231
+ {filteredSections !== primarySections && (
232
+ <Results
233
+ filteredSections={filteredSections}
234
+ primarySections={primarySections}
235
+ Onclose={Onclose}
236
+ activeQa={activeQa}
237
+ />
238
+ )}
239
+ </FormBuilder>
240
+ )}
241
+ <Grid>
242
+ {sections && sections.length > 0 ? (
243
+ sections.map(({ id: sectionId, title, qa }, index) => (
244
+ <React.Fragment key={index}>
245
+ <Heading id={createId(sectionId, title)} size="lg">
246
+ {title}
247
+ </Heading>
248
+ <Accordion marginBottom={qa && qa.length > 0 ? 12 : 0}>
249
+ {qa?.map(({ id, question, answer }, indx) => (
250
+ <AccordionSection
251
+ key={indx}
252
+ {...section(createId(id, question))}
253
+ >
254
+ <AccordionSectionSummary>
255
+ <AccordionSectionSummaryHeading
256
+ aria-controls={createId(id, question)}
257
+ >
258
+ {question}
259
+ </AccordionSectionSummaryHeading>
260
+ </AccordionSectionSummary>
261
+ <AccordionSectionContent id={createId(id, question)}>
262
+ <Markdown content={answer} />
263
+ </AccordionSectionContent>
264
+ </AccordionSection>
265
+ ))}
266
+ </Accordion>
267
+ <SectionBreak visible={false} />
268
+ </React.Fragment>
269
+ ))
270
+ ) : (
271
+ <Hint marginBottom={10}>Δεν βρέθηκαν αποτελέσματα.</Hint>
272
+ )}
273
+ </Grid>
274
+ <BackToTop topLimitId="contents" id="back-to-top">
275
+ Επιστροφή στα Περιεχόμενα
276
+ </BackToTop>
277
+ </Main>
278
+ {placement !== 'none' && placement === 'right' && (
279
+ <Aside sticky={false}>
280
+ <NavigationList title={contents?.toc?.title} sections={sections} />
281
+ </Aside>
282
+ )}
283
+ </Container>
284
+ );
285
+ });
286
+ export default Faq;
@@ -0,0 +1,140 @@
1
+ export function slug(text: string, maxWidth = 50): string {
2
+ // Greek to Latin character mapping
3
+ const greekToLatinMap: Record<string, string> = {
4
+ α: 'a',
5
+ β: 'b',
6
+ γ: 'g',
7
+ δ: 'd',
8
+ ε: 'e',
9
+ ζ: 'z',
10
+ η: 'i',
11
+ θ: 'th',
12
+ ι: 'i',
13
+ κ: 'k',
14
+ λ: 'l',
15
+ μ: 'm',
16
+ ν: 'n',
17
+ ξ: 'x',
18
+ ο: 'o',
19
+ π: 'p',
20
+ ρ: 'r',
21
+ σ: 's',
22
+ τ: 't',
23
+ υ: 'y',
24
+ φ: 'f',
25
+ χ: 'ch',
26
+ ψ: 'ps',
27
+ ω: 'o',
28
+ ά: 'a',
29
+ έ: 'e',
30
+ ί: 'i',
31
+ ό: 'o',
32
+ ύ: 'y',
33
+ ή: 'i',
34
+ ώ: 'o',
35
+ ς: 's',
36
+ ϊ: 'i',
37
+ ΰ: 'y',
38
+ ϋ: 'y',
39
+ ΐ: 'i',
40
+ Α: 'A',
41
+ Β: 'B',
42
+ Γ: 'G',
43
+ Δ: 'D',
44
+ Ε: 'E',
45
+ Ζ: 'Z',
46
+ Η: 'I',
47
+ Θ: 'TH',
48
+ Ι: 'I',
49
+ Κ: 'K',
50
+ Λ: 'L',
51
+ Μ: 'M',
52
+ Ν: 'N',
53
+ Ξ: 'X',
54
+ Ο: 'O',
55
+ Π: 'P',
56
+ Ρ: 'R',
57
+ Σ: 'S',
58
+ Τ: 'T',
59
+ Υ: 'Y',
60
+ Φ: 'F',
61
+ Χ: 'CH',
62
+ Ψ: 'PS',
63
+ Ω: 'O',
64
+ Ά: 'A',
65
+ Έ: 'E',
66
+ Ί: 'I',
67
+ Ό: 'O',
68
+ Ύ: 'Y',
69
+ Ή: 'I',
70
+ Ώ: 'O',
71
+ Ϊ: 'I',
72
+ Ϋ: 'Y',
73
+ };
74
+
75
+ // Convert Greek characters to Latin
76
+ const latinText = text
77
+ .split('')
78
+ .map((char) => greekToLatinMap[char] || char)
79
+ .join('');
80
+
81
+ // Convert to lowercase, replace spaces with hyphens, remove special characters
82
+ const processedText = latinText
83
+ .toLowerCase()
84
+ .replace(/\s+/g, '-')
85
+ .replace(/[^\w-]+/g, '')
86
+ .replace(/--+/g, '-')
87
+ .replace(/^-+/, '')
88
+ .replace(/-+$/, '');
89
+
90
+ // Calculate the available width for the slug (subtracting 1 for the hyphen and at least 8 for the ID)
91
+ // const availableWidth = Math.max(0, maxWidth - 9);
92
+
93
+ // Split the processed text into slug and remaining text for ID
94
+ let slug = processedText.substring(0, maxWidth);
95
+ const remainingText = processedText.substring(maxWidth);
96
+
97
+ // Remove trailing hyphens from the slug
98
+ slug = slug.replace(/-+$/, '');
99
+
100
+ // Generate ID from the remaining text
101
+ const id = generateIDFromText(remainingText);
102
+
103
+ // Combine the slug and ID
104
+ return `${slug}${id && '-'}${id}`;
105
+ }
106
+ function generateIDFromText(text: string): string {
107
+ // If text is empty or maxLength is 0 or less, return a default ID
108
+ if (!text) return '';
109
+
110
+ // Remove hyphens and take only alphanumeric characters
111
+ let processedText = text.replace(/-/g, '').replace(/[^a-z0-9]/g, '');
112
+
113
+ // If processed text is empty, use a default base
114
+ if (!processedText) processedText = 'default';
115
+
116
+ // Calculate a simple hash of the processed text
117
+ let hash = 0;
118
+ for (let i = 0; i < processedText.length; i++) {
119
+ const char = processedText.charCodeAt(i);
120
+ hash = (hash << 5) - hash + char;
121
+ hash = hash & hash; // Convert to 32-bit integer
122
+ }
123
+
124
+ // Convert hash to a positive number and then to base 36 (0-9 and a-z)
125
+ const id = Math.abs(hash).toString(36);
126
+
127
+ // Ensure the ID is at least 8 characters long, padding with '0' if necessary
128
+ return id;
129
+ // return id.padEnd(8, '0').substring(0, maxLength);
130
+ }
131
+
132
+ // Test the function
133
+ // console.log(createSlugWithID('Καλημέρα κόσμε! Hello world!', 10));
134
+ // console.log(createSlugWithID('Ελληνικά και English mixed', 80));
135
+ // console.log(
136
+ // createSlugWithID(
137
+ // 'Αυτό είναι ένα πολύ μεγάλο κείμενο για να δοκιμάσουμε το όριο πλάτους',
138
+ // 90
139
+ // )
140
+ // );
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import { test, expect } from '@playwright/experimental-ct-react';
3
+
4
+ import { Default } from '@digigov/react-modules/Faq/__stories__/Default';
5
+
6
+ test('renders the Default', async ({ mount, page }) => {
7
+ await mount(
8
+ <Default />
9
+ )
10
+ await page.evaluate(() => document.fonts.ready);
11
+
12
+ // Move the mouse to the top-left corner to avoid random hover issues
13
+ await page.mouse.move(0, 0);
14
+
15
+
16
+ const screenshot = await page.screenshot({ fullPage: true, animations: 'disabled' });
17
+ expect(screenshot).toMatchSnapshot();
18
+ });
19
+
@@ -0,0 +1,5 @@
1
+ import { slug } from '@digigov/react-modules/Faq/slug';
2
+
3
+ export const createId = (id: string | undefined, text: string) => {
4
+ return id ? id : slug(text); // Fallback to slug(text) when id is undefined
5
+ };
@@ -204,7 +204,7 @@ const initialFilters: InitialFiltersType = {
204
204
  rights: '',
205
205
  };
206
206
 
207
- export const Default = () => {
207
+ export const Default = (_: any) => {
208
208
  const { search, results } = useStaticSearch<
209
209
  Record<string, any>,
210
210
  InitialFiltersType
@@ -14,6 +14,10 @@ test('renders the All FilteredResults variants', async ({ mount, page }) => {
14
14
  )
15
15
  await page.evaluate(() => document.fonts.ready);
16
16
 
17
+ // Move the mouse to the top-left corner to avoid random hover issues
18
+ await page.mouse.move(0, 0);
19
+
20
+
17
21
  const screenshot = await page.screenshot({ fullPage: true, animations: 'disabled' });
18
22
  expect(screenshot).toMatchSnapshot();
19
23
  });
@@ -9,6 +9,10 @@ test('renders the Default', async ({ mount, page }) => {
9
9
  )
10
10
  await page.evaluate(() => document.fonts.ready);
11
11
 
12
+ // Move the mouse to the top-left corner to avoid random hover issues
13
+ await page.mouse.move(0, 0);
14
+
15
+
12
16
  const screenshot = await page.screenshot({ fullPage: true, animations: 'disabled' });
13
17
  expect(screenshot).toMatchSnapshot();
14
18
  });
package/src/index.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from '@digigov/react-modules/FilteredResults';
2
+ export * from '@digigov/react-modules/Faq';
package/src/lazy.js ADDED
@@ -0,0 +1,11 @@
1
+ import { lazy } from 'react';
2
+ export default {
3
+ 'FormBuilderSyncValues': lazy(() => import('@digigov/react-modules/FilteredResults').then((module) => ({ default: module['FormBuilderSyncValues'] }))),
4
+ 'DrawerFilteredResults': lazy(() => import('@digigov/react-modules/FilteredResults').then((module) => ({ default: module['DrawerFilteredResults'] }))),
5
+ 'BlockFilteredResults': lazy(() => import('@digigov/react-modules/FilteredResults').then((module) => ({ default: module['BlockFilteredResults'] }))),
6
+ 'FilteredResults': lazy(() => import('@digigov/react-modules/FilteredResults').then((module) => ({ default: module['FilteredResults'] }))),
7
+ 'Faq': lazy(() => import('@digigov/react-modules/Faq').then((module) => ({ default: module['Faq'] }))),
8
+ 'DataTable': lazy(() => import('@digigov/react-modules/FilteredResults/DataTable').then((module) => ({ default: module['DataTable'] }))),
9
+ 'FilterChips': lazy(() => import('@digigov/react-modules/FilteredResults/FilterChips').then((module) => ({ default: module['FilterChips'] }))),
10
+ 'FilterFields': lazy(() => import('@digigov/react-modules/FilteredResults/FilterFields').then((module) => ({ default: module['FilterFields'] })))
11
+ };
@@ -0,0 +1,43 @@
1
+
2
+ import * as _digigov_react_modules from "@digigov/react-modules";
3
+ import * as _digigov_react_modules_Faq_Results from "@digigov/react-modules/Faq/Results";
4
+ import * as _digigov_react_modules_Faq_hooks from "@digigov/react-modules/Faq/hooks";
5
+ import * as _digigov_react_modules_Faq from "@digigov/react-modules/Faq";
6
+ import * as _digigov_react_modules_Faq_slug from "@digigov/react-modules/Faq/slug";
7
+ import * as _digigov_react_modules_Faq_utils from "@digigov/react-modules/Faq/utils";
8
+ import * as _digigov_react_modules_FilteredResults_DataTable from "@digigov/react-modules/FilteredResults/DataTable";
9
+ import * as _digigov_react_modules_FilteredResults_FilterChips from "@digigov/react-modules/FilteredResults/FilterChips";
10
+ import * as _digigov_react_modules_FilteredResults_FilterFields from "@digigov/react-modules/FilteredResults/FilterFields";
11
+ import * as _digigov_react_modules_FilteredResults_hooks from "@digigov/react-modules/FilteredResults/hooks";
12
+ import * as _digigov_react_modules_FilteredResults from "@digigov/react-modules/FilteredResults";
13
+ function lazyImport(pkgImport) {
14
+ return new Proxy(
15
+ {},
16
+ {
17
+ get: (_target, name) => {
18
+ if (name === '__esModule' || name === 'default') {
19
+ return pkgImport.default;
20
+ } else if(
21
+ name === '*'
22
+ ) {
23
+ return pkgImport;
24
+ } else {
25
+ return pkgImport[name];
26
+ }
27
+ },
28
+ }
29
+ )
30
+ }
31
+ export default {
32
+ '@digigov/react-modules': lazyImport(_digigov_react_modules),
33
+ '@digigov/react-modules/Faq/Results': lazyImport(_digigov_react_modules_Faq_Results),
34
+ '@digigov/react-modules/Faq/hooks': lazyImport(_digigov_react_modules_Faq_hooks),
35
+ '@digigov/react-modules/Faq': lazyImport(_digigov_react_modules_Faq),
36
+ '@digigov/react-modules/Faq/slug': lazyImport(_digigov_react_modules_Faq_slug),
37
+ '@digigov/react-modules/Faq/utils': lazyImport(_digigov_react_modules_Faq_utils),
38
+ '@digigov/react-modules/FilteredResults/DataTable': lazyImport(_digigov_react_modules_FilteredResults_DataTable),
39
+ '@digigov/react-modules/FilteredResults/FilterChips': lazyImport(_digigov_react_modules_FilteredResults_FilterChips),
40
+ '@digigov/react-modules/FilteredResults/FilterFields': lazyImport(_digigov_react_modules_FilteredResults_FilterFields),
41
+ '@digigov/react-modules/FilteredResults/hooks': lazyImport(_digigov_react_modules_FilteredResults_hooks),
42
+ '@digigov/react-modules/FilteredResults': lazyImport(_digigov_react_modules_FilteredResults)
43
+ };
package/.prettierrc.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require('@digigov/cli-lint/prettierrc')();
@@ -1,8 +0,0 @@
1
- {"kind":"O","text":"Invoking: digigov build --generate-registry \n"}
2
- {"kind":"O","text":" LOG Running: rimraf dist\n"}
3
- {"kind":"O","text":" LOG Running: tsc --emitDeclarationOnly --outDir dist --project /Users/dimitristsironis/grnet/digigov-sdk/libs/react-modules/tsconfig.production.json\n"}
4
- {"kind":"O","text":" LOG Running: esbuild for CJS format\n"}
5
- {"kind":"O","text":" LOG Running: esbuild for ESM format\n"}
6
- {"kind":"O","text":" LOG Running: esbuild for CJS format\n"}
7
- {"kind":"O","text":" LOG Generated registry files\n"}
8
- {"kind":"O","text":"⏱️ \"build\" execution time: 3.980s\n"}