@openmrs/esm-form-engine-lib 2.1.0-pre.1443 → 2.1.0-pre.1462

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-form-engine-lib",
3
- "version": "2.1.0-pre.1443",
3
+ "version": "2.1.0-pre.1462",
4
4
  "description": "React Form Engine for O3",
5
5
  "browser": "dist/openmrs-esm-form-engine-lib.js",
6
6
  "main": "src/index.ts",
@@ -91,7 +91,12 @@ export const FormRenderer = ({ processorContext, initialValues, setIsLoadingForm
91
91
  />
92
92
  );
93
93
  }
94
- return <PageRenderer page={page} />;
94
+ return (
95
+ <PageRenderer
96
+ key={page.label}
97
+ page={page}
98
+ />
99
+ );
95
100
  })}
96
101
  </FormProvider>
97
102
  );
@@ -1,4 +1,4 @@
1
- import React, { useMemo } from 'react';
1
+ import React, { useMemo, useState } from 'react';
2
2
  import { type FormPage } from '../../../types';
3
3
  import { isTrue } from '../../../utils/boolean-utils';
4
4
  import { useTranslation } from 'react-i18next';
@@ -7,6 +7,7 @@ import { Waypoint } from 'react-waypoint';
7
7
  import styles from './page.renderer.scss';
8
8
  import { Accordion, AccordionItem } from '@carbon/react';
9
9
  import { useFormFactory } from '../../../provider/form-factory-provider';
10
+ import { ChevronDownIcon, ChevronUpIcon } from '@openmrs/esm-framework';
10
11
 
11
12
  interface PageRendererProps {
12
13
  page: FormPage;
@@ -15,32 +16,47 @@ interface PageRendererProps {
15
16
  function PageRenderer({ page }: PageRendererProps) {
16
17
  const { t } = useTranslation();
17
18
  const pageId = useMemo(() => page.label.replace(/\s/g, ''), [page.label]);
19
+ const [isCollapsed, setIsCollapsed] = useState(false);
18
20
 
19
21
  const { setCurrentPage } = useFormFactory();
20
22
  const visibleSections = page.sections.filter((section) => {
21
23
  const hasVisibleQuestions = section.questions.some((question) => !isTrue(question.isHidden));
22
24
  return !isTrue(section.isHidden) && hasVisibleQuestions;
23
25
  });
26
+
27
+ const toggleCollapse = () => setIsCollapsed(!isCollapsed);
28
+
24
29
  return (
25
30
  <div>
26
31
  <Waypoint onEnter={() => setCurrentPage(pageId)} topOffset="50%" bottomOffset="60%">
27
32
  <div className={styles.pageContent}>
28
- <div className={styles.pageHeader}>
29
- <p className={styles.pageTitle}>{t(page.label)}</p>
33
+ <div className={styles.pageHeader} onClick={toggleCollapse}>
34
+ <p className={styles.pageTitle}>
35
+ {t(page.label)}
36
+ <span className={styles.collapseIconWrapper}>
37
+ {isCollapsed ? (
38
+ <ChevronDownIcon className={styles.collapseIcon} aria-label="Expand" />
39
+ ) : (
40
+ <ChevronUpIcon className={styles.collapseIcon} aria-label="Collapse" />
41
+ )}
42
+ </span>
43
+ </p>
30
44
  </div>
31
- <Accordion>
32
- {visibleSections.map((section) => (
33
- <AccordionItem
34
- title={t(section.label)}
35
- open={true}
36
- className={styles.sectionContainer}
37
- key={`section-${section.label}`}>
38
- <div className={styles.formSection}>
39
- <SectionRenderer section={section} />
40
- </div>
41
- </AccordionItem>
42
- ))}
43
- </Accordion>
45
+ {!isCollapsed && (
46
+ <Accordion>
47
+ {visibleSections.map((section) => (
48
+ <AccordionItem
49
+ title={t(section.label)}
50
+ open={true}
51
+ className={styles.sectionContainer}
52
+ key={`section-${section.label}`}>
53
+ <div className={styles.formSection}>
54
+ <SectionRenderer section={section} />
55
+ </div>
56
+ </AccordionItem>
57
+ ))}
58
+ </Accordion>
59
+ )}
44
60
  </div>
45
61
  </Waypoint>
46
62
  </div>
@@ -1,13 +1,19 @@
1
1
  @use '@carbon/colors';
2
+ @use '@carbon/type';
2
3
 
3
4
  .pageContent:last-child > hr {
4
5
  display: none;
5
6
  }
6
7
 
7
8
  .pageHeader {
8
- display: flex;
9
- flex-direction: row;
10
- margin: 0.5rem 1rem;
9
+ cursor: pointer;
10
+ transition: background-color 0.1s;
11
+ border-radius: 1px;
12
+ padding: 0.5rem 1rem;
13
+
14
+ &:hover {
15
+ background-color: colors.$gray-20;
16
+ }
11
17
  }
12
18
 
13
19
  .pageTitle {
@@ -16,6 +22,16 @@
16
22
  line-height: 1.4;
17
23
  color: colors.$gray-100;
18
24
  width: 100%;
25
+ display: flex;
26
+ align-items: center;
27
+ justify-content: space-between;
28
+ margin: 0;
29
+ }
30
+
31
+ .collapseIcon {
32
+ fill: colors.$gray-70;
33
+ width: 1rem;
34
+ height: 1rem;
19
35
  }
20
36
 
21
37
  .sectionContainer > div {
@@ -118,4 +118,4 @@
118
118
 
119
119
  .toggleContainer {
120
120
  margin-bottom: 0.5rem;
121
- }
121
+ }