jb-grid 0.0.1
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 +7 -0
- package/index.js +1 -0
- package/package.json +32 -0
- package/react/README.md +195 -0
- package/react/dist/JBGrid.cjs.js +17989 -0
- package/react/dist/JBGrid.cjs.js.map +1 -0
- package/react/dist/JBGrid.js +17983 -0
- package/react/dist/JBGrid.js.map +1 -0
- package/react/dist/JBGrid.umd.js +17989 -0
- package/react/dist/JBGrid.umd.js.map +1 -0
- package/react/dist/common/hooks/use-event.d.ts +3 -0
- package/react/dist/common/hooks/useLazyRef.d.ts +4 -0
- package/react/dist/common/hooks/useMobx.d.ts +4 -0
- package/react/dist/common/scripts/device-detection.d.ts +1 -0
- package/react/dist/common/scripts/persian-helper.d.ts +3 -0
- package/react/dist/web-component/jb-grid/react/lib/Components/Cell.d.ts +10 -0
- package/react/dist/web-component/jb-grid/react/lib/Components/ExpandRow.d.ts +11 -0
- package/react/dist/web-component/jb-grid/react/lib/Components/JBLoading.d.ts +6 -0
- package/react/dist/web-component/jb-grid/react/lib/Components/Row.d.ts +5 -0
- package/react/dist/web-component/jb-grid/react/lib/Components/content-error/ContentError.d.ts +10 -0
- package/react/dist/web-component/jb-grid/react/lib/Content.d.ts +16 -0
- package/react/dist/web-component/jb-grid/react/lib/Footer.d.ts +9 -0
- package/react/dist/web-component/jb-grid/react/lib/Header.d.ts +22 -0
- package/react/dist/web-component/jb-grid/react/lib/JBGrid.d.ts +24 -0
- package/react/dist/web-component/jb-grid/react/lib/JBGridData.d.ts +16 -0
- package/react/dist/web-component/jb-grid/react/lib/JBGridViewModel.d.ts +71 -0
- package/react/dist/web-component/jb-grid/react/lib/Types.d.ts +124 -0
- package/react/dist/web-component/jb-grid/react/lib/i18n.d.ts +2 -0
- package/react/dist/web-component/jb-searchbar/types.d.ts +1 -0
- package/react/index.js +1 -0
- package/react/lib/Components/Cell.scss +63 -0
- package/react/lib/Components/Cell.tsx +19 -0
- package/react/lib/Components/ExpandRow.scss +37 -0
- package/react/lib/Components/ExpandRow.tsx +19 -0
- package/react/lib/Components/JBLoading.scss +140 -0
- package/react/lib/Components/JBLoading.tsx +30 -0
- package/react/lib/Components/Row.scss +25 -0
- package/react/lib/Components/Row.tsx +18 -0
- package/react/lib/Components/content-error/ContentError.tsx +20 -0
- package/react/lib/Components/content-error/content-error.scss +26 -0
- package/react/lib/Content.tsx +76 -0
- package/react/lib/Footer.tsx +95 -0
- package/react/lib/Header.tsx +70 -0
- package/react/lib/JBGrid.scss +350 -0
- package/react/lib/JBGrid.tsx +62 -0
- package/react/lib/JBGridBridgeExample.js +90 -0
- package/react/lib/JBGridData.ts +51 -0
- package/react/lib/JBGridViewModel.ts +476 -0
- package/react/lib/Types.ts +142 -0
- package/react/lib/_constants.scss +7 -0
- package/react/lib/i18n.ts +15 -0
- package/react/package.json +42 -0
- package/react/tsconfig.json +18 -0
package/README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# jb-grid
|
|
2
|
+
|
|
3
|
+
> currently this component only available in react and does not support web-component but it will in the future.
|
|
4
|
+
|
|
5
|
+
## using with JS frameworks
|
|
6
|
+
|
|
7
|
+
to use this component in **react** see [`jb-grid/react`](https://github.com/javadbat/jb-grid/tree/main/react);
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
console.log("not implemented yet");
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "jb-grid",
|
|
3
|
+
"description": "grid web component",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "mohammad javad bathaei",
|
|
7
|
+
"email": "javadbat@gmail.com"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"jb",
|
|
11
|
+
"jb-grid",
|
|
12
|
+
"table",
|
|
13
|
+
"web component"
|
|
14
|
+
],
|
|
15
|
+
"version": "0.0.1",
|
|
16
|
+
"bugs": "https://github.com/javadbat/jb-button/issues",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"files": [
|
|
19
|
+
"LICENSE",
|
|
20
|
+
"README.md",
|
|
21
|
+
"lib/",
|
|
22
|
+
"dist/",
|
|
23
|
+
"react/",
|
|
24
|
+
"react/dist/"
|
|
25
|
+
],
|
|
26
|
+
"main": "index.js",
|
|
27
|
+
"types": "./dist/web-component/jb-button/lib/jb-button.d.ts",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git@github.com:javadbat/jb-button.git"
|
|
31
|
+
}
|
|
32
|
+
}
|
package/react/README.md
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# jb-grid React component
|
|
2
|
+
|
|
3
|
+
react mobx table grid with pagination, filtering and sorting functionality.
|
|
4
|
+
|
|
5
|
+
- responsive
|
|
6
|
+
- mobx ready
|
|
7
|
+
- easy filter implementation (customizable)
|
|
8
|
+
- customizable column templates
|
|
9
|
+
- flexible column size
|
|
10
|
+
- support for server side data fetching
|
|
11
|
+
|
|
12
|
+
## instructions
|
|
13
|
+
|
|
14
|
+
### install the package
|
|
15
|
+
```bash
|
|
16
|
+
npm i jb-grid
|
|
17
|
+
```
|
|
18
|
+
### import and use in your component
|
|
19
|
+
```JSX
|
|
20
|
+
import {Cell, Row, JBGrid} from 'jb-grid/react';
|
|
21
|
+
//this file is a class that implement `JBGridBridgeClassInterface` interface to translate your server data to jb-grid data interface see Bridge section for more detail
|
|
22
|
+
import {JBGridBridge} from './my-bridge';
|
|
23
|
+
// grid config that impl JBGridConfig type see config section for more detail
|
|
24
|
+
import {yourConfig} from './your-grid-config-file';
|
|
25
|
+
//jb-search-bar config so you can filter your data
|
|
26
|
+
import {filterConfig} from './my-filter-config';
|
|
27
|
+
|
|
28
|
+
<JBGrid config={yourConfig} bridge={JBGridBridge} title="user list" searchbarConfig={vm.filterConfig}></JBGrid>
|
|
29
|
+
```
|
|
30
|
+
### config
|
|
31
|
+
|
|
32
|
+
config is unique for each data table you want to show and contains information about columns,filters,sort,initData,...
|
|
33
|
+
you can create your own config from scratch using Mobx class Stores that implements `JBGridConfigInterface` or just create instance of `JBGridData` and start to config it's fields base on your need.
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
import { JBGridData } from "jb-grid/react";
|
|
37
|
+
|
|
38
|
+
const yourConfig = new JBGridData();
|
|
39
|
+
```
|
|
40
|
+
or in typescript: (in javascript you don't need to implements from `JBGridConfigInterface` but you have to check every detail manually to avoid errors)
|
|
41
|
+
```ts
|
|
42
|
+
import {JBGridConfigInterface} from "jb-grid/types"
|
|
43
|
+
|
|
44
|
+
class yourConfigClass implements JBGridConfigInterface{
|
|
45
|
+
//put your config here. for sample code see /lib/JBGridData in package files
|
|
46
|
+
}
|
|
47
|
+
export const yourConfig = new yourConfigClass();
|
|
48
|
+
```
|
|
49
|
+
you can config columns of table like this:
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
yourConfig.table.columns = [
|
|
53
|
+
{
|
|
54
|
+
//uniq identifier of column
|
|
55
|
+
id: 1,
|
|
56
|
+
//will be used as a key in sort object when sorting by column
|
|
57
|
+
name: 'name',
|
|
58
|
+
//showed in column header
|
|
59
|
+
title: 'نام',
|
|
60
|
+
//let us sort column default is false
|
|
61
|
+
sortable: true,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: 2,
|
|
65
|
+
name: 'age',
|
|
66
|
+
title: 'سن',
|
|
67
|
+
sortable: false,
|
|
68
|
+
//if you dont set width , it will be '1fr' mean it get 1 share of width from free space
|
|
69
|
+
width: '1fr'
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
id: 3,
|
|
73
|
+
name: 'expand',
|
|
74
|
+
title: 'باز کردن',
|
|
75
|
+
sortable: false,
|
|
76
|
+
//you can set px,em, auto, fr , % , ... in here
|
|
77
|
+
width: '200px'
|
|
78
|
+
}
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
to config backend service call config you can set `` like this:
|
|
83
|
+
```js
|
|
84
|
+
// your api endpoint
|
|
85
|
+
yourConfig.data.requestParams.url = "http://localhost:3000/grid/user-list",
|
|
86
|
+
//endpoint http method
|
|
87
|
+
yourConfig.data.requestParams.method = "POST";
|
|
88
|
+
// you can set any custom parameter your backend needs here. for example if you using grpc or graphql you can set any config they need
|
|
89
|
+
yourConfig.data.requestParams.custom1 = {aa:""};
|
|
90
|
+
yourConfig.data.requestParams.foo = "x";
|
|
91
|
+
```
|
|
92
|
+
### i18n
|
|
93
|
+
you can pass a i18n config to set a text, number display and other localization config to jb-grid
|
|
94
|
+
```tsx
|
|
95
|
+
const i18nMessages:JBGridI18nMessage = {
|
|
96
|
+
EnterPageNumberMessage:"شماره صفحه ای که میخواهید وارد آن شوید را وارد کنید",
|
|
97
|
+
serverErrorText:"متاسفانه در هنگام بارگذاری اطلاعات خطایی رخ داده است",
|
|
98
|
+
serverErrorTitle:"すみません",
|
|
99
|
+
serverErrorRefreshButtonTitle:"تلاش مجدد",
|
|
100
|
+
currentAvailableItem:"تعداد کل ایتم های موجود",
|
|
101
|
+
pageItemCount:"تعداد آیتم در هر صفحه",
|
|
102
|
+
from:"از"
|
|
103
|
+
};
|
|
104
|
+
export const i18n:JBGridI18nConfig = {
|
|
105
|
+
messages: i18nMessages,
|
|
106
|
+
showPersianNumber:false
|
|
107
|
+
};
|
|
108
|
+
<JBGrid i18n={i18n}></JBGrid>
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
### actions
|
|
112
|
+
|
|
113
|
+
there is some actions you may want to call inside a grid for example you need to refresh data by code after some entity insert/update or fullscreen grid by code. for doing so you just have to call `actionDispatchers` methods in your grid config after initialization process (after render of jb-grid finish grid will automatically extend your config and add this methods).
|
|
114
|
+
```typescript
|
|
115
|
+
//action dispatcher type in typescript:
|
|
116
|
+
type ActionDispatchers = Readonly<{
|
|
117
|
+
refreshData: () => Promise<void>,
|
|
118
|
+
fullScreenGrid: () => void,
|
|
119
|
+
exitFullScreenGrid: () => void
|
|
120
|
+
}>
|
|
121
|
+
// the call function:
|
|
122
|
+
yourConfig.actionDispatchers.refreshData();
|
|
123
|
+
//
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### bridge
|
|
127
|
+
|
|
128
|
+
bridge is a js/ts class, responsible for converting jb-grid standard data to your back-end standard data and reverse.
|
|
129
|
+
jb-grid doesn't send request by it self, instead it ask bridge to send request & and receive data. so you have freedom to use whatever standard and technology you may see fit.
|
|
130
|
+
the reason that we separate config & bridge is most of the time all tables of your project use same request and response data structure so you don't need to repeat yourself. you code 1 bridge for all of project and config each list for endpoints url ,...
|
|
131
|
+
|
|
132
|
+
### filter
|
|
133
|
+
|
|
134
|
+
### show list
|
|
135
|
+
|
|
136
|
+
### custom error page
|
|
137
|
+
|
|
138
|
+
if you want to show customized error page instead of default one use `contentError` prop
|
|
139
|
+
```jsx
|
|
140
|
+
<JBGrid contentError={<CustomErrorComponent />}></JBGrid>
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### full-screen grid
|
|
144
|
+
|
|
145
|
+
jb-grid has a fullscreenable feature and you can activate that by set `isFullscreen={value:bool}` for example
|
|
146
|
+
|
|
147
|
+
```jsx
|
|
148
|
+
const [isFullscreen,setIsFullscreen] = useState(false);
|
|
149
|
+
<JBGrid isFullscreen={isFullscreen} onFullscreenChange={(newValue)=>setIsFullscreen(newValue)}></JBGrid>
|
|
150
|
+
|
|
151
|
+
```
|
|
152
|
+
### expandable row
|
|
153
|
+
you can add expandable row so user can expand row to see more info about a row in detail
|
|
154
|
+
|
|
155
|
+
```jsx
|
|
156
|
+
<JBGrid config={jbGridConfig} bridge={JBGridBridge} title="general list" searchbarConfig={filterConfig}>
|
|
157
|
+
{
|
|
158
|
+
jbGridConfig.data.data.map(
|
|
159
|
+
(item) => {
|
|
160
|
+
return (
|
|
161
|
+
<React.Fragment key={item.id}>
|
|
162
|
+
<Row>
|
|
163
|
+
<Cell>{item.name}</Cell>
|
|
164
|
+
<Cell>{item.age}</Cell>
|
|
165
|
+
<Cell><button onClick={()=>{item.jbGridDetail.isExpanded = !item.jbGridDetail.isExpanded;}}>detail</button></Cell>
|
|
166
|
+
</Row>
|
|
167
|
+
<ExpandRow show={item.jbGridDetail.isExpanded}>
|
|
168
|
+
<YourExpandedData></YourExpandedData>
|
|
169
|
+
</ExpandRow>
|
|
170
|
+
</React.Fragment>
|
|
171
|
+
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
)
|
|
175
|
+
}
|
|
176
|
+
</JBGrid>
|
|
177
|
+
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## make it mobile friendly
|
|
181
|
+
|
|
182
|
+
jb-grid by default is mobile friendly but when it turns to mobile view it show row as cards. this cards show the table fields in themselves but without any label. to show label of columns beside the cell in mobile just add `label` property to each cell like this:
|
|
183
|
+
```jsx
|
|
184
|
+
<Row>
|
|
185
|
+
<Cell label="name:">{item.name}</Cell>
|
|
186
|
+
<Cell label="age:">{item.age}</Cell>
|
|
187
|
+
<Cell label="operations:"><button onClick={()=>{item.jbGridDetail.isExpanded = !item.jbGridDetail.isExpanded;}}>detail</button></Cell>
|
|
188
|
+
</Row>
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## styling
|
|
192
|
+
| css variable name | description |
|
|
193
|
+
| ------------- | ------------- |
|
|
194
|
+
| --jb-grid-loading-color | list loading color |
|
|
195
|
+
| --jb-grid-page-active-color | color of active page |
|