@digital-realty/ix-grid 1.0.6

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 (69) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +62 -0
  3. package/demo/columns.js +65 -0
  4. package/demo/contacts.js +292 -0
  5. package/demo/index.html +92 -0
  6. package/dist/IxGrid.d.ts +46 -0
  7. package/dist/IxGrid.js +227 -0
  8. package/dist/IxGrid.js.map +1 -0
  9. package/dist/components/IxGridColumnFilter.d.ts +20 -0
  10. package/dist/components/IxGridColumnFilter.js +133 -0
  11. package/dist/components/IxGridColumnFilter.js.map +1 -0
  12. package/dist/components/IxGridRowFilter.d.ts +37 -0
  13. package/dist/components/IxGridRowFilter.js +317 -0
  14. package/dist/components/IxGridRowFilter.js.map +1 -0
  15. package/dist/components/IxPagination.d.ts +13 -0
  16. package/dist/components/IxPagination.js +93 -0
  17. package/dist/components/IxPagination.js.map +1 -0
  18. package/dist/components/grid-column-filter-styles.d.ts +1 -0
  19. package/dist/components/grid-column-filter-styles.js +71 -0
  20. package/dist/components/grid-column-filter-styles.js.map +1 -0
  21. package/dist/components/grid-row-filter-styles.d.ts +1 -0
  22. package/dist/components/grid-row-filter-styles.js +414 -0
  23. package/dist/components/grid-row-filter-styles.js.map +1 -0
  24. package/dist/components/pagination-styles.d.ts +1 -0
  25. package/dist/components/pagination-styles.js +33 -0
  26. package/dist/components/pagination-styles.js.map +1 -0
  27. package/dist/grid-view-styles.d.ts +1 -0
  28. package/dist/grid-view-styles.js +265 -0
  29. package/dist/grid-view-styles.js.map +1 -0
  30. package/dist/index.d.ts +1 -0
  31. package/dist/index.js +2 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/ix-grid-copy.d.ts +10 -0
  34. package/dist/ix-grid-copy.js +11 -0
  35. package/dist/ix-grid-copy.js.map +1 -0
  36. package/dist/ix-grid.d.ts +1 -0
  37. package/dist/ix-grid.js +3 -0
  38. package/dist/ix-grid.js.map +1 -0
  39. package/dist/test/ix-grid-column-filter.test.d.ts +1 -0
  40. package/dist/test/ix-grid-column-filter.test.js +36 -0
  41. package/dist/test/ix-grid-column-filter.test.js.map +1 -0
  42. package/dist/test/ix-grid-row-filter.test.d.ts +1 -0
  43. package/dist/test/ix-grid-row-filter.test.js +37 -0
  44. package/dist/test/ix-grid-row-filter.test.js.map +1 -0
  45. package/dist/test/ix-grid.test.d.ts +1 -0
  46. package/dist/test/ix-grid.test.js +43 -0
  47. package/dist/test/ix-grid.test.js.map +1 -0
  48. package/dist/test/ix-pagination.test.d.ts +1 -0
  49. package/dist/test/ix-pagination.test.js +28 -0
  50. package/dist/test/ix-pagination.test.js.map +1 -0
  51. package/package.json +95 -0
  52. package/src/IxGrid.ts +229 -0
  53. package/src/components/IxGridColumnFilter.ts +144 -0
  54. package/src/components/IxGridRowFilter.ts +352 -0
  55. package/src/components/IxPagination.ts +85 -0
  56. package/src/components/grid-column-filter-styles.ts +71 -0
  57. package/src/components/grid-row-filter-styles.ts +414 -0
  58. package/src/components/pagination-styles.ts +33 -0
  59. package/src/grid-view-styles.ts +265 -0
  60. package/src/index.ts +1 -0
  61. package/src/ix-grid-copy.ts +10 -0
  62. package/src/ix-grid.ts +3 -0
  63. package/src/test/ix-grid-column-filter.test.ts +47 -0
  64. package/src/test/ix-grid-row-filter.test.ts +48 -0
  65. package/src/test/ix-grid.test.ts +50 -0
  66. package/src/test/ix-pagination.test.ts +33 -0
  67. package/tsconfig.json +22 -0
  68. package/web-dev-server.config.mjs +27 -0
  69. package/web-test-runner.config.mjs +43 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 ix-grid
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # \<ix-grid>
2
+
3
+ This webcomponent follows the [open-wc](https://github.com/open-wc/open-wc) recommendation.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm i @digital-realty/ix-grid
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```html
14
+ <script type="module">
15
+ import '@digital-realty/ix-grid/ix-grid.js';
16
+ </script>
17
+
18
+ <ix-grid></ix-grid>
19
+ ```
20
+
21
+ ## Linting and formatting
22
+
23
+ To scan the project for linting and formatting errors, run
24
+
25
+ ```bash
26
+ npm run lint
27
+ ```
28
+
29
+ To automatically fix linting and formatting errors, run
30
+
31
+ ```bash
32
+ npm run format
33
+ ```
34
+
35
+ ## Testing with Web Test Runner
36
+
37
+ To execute a single test run:
38
+
39
+ ```bash
40
+ npm run test
41
+ ```
42
+
43
+ To run the tests in interactive watch mode run:
44
+
45
+ ```bash
46
+ npm run test:watch
47
+ ```
48
+
49
+
50
+ ## Tooling configs
51
+
52
+ For most of the tools, the configuration is in the `package.json` to reduce the amount of files in your project.
53
+
54
+ If you customize the configuration a lot, you can consider moving them to individual files.
55
+
56
+ ## Local Demo with `web-dev-server`
57
+
58
+ ```bash
59
+ npm start
60
+ ```
61
+
62
+ To run a local development server that serves the basic demo located in `demo/index.html`
@@ -0,0 +1,65 @@
1
+ import { html } from 'lit';
2
+
3
+ const contactIcon = (status) => {
4
+ const statusMap = {
5
+ active: ['check_circle', 'Active'],
6
+ invited: ['mail', 'Invited'],
7
+ declined: ['do_not_disturb_on', 'Declined'],
8
+ suspended: ['warning', 'Suspended'],
9
+ removed: ['delete', 'Removed'],
10
+ };
11
+
12
+ const [icon, title] = statusMap[status] || [null, null];
13
+
14
+ if (icon && title) {
15
+ return html`<span class="${icon} material-icons" title="${title}"
16
+ >${icon}</span
17
+ >`;
18
+ }
19
+ return null;
20
+ };
21
+
22
+ export const columns = [
23
+ {
24
+ name: 'firstName',
25
+ header: 'First name',
26
+ bodyRenderer: (row) => html` <span>${row.firstName}</span>`,
27
+ sortable: true,
28
+ filterable: true,
29
+ hidden: false
30
+ },
31
+ {
32
+ name: 'lastName',
33
+ header: 'Last name',
34
+ bodyRenderer: (row) => html` <span>${row.lastName}</span>`,
35
+ sortable: true,
36
+ filterable: true,
37
+ },
38
+ {
39
+ name: 'email',
40
+ header: 'Email',
41
+ bodyRenderer: (row) => html` <span>${row.email}</span>`,
42
+ sortable: true,
43
+ filterable: true,
44
+ },
45
+ {
46
+ name: 'phone',
47
+ header: 'Phone',
48
+ bodyRenderer: (row) => html` <span>${row.phone}</span>`,
49
+ sortable: true,
50
+ },
51
+ {
52
+ name: 'accounts',
53
+ header: 'Account',
54
+ width: '40%',
55
+ bodyRenderer: (row) => html` <div class="accounts">
56
+ ${row.accounts.map(
57
+ (account) =>
58
+ html` ${contactIcon(account.status.toLowerCase())}<span
59
+ class="account-name"
60
+ >${account.name}</span
61
+ >`
62
+ )}
63
+ </div>`,
64
+ }
65
+ ]
@@ -0,0 +1,292 @@
1
+ export const contacts = [
2
+ {
3
+ "id": "user-id-001",
4
+ "firstName": "John",
5
+ "lastName": "Doe",
6
+ "email": "john.doe@google.com",
7
+ "phone": "+44892418222",
8
+ "status": "Active",
9
+ "accounts": [
10
+ {
11
+ "id": "microsoft-us-001",
12
+ "name": "Microsoft US",
13
+ "status": "ACTIVE"
14
+ },
15
+ {
16
+ "id": "google-ca-002",
17
+ "name": "Google Canada",
18
+ "status": "INVITED"
19
+ },
20
+ {
21
+ "id": "amazon-us-003",
22
+ "name": "Amazon US",
23
+ "status": "INACTIVE"
24
+ },
25
+ {
26
+ "id": "meta-emea-004",
27
+ "name": "Meta EMEA",
28
+ "status": "REMOVED"
29
+ }
30
+ ]
31
+ },
32
+ {
33
+ "id": "user-id-002",
34
+ "firstName": "John",
35
+ "lastName": "Smith",
36
+ "email": "john@smith.com",
37
+ "phone": "+447777777777",
38
+ "status": "Active",
39
+ "accounts": [
40
+ {
41
+ "id": "microsoft-us-001",
42
+ "name": "Microsoft US",
43
+ "status": "ACTIVE"
44
+ },
45
+ {
46
+ "id": "google-ca-002",
47
+ "name": "Google Canada",
48
+ "status": "ACTIVE"
49
+ }
50
+ ]
51
+ },
52
+ {
53
+ "id": "user-id-003",
54
+ "firstName": "Jane",
55
+ "lastName": "Smith",
56
+ "email": "jane.s@yahoo.com",
57
+ "phone": "+44867384383",
58
+ "status": "Active",
59
+ "accounts": [
60
+ {
61
+ "id": "microsoft-us-001",
62
+ "name": "Microsoft US",
63
+ "status": "ACTIVE"
64
+ },
65
+ {
66
+ "id": "google-ca-002",
67
+ "name": "Google Canada",
68
+ "status": "ACTIVE"
69
+ }
70
+ ]
71
+ },
72
+ {
73
+ "id": "user-id-004",
74
+ "firstName": "Michael",
75
+ "lastName": "Crout",
76
+ "email": "m.crout@gmail.com",
77
+ "phone": "+44852741827",
78
+ "status": "Active",
79
+ "accounts": [
80
+ {
81
+ "id": "microsoft-us-001",
82
+ "name": "Microsoft US",
83
+ "status": "ACTIVE"
84
+ },
85
+ {
86
+ "id": "google-ca-002",
87
+ "name": "Google Canada",
88
+ "status": "ACTIVE"
89
+ }
90
+ ]
91
+ },
92
+ {
93
+ "id": "user-id-005",
94
+ "firstName": "Brian S.",
95
+ "lastName": "Tropey",
96
+ "email": "briantropey@outlook.com",
97
+ "phone": "+44827463923",
98
+ "status": "Active",
99
+ "accounts": [
100
+ {
101
+ "id": "microsoft-us-001",
102
+ "name": "Microsoft US",
103
+ "status": "ACTIVE"
104
+ },
105
+ {
106
+ "id": "google-ca-002",
107
+ "name": "Google Canada",
108
+ "status": "ACTIVE"
109
+ }
110
+ ]
111
+ },
112
+ {
113
+ "id": "user-id-006",
114
+ "firstName": "Mary",
115
+ "lastName": "Stewart",
116
+ "email": "mary.stewart@gmail.com",
117
+ "phone": "+44837438442",
118
+ "status": "Active",
119
+ "accounts": [
120
+ {
121
+ "id": "microsoft-us-001",
122
+ "name": "Microsoft US",
123
+ "status": "ACTIVE"
124
+ },
125
+ {
126
+ "id": "google-ca-002",
127
+ "name": "Google Canada",
128
+ "status": "ACTIVE"
129
+ }
130
+ ]
131
+ },
132
+ {
133
+ "id": "user-id-007",
134
+ "firstName": "Josephina",
135
+ "lastName": "Miller",
136
+ "email": "josephinarmiller@gmail.com",
137
+ "phone": "+44837537812",
138
+ "status": "Active",
139
+ "accounts": [
140
+ {
141
+ "id": "microsoft-us-001",
142
+ "name": "Microsoft US",
143
+ "status": "ACTIVE"
144
+ },
145
+ {
146
+ "id": "google-ca-002",
147
+ "name": "Google Canada",
148
+ "status": "ACTIVE"
149
+ }
150
+ ]
151
+ },
152
+ {
153
+ "id": "user-id-008",
154
+ "firstName": "James",
155
+ "lastName": "Holmes",
156
+ "email": "j.holmes@yahoo.com",
157
+ "phone": "+44853573958",
158
+ "status": "Active",
159
+ "accounts": [
160
+ {
161
+ "id": "microsoft-us-001",
162
+ "name": "Microsoft US",
163
+ "status": "ACTIVE"
164
+ },
165
+ {
166
+ "id": "google-ca-002",
167
+ "name": "Google Canada",
168
+ "status": "ACTIVE"
169
+ }
170
+ ]
171
+ },
172
+ {
173
+ "id": "user-id-009",
174
+ "firstName": "Robert",
175
+ "lastName": "Collins",
176
+ "email": "rob.collins@gmail.com",
177
+ "phone": "+44384284278",
178
+ "status": "Active",
179
+ "accounts": [
180
+ {
181
+ "id": "microsoft-us-001",
182
+ "name": "Microsoft US",
183
+ "status": "ACTIVE"
184
+ },
185
+ {
186
+ "id": "google-ca-002",
187
+ "name": "Google Canada",
188
+ "status": "ACTIVE"
189
+ }
190
+ ]
191
+ },
192
+ {
193
+ "id": "user-id-010",
194
+ "firstName": "Darlene",
195
+ "lastName": "Lucas",
196
+ "email": "darlene.lucas@outlook.com",
197
+ "phone": "+44924284287",
198
+ "status": "Active",
199
+ "accounts": [
200
+ {
201
+ "id": "microsoft-us-001",
202
+ "name": "Microsoft US",
203
+ "status": "ACTIVE"
204
+ },
205
+ {
206
+ "id": "google-ca-002",
207
+ "name": "Google Canada",
208
+ "status": "ACTIVE"
209
+ }
210
+ ]
211
+ },
212
+ {
213
+ "id": "user-id-011",
214
+ "firstName": "Dorothy",
215
+ "lastName": "Villagomez",
216
+ "email": "dorothyvillagomez@outlook.com",
217
+ "phone": "+44981241282",
218
+ "status": "Active",
219
+ "accounts": [
220
+ {
221
+ "id": "microsoft-us-001",
222
+ "name": "Microsoft US",
223
+ "status": "ACTIVE"
224
+ },
225
+ {
226
+ "id": "google-ca-002",
227
+ "name": "Google Canada",
228
+ "status": "ACTIVE"
229
+ }
230
+ ]
231
+ },
232
+ {
233
+ "id": "user-id-012",
234
+ "firstName": "Richard",
235
+ "lastName": "Jackson",
236
+ "email": "ricky.jackson@gmail.com",
237
+ "phone": "+44772489128",
238
+ "status": "Active",
239
+ "accounts": [
240
+ {
241
+ "id": "microsoft-us-001",
242
+ "name": "Microsoft US",
243
+ "status": "ACTIVE"
244
+ },
245
+ {
246
+ "id": "google-ca-002",
247
+ "name": "Google Canada",
248
+ "status": "ACTIVE"
249
+ }
250
+ ]
251
+ },
252
+ {
253
+ "id": "user-id-013",
254
+ "firstName": "Janet",
255
+ "lastName": "Lewis",
256
+ "email": "j.lewis@gmail.com",
257
+ "phone": "+44218519222",
258
+ "status": "Active",
259
+ "accounts": [
260
+ {
261
+ "id": "microsoft-us-001",
262
+ "name": "Microsoft US",
263
+ "status": "ACTIVE"
264
+ },
265
+ {
266
+ "id": "google-ca-002",
267
+ "name": "Google Canada",
268
+ "status": "ACTIVE"
269
+ }
270
+ ]
271
+ },
272
+ {
273
+ "id": "user-id-014",
274
+ "firstName": "James",
275
+ "lastName": "Smoky",
276
+ "email": "Smoky@smith.com",
277
+ "phone": "+443333333333",
278
+ "status": "Active",
279
+ "accounts": [
280
+ {
281
+ "id": "microsoft-us-001",
282
+ "name": "Microsoft US",
283
+ "status": "ACTIVE"
284
+ },
285
+ {
286
+ "id": "google-ca-002",
287
+ "name": "Google Canada",
288
+ "status": "ACTIVE"
289
+ }
290
+ ]
291
+ }
292
+ ]
@@ -0,0 +1,92 @@
1
+ <!doctype html>
2
+ <html lang="en-GB">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200" />
6
+ <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200" />
7
+ <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Sharp:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200" />
8
+
9
+ <style>
10
+ body {
11
+ background: #fafafa;
12
+ }
13
+ </style>
14
+ </head>
15
+ <body>
16
+ <div id="demo"></div>
17
+
18
+ <script type="module">
19
+ import { html, render } from 'lit';
20
+ import '@digital-realty/theme';
21
+ import '../dist/ix-grid.js';
22
+ import { contacts } from './contacts.js';
23
+ import { columns } from './columns.js';
24
+
25
+ let pageData;
26
+ let pageNumber = 1;
27
+ const pageSize = 10;
28
+ let rowsLength = contacts.length;
29
+
30
+ const getPageData = (start, end, col, dir, filters = {}) => {
31
+ let thisPage = [...contacts];
32
+ // apply filters
33
+ Object.entries(filters).forEach(([filterName, filterVal])=>{
34
+ thisPage = thisPage.filter(row=>row[filterName].toLowerCase().includes(filterVal.toLowerCase()));
35
+ });
36
+ // sort
37
+ if(col !== '' && dir === 'asc'){
38
+ thisPage.sort(
39
+ (a,b) => a[col] > b[col] ? 1 : -1
40
+ )
41
+ } else if(col !== '' && dir === 'desc'){
42
+ thisPage.sort(
43
+ (a,b) => a[col] > b[col] ? -1 : 1
44
+ )
45
+ }
46
+ if(thisPage.length < contacts.length) {
47
+ rowsLength = thisPage.length;
48
+ } else {
49
+ rowsLength = contacts.length;
50
+ }
51
+ pageData = thisPage.slice(start,end);
52
+ }
53
+
54
+ const handleChange = (e) => {
55
+ // eslint-disable-next-line
56
+ const { columnName, page, pageSize, sortOrder, filters } = e.detail;
57
+ pageNumber = page;
58
+ const start = (page - 1) * pageSize;
59
+ const end = start + pageSize;
60
+ getPageData(start, end, columnName, sortOrder, filters);
61
+ // eslint-disable-next-line
62
+ refresh();
63
+ }
64
+
65
+ /*
66
+ localStorageID
67
+ @property({ type: String }) sortedColumn = '';
68
+
69
+ @property({ type: String }) sortDirection = '';
70
+ */
71
+
72
+ const refresh = () => render(
73
+ html`
74
+ <div data-theme="ix-theme" class="container">
75
+ <ix-grid
76
+ .columns=${columns}
77
+ .rows=${pageData}
78
+ .recordCount=${rowsLength}
79
+ .page=${pageNumber}
80
+ .pageSize=${pageSize}
81
+ @change=${handleChange}
82
+ ></ix-grid>
83
+ </div>
84
+ `,
85
+ document.querySelector('#demo')
86
+ );
87
+
88
+ getPageData(0,9,'firstName','asc');
89
+ refresh();
90
+ </script>
91
+ </body>
92
+ </html>
@@ -0,0 +1,46 @@
1
+ import { LitElement } from 'lit';
2
+ import '@vaadin/grid';
3
+ import '@digital-realty/ix-icon-button/ix-icon-button.js';
4
+ import '@digital-realty/ix-icon/ix-icon.js';
5
+ import './components/IxPagination.js';
6
+ import './components/IxGridColumnFilter.js';
7
+ import './components/IxGridRowFilter.js';
8
+ export interface Row {
9
+ [key: string]: string;
10
+ }
11
+ export interface Column {
12
+ name: string;
13
+ header: string;
14
+ bodyRenderer: (row: Row) => any;
15
+ width?: string;
16
+ sortable?: boolean;
17
+ filterable?: boolean;
18
+ hidden?: boolean;
19
+ frozenToEnd?: boolean;
20
+ }
21
+ export declare class IxGrid extends LitElement {
22
+ static readonly styles: import("lit").CSSResult[];
23
+ columns: Column[];
24
+ rows: Row[];
25
+ defaultEmptyText: string;
26
+ sortedColumn: string;
27
+ sortDirection: string;
28
+ hideHeader: boolean;
29
+ rowLimit: number;
30
+ page: number;
31
+ pageSize: number;
32
+ pageSizes: number[];
33
+ recordCount: number;
34
+ localStorageID: string | undefined;
35
+ private filters;
36
+ isLoading: boolean;
37
+ isExpanded: boolean;
38
+ get columnNames(): string[];
39
+ private updatePage;
40
+ handleSort(column?: string): void;
41
+ private renderColumnHeader;
42
+ private renderHeader;
43
+ private renderRowLimitControls;
44
+ private renderPaginationControls;
45
+ render(): import("lit").TemplateResult<1>;
46
+ }