Skip to content

Commit

Permalink
Merge pull request #623 from icflorescu/next
Browse files Browse the repository at this point in the history
Implement DnD support, update deps, changelog, bump version
  • Loading branch information
icflorescu authored Jul 30, 2024
2 parents b8e58cb + 3ad2a3b commit 6652b94
Show file tree
Hide file tree
Showing 22 changed files with 9,900 additions and 713 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
node-version: '22'
cache: yarn
- name: Restore cache
uses: actions/cache@v4
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
The following is a list of notable changes to the Mantine DataTable component.
Minor versions that are not listed in the changelog are bug fixes and small improvements.

## 7.11.3 (2024-07-30)

- Update dev dependencies
- Implement drag and drop support (see [#616](https://github.com/icflorescu/mantine-datatable/pull/616))

## 7.11.2 (2024-07-10)

- Update dev dependencies
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ The [lightweight](https://bundlephobia.com/package/mantine-datatable), dependenc
- **[Automatically-scrollable](https://icflorescu.github.io/mantine-datatable/examples/scrollable-vs-auto-height)** - automatically scrollable or auto-height
- **[AutoAnimate support](https://icflorescu.github.io/mantine-datatable/examples/using-with-auto-animate)** - animate row sorting, addition and removal
- **[Column reordering, toggling](https://icflorescu.github.io/mantine-datatable/examples/column-dragging-and-toggling)** and **[resizing](https://icflorescu.github.io/mantine-datatable/examples/column-resizing)** - thanks to the outstanding work of [Giovambattista Fazioli](https://github.com/gfazioli)
- **[Drag-and-drop support](https://icflorescu.github.io/mantine-datatable/examples/row-dragging)** - implemented using [@hello-pangea/dnd](https://github.com/hello-pangea/dnd) thanks to the outstanding work of [Mohd Ahmad](https://github.com/MohdAhmad1)
- **More** - check out the [full documentation](https://icflorescu.github.io/mantine-datatable/)

## Trusted by the community
Expand Down
3 changes: 2 additions & 1 deletion app/(home)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export default function HomePage() {
<InternalLink to="/examples/column-properties-and-styling">cell data rendering</InternalLink>,{' '}
<InternalLink to="/examples/using-with-mantine-contextmenu">context menus</InternalLink>,{' '}
<InternalLink to="/examples/expanding-rows">row expansion</InternalLink>,{' '}
<InternalLink to="/examples/nested-tables">nesting</InternalLink> and{' '}
<InternalLink to="/examples/nested-tables">nesting</InternalLink>,{' '}
<InternalLink to="/examples/row-dragging">drag-and-drop reordering support</InternalLink> and{' '}
<InternalLink to="/examples/complex-usage-scenario">more</InternalLink>
</Feature>
<Feature icon={IconLifebuoy} title="Typescript based">
Expand Down
5 changes: 5 additions & 0 deletions app/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ export const ROUTES: RouteInfo[] = [
title: 'Column dragging and toggling',
description: `Example: dragging & toggling ${PRODUCT_NAME} columns`,
},
{
href: '/examples/row-dragging',
title: 'Row dragging',
description: `Example: dragging ${PRODUCT_NAME} rows`,
},
{
href: '/examples/column-resizing',
title: 'Column resizing',
Expand Down
84 changes: 84 additions & 0 deletions app/examples/row-dragging/RowDraggingExample.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
'use client';

import { DragDropContext, Draggable, type DropResult, Droppable } from '@hello-pangea/dnd';
import { TableTd } from '@mantine/core';
import { notifications } from '@mantine/notifications';
import { IconGripVertical } from '@tabler/icons-react';
import { DataTable, DataTableColumn, DataTableDraggableRow } from '__PACKAGE__';
import { useState } from 'react';
import companies from '~/data/companies.json';

interface RecordData {
id: string;
name: string;
streetAddress: string;
city: string;
state: string;
missionStatement: string;
}

export function RowDraggingExample() {
const [records, setRecords] = useState<RecordData[]>(companies);

const handleDragEnd = (result: DropResult) => {
if (!result.destination) return;

const items = Array.from(records);
const sourceIndex = result.source.index;
const destinationIndex = result.destination.index;
const [reorderedItem] = items.splice(sourceIndex, 1);
items.splice(destinationIndex, 0, reorderedItem);

setRecords(items);
notifications.show({
title: 'Table reordered',
message: `The company named "${items[sourceIndex].name}" has been moved from position ${sourceIndex + 1} to ${destinationIndex + 1}.`,
color: 'blue',
});
};

const columns: DataTableColumn<RecordData>[] = [
// add empty header column for the drag handle
{ accessor: '', hiddenContent: true, width: 30 },
{ accessor: 'name', width: 150 },
{ accessor: 'streetAddress', width: 150 },
{ accessor: 'city', width: 150 },
{ accessor: 'state', width: 150 },
];

return (
<DragDropContext onDragEnd={handleDragEnd}>
<DataTable<RecordData>
columns={columns}
records={records}
height={400}
withTableBorder
withColumnBorders
tableWrapper={({ children }) => (
<Droppable droppableId="datatable">
{(provided) => (
<div {...provided.droppableProps} ref={provided.innerRef}>
{children}
{provided.placeholder}
</div>
)}
</Droppable>
)}
styles={{ table: { tableLayout: 'fixed' } }}
rowFactory={({ record, index, rowProps, children }) => (
<Draggable key={record.id} draggableId={record.id} index={index}>
{(provided, snapshot) => (
<DataTableDraggableRow isDragging={snapshot.isDragging} {...rowProps} {...provided.draggableProps}>
{/** custom drag handle */}
<TableTd {...provided.dragHandleProps} ref={provided.innerRef}>
<IconGripVertical size={16} />
</TableTd>
{children}
</DataTableDraggableRow>
)}
</Draggable>
)}
/>
</DragDropContext>
);
}
40 changes: 40 additions & 0 deletions app/examples/row-dragging/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Code } from '@mantine/core';
import type { Route } from 'next';
import { PRODUCT_NAME, REPO_LINK } from '~/app/config';
import { CodeBlock } from '~/components/CodeBlock';
import { ExternalLink } from '~/components/ExternalLink';
import { PageNavigation } from '~/components/PageNavigation';
import { PageTitle } from '~/components/PageTitle';
import { Txt } from '~/components/Txt';
import { readCodeFile } from '~/lib/code';
import { allPromiseProps, getRouteMetadata } from '~/lib/utils';
import { RowDraggingExample } from './RowDraggingExample';

const PATH: Route = '/examples/row-dragging';

export const metadata = getRouteMetadata(PATH);

export default async function BasicUsageExamplePage() {
const code = await allPromiseProps({
'RowDraggingExample.tsx': readCodeFile<string>(`${PATH}/RowDraggingExample.tsx`),
'companies.json': readCodeFile<string>('/../data/companies.json'),
});

return (
<>
<PageTitle of={PATH} />
<Txt>
Starting with <Code>v7.11.3</Code>, {PRODUCT_NAME} also supports row dragging (implemented with{' '}
<ExternalLink to="https://github.com/hello-pangea/dnd">@hello-pangea/dnd library</ExternalLink> in{' '}
<ExternalLink to={`${REPO_LINK}/pull/616`}>this PR</ExternalLink>).
<br />
Here is how you would implement it in your project:
</Txt>
<CodeBlock tabs={{ code, keys: ['RowDraggingExample.tsx', 'companies.json'] }} />
<Txt>The code above will produce the following result:</Txt>
<RowDraggingExample />

<PageNavigation of={PATH} />
</>
);
}
24 changes: 24 additions & 0 deletions data/companies.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,29 @@
"city": "West Gerry",
"state": "KS",
"missionStatement": "Synthesize customized portals."
},
{
"id": "a9c0b7f0-3a1b-4b0c-8f3d-6a6a7b7b7b7q2",
"name": "Kling - McLaughlin",
"streetAddress": "8346 Kertzmann Square",
"city": "South Joesph",
"state": "ID",
"missionStatement": "Reinvent cross-platform channels."
},
{
"id": "a9c0b7f0-3a1b-4b0c-8f3d-6a6a7b7b7b72b",
"name": "Jogi - McLaughlin",
"streetAddress": "83462 Shazam Street",
"city": "North Joesph",
"state": "ID",
"missionStatement": "Eliminate best-of-breed e-markets."
},
{
"id": "a9c0b7f0-3a1b-4b0c-8f3d-6a6af7b7b7b7b",
"name": "Jogi - McLaughlin",
"streetAddress": "83462 Shazam Street",
"city": "North Joesph",
"state": "ID",
"missionStatement": "Eliminate best-of-breed e-markets."
}
]
51 changes: 26 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mantine-datatable",
"version": "7.11.2",
"version": "7.11.3",
"description": "The lightweight, dependency-free, dark-theme aware table component for your Mantine UI data-rich applications, featuring asynchronous data loading support, pagination, intuitive Gmail-style additive batch rows selection, column sorting, custom cell data rendering, row expansion, nesting, context menus, and much more",
"keywords": [
"mantine",
Expand Down Expand Up @@ -71,46 +71,47 @@
"format": "prettier --write ."
},
"devDependencies": {
"@docsearch/react": "^3.6.0",
"@ducanh2912/next-pwa": "^10.2.7",
"@docsearch/react": "^3.6.1",
"@ducanh2912/next-pwa": "^10.2.8",
"@faker-js/faker": "^8.4.1",
"@formkit/auto-animate": "^0.8.2",
"@mantine/code-highlight": "^7.11.1",
"@mantine/core": "^7.11.1",
"@mantine/dates": "^7.11.1",
"@mantine/hooks": "^7.11.1",
"@mantine/modals": "^7.11.1",
"@mantine/notifications": "^7.11.1",
"@tabler/icons-react": "^3.10.0",
"@tanstack/react-query": "^5.50.1",
"@types/lodash": "^4.17.6",
"@types/node": "^20.14.10",
"@hello-pangea/dnd": "^16.6.0",
"@mantine/code-highlight": "^7.11.2",
"@mantine/core": "^7.11.2",
"@mantine/dates": "^7.11.2",
"@mantine/hooks": "^7.11.2",
"@mantine/modals": "^7.11.2",
"@mantine/notifications": "^7.11.2",
"@tabler/icons-react": "^3.11.0",
"@tanstack/react-query": "^5.51.15",
"@types/lodash": "^4.17.7",
"@types/node": "^22.0.0",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@typescript-eslint/eslint-plugin": "^7.16.0",
"@typescript-eslint/parser": "^7.16.0",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"clsx": "^2.1.1",
"cssnano": "^7.0.4",
"dayjs": "^1.11.11",
"dayjs": "^1.11.12",
"eslint": "^8",
"eslint-config-next": "^14.2.4",
"eslint-config-next": "^14.2.5",
"eslint-config-prettier": "^9.1.0",
"lodash": "^4.17.21",
"mantine-contextmenu": "^7.11.2",
"next": "^14.2.4",
"postcss": "^8.4.39",
"mantine-contextmenu": "^7.11.3",
"next": "^14.2.5",
"postcss": "^8.4.40",
"postcss-cli": "^11.0.0",
"postcss-import": "^16.1.0",
"postcss-preset-mantine": "^1.15.0",
"postcss-preset-mantine": "^1.17.0",
"postcss-simple-vars": "^7.0.1",
"prettier": "^3.3.2",
"prettier": "^3.3.3",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"sharp": "^0.33.4",
"swr": "^2.2.5",
"tsup": "^8.1.0",
"typescript": "^5.5.3",
"webpack": "^5.92.1"
"tsup": "^8.2.3",
"typescript": "^5.5.4",
"webpack": "^5.93.0"
},
"peerDependencies": {
"@mantine/core": ">=7.8",
Expand Down
Loading

0 comments on commit 6652b94

Please sign in to comment.