@espresso-lab/mantine-data-table 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -50
- package/dist/DataTable/CreateModal.d.ts +11 -0
- package/dist/DataTable/DataTable.d.ts +54 -0
- package/dist/DataTable/DeleteModal.d.ts +9 -0
- package/dist/DataTable/UpdateModal.d.ts +12 -0
- package/dist/Hooks/useApi.d.ts +16 -0
- package/dist/Hooks/usePersitentState.d.ts +1 -0
- package/dist/index.d.ts +3 -0
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -1,54 +1,14 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Mantine Data Table 🚀
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
This is a simple wrapper for the [Mantine Datatable](https://icflorescu.github.io/mantine-datatable/) library to work
|
|
4
|
+
with a single configuration object.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
[](#license)
|
|
7
|
+
[](https://www.npmjs.com/package/@espresso-lab/mantine-data-table)
|
|
8
|
+
[](https://www.npmjs.com/package/@espresso-lab/mantine-data-table)
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
|
10
|
+
## Installation
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
```js
|
|
15
|
-
export default tseslint.config({
|
|
16
|
-
extends: [
|
|
17
|
-
// Remove ...tseslint.configs.recommended and replace with this
|
|
18
|
-
...tseslint.configs.recommendedTypeChecked,
|
|
19
|
-
// Alternatively, use this for stricter rules
|
|
20
|
-
...tseslint.configs.strictTypeChecked,
|
|
21
|
-
// Optionally, add this for stylistic rules
|
|
22
|
-
...tseslint.configs.stylisticTypeChecked,
|
|
23
|
-
],
|
|
24
|
-
languageOptions: {
|
|
25
|
-
// other options...
|
|
26
|
-
parserOptions: {
|
|
27
|
-
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
28
|
-
tsconfigRootDir: import.meta.dirname,
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
})
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
|
|
35
|
-
|
|
36
|
-
```js
|
|
37
|
-
// eslint.config.js
|
|
38
|
-
import reactX from 'eslint-plugin-react-x'
|
|
39
|
-
import reactDom from 'eslint-plugin-react-dom'
|
|
40
|
-
|
|
41
|
-
export default tseslint.config({
|
|
42
|
-
plugins: {
|
|
43
|
-
// Add the react-x and react-dom plugins
|
|
44
|
-
'react-x': reactX,
|
|
45
|
-
'react-dom': reactDom,
|
|
46
|
-
},
|
|
47
|
-
rules: {
|
|
48
|
-
// other rules...
|
|
49
|
-
// Enable its recommended typescript rules
|
|
50
|
-
...reactX.configs['recommended-typescript'].rules,
|
|
51
|
-
...reactDom.configs.recommended.rules,
|
|
52
|
-
},
|
|
53
|
-
})
|
|
54
|
-
```
|
|
12
|
+
```bash
|
|
13
|
+
npm i @espresso-lab/mantine-data-table
|
|
14
|
+
```
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseEntity } from '../Hooks/useApi';
|
|
2
|
+
import { Field, StepConfig } from './DataTable.tsx';
|
|
3
|
+
export interface CreateModalProps<T> {
|
|
4
|
+
fields: Field<T>[];
|
|
5
|
+
onClose: () => void;
|
|
6
|
+
queryKey: (string | number)[];
|
|
7
|
+
apiPath: string;
|
|
8
|
+
steps?: StepConfig[];
|
|
9
|
+
onCreated?: (id: string | number) => void;
|
|
10
|
+
}
|
|
11
|
+
export declare function CreateModal<T extends BaseEntity>({ fields, onClose, queryKey, apiPath, steps, onCreated, }: CreateModalProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { BaseEntity, Headers } from '../Hooks/useApi';
|
|
2
|
+
import { default as React } from 'react';
|
|
3
|
+
import { DataTableColumn } from 'mantine-datatable';
|
|
4
|
+
import { DatesRangeValue } from '@mantine/dates';
|
|
5
|
+
interface Filter {
|
|
6
|
+
id: string | number;
|
|
7
|
+
type: "query" | "date";
|
|
8
|
+
value?: string | DatesRangeValue;
|
|
9
|
+
}
|
|
10
|
+
export type FieldType = "text" | "number" | "boolean" | "custom" | "date";
|
|
11
|
+
export interface Field<T> {
|
|
12
|
+
id: string;
|
|
13
|
+
defaultValue?: T[keyof T];
|
|
14
|
+
required?: boolean;
|
|
15
|
+
step?: number;
|
|
16
|
+
list: boolean;
|
|
17
|
+
create: boolean;
|
|
18
|
+
update: boolean;
|
|
19
|
+
delete: boolean;
|
|
20
|
+
type?: FieldType;
|
|
21
|
+
placeholder?: string;
|
|
22
|
+
render?: (values: T, onChange: (value: T) => void, hideButtons: (value: boolean) => void, setValues: (values: T) => void) => React.ReactNode;
|
|
23
|
+
column: DataTableColumn<T>;
|
|
24
|
+
}
|
|
25
|
+
interface Action<T extends BaseEntity> {
|
|
26
|
+
icon?: React.ReactNode;
|
|
27
|
+
label: string;
|
|
28
|
+
onClick: (records: T[]) => void;
|
|
29
|
+
}
|
|
30
|
+
export interface StepConfig {
|
|
31
|
+
label: string;
|
|
32
|
+
description?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface DataTableProps<T extends BaseEntity> {
|
|
35
|
+
title?: string | React.ReactNode;
|
|
36
|
+
queryKey: (string | number)[];
|
|
37
|
+
connectedQueryKeys?: (string | number)[][];
|
|
38
|
+
apiPath: string;
|
|
39
|
+
apiHeaders?: Headers;
|
|
40
|
+
filters?: Filter[];
|
|
41
|
+
buttons?: React.ReactNode[];
|
|
42
|
+
createButtonText?: string;
|
|
43
|
+
actions?: Action<T>[];
|
|
44
|
+
selection?: boolean;
|
|
45
|
+
pagination?: boolean;
|
|
46
|
+
steps?: StepConfig[];
|
|
47
|
+
fields: Field<T>[];
|
|
48
|
+
defaultSort?: {
|
|
49
|
+
field: string;
|
|
50
|
+
direction: "asc" | "desc";
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export declare function DataTable<T extends BaseEntity>({ title, queryKey, connectedQueryKeys, apiPath, buttons, fields, selection, pagination, filters, actions, steps, defaultSort, createButtonText, }: DataTableProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
54
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BaseEntity } from '../Hooks/useApi';
|
|
2
|
+
interface DeleteModalProps<T> {
|
|
3
|
+
onClose: () => void;
|
|
4
|
+
queryKey: (string | number)[];
|
|
5
|
+
apiPath: string;
|
|
6
|
+
selectedRecords: T[];
|
|
7
|
+
}
|
|
8
|
+
export declare function DeleteModal<T extends BaseEntity>({ queryKey, apiPath, onClose, selectedRecords, }: DeleteModalProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseEntity } from '../Hooks/useApi';
|
|
2
|
+
import { Field, StepConfig } from './DataTable.tsx';
|
|
3
|
+
interface UpdateModalProps<T> {
|
|
4
|
+
fields: Field<T>[];
|
|
5
|
+
steps?: StepConfig[];
|
|
6
|
+
onClose: () => void;
|
|
7
|
+
queryKey: (string | number)[];
|
|
8
|
+
apiPath: string;
|
|
9
|
+
id: string | number;
|
|
10
|
+
}
|
|
11
|
+
export declare function UpdateModal<T extends BaseEntity>({ fields, onClose, queryKey, apiPath, id, steps, }: UpdateModalProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface BaseEntity {
|
|
2
|
+
id: string | number;
|
|
3
|
+
}
|
|
4
|
+
type AtLeast<T, K extends keyof T> = Partial<T> & Pick<T, K>;
|
|
5
|
+
export type Headers = Record<string, string>;
|
|
6
|
+
export declare function getOne<T extends BaseEntity>(path: string, id: string | number, headers?: Headers): Promise<T>;
|
|
7
|
+
export declare function useGetOne<T extends BaseEntity>(apiPath: string, queryKey: (string | number)[], id: string | number, headers?: Headers): import('@tanstack/react-query').UseQueryResult<T, Error>;
|
|
8
|
+
export declare function useGetMany<T extends BaseEntity>(apiPath: string, queryKey: (string | number)[], ids: string[] | number[], headers?: Headers): (unknown extends T | import('@tanstack/query-core').InitialDataFunction<T> ? import('@tanstack/react-query').UseQueryResult<unknown extends T ? T : T, Error> : (T extends (unknown extends T ? T : T) ? import('@tanstack/react-query').DefinedUseQueryResult<unknown extends T ? T : T, Error> : T extends () => infer TInitialDataResult ? unknown extends TInitialDataResult ? import('@tanstack/react-query').UseQueryResult<unknown extends T ? T : T, Error> : TInitialDataResult extends (unknown extends T ? T : T) ? import('@tanstack/react-query').DefinedUseQueryResult<unknown extends T ? T : T, Error> : import('@tanstack/react-query').UseQueryResult<unknown extends T ? T : T, Error> : import('@tanstack/react-query').UseQueryResult<unknown extends T ? T : T, Error>) | (import('@tanstack/query-core').InitialDataFunction<T> extends infer T_1 ? T_1 extends import('@tanstack/query-core').InitialDataFunction<T> ? T_1 extends (unknown extends T ? T : T) ? import('@tanstack/react-query').DefinedUseQueryResult<unknown extends T ? T : T, Error> : T_1 extends () => infer TInitialDataResult ? unknown extends TInitialDataResult ? import('@tanstack/react-query').UseQueryResult<unknown extends T ? T : T, Error> : TInitialDataResult extends (unknown extends T ? T : T) ? import('@tanstack/react-query').DefinedUseQueryResult<unknown extends T ? T : T, Error> : import('@tanstack/react-query').UseQueryResult<unknown extends T ? T : T, Error> : import('@tanstack/react-query').UseQueryResult<unknown extends T ? T : T, Error> : never : never))[];
|
|
9
|
+
export declare function useGetAll<T extends BaseEntity>(apiPath: string, queryKey: (string | number)[], enabled?: boolean, headers?: Headers): import('@tanstack/react-query').UseQueryResult<T[], Error>;
|
|
10
|
+
interface MutationContext<T> {
|
|
11
|
+
previousItems: T[] | undefined;
|
|
12
|
+
}
|
|
13
|
+
export declare function useAddOne<T extends BaseEntity>(apiPath: string, queryKey: (string | number)[], headers?: Headers): import('@tanstack/react-query').UseMutationResult<T, Error, Omit<T, "id">, MutationContext<T>>;
|
|
14
|
+
export declare function useUpdateOne<T extends BaseEntity>(apiPath: string, queryKey: (string | number)[], headers?: Headers): import('@tanstack/react-query').UseMutationResult<T, Error, AtLeast<T, "id">, MutationContext<T>>;
|
|
15
|
+
export declare function useDeleteOne<T extends BaseEntity>(apiPath: string, queryKey: (string | number)[], headers?: Headers): import('@tanstack/react-query').UseMutationResult<void, Error, string | number, MutationContext<T>>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function usePersistentState<T>(initialValue: T, key: string): [T, (value: T) => void];
|
package/dist/index.d.ts
ADDED
package/package.json
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
"name": "@espresso-lab/mantine-data-table",
|
|
3
3
|
"private": false,
|
|
4
4
|
"description": "Mantine UI Data Table component",
|
|
5
|
-
"version": "1.0.
|
|
5
|
+
"version": "1.0.2",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"main": "dist/index.umd.js",
|
|
8
|
-
"module": "dist/index.es.js",
|
|
9
|
-
"types": "dist/index.d.ts",
|
|
7
|
+
"main": "./dist/index.umd.js",
|
|
8
|
+
"module": "./dist/index.es.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"author": {
|
|
12
12
|
"name": "Espresso Lab",
|
|
@@ -20,12 +20,13 @@
|
|
|
20
20
|
".": {
|
|
21
21
|
"types": "./dist/index.d.ts",
|
|
22
22
|
"import": "./dist/index.es.js",
|
|
23
|
-
"require": "./dist/index.umd.js"
|
|
23
|
+
"require": "./dist/index.umd.js",
|
|
24
|
+
"default": "./dist/index.es.js"
|
|
24
25
|
},
|
|
25
26
|
"./styles": "./dist/style.css"
|
|
26
27
|
},
|
|
27
28
|
"files": [
|
|
28
|
-
"
|
|
29
|
+
"dist"
|
|
29
30
|
],
|
|
30
31
|
"publishConfig": {
|
|
31
32
|
"access": "public"
|