diff --git a/src/Plate/ColumnLabel.tsx b/src/Plate/ColumnLabel.tsx new file mode 100644 index 0000000..4d0092f --- /dev/null +++ b/src/Plate/ColumnLabel.tsx @@ -0,0 +1,15 @@ +import React from 'react'; + +export function ColumnLabel({ column }: { column: number }) { + return ( + + {column} + + ); +} diff --git a/src/Plate/EmptyWell.tsx b/src/Plate/EmptyWell.tsx index f6e5b87..9a674d7 100644 --- a/src/Plate/EmptyWell.tsx +++ b/src/Plate/EmptyWell.tsx @@ -8,23 +8,18 @@ import { CoordinateSystem } from './types'; import { columnForPosition, rowForPosition } from './utils'; import { GENERAL_WELL_STYLE } from './wellUtils'; -export function EmptyWell(props: { - position: number; +export function EmptyWell({ + coordinateSystem, + position, +}: { coordinateSystem: TCoordinateSystem; + position: number; }) { - const row = rowForPosition( - props.position, - PLATE_FLOW, - props.coordinateSystem, - ); - const column = columnForPosition( - props.position, - PLATE_FLOW, - props.coordinateSystem, - ); + const row = rowForPosition(position, PLATE_FLOW, coordinateSystem); + const column = columnForPosition(position, PLATE_FLOW, coordinateSystem); const { setNodeRef, isOver } = useDroppable({ - id: props.position, + id: position, data: { coordinates: { row, diff --git a/src/Plate/FilledWell.tsx b/src/Plate/FilledWell.tsx index 527eb59..7546274 100644 --- a/src/Plate/FilledWell.tsx +++ b/src/Plate/FilledWell.tsx @@ -9,27 +9,28 @@ import { CoordinateSystem, PlateWell } from './types'; import { columnForPosition, rowForPosition } from './utils'; import { GENERAL_WELL_STYLE } from './wellUtils'; -export function FilledWell(props: { - well: PlateWell; +export function FilledWell({ + coordinateSystem, + isDraggable, + position, + well, +}: { coordinateSystem: TCoordinateSystem; - position: number; isDraggable: boolean; + position: number; + well: PlateWell; }) { const data = { coordinates: { - row: rowForPosition(props.position, PLATE_FLOW, props.coordinateSystem), - column: columnForPosition( - props.position, - PLATE_FLOW, - props.coordinateSystem, - ), + row: rowForPosition(position, PLATE_FLOW, coordinateSystem), + column: columnForPosition(position, PLATE_FLOW, coordinateSystem), }, }; const { attributes, listeners, setNodeRef, transform } = useDraggable({ - id: props.position, + id: position, data, - disabled: !props.isDraggable, + disabled: !isDraggable, }); return ( @@ -40,10 +41,10 @@ export function FilledWell(props: { style={{ ...GENERAL_WELL_STYLE, transform: CSS.Translate.toString(transform), - backgroundColor: props.well.color ?? PALETTE.gray3, + backgroundColor: well.color ?? PALETTE.gray3, }} > - {props.well.content} + {well.content} ); } diff --git a/src/Plate/RowLabel.tsx b/src/Plate/RowLabel.tsx index 9d9e0c1..d4c4bc4 100644 --- a/src/Plate/RowLabel.tsx +++ b/src/Plate/RowLabel.tsx @@ -1,13 +1,6 @@ import React from 'react'; -import { PLATE_FLOW } from './constants'; -import { CoordinateSystem } from './types'; -import { rowForPosition } from './utils'; - -export function RowLabel(props: { - position: number; - coordinateSystem: CoordinateSystem; -}) { +export function RowLabel({ row }: { row: string }) { return ( - - {rowForPosition(props.position, PLATE_FLOW, props.coordinateSystem)} - + {row} ); } diff --git a/src/Plate/Well.tsx b/src/Plate/Well.tsx index c8d0bfc..b982759 100644 --- a/src/Plate/Well.tsx +++ b/src/Plate/Well.tsx @@ -5,23 +5,25 @@ import { EmptyWell } from './EmptyWell'; import { FilledWell } from './FilledWell'; import { CoordinateSystem, PlateWell } from './types'; -export function Well(props: { - position: number; - well: Maybe>; +export function Well({ + coordinateSystem, + isDraggable, + position, + well, +}: { coordinateSystem: TCoordinateSystem; isDraggable: boolean; + position: number; + well: Maybe>; }) { - return props.well?.content ? ( + return well?.content ? ( ) : ( - + ); } diff --git a/src/Plate/index.tsx b/src/Plate/index.tsx index 8054a8c..0108d84 100644 --- a/src/Plate/index.tsx +++ b/src/Plate/index.tsx @@ -4,6 +4,7 @@ import React, { Fragment } from 'react'; import { MllSpinnerIcon } from '../Spinner'; +import { ColumnLabel } from './ColumnLabel'; import { RowLabel } from './RowLabel'; import { Well } from './Well'; import { PLATE_FLOW } from './constants'; @@ -12,6 +13,7 @@ import { allCoordinateSystemPositions, assertUniquePositions, columnForPosition, + rowForPosition, wellAtPosition, } from './utils'; @@ -22,17 +24,21 @@ export * from './types'; export * from './utils'; export { GENERAL_WELL_STYLE } from './wellUtils'; -export function Plate( - props: PlateProps, -) { - if (props.data) { - assertUniquePositions(props.data); +export function Plate({ + coordinateSystem, + data, + dndContextProps, + isDraggable, + loading, +}: PlateProps) { + if (data) { + assertUniquePositions(data); } return ( - + (
+ {/* takes up the space in the upper left corner between A and 1 */} - {props.coordinateSystem.columns.map((column) => ( - - {column} - + {coordinateSystem.columns.map((column) => ( + ))} - {allCoordinateSystemPositions(props.coordinateSystem).map( - (position) => ( - - {columnForPosition( - position, - PLATE_FLOW, - props.coordinateSystem, - ) === 1 && ( - - )} - - ( + + {columnForPosition(position, PLATE_FLOW, coordinateSystem) === + 1 && ( + - - ), - )} + )} + + + + ))}