Polymorphism
Last updated: 2.0.0 (22/01/2024)
Last updated
Was this helpful?
Last updated: 2.0.0 (22/01/2024)
Last updated
Was this helpful?
Polymorphism is a complex subject, and is currently a weak point of Valence's type-checking systems. Dive into this subject at your own risk.
Polymorphism allows select Valence components to take different element form on the DOM, affording the components unique attributes and functionality that are usually disallowed by React or HTML.
Valence has three primary polymorphic components:
To use polymorphism on compatible components, simply use the component
prop to change the underlying DOM component.
Every component that at some point extends the PolymorphicTextProps
, PolymorphicButtonProps
or PolymorphicLayoutProps
will support polymorphism, which generally includes:
All buttons
link
component?, & all derivative components
&
The component="link"
prop sets the underlying element to a -compatible Link
component, allowing it to interact with the React Router API.
Polymorphic Button
Default: button
Polymorphic Layout
Default: div
Polymorphic Text
Default: p