PluginProbe
The Innovative Form Builder – IvyForms / 1.1
The Innovative Form Builder – IvyForms v1.1
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / frontend / src / views / _components / table / renderers / linkCellRenderer.ts

linkCellRenderer.ts in The Innovative Form Builder – IvyForms 1.1, at frontend/src/views/_components/table/renderers/linkCellRenderer.ts

43 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { h, type VNode } from 'vue'
2 import IvyLink from '@/views/_components/link/IvyLink.vue'
3 import type { CellRenderProps } from '@/views/_components/table/IvyCellRendererProps'
4
5 export interface LinkCellOptions<Row> {
6 text: (row: Row) => string | number
7 href?: string | ((row: Row) => string)
8 onClick?: (row: Row, e: Event) => void | Promise<void>
9 class?: string | ((row: Row) => string | undefined)
10 }
11
12 export function linkCellRenderer<Row extends Record<string, unknown>>(
13 options: LinkCellOptions<Row>,
14 ) {
15 return (props: CellRenderProps): VNode | null => {
16 const row = props.rowData as unknown as Row
17 if (!row) return null
18
19 const href =
20 typeof options.href === 'function'
21 ? options.href(row)
22 : (options.href ?? 'javascript:void(0)')
23
24 const className = typeof options.class === 'function' ? options.class(row) : options.class
25
26 return h(
27 IvyLink,
28 {
29 size: 's',
30 href,
31 class: className,
32 onClick: options.onClick
33 ? (e: Event) => {
34 if (href === '#' || href === 'javascript:void(0)') e.preventDefault()
35 return options.onClick!(row, e)
36 }
37 : undefined,
38 },
39 () => [String(options.text(row) ?? '')],
40 )
41 }
42 }
43