2019-10-28 16:16:49 +00:00
|
|
|
import makeStyles from "@material-ui/core/styles/makeStyles";
|
2019-08-09 10:17:04 +00:00
|
|
|
import TableBody, { TableBodyProps } from "@material-ui/core/TableBody";
|
|
|
|
import React from "react";
|
|
|
|
import { SortableContainer } from "react-sortable-hoc";
|
|
|
|
|
|
|
|
import { ReorderAction } from "@saleor/types";
|
|
|
|
|
|
|
|
const InnerSortableTableBody = SortableContainer<TableBodyProps>(
|
|
|
|
({ children, ...props }) => <TableBody {...props}>{children}</TableBody>
|
|
|
|
);
|
|
|
|
|
|
|
|
export interface SortableTableBodyProps {
|
|
|
|
onSortEnd: ReorderAction;
|
|
|
|
}
|
|
|
|
|
2019-12-03 15:28:40 +00:00
|
|
|
const useStyles = makeStyles(
|
|
|
|
theme => ({
|
|
|
|
ghost: {
|
|
|
|
"& td": {
|
|
|
|
borderBottom: "none"
|
|
|
|
},
|
|
|
|
background: theme.palette.background.paper,
|
|
|
|
fontFamily: theme.typography.fontFamily,
|
|
|
|
// FIXME: you damn know what
|
|
|
|
// fontSize: theme.overrides.MuiTableCell.root.fontSize,
|
|
|
|
opacity: 0.5
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
{ name: "SortableTableBody" }
|
|
|
|
);
|
2019-08-09 10:17:04 +00:00
|
|
|
|
|
|
|
const SortableTableBody: React.FC<
|
2019-10-30 14:34:24 +00:00
|
|
|
Omit<TableBodyProps & SortableTableBodyProps, "ref">
|
2019-08-09 10:17:04 +00:00
|
|
|
> = props => {
|
|
|
|
const classes = useStyles({});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<InnerSortableTableBody
|
|
|
|
helperClass={classes.ghost}
|
|
|
|
axis="y"
|
|
|
|
lockAxis="y"
|
|
|
|
useDragHandle
|
|
|
|
{...props}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default SortableTableBody;
|