@wishbone-media/spark 0.15.3 → 0.16.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wishbone-media/spark",
3
- "version": "0.15.3",
3
+ "version": "0.16.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -22,6 +22,7 @@
22
22
  "@formkit/themes": "^1.6.9",
23
23
  "@formkit/vue": "^1.6.9",
24
24
  "@fortawesome/fontawesome-svg-core": "^7.1.0",
25
+ "@fortawesome/pro-duotone-svg-icons": "^7.1.0",
25
26
  "@fortawesome/pro-regular-svg-icons": "^7.1.0",
26
27
  "@fortawesome/vue-fontawesome": "^3.1.2",
27
28
  "@handsontable/vue3": "^16.1.1",
@@ -26,6 +26,10 @@
26
26
  .spark-table-table thead th {
27
27
  @apply !border-t-0 !border-x-0;
28
28
 
29
+ &.can-sort .relative {
30
+ @apply cursor-pointer;
31
+ }
32
+
29
33
  &.ht__highlight .relative {
30
34
  @apply bg-gray-200;
31
35
  }
@@ -39,6 +43,33 @@
39
43
  tracking-wider focus:outline-hidden drop-shadow-sm filter flex items-center;
40
44
 
41
45
  @apply !px-5 !py-3;
46
+
47
+ .fa-sort-up,
48
+ .fa-sort-down {
49
+ @apply hidden;
50
+ }
51
+
52
+ &.asc {
53
+ .fa-sort-up {
54
+ @apply inline;
55
+ }
56
+
57
+ .fa-sort,
58
+ .fa-sort-down {
59
+ @apply hidden;
60
+ }
61
+ }
62
+
63
+ &.desc {
64
+ .fa-sort-down {
65
+ @apply inline;
66
+ }
67
+
68
+ .fa-sort,
69
+ .fa-sort-up {
70
+ @apply hidden;
71
+ }
72
+ }
42
73
  }
43
74
 
44
75
  .colHeader {
@@ -64,6 +95,5 @@
64
95
  }
65
96
 
66
97
  .spark-table-head-sorting {
67
- /* hidden for now */
68
- @apply hidden;
98
+ @apply absolute right-5 w-5 h-5 border border-gray-200 rounded-md grid place-items-center;
69
99
  }
@@ -75,7 +75,7 @@ import {
75
75
  } from 'handsontable/plugins'
76
76
  import { registerAllCellTypes } from 'handsontable/cellTypes'
77
77
  import { watchDebounced } from '@vueuse/core'
78
- import { customiseHeader } from '@/utils/sparkTable/header.js'
78
+ import { customiseHeader, syncSortClasses } from '@/utils/sparkTable/header.js'
79
79
  import { registerSparkRenderers } from '@/utils/sparkTable/renderers'
80
80
  import { updateRow } from '@/utils/sparkTable/update-row.js'
81
81
  import SparkTablePaginationDetails from './SparkTablePaginationDetails.vue'
@@ -324,6 +324,7 @@ const sparkTable = reactive({
324
324
  afterGetColHeader: (col, th) => customiseHeader(col, th, sparkTable),
325
325
  }),
326
326
  afterChange: (changes, source) => updateRow(changes, source, sparkTable),
327
+ afterRender: () => syncSortClasses(sparkTable),
327
328
  },
328
329
  ...props.settings,
329
330
  })),
@@ -42,6 +42,12 @@ import {
42
42
  faUndo,
43
43
  } from '@fortawesome/pro-regular-svg-icons'
44
44
 
