Using BEM naming conventions, how should situations where a component is a specialisation of a base component be handled? (I'm using Nicholas Gallagher's variant here).
So assuming I have a set of default styles for table
elements and a more specialised table with a class of DataTable
:
// Defaults
table {}
tr {}
th {}
td {}
// DataTable
.DataTable {}
.DataTable-header {}
.DataTable-header-row {}
.DataTable-header-cell {}
.DataTable-body {}
.DataTable-body-row {}
.DataTable-body-cell {}
I now have a table that is a specialisation of DataTable
, with a variety of tweaks to cells:
.SpecialTable {}
.SpecialTable-header {}
.SpecialTable-header-row {}
.SpecialTable-header-cell {}
.SpecialTable-header-alphaCell {}
.SpecialTable-header-betaCell {}
.SpecialTable-header-charlieCell {}
.SpecialTable-body {}
.SpecialTable-body-row {}
.SpecialTable-body-cell {}
.SpecialTable-body-alphaCell {}
.SpecialTable-body-betaCell {}
.SpecialTable-body-charlieCell {}
This would then mean my SpecialTable would look like this:
<table class="DataTable SpecialTable">
<theadclass="DataTable-header SpecialTable-header">
<tr class="DataTable-header-row SpecialTable-header-row">
<th class="DataTable-header-cell SpecialTable-header-cell SpecialTable-header-alphaCell"></th>
<th class="DataTable-header-cell SpecialTable-header-cell SpecialTable-header-betaCell"></th>
<th class="DataTable-header-cell SpecialTable-header-cell SpecialTable-header-betaCell"></th>
</tr>
</thead>
<tbody class="DataTable-body SpecialTable-body">
<tr class="DataTable-body-row SpecialTable-body-row">
<th class="DataTable-body-cell SpecialTable-body-cell SpecialTable-body-alphaCell"></th>
<th class="DataTable-body-cell SpecialTable-body-cell SpecialTable-row-betaCell"></th>
<th class="DataTable-body-cell SpecialTable-body-cell SpecialTable-row-betaCell"></th>
</tr>
</tbody>
</table>
Is this the correct way to class the table?