<war-grid> custom element
Use the grid as a standards-based custom element with attributes, properties and DOM events.
Live example
Expected behavior
Attribute changes apply live. Removing the element disposes the grid. Re-appending restores it with its last property state. Events show up in the log.
Source
import { defineWarGrid } from '@warlockcode/warui-core';
defineWarGrid();
const el = document.createElement('war-grid');
el.setAttribute('theme', 'dark');
el.setAttribute('row-height', '32');
el.rowData = [{ id: 1, name: 'Product 1' }];
el.addEventListener('war-cell-click', (e) => console.log(e.detail));
document.body.append(el);import { defineWarGrid } from '@warlockcode/warui-core';
defineWarGrid();
const el = document.createElement('war-grid');
el.setAttribute('theme', 'dark');
el.setAttribute('row-height', '32');
el.rowData = [{ id: 1, name: 'Product 1' }];
el.addEventListener('war-cell-click', (e) => console.log(e.detail));
document.body.append(el);import { defineWarGrid } from '@warlockcode/warui-core';
defineWarGrid();
const el = document.createElement('war-grid');
el.setAttribute('theme', 'dark');
el.setAttribute('row-height', '32');
el.rowData = [{ id: 1, name: 'Product 1' }];
el.addEventListener('war-cell-click', (e) => console.log(e.detail));
document.body.append(el);import { defineWarGrid } from '@warlockcode/warui-core';
defineWarGrid();
const el = document.createElement('war-grid');
el.setAttribute('theme', 'dark');
el.setAttribute('row-height', '32');
el.rowData = [{ id: 1, name: 'Product 1' }];
el.addEventListener('war-cell-click', (e) => console.log(e.detail));
document.body.append(el);// JavaScript interop module
import { defineWarGrid } from '@warlockcode/warui-core';
defineWarGrid();
const el = document.createElement('war-grid');
el.setAttribute('theme', 'dark');
el.setAttribute('row-height', '32');
el.rowData = [{ id: 1, name: 'Product 1' }];
el.addEventListener('war-cell-click', (e) => console.log(e.detail));
document.body.append(el);API reference
| Kind | Name | Type | Description |
|---|---|---|---|
| Function | defineWarGrid | — | Registers <war-grid>. Safe to call twice. |
| Attribute | row-height, theme, selection-mode | — | Simple options, kept in sync with properties. |
| Property | config, rowData, api | — | Complex data and the headless grid. |
| Event | war-cell-click, war-selection-change | — | Bubbling, composed CustomEvents. |
Acceptance criteria
- Attribute and property for the same option stay in sync, and the property wins on conflict (met)
- disconnectedCallback releases resources, and connectedCallback re-initializes them (met)
- Events bubble and are composed so they cross shadow boundaries (met)
- Registering the element twice does not throw (met)