vi-grid-builder 1.0.6 → 2.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.
Files changed (63) hide show
  1. package/README.md +240 -11
  2. package/ViGridBuilderPlugin.js +35 -36
  3. package/package.json +6 -2
  4. package/playground/.vscode/extensions.json +3 -0
  5. package/playground/README.md +29 -0
  6. package/playground/index.html +13 -0
  7. package/playground/jsconfig.json +8 -0
  8. package/playground/package-lock.json +2524 -0
  9. package/playground/package.json +20 -0
  10. package/playground/public/favicon.ico +0 -0
  11. package/playground/src/App.vue +84 -0
  12. package/playground/src/assets/base.css +86 -0
  13. package/playground/src/assets/logo.svg +1 -0
  14. package/playground/src/assets/main.css +35 -0
  15. package/playground/src/components/ActionsField.vue +99 -0
  16. package/playground/src/components/ClickableRow.vue +68 -0
  17. package/playground/src/components/ClientSideData.vue +86 -0
  18. package/playground/src/components/ColumnVisibility.vue +85 -0
  19. package/playground/src/components/CustomField.vue +64 -0
  20. package/playground/src/components/CustomHeader.vue +85 -0
  21. package/playground/src/components/GlobalOptions.vue +68 -0
  22. package/playground/src/components/LoadingSlot.vue +11 -0
  23. package/playground/src/components/PaginationOptions.vue +130 -0
  24. package/playground/src/components/RowSelect.vue +72 -0
  25. package/playground/src/components/ServerSideData.vue +62 -0
  26. package/playground/src/components/SortableColumnServerSide.vue +73 -0
  27. package/playground/src/components/TableStyle.vue +112 -0
  28. package/playground/src/components/fields/SampleCustomField.vue +24 -0
  29. package/playground/src/components/icons/IconCommunity.vue +7 -0
  30. package/playground/src/components/icons/IconDocumentation.vue +7 -0
  31. package/playground/src/components/icons/IconEcosystem.vue +7 -0
  32. package/playground/src/components/icons/IconSupport.vue +7 -0
  33. package/playground/src/components/icons/IconTooling.vue +19 -0
  34. package/playground/src/main.js +51 -0
  35. package/playground/vite.config.js +17 -0
  36. package/src/ViGridBuilder.scss +157 -58
  37. package/src/ViGridBuilder.vue +367 -207
  38. package/src/ViGridField.scss +1 -2
  39. package/src/ViGridField.vue +13 -6
  40. package/src/ViGridHeadCell.vue +32 -0
  41. package/src/ViGridHeadColumnCell.vue +42 -0
  42. package/src/ViGridHeader.vue +67 -0
  43. package/src/composables/useColumns.js +21 -0
  44. package/src/composables/useGridActions.js +17 -3
  45. package/src/composables/useGridSettings.js +18 -0
  46. package/src/composables/usePagination.js +39 -0
  47. package/src/composables/useRowHelper.js +38 -0
  48. package/src/composables/useRowSelect.js +53 -0
  49. package/src/composables/useSettings.js +29 -0
  50. package/src/composables/useSort.js +103 -0
  51. package/src/fields/ViGridActions.scss +0 -1
  52. package/src/fields/ViGridActions.vue +37 -13
  53. package/src/fields/ViGridCheckbox.vue +31 -0
  54. package/src/fields/ViGridNumber.vue +18 -0
  55. package/src/fields/partials/ViGridKebabMenu.scss +60 -25
  56. package/src/fields/partials/ViGridKebabMenu.vue +75 -54
  57. package/src/fields/partials/{ViGridBuilderActions.vue → ViGridSimpleActions.vue} +3 -3
  58. package/src/settings/GridSettings.js +24 -0
  59. package/vite.config.js +12 -2
  60. package/src/examples/App.vue +0 -123
  61. package/src/examples/components/TableTitle.vue +0 -20
  62. package/src/examples/main.js +0 -11
  63. /package/src/fields/partials/{ViGridBuilderActions.scss → ViGridSimpleActions.scss} +0 -0
package/README.md CHANGED
@@ -1,17 +1,246 @@
1
- # Vue 3 + Vite
2
1
 
3
- This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
2
+ # Grid builder plugin for Vue 3
4
3
 
5
- ## Recommended IDE Setup
6
4
 
7
- - [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin).
5
+ ## Installation
8
6
 
7
+ ```sh
8
+ npm install vi-grid-builder
9
+ ```
9
10
 
10
- import TableTitle from "./components/TableTitle.vue";
11
- createApp(App)
12
- .use(ViGridBuilderPlugin, {
13
- defaultSlots:{
14
- title: TableTitle
11
+ ## Integrate plugin in Vue app
12
+
13
+ ```js
14
+ import ViGridBuilder from "vi-grid-builder";
15
+ import {createApp} from 'vue'
16
+ import App from './App.vue'
17
+
18
+ const app = createApp(App).use(ViGridBuilder)
19
+ ```
20
+
21
+ ## Table options
22
+
23
+ | option | type | description | default value |
24
+ |------------|-----------------------------|--------------------------------------------------------|---------------|
25
+ |rows| Array | Data that needs to be displayed in the table| /
26
+ |row-key|String| Name of the field that is unique identifier for a single row|/
27
+ |columns| Array| Config for the column (in details below)|/
28
+ |title| String | Title for the table | /
29
+ |pagination|Object| Pagination config for the rows| in detilas under pagination section
30
+ |rowsNumber| Number| Total number of rows| /
31
+ |disable-pagination| Boolean| Option to hide pagination| false
32
+ |server-mode| Boolean | Is data fetched from server| true
33
+ |fetch-server-data| Function | Function that will fetch data from server|/
34
+ |fetch-on-init| Boolean| On initialisation make request to fetch data| true
35
+ |filter|fdf|fdf|fr
36
+ |loading| Boolean| For server side **loading** is handled, for client side you can you this prop| false
37
+ |no-data-label| String| Text to display when there is no data in the table|No data found
38
+ |no-cell-data-label| String| Text to display if there is no value for the cell| "/" is displayed by default
39
+ |clcikable-row| Boolean| emits rowClicked event with row as argumnet|false
40
+
41
+ ## Header options
42
+
43
+ | option | type | decsription | default value
44
+ |--|--| --| --
45
+ | title | String | title for the table | /
46
+
47
+ ## Header slots
48
+ |name | description | props
49
+ |--|--| --|
50
+ | title | slot for displaying title on top of the table| title
51
+ | vi-header-cell-[column_name] | slot for override default header cell for each column| column
52
+
53
+ ## Columns options
54
+
55
+ | option | type | description | default value |
56
+ |------------|-----------------------------|--------------------------------------------------------|---------------|
57
+ | label | String | Title for the column | / |
58
+ |type| text, link, image, date, badge, actions| Type of the field| text
59
+ | name | String | Name of the field for which data will be presented | / |
60
+ | sortable | Boolean | Is the column sortable? | false |
61
+ | isVisible | Boolean | Is the column visible? | true |
62
+ | format | Function | Function to format the data before display | / |
63
+ | align | centre, left, right | How to align the content in the cells for this column | / |
64
+ | sort | Function | Compare function for sorting data in this column | / |
65
+ mode| date, dateTime, time| Option for date field | dateTime|
66
+ format| String| Option for formatting the date field | yyyy-MM-dd HH:mm:ss
67
+ actions |Array| Option for field of type action | /|
68
+ link |String| Option for field of type link, this will be name of the field from which we need to get the link, and name attribute is for the text of the link| /
69
+
70
+ ## Example config for columns
71
+
72
+ ```js
73
+ columns: [
74
+ {
75
+ label: 'ID',
76
+ type: 'vi-grid-text',
77
+ name: 'id',
78
+ sortable: true,
79
+ align: 'right'
80
+ },
81
+ {
82
+ label: 'Name',
83
+ type: 'vi-grid-text',
84
+ name: 'user',
85
+ format: (row) => `${row.firstName} ${row.lastName}`,
86
+ align: 'center'
87
+ },
88
+ {
89
+ label: 'Hidden column',
90
+ type: 'vi-grid-text',
91
+ name: 'title',
92
+ isVisible: false // This can be a function as well
93
+ },
94
+ {
95
+ label: 'Hidden column with custom rule',
96
+ type: 'vi-grid-text',
97
+ name: 'title',
98
+ isVisible: () => user.role === 'member'
15
99
  }
16
- })
17
- .mount('#app')
100
+ ]
101
+ ```
102
+
103
+ ## Table body slots
104
+ |name | description | props
105
+ |--|--| --|
106
+ | empty-data | slot for when no data in table| /
107
+ | loading | slot for displaying loading when data is fetching from server| /
108
+ |footer | slot for overriding footer of table | pagination
109
+
110
+ ## Registering custom field type
111
+ By default the gird builder for displaying data in the cells supports the following types of fields : **text**, **link**, **image**, **date** , **badge**, **actions** and **checkbox**?. If this fields does not full-fill the needs for you application you can register your own type of fields.
112
+ For example if we need an "avatar" field that will display the user's picture and if there is no picture for the user it will display the user's initials.
113
+ First we need to create the component for the new field, and then we need to define it in the options for the plugin. Props that you will receive for the custom field are:
114
+
115
+ - **field** - all options for the column
116
+ - **value** - value for the field or '/' if no value
117
+ - **original-value** - original value for the field
118
+ - **row** - value for the whole row (ex if the table display name and id of a user, that row would be one user)
119
+
120
+ The componenet can look like this
121
+
122
+ ```js
123
+ <template>
124
+ <div class="avatar">
125
+ <img v-if="row.picture" :src="row.picture" alt="User Avatar" class="avatar-img" />
126
+ <div v-else class="avatar-initials">{{ initials }}</div>
127
+ </div>
128
+ </template>
129
+
130
+ <script>
131
+ export default {
132
+ name: 'UserAvatar',
133
+ props: {
134
+ field: {
135
+ type: Object,
136
+ },
137
+ value: {},
138
+ originalValue: {},
139
+ row: {
140
+ type: Object,
141
+ }
142
+ },
143
+ computed: {
144
+ initials() {
145
+ if (this.row.name) {
146
+ const nameParts = this.row.name.split(' ');
147
+ return nameParts.map(part => part[0].toUpperCase()).join('');
148
+ }
149
+ return '';
150
+ }
151
+ }
152
+ };
153
+ </script>
154
+ ```
155
+ Then we need to add this component as part of the settings for the plugin.
156
+ See example:
157
+
158
+ ```js
159
+ import UserAvatar from "./components/user/UserAvatar.vue";
160
+ import ViGridBuilder from "vi-grid-builder";
161
+
162
+ const app = createApp(App)
163
+ .use(ViGridBuilder, {
164
+ fieldComponents:{
165
+ UserAvatar
166
+ }
167
+ })
168
+
169
+ After adding the component in the fieldComponents we can use the new field type in the definition for the columns, like this :
170
+
171
+ columns: [
172
+ {
173
+ label: 'User',
174
+ type: 'user-avatar',
175
+ name: 'picture',
176
+ }]
177
+ ```
178
+
179
+
180
+ ## Pagination
181
+
182
+ Pagination is passed as object in table prop, the obejct should have this fields:
183
+
184
+ |name |type| description | default value
185
+ |--|--|--|--|
186
+ | page | Number|number for the current page| /
187
+ | rowsPerPage | Number|number of rows displayed per page| 10
188
+ |rowsNumber | Number| number of total avaliable rows - only for server side| /
189
+ |sortBy | array of objects | sort by field and direction| null
190
+
191
+
192
+
193
+
194
+
195
+ ## Pagination otpions
196
+
197
+
198
+ |name | type| description | default value
199
+ |--|--| --|--|
200
+ |disablePagination | Boolean| hide pagination | false
201
+ | compactPagination | Boolean| should the pagination be compact (no pages displayed) | false
202
+ | rowsPerPageOptions |Array of obecjts| Droprdown options for displayin how many rows per page| /
203
+
204
+
205
+ ## Table css classes
206
+
207
+ |class name | description
208
+ |--|--|
209
+ | .vi-table-container | wrapper around table|
210
+ | .vi-table-container.loading| classes for loading state of table|
211
+ | .vi-table | class for the table tag|
212
+ | .vi-table.stripped | class used to apply alternating background colors to table rows|
213
+ | .vi-table.bordered | class used to apply borders on table cells|
214
+ | .vi-table-head | class for the head tag|
215
+ | .vi-table-body | class for the tbody tag|
216
+ | .vi-table-row| class for all rows in table|
217
+ | .vi-header-row| class for rows only in table header|
218
+ | .vi-body-row| class for rows only in table body|
219
+ | .vi-body-row.selected| class for selected row|
220
+ | .vi-body-row.clickable| class for clickable row|
221
+ | .vi-title-row| class for row that displays the table tite|
222
+ | .vi-loading-row| class for row that holds the loading bar|
223
+ | .vi-no-data-row| class for row that appears when no data is avaliable in table|
224
+ | .vi-cell| class for all cells in table|
225
+ | .vi-header-cell| class for header cells in table|
226
+ | .vi-body-cell| class for body cells in table|
227
+ | .vi-header-cell-content| class that wrapes content in header cells|
228
+ | .vi-select-cell| class for cells that holds checkbox for selecting row or master select|
229
+ | .vi-grid-field| wraaper clas for content in body cells|
230
+ | .vi-footer-row| class for last row in table that holds usually pagination|
231
+ | .vi-footer-cell| class for cell in last row|
232
+
233
+
234
+
235
+
236
+
237
+
238
+
239
+
240
+
241
+
242
+
243
+
244
+
245
+
246
+
@@ -1,51 +1,50 @@
1
1
  import ViGridBuilder from "./src/ViGridBuilder.vue"
2
2
  import DateSettings from "./src/settings/DateSettings.js"
3
3
  import ViPaginationPlugin from 'vi-pagination'
4
- import fieldMixin from "./src/mixins/field-mixin.js"
5
- import {useGridActions} from "./src/composables/useGridActions.js"
4
+ import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
5
+
6
+ import { library } from '@fortawesome/fontawesome-svg-core'
7
+ import {globalGridSettings} from "./src/composables/useSettings.js";
8
+ /* import specific icons */
9
+ import { faChevronDown, faChevronUp, faEllipsisH} from '@fortawesome/free-solid-svg-icons'
10
+
11
+
6
12
  export default {
7
- install(app, options ={pagination:{}, fieldComponents:{}, defaultSlots:{}, dateFormats: {}}) {
13
+ install(app, options ={}) {
14
+ library.add(faChevronDown, faChevronUp,faEllipsisH)
15
+
16
+ const {fieldComponents, dateFormats, style, ...restGridSettings} = options
8
17
 
9
- // if (options?.fieldComponents) {
10
- // Object.keys(options.fieldComponents).forEach(key => {
11
- // ViGridBuilder.components[key] = options.fieldComponents[key]
12
- // });
13
- // }
14
18
  app.provide('ViDateSettings', {
15
19
  ...DateSettings,
16
20
  format:{
17
21
  ...DateSettings.format,
18
- ...options?.dateFormats
22
+ ...dateFormats
19
23
  }
20
24
  });
21
25
 
22
- app.use(ViPaginationPlugin, options?.pagination);
23
- app.component('ViGridBuilder', {
24
- extends:ViGridBuilder,
25
- components:options.fieldComponents ?? {},
26
- props:{
27
- defaultSlots: {
28
- type: Object,
29
- default: function () {
30
-
31
- return options?.defaultSlots ?? {}
32
- }
33
- },
34
- noDataLabel:{
35
- type: String,
36
- default: options.noDataLabel ?? 'No data found'
37
- },
38
- noCellDataLabel:{
39
- type: String,
40
- default: options.noCellDataLabel ?? '/'
41
- }
26
+ // // Set CSS variables in :root
27
+ if (style) {
28
+ for (const [key, value] of Object.entries(style)) {
29
+ document.documentElement.style.setProperty(`--vi-grid-${key}`, value);
42
30
  }
43
- });
31
+ }
32
+
33
+ app.use(ViPaginationPlugin, {}, style);
34
+ app.component('FontAwesomeIcon',FontAwesomeIcon);
35
+
36
+ globalGridSettings.value = restGridSettings;
37
+
38
+
39
+ const ViGridBuilderExtended = {
40
+ ...ViGridBuilder,
41
+ components:{
42
+ ...ViGridBuilder.components,
43
+ ...options.fieldComponents ?? {},
44
+ },
45
+ }
46
+
47
+ app.component('ViGridBuilder', ViGridBuilderExtended);
48
+
44
49
  }
45
50
  };
46
- const mixins = {fieldMixin};
47
- const composables = {useGridActions};
48
- export {
49
- mixins,
50
- composables
51
- }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vi-grid-builder",
3
3
  "main": "ViGridBuilderPlugin",
4
- "version": "1.0.6",
4
+ "version": "2.0.1",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
@@ -9,8 +9,12 @@
9
9
  "preview": "vite preview"
10
10
  },
11
11
  "dependencies": {
12
+ "@fortawesome/fontawesome-svg-core": "^6.7.1",
13
+ "@fortawesome/free-regular-svg-icons": "^6.7.1",
14
+ "@fortawesome/free-solid-svg-icons": "^6.7.1",
15
+ "@fortawesome/vue-fontawesome": "^3.0.8",
12
16
  "date-fns": "^2.30.0",
13
- "vi-pagination": "^0.0.8",
17
+ "vi-pagination": "^1.0.0",
14
18
  "vue": "^3.3.4"
15
19
  },
16
20
  "devDependencies": {
@@ -0,0 +1,3 @@
1
+ {
2
+ "recommendations": ["Vue.volar"]
3
+ }
@@ -0,0 +1,29 @@
1
+ # vi-grid-builder-playground
2
+
3
+ This template should help get you started developing with Vue 3 in Vite.
4
+
5
+ ## Recommended IDE Setup
6
+
7
+ [VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).
8
+
9
+ ## Customize configuration
10
+
11
+ See [Vite Configuration Reference](https://vite.dev/config/).
12
+
13
+ ## Project Setup
14
+
15
+ ```sh
16
+ npm install
17
+ ```
18
+
19
+ ### Compile and Hot-Reload for Development
20
+
21
+ ```sh
22
+ npm run dev
23
+ ```
24
+
25
+ ### Compile and Minify for Production
26
+
27
+ ```sh
28
+ npm run build
29
+ ```
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html lang="">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <link rel="icon" href="/favicon.ico">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>Vite App</title>
8
+ </head>
9
+ <body>
10
+ <div id="app"></div>
11
+ <script type="module" src="/src/main.js"></script>
12
+ </body>
13
+ </html>
@@ -0,0 +1,8 @@
1
+ {
2
+ "compilerOptions": {
3
+ "paths": {
4
+ "@/*": ["./src/*"]
5
+ }
6
+ },
7
+ "exclude": ["node_modules", "dist"]
8
+ }