import { Components } from '@formio/js'; const EditGrid = Components.components.editgrid; // The row template is stored in each form, so its icon-only buttons are named here. const BUTTON = /]*)>/g; export const nameRowButtons = (html: string, edit: string, remove: string): string => html.replace(BUTTON, (match, attrs: string) => { if (/\baria-label=|\baria-labelledby=/.test(attrs)) { return match; } if (/\beditRow\b/.test(attrs)) { return ``; } if (/\bremoveRow\b/.test(attrs)) { return ``; } return match; }); export default class GDSEditGrid extends EditGrid { // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types public renderRow(row: any, rowIndex: number): string { const html: string = super.renderRow(row, rowIndex); if (typeof html !== 'string' || !html.includes(' (this as unknown as { getFormattedAttribute: (v: string) => string }).getFormattedAttribute(text); return nameRowButtons( html, attr(`${this.t('Edit row')}${label}${n}`), attr(`${this.t('Remove row')}${label}${n}`), ); } }