Extension on Stencils #2579
NicholasBoll
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Problem
A component may often extend another component and either add additional modifiers or use existing modifiers. For example, in buttons, the
BaseButton
has asize
modifier that changes the padding. TheTertiaryButton
uses thesize
modifier and adds additional styling with the same modifier name.We need to auto-document stencils and an
extends
config would help documentation understand the relationship between stencils for documentation purposes.For example:
CSS
The CSS generated could do one of 2 things:
Option 1 is simpler to implement, but could lead to mistakes because a modifier of each extension level needs to be added to the
ClassList
in order correctly display:class="cnvs-button cnvs-tertiary-button cnvs-button--size-large cnvs-tertiary-button--size-large"
Option 2 is simpler for people using CSS
React
If we have stencil extension, what does this mean for authoring React components. The following works now:
At that point, the
extends
isn't doing anything more than informing documentation about the relationship between the stencils. It is safer and allows us to manually ferry props to stencils. It can be verbose and boilerplate though. Most likely, the same modifiers need to be passed to both since we're extending.The next option is to treat an extension as special to the stencil.
Here, the
tertiaryButtonStencil
understands the relationship to thebuttonStencil
and can forward options to thebuttonStencil
, removing the need to duplicate prop-ferrying to more than one stencil. The documentation understands the actual relationship of stencils and the relationship doesn't need to be enforced in multiple places. Any time something needs to be done in multiple places, mistakes can be made.Beta Was this translation helpful? Give feedback.
All reactions