design-system-next 2.7.17 → 2.7.19

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.
@@ -124,7 +124,7 @@ export const useTable = (props: TablePropTypes, emit: SetupContext<TableEmitType
124
124
  'spr-h-[360px]': !fullHeight.value && !slots.footer,
125
125
  });
126
126
 
127
- const emptyStateClasses = classNames({
127
+ const emptyStateBaseClasses = classNames({
128
128
  'spr-overflow-y-hidden spr-h-[calc(90vh-150px)] md:spr-h-[calc(80vh-150px)] sm:spr-h-[calc(70vh-150px)]':
129
129
  fullHeight.value && slots.footer, // Adjust tbody height for header/footer
130
130
  'spr-overflow-y-auto spr-h-[75vh]': fullHeight.value && !slots.footer, // Adjust tbody height for header/footer
@@ -154,10 +154,12 @@ export const useTable = (props: TablePropTypes, emit: SetupContext<TableEmitType
154
154
  tableBackgroundClasses,
155
155
  tableBodyClasses,
156
156
  tableFooterClasses,
157
- emptyStateClasses,
157
+ emptyStateBaseClasses,
158
158
  };
159
159
  });
160
160
 
161
+ const emptyStateClasses = computed(() => `${getTableClasses.value.emptyStateBaseClasses} ${props.emptyStateCustomClasses}` )
162
+
161
163
  //assert type TableDataProps
162
164
  const sortedDataItem = (rowIndex: number, headerField: string) => {
163
165
  return sortedData.value[rowIndex][headerField] as TableDataProps;
@@ -186,6 +188,8 @@ export const useTable = (props: TablePropTypes, emit: SetupContext<TableEmitType
186
188
  } else {
187
189
  selectedData.value.push(item);
188
190
  }
191
+
192
+ emitSelectedData()
189
193
  };
190
194
 
191
195
  const handleSelectAll = () => {
@@ -194,6 +198,8 @@ export const useTable = (props: TablePropTypes, emit: SetupContext<TableEmitType
194
198
  } else {
195
199
  selectedData.value = [...sortedData.value];
196
200
  }
201
+
202
+ emitSelectedData()
197
203
  };
198
204
 
199
205
  const isRowSelected = (item: TableData) => {
@@ -210,9 +216,7 @@ export const useTable = (props: TablePropTypes, emit: SetupContext<TableEmitType
210
216
  });
211
217
  };
212
218
 
213
- watch(
214
- () => selectedData.value.length,
215
- () => {
219
+ const emitSelectedData = () => {
216
220
  if (returnCompleteSelectedProperties.value) {
217
221
  emit('update:selectedData', selectedData.value);
218
222
  } else {
@@ -226,8 +230,31 @@ export const useTable = (props: TablePropTypes, emit: SetupContext<TableEmitType
226
230
  });
227
231
  emit('update:selectedData', mappedData);
228
232
  }
229
- },
230
- );
233
+ }
234
+
235
+ watch(sortedData, (newVal) => {
236
+ if(newVal && props.isMultiSelect && selectedData.value.length > 0) {
237
+ // Remove items from selectedData that are not in the new sortedData
238
+ // This is to ensure that the selectedData is always in sync with the sortedData
239
+
240
+ newVal.forEach((item) => {
241
+ const selectedIndex = selectedData.value.findIndex((data) => {
242
+ const typedSelectedData = data[selectedKeyId.value] as TableDataProps;
243
+ const typedSortedData = item[selectedKeyId.value] as TableDataProps;
244
+
245
+ if (isTableDataObject(typedSelectedData) && isTableDataObject(typedSortedData)) {
246
+ return typedSelectedData.title === typedSortedData.title;
247
+ } else {
248
+ return data[selectedKeyId.value] === item[selectedKeyId.value];
249
+ }
250
+ });
251
+
252
+ if (selectedIndex === -1) {
253
+ selectedData.value.splice(selectedIndex, 1);
254
+ }
255
+ })
256
+ }
257
+ });
231
258
 
232
259
  return {
233
260
  sortData,
@@ -246,6 +273,7 @@ export const useTable = (props: TablePropTypes, emit: SetupContext<TableEmitType
246
273
  isAllSelected,
247
274
  isRowSelected,
248
275
  isIndeterminate,
249
- sortedDataItem
276
+ sortedDataItem,
277
+ emptyStateClasses
250
278
  };
251
279
  };