@opengis/fastify-table
Version:
core-plugins
15 lines (12 loc) • 720 B
JavaScript
import getSelect from '../../plugins/table/funcs/getSelect.js';
export default async function badge(id, options) {
if (!id?.toString) return '-';
const data = options.hash?.data;
if (!data) return id;
const classifier = await getSelect(data);
if (!classifier?.arr) return id;
const item = classifier?.arr.find(el => el.id?.toString?.() === id.toString());
if (!item) return id;
return `<span style='color:${item.color || '#14b8a6'};border-color:${item.color || '#14b8a6'}; overflow:hidden;
text-overflow:ellipsis; white-space:nowrap;' class="block w-fit py-1.5 px-3 rounded-full text-xs font-medium border border-teal-500 text-teal-500 max-w-[220px] text-nowrap ">${item.text}</span>`;
}