I am currently implementing a data table element using custom elements (web components). The table may have different types of cells (text, number, date, etc.), which are used to render each row.
eg
<my-table>
<my-table-cell-text column="name"></my-table-cell-text>
<my-table-cell-date column="dob" format="YYYY-MM-DD"></my-table-cell-date>
<my-table-cell-number column="salary" decimals="2"></my-table-cell-number >
</my-table>
I also have a class MyTableCellthat all elements of the cell expand. This is great for sharing common functions, however styling can be a pain, because each cell type is its own html tag. I am currently adding the css class when expanding MyTableCell, but for the argument, let's say I don't want to do this.
An ideal solution would be to be able to extend the user element using a keyword is, for example <my-table-cell is="my-table-cell-text">, but this is only allowed for inline html elements .
I can think of 3 approaches to solving this problem:
It has a syntax similar to <input type="">, but it works a lot more, because you no longer extend the base class, but rather create variations of the same element, and this means that you need a special way to register different options, something like staticMyTableCell.registerType
, <my-table-renderer-text> <my-table-cell>. , , , , .
, <my-table-cell type="text">, - document.createElement('my-table-rendener-'+ type). 1, , 2.
? - ?