Browse Source

[feat] Add accordion component to advice list page

eliam.ruiz 2 years ago
parent
commit
aa667f76f7

+ 3
- 0
src/components/DropdownComponent.css View File

1
+.accordion-list-container {
2
+    width: 100%;
3
+}

+ 6
- 17
src/components/DropdownComponent.tsx View File

4
   IonItem,
4
   IonItem,
5
   IonLabel,
5
   IonLabel,
6
 } from "@ionic/react";
6
 } from "@ionic/react";
7
-import "../components/ListComponent";
8
 import ListComponent from "../components/ListComponent";
7
 import ListComponent from "../components/ListComponent";
9
-import "../intefaces";
10
-import Category from "../intefaces";
8
+import { Category } from "../types";
9
+import "./DropdownComponent.css";
11
 
10
 
12
 const DropdownComponent: React.FC<{
11
 const DropdownComponent: React.FC<{
13
   category: Category[];
12
   category: Category[];
16
   return (
15
   return (
17
     <IonAccordionGroup>
16
     <IonAccordionGroup>
18
       {category.map((catItem: Category, index) => {
17
       {category.map((catItem: Category, index) => {
19
-        var position = "";
20
-        if (index === 1) {
21
-          position = "first";
22
-        } else if (index === 2) {
23
-          position = "second";
24
-        } else if (index === 3) {
25
-          position = "third";
26
-        } else if (index === 4) {
27
-          position = "fourth";
28
-        } else if (index === 5) {
29
-          position = "fifth";
30
-        }
31
         return (
18
         return (
32
-          <IonAccordion value={position}>
19
+          <IonAccordion value={`${index}`}>
33
             <IonItem slot="header" color="light">
20
             <IonItem slot="header" color="light">
34
               <IonLabel>{catItem.name}</IonLabel>
21
               <IonLabel>{catItem.name}</IonLabel>
35
             </IonItem>
22
             </IonItem>
36
             <IonItem slot="content">
23
             <IonItem slot="content">
37
-              <ListComponent items={catItem.listItems} />
24
+              <div className="accordion-list-container">
25
+                <ListComponent items={catItem.listItems} />
26
+              </div>
38
             </IonItem>
27
             </IonItem>
39
           </IonAccordion>
28
           </IonAccordion>
40
         );
29
         );

+ 3
- 3
src/components/ListComponent.tsx View File

1
-import { IonContent, IonItem, IonLabel, IonListHeader } from "@ionic/react";
1
+import { IonItem, IonLabel, IonList, IonListHeader } from "@ionic/react";
2
 import "../components/ListComponent.css";
2
 import "../components/ListComponent.css";
3
 
3
 
4
 const ListComponent: React.FC<{ title?: string; items: string[] }> = (
4
 const ListComponent: React.FC<{ title?: string; items: string[] }> = (
7
   const title = props.title;
7
   const title = props.title;
8
   const items = props.items;
8
   const items = props.items;
9
   return (
9
   return (
10
-    <IonContent>
10
+    <IonList>
11
       {title ? (
11
       {title ? (
12
         <IonListHeader>
12
         <IonListHeader>
13
           <IonLabel>{title}</IonLabel>
13
           <IonLabel>{title}</IonLabel>
21
           </IonItem>
21
           </IonItem>
22
         );
22
         );
23
       })}
23
       })}
24
-    </IonContent>
24
+    </IonList>
25
   );
25
   );
26
 };
26
 };
27
 export default ListComponent;
27
 export default ListComponent;

+ 0
- 6
src/intefaces.ts View File

1
-interface Category {
2
-    name: string;
3
-    listItems: string[];
4
-}
5
-
6
-export default Category;

+ 3
- 5
src/pages/AdviceListPage.tsx View File

4
   IonPage,
4
   IonPage,
5
   IonTitle,
5
   IonTitle,
6
   IonToolbar,
6
   IonToolbar,
7
-  IonCard,
8
 } from "@ionic/react";
7
 } from "@ionic/react";
9
 import DropdownComponent from "../components/DropdownComponent";
8
 import DropdownComponent from "../components/DropdownComponent";
10
-import "../intefaces";
9
+import "../types";
11
 
10
 
12
 const categories = [
11
 const categories = [
13
   {
12
   {
34
             <IonTitle size="large">Consejos</IonTitle>
33
             <IonTitle size="large">Consejos</IonTitle>
35
           </IonToolbar>
34
           </IonToolbar>
36
         </IonHeader>
35
         </IonHeader>
37
-        <IonCard>
38
-          <DropdownComponent category={categories} />
39
-        </IonCard>
36
+
37
+        <DropdownComponent category={categories} />
40
       </IonContent>
38
       </IonContent>
41
     </IonPage>
39
     </IonPage>
42
   );
40
   );

+ 4
- 0
src/types.ts View File

1
+export interface Category {
2
+    name: string;
3
+    listItems: string[];
4
+}