Skip to content

Commit

Permalink
Merge pull request #119 from Kuechlin/v0.0.21
Browse files Browse the repository at this point in the history
V0.0.21
  • Loading branch information
Kuechlin authored Oct 28, 2022
2 parents 1ac4ac1 + 5bc1f68 commit 18b1fcc
Show file tree
Hide file tree
Showing 14 changed files with 1,052 additions and 498 deletions.
28 changes: 25 additions & 3 deletions docs/pages/Demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ import {
import { useState } from 'react';

import {
createBooleanFilter,
createDateFilter,
createNumberFilter,
createStringFilter,
DataGrid,
DataGridFilterFn,
DataGridFiltersState,
DataGridPaginationState,
DataGridSortingState,
createBooleanFilter,
highlightFilterValue,
createNumberFilter,
createStringFilter,
StringFilterOperator,
} from '../../src';
import { Data, demoData } from '../demoData';
Expand Down Expand Up @@ -102,6 +102,8 @@ export default function Demo() {
noFlexLayout: false,
withColumnResizing: true,
striped: true,
withBorder: false,
withColumnBorders: false,
highlightOnHover: true,
loading: false,
showEmpty: false,
Expand Down Expand Up @@ -150,6 +152,8 @@ export default function Demo() {
withColumnResizing={state.withColumnResizing}
noFlexLayout={state.noFlexLayout}
striped={state.striped}
withBorder={state.withBorder}
withColumnBorders={state.withColumnBorders}
highlightOnHover={state.highlightOnHover}
loading={state.loading}
iconColor={state.iconColor}
Expand Down Expand Up @@ -325,6 +329,24 @@ export default function Demo() {
})
}
/>
<Switch
label="With Border"
checked={state.withBorder}
onChange={(e) =>
update({
withBorder: e.target.checked,
})
}
/>
<Switch
label="With Column Borders"
checked={state.withColumnBorders}
onChange={(e) =>
update({
withColumnBorders: e.target.checked,
})
}
/>
<Switch
label="Highlight on hover"
checked={state.highlightOnHover}
Expand Down
118 changes: 118 additions & 0 deletions docs/pages/examples/ColumnDragDropExample.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import { ActionIcon, Box, Button, Card, Group } from '@mantine/core';
import { ColumnOrderState, TableOptions } from '@tanstack/react-table';
import { useState } from 'react';

import {
closestCenter,
DndContext,
DragOverlay,
KeyboardSensor,
MouseSensor,
TouchSensor,
UniqueIdentifier,
useSensor,
useSensors,
} from '@dnd-kit/core';
import { restrictToHorizontalAxis } from '@dnd-kit/modifiers';
import { arrayMove, horizontalListSortingStrategy, SortableContext, useSortable } from '@dnd-kit/sortable';
import { CSS } from '@dnd-kit/utilities';
import { GridDots } from 'tabler-icons-react';
import { DataGrid, DataGridHeaderCellProps } from '../../../src';
import { Data, demoData } from '../../demoData';

export default function ColumnDragDropExample() {
const columns: TableOptions<Data>['columns'] = [
{ id: 'cat', accessorFn: (row) => row.cat },
{ id: 'fish', accessorFn: (row) => row.fish },
{ id: 'city', accessorFn: (row) => row.city },
{ id: 'value', accessorFn: (row) => row.value },
];
const [columnOrder, setColumnOrder] = useState<ColumnOrderState>(
columns.map((column) => column.id as string) //must start out with populated columnOrder so we can splice
);

const resetOrder = () => setColumnOrder(columns.map((column) => column.id as string));
const [activeId, setActiveId] = useState<UniqueIdentifier | null>(null);
const sensors = useSensors(useSensor(MouseSensor, {}), useSensor(TouchSensor, {}), useSensor(KeyboardSensor, {}));
console.log(columnOrder);

return (
<>
<Button onClick={resetOrder}>Reset column order</Button>
<DndContext
sensors={sensors}
onDragEnd={(event) => {
const { active, over } = event;
if (over && active.id !== over.id) {
setColumnOrder((data) => {
const oldIndex = columnOrder.indexOf(String(active.id));
const newIndex = columnOrder.indexOf(String(over.id));
return arrayMove(data, oldIndex, newIndex);
});
}

setActiveId(null);
}}
onDragStart={(e) => setActiveId(String(e.active.id))}
onDragCancel={() => setActiveId(null)}
collisionDetection={closestCenter}
modifiers={[restrictToHorizontalAxis]}
>
<DragOverlay>
<Card p="xs">
<Group position="apart">
{activeId}
<ActionIcon ml="auto">
<GridDots />
</ActionIcon>
</Group>
</Card>
</DragOverlay>
<DataGrid
data={demoData}
columns={columns}
withPagination
state={{ columnOrder }}
components={{
headerWrapper: ({ children, ...props }) => (
<thead {...props}>
<SortableContext items={columnOrder} strategy={horizontalListSortingStrategy}>
{children}
</SortableContext>
</thead>
),
headerCell: ({ children, header, ...props }) => (
<DraggableColumnHeader {...props} header={header}>
{children}
</DraggableColumnHeader>
),
}}
/>
</DndContext>
</>
);
}
const DraggableColumnHeader = ({ children, header, ...props }: DataGridHeaderCellProps<Data>) => {
const { attributes, listeners, transform, transition, setNodeRef } = useSortable({
id: header.column.id,
});

return (
<th
{...props}
ref={setNodeRef}
style={{
...props?.style,
transform: CSS.Transform.toString(transform),
transition: transition,
}}
>
<Box sx={{ display: 'flex' }}>
{children}
<ActionIcon ml="auto">
<GridDots {...attributes} {...listeners} />
</ActionIcon>
</Box>
</th>
);
};
72 changes: 72 additions & 0 deletions docs/pages/examples/CustomPaginationExample.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { Center, Pagination } from '@mantine/core';
import {
booleanFilterFn,
DataGrid,
dateFilterFn,
highlightFilterValue,
numberFilterFn,
stringFilterFn,
} from '../../../src';
import { demoData } from '../../demoData';

export default function CustomPaginationExample() {
return (
<DataGrid
data={demoData}
striped
highlightOnHover
withGlobalFilter
withPagination
withColumnFilters
withSorting
withColumnResizing
components={{
pagination: ({ table }) => (
<Center>
<Pagination
size="xl"
page={table.getState().pagination.pageIndex + 1}
total={table.getPageCount()}
onChange={(pageNum) => table.setPageIndex(Number(pageNum) - 1)}
siblings={1}
color="red"
/>
</Center>
),
}}
columns={[
{
accessorKey: 'text',
header: 'Text that is too long for a Header',
filterFn: stringFilterFn,
size: 300,
cell: highlightFilterValue,
},
{
header: 'Animal',
columns: [
{ accessorKey: 'cat', filterFn: stringFilterFn },
{
accessorKey: 'fish',
filterFn: stringFilterFn,
},
],
},
{
accessorKey: 'city',
filterFn: stringFilterFn,
},
{ accessorKey: 'value', filterFn: numberFilterFn },
{
accessorKey: 'date',
cell: (cell) => cell.getValue<Date>()?.toLocaleDateString(),
filterFn: dateFilterFn,
},
{
accessorKey: 'bool',
filterFn: booleanFilterFn,
},
]}
/>
);
}
20 changes: 20 additions & 0 deletions docs/pages/examples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ import ExternalFilterExample from './ExternalFilterExample';
// @ts-ignore
import ExternalFilterExampleCode from './ExternalFilterExample.tsx?raw';

import ColumnDragDropExample from './ColumnDragDropExample';
// @ts-ignore
import ColumnDragDropExampleCode from './ColumnDragDropExample.tsx?raw';

import CustomPaginationExample from './CustomPaginationExample';
// @ts-ignore
import CustomPaginationExampleCode from './CustomPaginationExample.tsx?raw';

export type Example = {
label: string;
path: string;
Expand Down Expand Up @@ -138,4 +146,16 @@ export const examples = {
element: ExternalFilterExample,
code: ExternalFilterExampleCode,
}),
columnDragDrop: ex({
label: 'Column Drag&Drop',
path: '/example/column-drag-drop',
element: ColumnDragDropExample,
code: ColumnDragDropExampleCode,
}),
customPagination: ex({
label: 'Custom Pagination',
path: '/example/pagination',
element: CustomPaginationExample,
code: CustomPaginationExampleCode,
}),
};
48 changes: 27 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mantine-data-grid",
"version": "0.0.20",
"version": "0.0.21",
"homepage": "https://kuechlin.github.io/mantine-data-grid/",
"repository": {
"type": "git",
Expand Down Expand Up @@ -31,43 +31,49 @@
"prepare": "husky install"
},
"dependencies": {
"@emotion/react": "^11.10.4",
"@mantine/core": "^5.4.0",
"@mantine/dates": "^5.4.0",
"@mantine/hooks": "^5.4.0",
"@tanstack/react-table": "^8.5.13",
"dayjs": "^1.11.5",
"@emotion/react": "11.10.5",
"@mantine/core": "5.6.3",
"@mantine/dates": "5.6.3",
"@mantine/hooks": "5.6.3",
"@tanstack/react-table": "8.5.18",
"@types/react-window": "^1.8.5",
"dayjs": "1.11.6",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"tabler-icons-react": "^1.55.0"
},
"devDependencies": {
"@commitlint/cli": "^17.1.2",
"@commitlint/config-conventional": "^17.1.0",
"@faker-js/faker": "^7.5.0",
"@mantine/prism": "^5.4.0",
"@types/node": "^18.7.18",
"@types/react": "^18.0.20",
"@types/react-dom": "^18.0.6",
"@typescript-eslint/eslint-plugin": "^5.38.0",
"@typescript-eslint/parser": "^5.38.0",
"@vitejs/plugin-react": "^2.1.0",
"eslint": "^8.23.1",
"@dnd-kit/core": "^6.0.5",
"@dnd-kit/modifiers": "^6.0.0",
"@dnd-kit/sortable": "^7.0.1",
"@dnd-kit/utilities": "^3.2.0",
"@faker-js/faker": "7.6.0",
"@mantine/prism": "5.6.3",
"@types/node": "18.11.7",
"@types/react": "18.0.24",
"@types/react-dom": "18.0.8",
"@typescript-eslint/eslint-plugin": "5.41.0",
"@typescript-eslint/parser": "5.41.0",
"@vitejs/plugin-react": "2.2.0",
"eslint": "8.26.0",
"eslint-config-prettier": "^8.5.0",
"eslint-import-resolver-typescript": "^3.5.1",
"eslint-import-resolver-typescript": "3.5.2",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react-hooks": "^4.6.0",
"husky": "^8.0.1",
"lint-staged": "^13.0.3",
"prettier": "^2.7.1",
"react-markdown": "^8.0.3",
"react-router-dom": "^6.4.0",
"react-router-dom": "6.4.2",
"react-window": "^1.8.7",
"remark-gfm": "^3.0.1",
"rollup": "^2.79.0",
"rollup-plugin-visualizer": "^5.8.1",
"typescript": "^4.8.3",
"vite": "^3.1.3"
"rollup-plugin-visualizer": "5.8.3",
"typescript": "4.8.4",
"vite": "3.2.1"
},
"peerDependencies": {
"@mantine/core": "^5.0.0",
Expand Down
Loading

0 comments on commit 18b1fcc

Please sign in to comment.