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 / starCellRenderer.ts

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

33 lines 1005 B
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 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