2
I have a reusable component (main), it would be something like a widget, that the main structure is separated into 3 parts (or sub-components), which will not be reused anywhere else but the main component (main):
<!-- Código resumido -->
<!-- Componente Main -->
<div class="main">
<!-- Sub Componente Header -->
<div class="header"></div>
<!-- Sub Componente Content -->
<div class="content"></div>
<!-- Sub Componente Footer -->
<div class="footer"></div>
</div>
Each of them will grow separately in terms of HTML, CSS and Javascript/Typescript. My question is, the best form/best practice used in the CSS organization in this case?
1) Cluster styles within the css of the main component?
<!-- main-component.scss -->
:host {
<!-- Css do componente main -->
.header {
<!-- Css do componente header -->
}
.content {
<!-- Css do componente content -->
}
.footer {
<!-- Css do componente footer -->
}
.header,
.footer{
<!-- Css recorrente nos dois componentes -->
}
}
2) Segregate css, each with its own, leaving idepentende, although these components are never used separately?
<!-- main-component.scss -->
:host {
<!-- Css do componente main -->
}
<!-- header-component.scss -->
:host {
<!-- Css do componente header -->
}
<!-- content-component.scss -->
:host {
<!-- Css do componente content -->
}
<!-- footer-component.scss -->
:host {
<!-- Css do componente footer -->
}
Angular itself already answers your question, every time it creates a component it creates together the Html, Scss, TS and depending on the spec referring to that component.
– LeAndrade
I agree, but that premise comes from good componetization practices, when it comes to creating a front-end architecture, for better organization/reuse of code, but in the case I mentioned, if I use the "angular pattern", I gain in organization and lose in reuse, since I will have duplicated css in some cases.
– EJSpawn