| 1 |
import { h, type VNode } from 'vue' |
| 2 |
import IvyIcon from '@/views/_components/icon/IvyIcon.vue' |
| 3 |
import type { CellRenderProps } from '@/views/_components/table/IvyCellRendererProps' |
| 4 |
|
| 5 |
export interface StarCellOptions<Row> { |
| 6 |
field: keyof Row & string |
| 7 |
onChange: (row: Row, value: boolean) => void | Promise<void> |
| 8 |
ariaLabel?: string |
| 9 |
} |
| 10 |
|
| 11 |
export function starCellRenderer<Row extends Record<string, unknown>>( |
| 12 |
options: StarCellOptions<Row>, |
| 13 |
) { |
| 14 |
const field = options.field |
| 15 |
return (props: CellRenderProps): VNode | null => { |
| 16 |
const row = props.rowData as unknown as Row |
| 17 |
if (!row) return null |
| 18 |
const starred = Boolean(row[field]) |
| 19 |
|
| 20 |
return h(IvyIcon, { |
| 21 |
name: starred ? 'star-2' : 'star', |
| 22 |
type: 'fill', |
| 23 |
size: 'd', |
| 24 |
color: starred ? 'var(--map-accent-amber-symbol-0)' : 'var(--map-base-dusk-symbol--1)', |
| 25 |
style: 'cursor: pointer;', |
| 26 |
ariaLabel: options.ariaLabel, |
| 27 |
onClick: async () => { |
| 28 |
await options.onChange(row, !starred) |
| 29 |
}, |
| 30 |
}) |
| 31 |
} |
| 32 |
} |
| 33 |
|