@globalbrain/sefirot 2.28.0 → 2.29.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.
@@ -114,6 +114,16 @@ function lockBody(value: boolean) {
114
114
  function updateColWidth(key: string, value: string) {
115
115
  colWidths[key] = value
116
116
  }
117
+
118
+ function isSummary(index: number) {
119
+ return index === records?.value?.length
120
+ }
121
+
122
+ function getCell(key: string, index: number) {
123
+ return (isSummary(index) && columns.value[key]?.summaryCell)
124
+ ? columns.value[key]?.summaryCell
125
+ : columns.value[key]?.cell
126
+ }
117
127
  </script>
118
128
 
119
129
  <template>
@@ -171,7 +181,7 @@ function updateColWidth(key: string, value: string) {
171
181
  v-for="(record, rIndex) in recordsWithSummary"
172
182
  :key="rIndex"
173
183
  class="row"
174
- :class="rIndex === records?.length && 'summary'"
184
+ :class="isSummary(rIndex) && 'summary'"
175
185
  >
176
186
  <STableItem
177
187
  v-for="key in orders"
@@ -182,9 +192,9 @@ function updateColWidth(key: string, value: string) {
182
192
  >
183
193
  <STableCell
184
194
  :name="key"
185
- :class="rIndex === records?.length && 'summary'"
195
+ :class="isSummary(rIndex) && 'summary'"
186
196
  :class-name="columns[key].className"
187
- :cell="columns[key].cell"
197
+ :cell="getCell(key, rIndex)"
188
198
  :value="record[key]"
189
199
  :record="record"
190
200
  :records="records"
@@ -6,14 +6,15 @@ import type { DropdownSection } from './Dropdown'
6
6
 
7
7
  export interface Table<
8
8
  O extends string = any,
9
- R extends Record<string, any> = any
9
+ R extends Record<string, any> = any,
10
+ SR extends Record<string, any> = any
10
11
  > {
11
12
  orders: O[]
12
- columns: TableColumns<O, R>
13
+ columns: TableColumns<O, R, SR>
13
14
  records?: R[] | null
14
15
  header?: boolean
15
16
  footer?: boolean
16
- summary?: TableSummary<R> | null
17
+ summary?: SR | null
17
18
  total?: number | null
18
19
  page?: number | null
19
20
  perPage?: number | null
@@ -27,21 +28,23 @@ export interface Table<
27
28
 
28
29
  export type TableColumns<
29
30
  O extends string,
30
- R extends Record<string, any>
31
+ R extends Record<string, any>,
32
+ SR extends Record<string, any>
31
33
  > = {
32
- [K in O]: K extends keyof R
33
- ? TableColumn<R[K], R>
34
- : TableColumn<undefined, R>
34
+ [K in O]: TableColumn<R[K], R, SR[K], SR>
35
35
  }
36
36
 
37
- export interface TableColumn<V, R> {
37
+ export interface TableColumn<V, R, SV, SR> {
38
38
  label?: string
39
39
  className?: string
40
40
  dropdown?: DropdownSection[]
41
41
  resizable?: boolean
42
- cell?: TableCell | ((value: V, record: R) => TableCell)
42
+ cell?: TableCell | TableColumnCellFn<V, R>
43
+ summaryCell?: TableCell | TableColumnCellFn<SV, SR>
43
44
  }
44
45
 
46
+ export type TableColumnCellFn<V, R> = (value: V, record: R) => TableCell
47
+
45
48
  export type TableCell =
46
49
  | TableCellText
47
50
  | TableCellDay
@@ -139,17 +142,17 @@ export interface TableCellComponent extends TableCellBase {
139
142
  props?: Record<string, any>
140
143
  }
141
144
 
142
- export type TableSummary<T> = {
143
- [P in keyof T]?: T[P] | null | undefined
144
- }
145
-
146
- export interface UseTableOptions<O extends string, R extends Record<string, any>> {
145
+ export interface UseTableOptions<
146
+ O extends string,
147
+ R extends Record<string, any>,
148
+ SR extends Record<string, any>
149
+ > {
147
150
  orders: MaybeRef<O[]>
148
- columns: MaybeRef<TableColumns<O, R>>
151
+ columns: MaybeRef<TableColumns<O, R, SR>>
149
152
  records?: MaybeRef<R[] | null | undefined>
150
153
  header?: MaybeRef<boolean | undefined>
151
154
  footer?: MaybeRef<boolean | undefined>
152
- summary?: MaybeRef<TableSummary<R> | null | undefined>
155
+ summary?: MaybeRef<SR | null | undefined>
153
156
  total?: MaybeRef<number | null | undefined>
154
157
  page?: MaybeRef<number | null | undefined>
155
158
  perPage?: MaybeRef<number | null | undefined>
@@ -161,8 +164,12 @@ export interface UseTableOptions<O extends string, R extends Record<string, any>
161
164
  onReset?(): void
162
165
  }
163
166
 
164
- export function useTable<O extends string, R extends Record<string, any>>(
165
- options: UseTableOptions<O, R>
166
- ): Table<O, R> {
167
- return reactive(options) as Table<O, R>
167
+ export function useTable<
168
+ O extends string,
169
+ R extends Record<string, any>,
170
+ SR extends Record<string, any>
171
+ >(
172
+ options: UseTableOptions<O, R, SR>
173
+ ): Table<O, R, SR> {
174
+ return reactive(options) as Table<O, R, SR>
168
175
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@globalbrain/sefirot",
3
- "version": "2.28.0",
3
+ "version": "2.29.0",
4
4
  "packageManager": "pnpm@7.26.2",
5
5
  "description": "Vue Components for Global Brain Design System.",
6
6
  "author": "Kia Ishii <ka.ishii@globalbrains.com>",