⚡️ feat: add polymorphic prop type for heading component
This commit is contained in:
parent
66277d6c3b
commit
1fbaf6fdf0
@ -1,3 +1,9 @@
|
|||||||
|
import {
|
||||||
|
type ElementType,
|
||||||
|
type ComponentPropsWithoutRef,
|
||||||
|
forwardRef,
|
||||||
|
} from 'react';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a type by excluding common keys from one type to another.
|
* Construct a type by excluding common keys from one type to another.
|
||||||
* @template T - The type from which to omit properties.
|
* @template T - The type from which to omit properties.
|
||||||
@ -7,3 +13,15 @@
|
|||||||
* @returns A new type that includes all properties from T except those that are common with U.
|
* @returns A new type that includes all properties from T except those that are common with U.
|
||||||
*/
|
*/
|
||||||
export type OmitCommon<T, U> = Pick<T, Exclude<keyof T, keyof U>>;
|
export type OmitCommon<T, U> = Pick<T, Exclude<keyof T, keyof U>>;
|
||||||
|
|
||||||
|
export type PolymorphicProps<Element extends ElementType, Props> = Props &
|
||||||
|
Omit<ComponentPropsWithoutRef<Element>, 'as'> & {
|
||||||
|
as?: Element;
|
||||||
|
};
|
||||||
|
|
||||||
|
// taken from : https://github.com/total-typescript/react-typescript-tutorial/blob/main/src/08-advanced-patterns/72-as-prop-with-forward-ref.solution.tsx
|
||||||
|
type FixedForwardRef = <T, P = object>(
|
||||||
|
render: (props: P, ref: React.Ref<T>) => React.ReactNode,
|
||||||
|
) => (props: P & React.RefAttributes<T>) => JSX.Element;
|
||||||
|
|
||||||
|
export const fixedForwardRef = forwardRef as FixedForwardRef;
|
||||||
|
Loading…
Reference in New Issue
Block a user