diff --git a/src/components/Accordion/AccordionDesign1/index.js b/src/components/Accordion/AccordionDesign1/index.js index e11f42e..2cf4421 100644 --- a/src/components/Accordion/AccordionDesign1/index.js +++ b/src/components/Accordion/AccordionDesign1/index.js @@ -1,105 +1,152 @@ import React, { useState } from "react"; import CircleInCircle from "../../MiniComponents/CircleInCircle"; import Button from "../../ButtonDesign/Button"; +import { DragDropContext, Droppable, Draggable } from "react-beautiful-dnd"; const AccordionDesign1 = ({ items, vod }) => { const [activeAccordion, setActiveAccordion] = useState(null); + const [accordions, updateAccordion] = useState(items); + + function handleOnDragEnd(result) { + if (!result.destination) return; + + const items = Array.from(accordions); + const [reorderedItem] = items.splice(result.source.index, 1); + items.splice(result.destination.index, 0, reorderedItem); + + updateAccordion(items); + } return ( -
- {items.map((item, index) => ( -
- {/* parent */} -
- setActiveAccordion(activeAccordion === item ? null : item) - } + + + {(provided) => ( +
- -

{item.title}

- {vod && ( -
-

- دقیقه: - {item.min} -

-
-

- ویدیو: - {item.video} -

-
- )} - -
- {/* child */} - {activeAccordion === item && - item.subItems.map((subItem, i) => ( -
-
- {vod === !true && ( - line - )} - - {i + 1} - -
-
-

{subItem.name}

-
- {vod ? ( - <> -
-

- دقیقه: - {item.min} -

-
- - ) : ( - <> - delete-button ( + + {(provided) => ( +
+ {/* parent */} +
+ setActiveAccordion( + activeAccordion === item ? null : item + ) + } + > + +

{item.title}

+ {vod && ( +
+

+ دقیقه: + {item.min} +

+
+

+ ویدیو: + {item.video} +

+
+ )} edit-button - - )} -
-
+
+ {/* child */} + {activeAccordion === item && + item.subItems.map((subItem, i) => ( +
+
+ {vod === !true && ( + line + )} + + {i + 1} + +
+
+

{subItem.name}

+
+ {vod ? ( + <> +
+

+ دقیقه: + {item.min} +

+
+ + ) : ( + <> + delete-button + edit-button + + )} +
+
+ ))} + {provided.placeholder} +
+ )} + ))} -
- ))} -
+ + )} + + ); };