Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrade react-dnd and react-dnd-html5-backend to v16 #7106

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { Config } from "jest";
import coverageThresholds from "./coverage-thresholds.json";

const esmOnlyPackages = [
"react-dnd",
"core-dnd",
"@react-dnd",
"dnd-core",
"react-dnd-html5-backend",
];

const isCI = process.env.CI === "true";

const config: Config = {
Expand Down Expand Up @@ -30,6 +38,9 @@ const config: Config = {
"^.+\\.(js|mjs|jsx|ts|tsx)$": "babel-jest",
"^.+\\.svg$": "<rootDir>/svgTransform.mjs",
},
transformIgnorePatterns: [
`<rootDir>/node_modules/(?!(${esmOnlyPackages.join("|")}))`,
],
};

export default config;
61 changes: 34 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@
"polished": "^4.2.2",
"prop-types": "^15.8.1",
"react-day-picker": "~7.4.10",
"react-dnd": "^15.1.2",
"react-dnd-html5-backend": "^15.1.3",
"react-dnd": "^16.0.1",
"react-dnd-html5-backend": "^16.0.1",
"react-is": "^17.0.2",
"react-transition-group": "^4.4.5",
"styled-system": "^5.1.5"
Expand Down
209 changes: 0 additions & 209 deletions src/components/card/card-test.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import React from "react";
import { Meta } from "@storybook/react";
import { DndProvider, useDrag, useDrop } from "react-dnd";
import { HTML5Backend } from "react-dnd-html5-backend";
import { Card, CardRow, CardFooter, CardColumn, CardProps } from ".";

import Link from "../link";
import Heading from "../heading";
import Typography from "../typography";
import Icon from "../icon";
import Box from "../box";

export default {
title: "Card/Test",
includeStories: ["DefaultStory", "CustomHeight"],
component: Card,
parameters: {
docs: {
Expand Down Expand Up @@ -73,211 +69,6 @@ export const DefaultStory = (
};
DefaultStory.storyName = "default";

export const CardComponent = (props: Partial<CardProps>) => {
return (
<Card {...props}>
<CardRow>
<CardColumn align="left">
<Heading title="Stripe - [account name]" divider={false} />
<Typography fontSize="16px" m={0}>
user.name@sage.com
</Typography>
</CardColumn>
<CardColumn align="right">
<Icon type="image" />
</CardColumn>
</CardRow>
<CardRow>
<CardColumn>
<Typography fontSize="16px" m={0} fontWeight="bold">
Stripe Balance
</Typography>
<Heading title="£ 0.00" divider={false} />
<Typography>LAST ENTRY: 15 DAYS AGO</Typography>
</CardColumn>
</CardRow>
<CardFooter>
<CardColumn>
<Link icon="link" href="https://carbon.sage.com/">
View Stripe Dashboard
</Link>
</CardColumn>
</CardFooter>
</Card>
);
};

export const DraggableExample = () => {
const columnNames = {
PRODUCT_ONE: "Product One",
PRODUCT_TWO: "Product Two",
};

const ITEM_TYPE = "Card";
interface MovableItemProps {
"data-element"?: string;
name: string;
changeColumn: (column: string) => void;
}

interface ColumnProps {
"data-element"?: string;
children?: React.ReactNode;
title: string;
}

const MovableItem = ({
"data-element": dataElement,
name,
changeColumn,
}: MovableItemProps) => {
const [{ isDragging }, drag] = useDrag({
type: ITEM_TYPE,
item: { name },
collect: (monitor) => ({
isDragging: monitor.isDragging(),
}),
end: (_, monitor) => {
const dropResult = monitor.getDropResult<{ column: string }>();
if (!dropResult) return;
changeColumn(dropResult.column);
},
});

return (
<Box
ref={drag}
opacity={isDragging ? 0.4 : 1}
width="80%"
height="100px"
margin="16px auto"
display="flex"
justifyContent="center"
alignItems="center"
>
<Card draggable data-element={dataElement}>
<CardRow pt={0}>
<CardColumn align="left">
<Heading title={name} divider={false} />
<Typography>user.name@sage.com</Typography>
</CardColumn>
<CardColumn align="right">
<Icon type="image" />
</CardColumn>
</CardRow>
</Card>
</Box>
);
};

const Column = ({
"data-element": dataElement,
children,
title,
}: ColumnProps) => {
const [{ isOver }, drop] = useDrop({
accept: ITEM_TYPE,
drop: () => ({ column: title }),
collect: (monitor) => ({
isOver: monitor.isOver(),
}),
});

return (
<Box
ref={drop}
backgroundColor={
isOver
? "var(--colorsActionMajor500)"
: "var(--colorsUtilityMajor075)"
}
data-element={dataElement}
height="max-content"
minHeight="100px"
width="260px"
display="flex"
justifyContent="center"
flexWrap="wrap"
m={2}
py={2}
>
<Typography
variant="b"
color={isOver ? "var(--colorsGray000)" : undefined}
>
{title}
</Typography>
{children}
</Box>
);
};

const [cards, setCards] = React.useState([
{ id: 0, name: "Item 1", column: columnNames.PRODUCT_ONE },
{ id: 1, name: "Item 2", column: columnNames.PRODUCT_ONE },
{ id: 2, name: "Item 3", column: columnNames.PRODUCT_TWO },
{ id: 3, name: "Item 4", column: columnNames.PRODUCT_ONE },
]);

const changeItemColumn = (id: number, column: string) => {
setCards((prevState) =>
prevState.map((card) => ({
...card,
column: card.id === id ? column : card.column,
})),
);
};

const returnColumnItems = (column: string) =>
cards
.filter((card) => card.column === column)
.map(({ id, name }) => (
<MovableItem
key={id}
name={name}
changeColumn={(newColumn) => changeItemColumn(id, newColumn)}
data-element={`draggable-card-${id}`}
/>
));

return (
<Box width="700px" height="450px">
<Box display="flex" flexDirection="row" justifyContent="space-around">
<DndProvider backend={HTML5Backend}>
<Column
title={columnNames.PRODUCT_ONE}
data-element="draggable-container-1"
>
{returnColumnItems(columnNames.PRODUCT_ONE)}
</Column>
<Column
title={columnNames.PRODUCT_TWO}
data-element="draggable-container-2"
>
{returnColumnItems(columnNames.PRODUCT_TWO)}
</Column>
</DndProvider>
</Box>
</Box>
);
};

export const CardTextAlignment = ({ ...props }) => {
return (
<Card>
<CardRow>
<CardColumn {...props}>
<Typography fontSize="16px" m={0} fontWeight="bold">
Stripe Balance
</Typography>
<Heading title="£ 0.00" divider={false} />
<Typography>LAST ENTRY: 15 DAYS AGO</Typography>
</CardColumn>
</CardRow>
</Card>
);
};

export const CustomHeight = () => {
return (
<>
Expand Down
Loading