design-system-next 2.7.10 → 2.7.11

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.
Binary file
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "design-system-next",
3
3
  "private": false,
4
- "version": "2.7.10",
4
+ "version": "2.7.11",
5
5
  "main": "./dist/design-system-next.js",
6
6
  "module": "./dist/design-system-next.js",
7
7
  "repository": {
@@ -92,7 +92,7 @@ export const useRadioButton = (
92
92
  );
93
93
 
94
94
  const labelClasses = classNames(
95
- 'spr-group spr-m-0 spr-inline-flex spr-w-auto spr-items-center spr-space-x-2 spr-p-0 spr-font-main',
95
+ 'spr-group spr-m-0 spr-inline-flex spr-w-auto spr-items-center spr-p-0 spr-font-main',
96
96
  'spr-text-color-strong spr-inline-flex spr-items-center spr-p-0',
97
97
  {
98
98
  'spr-text-color-disabled': disabled.value && !bordered.value,
@@ -18,7 +18,7 @@ interface Header {
18
18
  }
19
19
 
20
20
  export interface TableData {
21
- [key: string]: TableDataProps;
21
+ [key: string]: TableDataProps | string | number;
22
22
  }
23
23
 
24
24
  export interface TableDataProps {
@@ -132,16 +132,16 @@ export const tablePropTypes = {
132
132
  },
133
133
  isMultiSelect: {
134
134
  type: Boolean,
135
- default: false
135
+ default: false,
136
136
  },
137
137
  selectedKeyId: {
138
138
  type: String,
139
- default: ''
139
+ default: '',
140
140
  },
141
141
  returnCompleteSelectedProperties: {
142
142
  type: Boolean,
143
- default: false
144
- }
143
+ default: false,
144
+ },
145
145
  };
146
146
 
147
147
  export const tableEmitTypes = {
@@ -152,8 +152,11 @@ export const tableEmitTypes = {
152
152
  typeof rowData === 'object' && typeof rowKey === 'number',
153
153
  onHover: (value: { active: boolean; data: TableData }): value is { active: boolean; data: TableData } =>
154
154
  typeof value.active === 'boolean' && typeof value.data === 'object',
155
- 'update:selectedData': (value: TableDataProps[] | TableData[]): value is TableDataProps[] | TableData[] =>
156
- Array.isArray(value) && value.every(item => typeof item === 'object' && item !== null),
155
+ 'update:selectedData': (value: (string | number | TableDataProps)[] | TableData[]) =>
156
+ Array.isArray(value) &&
157
+ value.every(
158
+ (item) => (typeof item === 'object' || typeof item === 'string' || typeof item === 'number') && item !== null,
159
+ ),
157
160
  };
158
161
 
159
162
  export type TablePropTypes = ExtractPropTypes<typeof tablePropTypes>;
@@ -80,24 +80,24 @@
80
80
  <spr-avatar
81
81
  v-if="column.hasAvatar"
82
82
  size="lg"
83
- :src="sortedData[keyIndex][column.field].image"
83
+ :src="sortedDataItem(keyIndex, column.field).image"
84
84
  alt="User Avatar"
85
85
  :variant="column.avatarVariant ? column.avatarVariant : 'initial'"
86
- :initial="sortedData[keyIndex][column.field].title as string"
86
+ :initial="sortedDataItem(keyIndex, column.field).title as string"
87
87
  />
88
88
  <div
89
89
  v-if="column.hasIcon"
90
90
  class="spr-flex spr-items-center spr-rounded-full spr-bg-mushroom-200 spr-p-1"
91
91
  >
92
- <Icon :icon="sortedData[keyIndex][column.field].icon || ''" />
92
+ <Icon :icon="sortedDataItem(keyIndex, column.field).icon || ''" />
93
93
  </div>
94
94
  <div>
95
95
  <!-- Array Title -->
96
96
  <div
97
- v-if="Array.isArray(sortedData[keyIndex][column.field].title)"
97
+ v-if="Array.isArray(sortedDataItem(keyIndex, column.field).title)"
98
98
  class="spr-flex spr-flex-wrap spr-gap-2"
99
99
  >
100
- <div v-for="(cell, index) in sortedData[keyIndex][column.field].title" :key="index">
100
+ <div v-for="(cell, index) in sortedDataItem(keyIndex, column.field).title" :key="index">
101
101
  <div v-if="column.hasLozengeTitle" class="spr-mt-1">
102
102
  <spr-table-lozenge-title :cell="cell as LozengeTitle" />
103
103
  </div>
@@ -112,21 +112,21 @@
112
112
  <div v-if="column.hasLozengeTitle" class="spr-mt-1">
113
113
  <!-- Defining lozenge title in the title so it wont confuse the consumer; hence the title.title-->
114
114
  <!-- Also this structure allows multiple instances -->
115
- <spr-table-lozenge-title :cell="sortedData[keyIndex][column.field].title as LozengeTitle" />
115
+ <spr-table-lozenge-title :cell="sortedDataItem(keyIndex, column.field).title as LozengeTitle" />
116
116
  </div>
117
117
  <!-- Defining the chip title so it wont confuse the consumer; hence the title.title -->
118
118
  <!-- Also this structure allows multiple instances -->
119
119
  <div v-else-if="column.hasChipTitle" class="spr-mt-1">
120
- <spr-table-chips-title :cell="sortedData[keyIndex][column.field].title as ChipTitle" />
120
+ <spr-table-chips-title :cell="sortedDataItem(keyIndex, column.field).title as ChipTitle" />
121
121
  </div>
122
122
  <div v-else class="spr-text-color-strong spr-font-size-200 spr-font-normal">
123
- {{ sortedData[keyIndex][column.field].title }}
123
+ {{ sortedDataItem(keyIndex, column.field).title }}
124
124
  </div>
125
125
  </div>
126
126
 
127
127
  <!-- Subtitle -->
128
128
  <div v-if="column.hasSubtext" class="spr-text-color-base spr-text-xs spr-font-normal">
129
- {{ sortedData[keyIndex][column.field].subtext }}
129
+ {{ sortedDataItem(keyIndex, column.field).subtext }}
130
130
  </div>
131
131
  </div>
132
132
  </div>
@@ -199,5 +199,6 @@ const {
199
199
  handleRowClick,
200
200
  handleSelect,
201
201
  handleSelectAll,
202
+ sortedDataItem
202
203
  } = useTable(props, emit, slots);
203
204
  </script>
@@ -1,6 +1,6 @@
1
1
  import { ref, computed, toRefs, Slots, watch } from 'vue';
2
2
 
3
- import type { TablePropTypes, TableEmitTypes, TABLE_SORT, TableData } from './table';
3
+ import type { TablePropTypes, TableEmitTypes, TABLE_SORT, TableData, TableDataProps } from './table';
4
4
  import type { SetupContext } from 'vue';
5
5
 
6
6
  import classNames from 'classnames';
@@ -158,12 +158,28 @@ export const useTable = (props: TablePropTypes, emit: SetupContext<TableEmitType
158
158
  };
159
159
  });
160
160
 
161
+ //assert type TableDataProps
162
+ const sortedDataItem = (rowIndex: number, headerField: string) => {
163
+ return sortedData.value[rowIndex][headerField] as TableDataProps;
164
+ }
165
+
166
+ const isTableDataObject = (data: TableDataProps) => {
167
+ return typeof data === 'object' && 'title' in data
168
+ }
169
+
161
170
  const handleSelect = (item: TableData) => {
162
171
  if (!selectedKeyId.value || !(selectedKeyId.value in item)) return;
163
172
 
164
- const selectedIndex = selectedData.value.findIndex(
165
- (data) => data[selectedKeyId.value].title === item[selectedKeyId.value].title,
166
- );
173
+ const selectedIndex = selectedData.value.findIndex((data) => {
174
+ const typedData = data[selectedKeyId.value] as TableDataProps;
175
+ const typedItemData = item[selectedKeyId.value] as TableDataProps;
176
+
177
+ if (isTableDataObject(typedData) && isTableDataObject(typedItemData)) {
178
+ return typedData.title === typedItemData.title;
179
+ } else {
180
+ return data[selectedKeyId.value] === item[selectedKeyId.value];
181
+ }
182
+ });
167
183
 
168
184
  if (selectedIndex !== -1) {
169
185
  selectedData.value.splice(selectedIndex, 1);
@@ -182,7 +198,16 @@ export const useTable = (props: TablePropTypes, emit: SetupContext<TableEmitType
182
198
 
183
199
  const isRowSelected = (item: TableData) => {
184
200
  if (!selectedKeyId.value || !(selectedKeyId.value in item)) return false;
185
- return selectedData.value.some((data) => data[selectedKeyId.value].title === item[selectedKeyId.value].title);
201
+
202
+ return selectedData.value.some((data) => {
203
+ const typedData = data[selectedKeyId.value] as TableDataProps;
204
+ const typedItemData = item[selectedKeyId.value] as TableDataProps;
205
+ if (isTableDataObject(typedData) && isTableDataObject(typedItemData)) {
206
+ return typedData.title === typedItemData.title;
207
+ } else {
208
+ return data[selectedKeyId.value] === item[selectedKeyId.value];
209
+ }
210
+ });
186
211
  };
187
212
 
188
213
  watch(
@@ -191,7 +216,14 @@ export const useTable = (props: TablePropTypes, emit: SetupContext<TableEmitType
191
216
  if (returnCompleteSelectedProperties.value) {
192
217
  emit('update:selectedData', selectedData.value);
193
218
  } else {
194
- const mappedData = selectedData.value.map((item) => ({ ...item[selectedKeyId.value] }));
219
+ const mappedData = selectedData.value.map((item) => {
220
+ const typedItem = item[selectedKeyId.value] as TableDataProps | string | number;
221
+ if (typeof typedItem === 'object') {
222
+ return { ...typedItem };
223
+ } else {
224
+ return typedItem;
225
+ }
226
+ });
195
227
  emit('update:selectedData', mappedData);
196
228
  }
197
229
  },
@@ -214,5 +246,6 @@ export const useTable = (props: TablePropTypes, emit: SetupContext<TableEmitType
214
246
  isAllSelected,
215
247
  isRowSelected,
216
248
  isIndeterminate,
249
+ sortedDataItem
217
250
  };
218
251
  };