-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from concord-consortium/186024265-add-table-re…
…order feat: Added re-order and move attributes [PT-186024265] [PT-186024290]
- Loading branch information
Showing
10 changed files
with
380 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import React from "react"; | ||
import { useDraggableTableContext, Side } from "../hooks/useDraggableTable"; | ||
|
||
import css from "./tables.scss"; | ||
|
||
const border = "5px solid #FBF719"; | ||
const borderLeft = border; | ||
const borderRight = border; | ||
|
||
const getStyle = (id: string, dragOverId?: string, dragSide?: Side) => { | ||
return id === dragOverId ? (dragSide === "left" ? {borderLeft} : {borderRight}) : {}; | ||
}; | ||
|
||
const getIdAndStyle = (collectionId: number, attrTitle: string, dragOverId?: string, dragSide?: Side) | ||
: {id: string, style: React.CSSProperties} => { | ||
const id = `${collectionId}-${attrTitle}`; | ||
const style = getStyle(id, dragOverId, dragSide); | ||
return { id, style }; | ||
}; | ||
|
||
interface DraggagleTableHeaderProps { | ||
collectionId: number; | ||
attrTitle: string; | ||
colSpan?: number; | ||
} | ||
|
||
export const DraggagleTableHeader: React.FC<DraggagleTableHeaderProps> = ({collectionId, attrTitle, children}) => { | ||
const {dragOverId, dragSide, handleDragStart, handleDragOver, handleOnDrop, handleDragEnter, | ||
handleDragLeave} = useDraggableTableContext(); | ||
const {id, style} = getIdAndStyle(collectionId, attrTitle, dragOverId, dragSide); | ||
|
||
return ( | ||
<th | ||
data-id={id} | ||
style={style} | ||
draggable={true} | ||
className={css.draggable} | ||
onDragStart={handleDragStart} | ||
onDragOver={handleDragOver} | ||
onDrop={handleOnDrop} | ||
onDragEnter={handleDragEnter} | ||
onDragLeave={handleDragLeave} | ||
> | ||
{children} | ||
</th> | ||
); | ||
}; | ||
|
||
interface DroppableTableHeaderProps { | ||
collectionId: number; | ||
} | ||
|
||
export const DroppableTableHeader: React.FC<DroppableTableHeaderProps> = ({collectionId, children}) => { | ||
const {dragOverId, handleDragOver, handleOnDrop, handleDragEnter, | ||
handleDragLeave} = useDraggableTableContext(); | ||
|
||
const id = `${collectionId}`; | ||
const style = getStyle(id, dragOverId, "left"); | ||
|
||
return ( | ||
<th | ||
data-id={id} | ||
style={style} | ||
onDragOver={handleDragOver} | ||
onDrop={handleOnDrop} | ||
onDragEnter={handleDragEnter} | ||
onDragLeave={handleDragLeave} | ||
> | ||
{children} | ||
</th> | ||
); | ||
}; | ||
|
||
interface DraggagleTableDataProps { | ||
collectionId: number; | ||
attrTitle: string; | ||
style?: React.CSSProperties; | ||
} | ||
|
||
export const DraggagleTableData: React.FC<DraggagleTableDataProps> = ({collectionId, attrTitle, children}) => { | ||
const {dragOverId, dragSide} = useDraggableTableContext(); | ||
const {style} = getIdAndStyle(collectionId, attrTitle, dragOverId, dragSide); | ||
|
||
return ( | ||
<td style={style}> | ||
{children} | ||
</td> | ||
); | ||
}; | ||
|
||
interface DroppableTableDataProps { | ||
collectionId: number; | ||
style?: React.CSSProperties; | ||
} | ||
|
||
export const DroppableTableData: React.FC<DroppableTableDataProps> = ({collectionId, style, children}) => { | ||
const {dragOverId, dragSide} = useDraggableTableContext(); | ||
const dragStyle = getStyle(`${collectionId}`, dragOverId, dragSide); | ||
|
||
return ( | ||
<td style={{...dragStyle, ...style}}> | ||
{children} | ||
</td> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.