| 1 |
import { TableV2FixedDir } from 'element-plus' |
| 2 |
import type { VNode } from 'vue' |
| 3 |
import type { TableColumn } from '@/views/_components/table/IvyTableColumn' |
| 4 |
import { actionsCellRenderer } from '@/views/_components/table/renderers' |
| 5 |
import type { |
| 6 |
ActionsCellOptions, |
| 7 |
CellAction, |
| 8 |
} from '@/views/_components/table/renderers/actionsCellRenderer' |
| 9 |
|
| 10 |
export interface ActionsColumnOptions<Row extends Record<string, unknown>> { |
| 11 |
actions: CellAction<Row>[] | ((row: Row) => CellAction<Row>[]) |
| 12 |
idKey?: ActionsCellOptions<Row>['idKey'] |
| 13 |
onButtonRef?: ActionsCellOptions<Row>['onButtonRef'] |
| 14 |
headerRenderer?: () => VNode |
| 15 |
title?: string |
| 16 |
width?: number |
| 17 |
minWidth?: number |
| 18 |
className?: string |
| 19 |
overrides?: Partial<TableColumn> |
| 20 |
} |
| 21 |
|
| 22 |
export function actionsColumn<Row extends Record<string, unknown>>( |
| 23 |
options: ActionsColumnOptions<Row>, |
| 24 |
): TableColumn { |
| 25 |
const width = options.width ?? 120 |
| 26 |
return { |
| 27 |
key: 'actions', |
| 28 |
width, |
| 29 |
minWidth: options.minWidth ?? width, |
| 30 |
title: options.title, |
| 31 |
class: options.className, |
| 32 |
headerRenderer: options.headerRenderer, |
| 33 |
cellRenderer: actionsCellRenderer<Row>({ |
| 34 |
actions: options.actions, |
| 35 |
idKey: options.idKey, |
| 36 |
onButtonRef: options.onButtonRef, |
| 37 |
}), |
| 38 |
visible: true, |
| 39 |
showInModal: false, |
| 40 |
fixed: TableV2FixedDir.RIGHT, |
| 41 |
...options.overrides, |
| 42 |
} |
| 43 |
} |
| 44 |
|