This repository was archived by the owner on Mar 4, 2020. It is now read-only.
RFC: Shorthand polymorphism using kind
property
#512
Labels
kind
property
#512
Feature Request
Problem description
Shorthand is a powerful way how you can define component slots:
In the example above, both
icon
andcontent
are shorthands. It allows you to define as few properties as possible while still giving you full control over the slot props. And in all cases shorthand still manages state, styling and accessibility for you.Shorthand becomes extremely useful when defining collection of children, for example in
ButtonGroup
:But what if you would like to add different component to the collection of buttons? What if you want to add a divider?
kind
For that reason we plan to add
kind
property to the shorthand definition. With that, you can choose which component will be created using the shorthand:Difference between
as
andkind
All Startdust components already support
as
property which allows you to override element type in the rendered result. So what is the reason for introducingkind
? What is the difference between the two?Stardust component defines resulting DOM structure, state, styles and accessibility. With
as
, you are overridingElementType
- that is usually the root element in the resulting DOM structure.But the original component is still created - with the structure, state, styles and accessibility of the original component.
On the other hand when
kind
is used, different component is created - with its own structure, state, styles and accessibility.To summarize -
kind
defines what component is created.as
definesElementType
of the created component.It is technically possible to combine the two:
Component implementation
There is no magic happening in factory, it is component's responsibility to handle
kind
attribute.Component should allow the
kind
to be only one of predefined options (ButtonGroup
should allow only'button'
or'divider'
and default to'button'
if no kind is specified and nothing else).Possible use cases considered:
Other syntaxes considered
The text was updated successfully, but these errors were encountered: