Skip to content

Commit

Permalink
fix: allow components to be specified for Heading and Paragraph
Browse files Browse the repository at this point in the history
  • Loading branch information
maxholman committed Jun 24, 2024
1 parent ca609ba commit 74e77fb
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/typography.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,15 @@ export const ExactText = forwardRef(
),
);

export const Heading = forwardRef<HTMLHeadingElement, HeadingProps>(
({ className, secondary, level = '3', ...props }, ref) => {
export const Heading = forwardRef(
<T extends keyof ReactHTMLElementsHacked>(
{ className, secondary, level = '3', ...props }: HeadingProps<T>,
forwardedRef: ForwardedRef<ReactHTMLElementsHacked[T]>,
) => {
const { secondary: headingIsSecondary, ...rest } = headingProps(level);
return (
<Box

Check failure on line 77 in lib/typography.tsx

View workflow job for this annotation

GitHub Actions / test

Type '{ color?: string | undefined; content?: string | undefined; flexGrow?: boolean | Partial<{ all: boolean; mobile: boolean; tablet: boolean; desktop: boolean; wide: boolean; }> | null | undefined; ... 291 more ...; ref: ForwardedRef<...>; } & Omit<...>' is not assignable to type 'IntrinsicAttributes & Omit<ReactHTMLAttributesHacked[("h1" & HeadingProps<T>["component"]) | ("h2" & HeadingProps<...>["component"]) | ... 4 more ... | ("p" & HeadingProps<...>["component"])], "flexDirection" | ... 29 more ... | "roundedEndEnd"> & { ...; } & RefAttributes<...>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
ref={ref}
ref={forwardedRef}
lineHeight="heading"
className={[
className,
Expand All @@ -86,10 +89,13 @@ export const Heading = forwardRef<HTMLHeadingElement, HeadingProps>(
},
);

export const Paragraph = forwardRef<HTMLParagraphElement, ParagraphProps>(
({ className, secondary, ...props }, ref) => (
export const Paragraph = forwardRef(
<T extends keyof ReactHTMLElementsHacked = 'p'>(
{ className, secondary, ...props }: ParagraphProps<T>,
forwardedRef: ForwardedRef<ReactHTMLElementsHacked[T]>,
) => (
<Box

Check failure on line 97 in lib/typography.tsx

View workflow job for this annotation

GitHub Actions / test

Type '{ ref: ForwardedRef<ReactHTMLElementsHacked[T]>; className: (string | Falsy)[]; lineHeight: "paragraph"; component: "p"; } & Omit<ParagraphProps<...>, "className" | "secondary">' is not assignable to type 'IntrinsicAttributes & Omit<ReactHTMLAttributesHacked["p" & ParagraphProps<T>["component"]], "flexDirection" | ... 29 more ... | "roundedEndEnd"> & { ...; } & RefAttributes<...>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
ref={ref}
ref={forwardedRef}
className={[className, secondary && secondaryClassName]}
lineHeight="paragraph"
component="p"
Expand Down

0 comments on commit 74e77fb

Please sign in to comment.