aio-table 12.0.2 → 14.0.0

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.
Files changed (5) hide show
  1. package/filter.css +282 -0
  2. package/index.css +9 -9
  3. package/index.d.ts +168 -52
  4. package/index.js +943 -253
  5. package/package.json +4 -2
package/filter.css ADDED
@@ -0,0 +1,282 @@
1
+ .aio-table-filter-modal-size>.aio-popup {
2
+ padding: 12px;
3
+ width: 100vw;
4
+ max-width: 772px;
5
+ max-height: 100vh;
6
+ }
7
+
8
+ .aio-table-filter-button {
9
+ display: flex;
10
+ align-items: center;
11
+ gap: 3px;
12
+ border: none;
13
+ background: none;
14
+ height: 24px;
15
+ font-size: inherit;
16
+ cursor: pointer;
17
+ }
18
+ .aio-table-filter-remove-button{
19
+ background:none;
20
+ flex-shrink:0;
21
+ }
22
+ .aio-table-filter-button {
23
+ background: none;
24
+ border: none;
25
+ display: flex;
26
+ align-items: center;
27
+ justify-content: center;
28
+ flex-shrink: 0;
29
+ height: 30px;
30
+ border-radius: 4px;
31
+ color: #0069ff;
32
+ gap: 6px;
33
+ padding: 0 12px;
34
+ cursor: pointer;
35
+ position: relative;
36
+ }
37
+
38
+ .aio-table-filter-badge {
39
+ background: orange;
40
+ color: #fff;
41
+ min-width: 16px;
42
+ height: 12px;
43
+ border-radius: 12px;
44
+ display: flex;
45
+ align-items: center;
46
+ justify-content: center;
47
+ font-size: 10px;
48
+ position: absolute;
49
+ top: -6px;
50
+ right: -3px;
51
+ }
52
+
53
+ .aio-table-filter-modal .aio-popup-header {
54
+ height: 36px;
55
+ }
56
+
57
+ .aio-table-filter-body {
58
+ gap: 0.8em;
59
+ display: flex;
60
+ flex-direction: column;
61
+ padding:0.8em;
62
+ }
63
+ .aio-table-filter-body-rtl{
64
+ direction:rtl;
65
+ }
66
+
67
+ .aio-table-filter-body .aio-table-current-filters {
68
+ display: flex;
69
+ flex-direction: column;
70
+ }
71
+ .aio-table-filter-body .aio-table-current-filters .aio-input{
72
+ min-height:36px;
73
+ }
74
+
75
+ .aio-table-filter-body .aio-table-saved-filters {
76
+ width: 100%;
77
+ display: flex;
78
+ flex-direction: column;
79
+ gap: 6px;
80
+ height: 100%;
81
+ padding:0.4em;
82
+ }
83
+
84
+ .aio-table-filter-body .aio-table-saved-filters .aio-table-saved-filter {
85
+ display: flex;
86
+ flex-direction: column;
87
+ background: #eee;
88
+ flex-shrink: 0;
89
+ border: 1px solid #f4f4f4;
90
+ border-radius: 6px;
91
+ position: relative;
92
+ color: #333;
93
+ }
94
+
95
+ .aio-table-filter-button:disabled {
96
+ opacity: 0.5;
97
+ cursor: not-allowed;
98
+ }
99
+
100
+ .aio-table-filter-active-button {
101
+ background: #0069ff;
102
+ color: #fff;
103
+ }
104
+
105
+ .aio-table-filter-panel {
106
+ position: relative;
107
+ display: flex;
108
+ flex-direction: column;
109
+ border: 1px solid #ddd;
110
+ border-radius: 6px;
111
+ }
112
+ .aio-table-saved-filters-empty {
113
+ font-size: 12px;
114
+ width: 100%;
115
+ display: flex;
116
+ justify-content: center;
117
+ }
118
+
119
+ .aio-table-filter-panel-header {
120
+ display: flex;
121
+ align-items: center;
122
+ padding:0 0.8em;
123
+ height:3em;
124
+ }
125
+
126
+ .aio-table-filter-panel-label {
127
+ flex: 1;
128
+ }
129
+
130
+ .aio-table-filter-row {
131
+ display: flex;
132
+ align-items: center;
133
+ gap: 0.4em;
134
+ padding:0.4em;
135
+ margin:0.4em;
136
+ margin-top:0;
137
+ background:#f2f2f2;
138
+ border-radius:6px;
139
+ position: relative;
140
+ }
141
+
142
+ .aio-table-filter-row .aio-input {
143
+ flex: 1;
144
+ padding:0 12px;
145
+ }
146
+ .aio-table-filter-row .aio-input.aio-table-filter-operator-select{
147
+ flex:none;
148
+ width:10em;
149
+ }
150
+
151
+ .aio-table-filter-toolbar {
152
+ display: flex;
153
+ align-items: center;
154
+ justify-content: center;
155
+ gap: 6px;
156
+ }
157
+
158
+
159
+ .aio-table-filter-save-modal {
160
+ padding: 12px;
161
+ display: flex;
162
+ flex-direction: column;
163
+ gap: 12px;
164
+ }
165
+
166
+ .aio-table-filter-save-modal-footer {
167
+ display: flex;
168
+ gap: 6px;
169
+ }
170
+
171
+
172
+ .aio-table-filter-backdrop {
173
+ background: rgba(0, 0, 0, 0.7);
174
+ }
175
+
176
+
177
+
178
+
179
+ .aio-table-filter-row .aio-input{
180
+ border:none;
181
+ }
182
+
183
+ /*******************************tags**************************************/
184
+ .aio-table-filter-tags{
185
+ padding:0.4em;
186
+ border-radius:4px;
187
+ display:flex;
188
+ flex-wrap:wrap;
189
+ gap:0.4em
190
+ }
191
+ .aio-table-filter-tag{
192
+ color: #666;
193
+ width: fit-content;
194
+ display: flex;
195
+ align-items: center;
196
+ overflow: hidden;
197
+ white-space: nowrap;
198
+ max-width: 100%;
199
+ cursor: pointer;
200
+ background: #fff;
201
+ flex-shrink: 0;
202
+ gap: 0.4em;
203
+ font-size:0.9em;
204
+ border-radius:0.2em;
205
+ padding:0.2em 0.8em;
206
+ }
207
+ .aio-table-filter-panel{
208
+ background:#fff;
209
+ }
210
+ /*************************************************************************/
211
+ /*******************************saved filter******************************/
212
+ .aio-table-saved-filter {
213
+ display: flex;
214
+ flex-direction: column;
215
+ background: #f8f8f8;
216
+ flex-shrink: 0;
217
+ border: 1px solid #f4f4f4;
218
+ border-radius: 6px;
219
+ position: relative;
220
+ color: #333;
221
+ }
222
+
223
+ .aio-table-saved-filter-header {
224
+ height: 3em;
225
+ display: flex;
226
+ align-items: center;
227
+ gap: 0.4em;
228
+ padding: 0 12px;
229
+ }
230
+ .aio-table-saved-filters-empty{
231
+ height:4em;
232
+ display:flex;
233
+ align-items: center;
234
+ justify-content: center;
235
+ }
236
+ .aio-table-filter-remove-button {
237
+ position: absolute;
238
+ background: #fff;
239
+ width: 24px;
240
+ border: 1px solid #ddd;
241
+ height: 24px;
242
+ display: flex;
243
+ align-items: center;
244
+ justify-content: center;
245
+ border-radius: 100%;
246
+ top: -6px;
247
+ cursor:pointer;
248
+ }
249
+
250
+ .aio-table-saved-filter-body {
251
+ display: flex;
252
+ gap: 6px;
253
+ padding: 0.4em;
254
+ padding-top:0;
255
+ }
256
+
257
+ .aio-table-saved-filter-name {
258
+ flex: 1;
259
+ padding-inline-start: 16px;
260
+ }
261
+ /*************************************************************************/
262
+ .aio-table-saved-filter .ai-form-tags{
263
+ padding:0.4em;
264
+ border-radius:4px;
265
+ }
266
+
267
+
268
+ .aio-table-filter-inline-label{
269
+ flex:1;
270
+ padding:0 12px;
271
+ box-sizing: border-box;
272
+ }
273
+ .aio-table-filter-label{
274
+ top:0;
275
+ z-index:10;
276
+ padding:0 12px;
277
+ box-sizing: border-box;
278
+ }
279
+ .aio-table-filter-modal .aio-popup{
280
+ background:#ddd;
281
+ max-width: 772px !important;
282
+ }
package/index.css CHANGED
@@ -1,8 +1,8 @@
1
+ @import './filter.css';
1
2
  :root {
2
3
  --aio-table-color: #0069ff;
3
4
  --aio-table-transition: 0.3s;
4
5
  }