45
+ import {
46
+ faSort as faSortDuotone,
47
+ faSortDown as faSortDownDuotone,
48
+ faSortUp as faSortUpDuotone,
49
+ } from '@fortawesome/pro-duotone-svg-icons'
50
+
45
51
  export const Icons = {
46
52
  farArrowLeftToLine: faArrowLeftToLine,
47
53
  farArrowRightToLine: faArrowRightToLine,
@@ -81,6 +87,9 @@ export const Icons = {
81
87
  farSignOut: faSignOut,
82
88
  farEye: faEye,
83
89
  farUndo: faUndo,
90
+ fadSort: faSortDuotone,
91
+ fadSortDown: faSortDownDuotone,
92
+ fadSortUp: faSortUpDuotone,
84
93
  }
85
94
 
86
95
  export function addIcons(newIcons) {
@@ -11,33 +11,36 @@ const customSort = (prop, th, sparkTable) => {
11
11
  const iconContainer = document.createElement('span')
12
12
  iconContainer.classList.add('spark-table-head-sorting')
13
13
  iconContainer.innerHTML =
14
- icon({ prefix: 'far', iconName: 'sort' }).html +
15
- icon({ prefix: 'far', iconName: 'sort-up' }).html +
16
- icon({ prefix: 'far', iconName: 'sort-down' }).html
14
+ icon({ prefix: 'fad', iconName: 'sort' }).html +
15
+ icon({ prefix: 'fad', iconName: 'sort-up' }).html +
16
+ icon({ prefix: 'fad', iconName: 'sort-down' }).html
17
17
  heading.appendChild(iconContainer)
18
18
 
19
19
  heading.addEventListener('click', async () => {
20
- const currentSorting = sparkTable.params.sort
20
+ const currentOrderingBy = sparkTable.params.orderBy
21
+ const currentSortingBy = sparkTable.params.sortedBy
21
22
 
22
- if (currentSorting === prop) {
23
+ if (currentOrderingBy === prop && currentSortingBy === 'asc') {
23
24
  heading.classList.remove('asc')
24
25
  heading.classList.add('desc')
25
26
 
26
27
  return sparkTable.methods.applyParams({
27
- sort: `-${prop}`,
28
+ orderBy: prop,
29
+ sortedBy: 'desc',
28
30
  })
29
31
  }
30
32
 
31
- if (currentSorting === `-${prop}`) {
33
+ if (currentOrderingBy === prop) {
32
34
  heading.classList.remove('desc')
33
35
 
34
- return await sparkTable.methods.removeParam('sort')
36
+ return await sparkTable.methods.clearParams(['orderBy', 'sortedBy'])
35
37
  }
36
38
 
37
39
  heading.classList.add('asc')
38
40
 
39
41
  return sparkTable.methods.applyParams({
40
- sort: prop,
42
+ orderBy: prop,
43
+ sortedBy: 'asc',
41
44
  })
42
45
  })
43
46
  }
@@ -134,4 +137,33 @@ const customiseHeader = (col, th, sparkTable) => {
134
137
  }
135
138
  }
136
139
 
137
- export { customiseHeader }
140
+ const syncSortClasses = (sparkTable) => {
141
+ if (!sparkTable.hotInstance || !sparkTable.hotInstance.rootElement) {
142
+ return
143
+ }
144
+
145
+ const orderBy = sparkTable.params.orderBy
146
+ const sortedBy = sparkTable.params.sortedBy
147
+
148
+ // Get all sortable headers and clear their sort classes
149
+ const headers = sparkTable.hotInstance.rootElement.querySelectorAll('thead th.can-sort .relative')
150
+
151
+ headers.forEach((heading) => {
152
+ heading.classList.remove('asc', 'desc')
153
+ })
154
+
155
+ // If there's an active sort, find the corresponding heading and add the class
156
+ if (orderBy && sortedBy) {
157
+ headers.forEach((heading) => {
158
+ const th = heading.closest('th')
159
+ const colIndex = Array.from(th.parentElement.children).indexOf(th)
160
+ const prop = sparkTable.methods.colToProp(colIndex)
161
+
162
+ if (prop === orderBy) {
163
+ heading.classList.add(sortedBy)
164
+ }
165
+ })
166
+ }
167
+ }
168
+
169
+ export { customiseHeader, syncSortClasses }