11import React , { useState , useEffect } from "react" ;
2- import { FormVariableIcon , DraggableIcon } from "../SvgIcons/index" ;
2+ import { FormVariableIcon , DraggableIcon } from "../SvgIcons/index" ;
3+ import { StyleServices } from "@formsflow/service" ;
34
45interface FilterItem {
56 label : string ;
@@ -16,27 +17,27 @@ interface DragAndDropFilterProps {
1617
1718export const DragandDropSort : React . FC < DragAndDropFilterProps > = ( { items, onUpdate } ) => {
1819
19- const computedStyle = getComputedStyle ( document . documentElement ) ;
20- const darkColor = computedStyle . getPropertyValue ( "--ff-gray-darkest" ) ;
20+ const darkColor = StyleServices . getCSSVariable ( '--ff-gray-darkest' ) ;
21+
2122 const [ filterItems , setFilterItems ] = useState < FilterItem [ ] > ( items ) ;
2223 const [ draggingIndex , setDraggingIndex ] = useState < number | null > ( null ) ;
2324
2425 useEffect ( ( ) => {
2526 onUpdate ( filterItems ) ;
2627 } , [ filterItems , onUpdate ] ) ;
2728
28- const onDragStart = ( e : React . DragEvent < HTMLDivElement > , index : number ) => {
29+ const onDragStart = ( e : React . DragEvent < HTMLLIElement > , index : number ) => {
2930 e . stopPropagation ( ) ;
3031 e . dataTransfer . setData ( "drag-index" , index . toString ( ) ) ;
3132 setDraggingIndex ( index ) ;
3233 } ;
3334
34- const onDragOver = ( e : React . DragEvent < HTMLDivElement > ) => {
35+ const onDragOver = ( e : React . DragEvent < HTMLLIElement > ) => {
3536 e . preventDefault ( ) ;
3637 } ;
3738
3839
39- const onDragEnter = ( e : React . DragEvent < HTMLDivElement > , targetIndex : number ) => {
40+ const onDragEnter = ( e : React . DragEvent < HTMLLIElement > , targetIndex : number ) => {
4041 e . preventDefault ( ) ;
4142 if ( draggingIndex === null || draggingIndex === targetIndex ) return ;
4243
@@ -49,7 +50,7 @@ export const DragandDropSort: React.FC<DragAndDropFilterProps> = ({ items, onUpd
4950 setDraggingIndex ( targetIndex ) ;
5051 } ;
5152
52- const onDrop = ( e : React . DragEvent < HTMLDivElement > ) => {
53+ const onDrop = ( e : React . DragEvent < HTMLLIElement > ) => {
5354 e . preventDefault ( ) ;
5455 setDraggingIndex ( null ) ;
5556 } ;
@@ -67,24 +68,26 @@ export const DragandDropSort: React.FC<DragAndDropFilterProps> = ({ items, onUpd
6768 } ;
6869 return (
6970 < div className = "drag-drop-container" >
70- { filterItems . map ( ( item , index ) => (
71- < div
71+ < ul >
72+ { filterItems . map ( ( item , index ) => (
73+ < li
7274 key = { item . name }
75+ draggable
7376 className = { `draggable-item ${ draggingIndex === index ? "dragging" : "" } ` }
7477 onDragOver = { onDragOver }
7578 onDrop = { onDrop }
7679 onDragEnter = { ( e ) => onDragEnter ( e , index ) }
7780 onDragEnd = { onDragEnd }
81+ onDragStart = { ( e ) => onDragStart ( e , index ) }
7882 >
79- < div
80- draggable
83+ < span
8184 className = "draggable-icon"
82- onDragStart = { ( e ) => onDragStart ( e , index ) }
8385 >
8486 < DraggableIcon />
85- </ div >
87+ </ span >
8688 < div className = "checkbox-container" >
8789 < input
90+ data-testid = { `${ item . name } -checkbox` }
8891 type = "checkbox"
8992 className = "form-check-input"
9093 checked = { item . isChecked }
@@ -96,8 +99,9 @@ export const DragandDropSort: React.FC<DragAndDropFilterProps> = ({ items, onUpd
9699 { item . isTaskVariable && (
97100 < FormVariableIcon color = { darkColor } />
98101 ) }
99- </ div >
102+ </ li >
100103 ) ) }
104+ </ ul >
101105 </ div >
102106 ) ;
103107} ;
0 commit comments