Bläddra i källkod

[feat] Add accordion component to advice list page

eliam.ruiz 1 år sedan
förälder
incheckning
aa667f76f7

+ 3
- 0
src/components/DropdownComponent.css Visa fil

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

+ 6
- 17
src/components/DropdownComponent.tsx Visa fil

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

+ 3
- 3
src/components/ListComponent.tsx Visa fil

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

+ 0
- 6
src/intefaces.ts Visa fil

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

+ 3
- 5
src/pages/AdviceListPage.tsx Visa fil

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

+ 4
- 0
src/types.ts Visa fil

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