const upDownBtn = (type: string) => {
if (checkList.length > 0) {
const updatedList = [...valueList]
const [movedItem] = updatedList.splice(selectChecked, 1)
if (type === 'up') {
const newIndex = selectChecked - 1 < 0 ? valueList.length - 1 : selectChecked - 1
updatedList.splice(newIndex, 0, movedItem)
setSelectChecked(newIndex)
setCheckList([newIndex])
}
if (type === 'down') {
const newIndex = selectChecked === valueList.length - 1 ? 0 : selectChecked + 1
updatedList.splice(newIndex, 0, movedItem)
setSelectChecked(newIndex)
setCheckList([newIndex])
}
setValueList(updatedList)
return
}
alert('체크박스를 선택해주세요.')
}
return(
<thead>
...생략
</thead>
<tbody>
<RowStyle
className="inputContainer"
key={index}
isChecked={selectChecked === index}>
</RowStyle>
...생략
<tbody>
<div>
<ul>
<li style={{ cursor: 'pointer' }} onClick={() => upDownBtn('down')}>
<DownBtn width={35} height={35} />
</li>
<li style={{ cursor: 'pointer' }} onClick={() => upDownBtn('up')}>
<UpBtn width={35} height={35} />
</li>
</div>
)
const RowStyle = styled.tr<{ isChecked: boolean }>`
background-color: ${({ isChecked }) => (isChecked ? '#e2eaf7' : 'white')};
`