5
-
6
6
  .aio-table-rtl {
7
7
  direction: rtl;
8
8
  }
@@ -34,7 +34,6 @@
34
34
  .aio-table {
35
35
  box-sizing: border-box;
36
36
  border-radius: 4px;
37
- font-size: 12px;
38
37
  height: fit-content;
39
38
  display: flex;
40
39
  flex-direction: column;
@@ -71,7 +70,8 @@
71
70
  .aio-table-title {
72
71
  padding: 0 12px;
73
72
  font-weight: bold;
74
- height: 36px;
73
+ height: 3em;
74
+ gap:0.4em;
75
75
  display: flex;
76
76
  align-items: center;
77
77
  box-sizing: border-box;
@@ -91,7 +91,7 @@
91
91
  .aio-table-row {
92
92
  display: flex;
93
93
  min-width: fit-content;
94
- height:40px;
94
+ height:3em;
95
95
  }
96
96
  .aio-table-cell {
97
97
  padding: 6px 12px;
@@ -177,15 +177,17 @@
177
177
  }
178
178
 
179
179
  .aio-table-toolbar-button {
180
- height: 36px;
180
+ width:3em;
181
+ height: 3em;
181
182
  display: flex;
182
183
  align-items: center;
183
184
  justify-content: center;
184
- width: 36px;
185
185
  border: 1px solid #ddd;
186
186
  background:#fff;
187
187
  border-radius:100%;
188
- width:36px;
188
+ padding:0 !important;
189
+ font-size:inherit;
190
+ flex-shrink:0;
189
191
  }
190
192
  .aio-table-remove {
191
193
  border: none;
@@ -216,13 +218,11 @@
216
218
  .aio-table-search {
217
219
  flex: 1;
218
220
  height: 100%;
219
- padding: 6px;
220
221
  box-sizing: border-box;
221
222
  }
222
223
 
223
224
  .aio-table-search .aio-input {
224
225
  background: #fff;
225
226
  border: none;
226
- min-height: 30px;
227
227
  }
228
228
 
package/index.d.ts CHANGED
@@ -1,72 +1,129 @@
1
1
  import { type ReactNode } from "react";
2
- import * as UT from 'aio-utils';
2
+ import { type I_AIOInput } from "aio-input";
3
3
  import "./index.css";
4
4
  type I_rowOption<T, R> = (p: I_rowDetail<T>) => R;
5
- type I_cellOption<T, R> = ((p: I_cellDetail<T>) => R) | string;
6
5
  type I_rowDetail<T> = {
7
6
  row: T;
8
7
  rowIndex: number;
9
- isFirst: boolean;
10
- isLast: boolean;
11
8
  };
12
- type I_cellDetail<T> = I_rowDetail<T> & {
13
- column: I_table_column<T>;
14
- change: (newRow: T) => void;
15
- date: number[];
16
- };
17
- export type I_table_paging = UT.I_paging;
18
- export type I_table_sort<T> = UT.I_sort<T>;
19
- export type I_table_filter = UT.I_filter;
20
- export type I_table_filter_item = UT.I_filter_item;
21
- export type I_table_filter_saved_item = UT.I_filter_collection;
22
9
  export type I_table_column<T> = {
23
10
  title?: any;
24
11
  sort?: true | I_table_sort<T>;
25
- jalali?: boolean;
26
- filter?: {
27
- operators?: UT.I_filter_operator[];
28
- options?: {
29
- text: string;
30
- value: any;
31
- }[];
32
- type?: I_table_column<any>["type"];
33
- };
12
+ filter?: boolean;
34
13
  search?: boolean;
35
- id: string;
36
14
  width?: any;
37
15
  minWidth?: any;
16
+ id: string;
38
17
  excel?: string | boolean;
39
18
  justify?: boolean;
40
- value?: string;
41
- attrs?: I_cellOption<T, {
42
- [attrs: string]: any;
43
- }>;
44
- before?: I_cellOption<T, ReactNode>;
45
- after?: I_cellOption<T, ReactNode>;
46
- subtext?: I_cellOption<T, ReactNode>;
47
- template?: I_cellOption<T, ReactNode>;
48
- titleAttrs?: {
49
- [attrs: string]: any;
19
+ filterInput?: I_AIOInput & {
20
+ type: I_table_column<any>["type"];
21
+ label?: string;
50
22
  };
51
- type?: 'text' | 'number' | 'date';
23
+ filterOperators?: ('less' | 'lessequal' | 'more' | 'moreequal' | 'equal' | 'notEqual' | 'contain' | 'notContain')[];
52
24
  show?: boolean;
53
- pattern?: string;
54
- data?: any;
55
25
  toggle?: boolean;
26
+ data?: any;
27
+ type?: 'text' | 'number' | 'date' | 'jalaliDate' | 'select' | 'multiSelect' | 'checkbox';
28
+ template?: string | ((p: {
29
+ row: T;
30
+ column: I_table_column<T>;
31
+ rowIndex: number;
32
+ change: (newRow: T) => void;
33
+ value: any;
34
+ dateObject?: {
35
+ year: number;
36
+ month: number;
37
+ day: number;
38
+ hour: number;
39
+ minute: number;
40
+ second: number;
41
+ };
42
+ }) => ReactNode | undefined);
43
+ before?: string | ((p: {
44
+ row: T;
45
+ column: I_table_column<T>;
46
+ rowIndex: number;
47
+ change: (newRow: T) => void;
48
+ value: any;
49
+ dateObject?: {
50
+ year: number;
51
+ month: number;
52
+ day: number;
53
+ hour: number;
54
+ minute: number;
55
+ second: number;
56
+ };
57
+ }) => ReactNode | undefined);
58
+ after?: string | ((p: {
59
+ row: T;
60
+ column: I_table_column<T>;
61
+ rowIndex: number;
62
+ change: (newRow: T) => void;
63
+ value: any;
64
+ dateObject?: {
65
+ year: number;
66
+ month: number;
67
+ day: number;
68
+ hour: number;
69
+ minute: number;
70
+ second: number;
71
+ };
72
+ }) => ReactNode | undefined);
73
+ subtext?: string | ((p: {
74
+ row: T;
75
+ column: I_table_column<T>;
76
+ rowIndex: number;
77
+ change: (newRow: T) => void;
78
+ value: any;
79
+ dateObject?: {
80
+ year: number;
81
+ month: number;
82
+ day: number;
83
+ hour: number;
84
+ minute: number;
85
+ second: number;
86
+ };
87
+ }) => ReactNode | undefined);
88
+ value?: string | ((p: {
89
+ row: T;
90
+ column: I_table_column<T>;
91
+ rowIndex: number;
92
+ }) => string | undefined);
93
+ pattern?: string;
94
+ affix?: string;
95
+ prefix?: string;
96
+ };
97
+ export type I_table_filter_saved = {
98
+ name: string;
99
+ data: any;
100
+ };
101
+ export type I_table_filter = {
102
+ onChange?: (newFilters: I_table_filter_item[]) => boolean;
103
+ getSavedItems?: () => Promise<{
104
+ name: string;
105
+ data: any;
106
+ }[]>;
107
+ setSavedItems?: (savedItems: {
108
+ name: string;
109
+ data: any;
110
+ }[]) => Promise<boolean>;
111
+ items?: I_table_filter_item[];
112
+ modalAttrs?: any;
113
+ cache?: string;
114
+ };
115
+ export type I_table_filter_item = {
116
+ columnId: string;
117
+ value: any;
118
+ operator?: 'less' | 'lessequal' | 'more' | 'moreequal' | 'equal' | 'notEqual' | 'contain' | 'notContain';
119
+ id: string;
56
120
  };
57
121
  export type I_table<T> = {
122
+ inlineSort?: boolean;
58
123
  fa?: boolean;
59
124
  addText?: ReactNode | ((value: any) => ReactNode);
60
125
  columns?: I_table_column<T>[];
61
126
  excel?: string | ((value: any[]) => any[]);
62
- getValue?: {
63
- [key: string]: (p: {
64
- row: T;
65
- column: I_table_column<T>;
66
- rowIndex: number;
67
- change: (newRow: T) => void;
68
- }) => any;
69
- };
70
127
  headerAttrs?: any;
71
128
  onAdd?: () => Promise<T | undefined>;
72
129
  onRemove?: (p: {
@@ -87,11 +144,6 @@ export type I_table<T> = {
87
144
  }>;
88
145
  template?: I_rowOption<T, ReactNode>;
89
146
  };
90
- cellAttrs?: string | ((p: {
91
- row: T;
92
- column: I_table_column<T>;
93
- rowIndex: number;
94
- }) => any);
95
147
  rowsTemplate?: (rows: T[]) => ReactNode;
96
148
  toolbar?: ReactNode | (() => ReactNode);
97
149
  toolbarAttrs?: any;
@@ -105,10 +157,74 @@ export type I_table<T> = {
105
157
  filter?: I_table_filter;
106
158
  gap?: [number, number];
107
159
  striped?: [string, string];
160
+ onChangeColumns?: (v: I_table_column<any>[]) => void;
108
161
  columnOption?: {
109
- [key in keyof I_table_column<any>]?: (p: I_cellDetail<any>) => any;
162
+ [key in keyof I_table_column<T>]?: (p: {
163
+ column: I_table_column<T>;
164
+ row: T;
165
+ rowIndex: number;
166
+ }) => any;
110
167
  };
111
- onChangeColumns?: (v: I_table_column<any>[]) => void;
168
+ templates?: {
169
+ [key: string]: (p: {
170
+ row: T;
171
+ column: I_table_column<T>;
172
+ rowIndex: number;
173
+ change: (newRow: T) => void;
174
+ value: any;
175
+ dateObject?: {
176
+ year: number;
177
+ month: number;
178
+ day: number;
179
+ hour: number;
180
+ minute: number;
181
+ second: number;
182
+ };
183
+ }) => ReactNode;
184
+ };
185
+ cellAttrs?: (p: {
186
+ row: T;
187
+ column: I_table_column<T>;
188
+ value: any;
189
+ rowIndex: number;
190
+ }) => any;
191
+ titleAttrs?: (column: I_table_column<T>) => any;
112
192
  };
113
193
  declare const AIOTable: <T>(props: I_table<T>) => import("react/jsx-runtime").JSX.Element;
114
194
  export default AIOTable;
195
+ export type I_table_sort<T> = {
196
+ active?: boolean;
197
+ dir?: 'dec' | 'inc';
198
+ title?: ReactNode;
199
+ sortId: string;
200
+ getValue?: (row: T) => any;
201
+ };
202
+ export declare const useSort: <T>(p: {
203
+ fa?: boolean;
204
+ sorts: I_table_sort<T>[];
205
+ rows: any[];
206
+ onChangeRows?: (rows: any) => void;
207
+ onChangeSort?: (sorts: I_table_sort<T>[]) => Promise<boolean | undefined>;
208
+ }) => {
209
+ sorts: I_table_sort<T>[];
210
+ setSorts: import("react").Dispatch<import("react").SetStateAction<I_table_sort<T>[]>>;
211
+ renderSortButton: (attrs?: any, limitTo?: string) => import("react/jsx-runtime").JSX.Element;
212
+ getSortedRows: (rows: T[]) => T[];
213
+ changeSort: (sortId: string, changeObject: Partial<I_table_sort<T>>) => void;
214
+ changeSorts: (sorts: I_table_sort<T>[]) => Promise<void>;
215
+ renderSortArrow: (option: I_table_sort<T> | false, inline?: boolean) => import("react/jsx-runtime").JSX.Element;
216
+ getSortByColumn: (column: I_table_column<T>) => I_table_sort<T> | false;
217
+ };
218
+ export type I_table_paging = {
219
+ serverSide?: boolean;
220
+ number: number;
221
+ size: number;
222
+ length?: number;
223
+ sizes?: number[];
224
+ };
225
+ export type I_pagingHook<T> = {
226
+ render: () => ReactNode;
227
+ getPagedRows: (rows: T[]) => T[];
228
+ changePaging: (obj: Partial<I_table_paging>) => void;
229
+ };
230
+ export declare function sortRows<T>(rows: T[], sorts: I_table_sort<T>[]): T[];