Polymorphic
Utility types for creating strongly typed polymorphic components.
An alternative to asChild
prop. Usually used for Icon components. It is preferred over asChild
to shorten the code and avoid unnecessary cloning.
Provides autocomplete and type checking for the given component. It's only necessary if you're using TypeScript.
Installation
Create a utils/polymorphic.ts
file and paste the following code into it.
/utils/polymorphic.ts
Examples
Without forwardRef
In this example, we're using Ri24HoursFill
icon by default for <Icon>
if as
prop is not specified.
/demo-polymorphic-without-forwardref.tsx
With forwardRef
Never used with forwardRef
in AlignUI, but here's how to use it if needed.
/demo-polymorphic-with-forwardref.tsx
© 2024 AlignUI Design System. All rights reserved.