Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- br 태그
- background-color 속성
- 아두이노
- width속성
- tag html
- Checked 의사 클래스
- Live Server
- 인접 형제 결합자
- iframe 태그
- css
- 전체 선택자
- i 태그
- sub태그
- height속성
- html
- id 선택자
- padding 속성
- RGBA
- 일반 형제 결합자
- 임베디드
- RGB
- 자식결합자
- reveal in file explorer
- go live
- sup태그
- not 의사클래스
- html 태그
- html tag i
- iframe
- focus 의사클래스
Archives
- Today
- Total
so woon!
[REACT] Drag and Drop - snapshot의 isDragging 본문
학습일 : 2023. 05. 02
DragabbleCard.tsx에서도 snapshot을 넘겨주고
오른쪽 마우스를 클릭하여 타입의 정의를 살펴보면
<DragabbleCard.tsx>
export interface DraggableStateSnapshot {
isDragging: boolean;
isDropAnimating: boolean;
isClone: boolean;
dropAnimation: DropAnimation | null | undefined;
draggingOver: DroppableId | null | undefined;
// the id of a draggable that you are combining with
combineWith: DraggableId | null | undefined;
// a combine target is being dragged over by
combineTargetFor: DraggableId | null | undefined;
// What type of movement is being done: 'FLUID' or 'SNAP'
mode: MovementMode | null | undefined;
}
이러한 것들을 얻을 수가 있는데,
일단은 isDragging만 필요하기 때문에 알아만 두도록 한다.
<DragabbleCard.tsx>
Card에 isDragging을 써주고
Card는 styled component라서 isDragging이라는 prop을 인식할 수 없기 때문에
Card styled component를 정의해준 부분에 <{ isDragging: boolean }>을 추가해주면 된다.
그리고 카드의 배경색을 isDragging일때 카드가 노란색이 되도록 조건을 추가해주었다.
import React from "react";
import { Draggable } from "react-beautiful-dnd";
import styled from "styled-components";
// 각각의 toDo들
const Card = styled.div<{ isDragging: boolean }>`
border-radius: 5px;
margin-bottom: 5px;
background-color: ${(props) =>
props.isDragging ? "yellow" : props.theme.cardColor}; //
padding: 10px 10px;
min-width: 18rem;
`;
interface IDragabbleCardProps {
toDo: string;
index: number;
}
function DragabbleCard({ toDo, index }: IDragabbleCardProps) {
return (
<Draggable key={toDo} draggableId={toDo} index={index}>
{(magic, snapshot) => (
<Card
isDragging={snapshot.isDragging}
ref={magic.innerRef}
{...magic.draggableProps}
{...magic.dragHandleProps}
>
{toDo}
</Card>
)}
</Draggable>
);
}
export default React.memo(DragabbleCard);
실행결과
css를 조금 수정
실행결과
색상 참고 사이트
https://flatuicolors.com/palette/us
'ReactJS > 개념정리' 카테고리의 다른 글
[REACT] Drag and Drop - 사용자로부터 입력받아 card 생성하기 (0) | 2023.05.06 |
---|---|
[REACT] useRef 사용하기 (0) | 2023.05.02 |
[REACT] Drag and Drop - snapshot의 draggingFromThis (0) | 2023.05.01 |
[REACT] Drag and Drop - 여러개의 보드에서의 재정렬 + snapshot의 isDraggingOver (0) | 2023.05.01 |
[REACT] Drag and Drop - 같은 보드 내에서 재정렬 (0) | 2023.04.30 |
Comments