Skip to content

Commit 4f96d58

Browse files
authored
feat(Ingress): Add asChild support to Ingress (#1460)
1 parent fa2e961 commit 4f96d58

File tree

1 file changed

+25
-15
lines changed
  • packages/react/src/components/Typography/Ingress

1 file changed

+25
-15
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { HTMLAttributes } from 'react';
22
import React, { forwardRef } from 'react';
33
import cl from 'clsx';
4+
import { Slot } from '@radix-ui/react-slot';
45

56
import type { OverridableComponent } from '../../../types/OverridableComponent';
67

@@ -11,26 +12,35 @@ export type IngressProps = {
1112
size?: 'medium';
1213
/** Adds margin-bottom */
1314
spacing?: boolean;
15+
/**
16+
* Change the default rendered element for the one passed as a child, merging their props and behavior.
17+
* @default false
18+
*/
19+
asChild?: boolean;
1420
} & HTMLAttributes<HTMLParagraphElement>;
1521

1622
/** Use `Ingress` to display text as ingress. */
1723
export const Ingress: OverridableComponent<IngressProps, HTMLParagraphElement> =
1824
forwardRef(
1925
(
20-
{ className, size = 'medium', spacing, as: Component = 'p', ...rest },
26+
{ className, size = 'medium', spacing, as = 'p', asChild, ...rest },
2127
ref,
22-
) => (
23-
<Component
24-
ref={ref}
25-
className={cl(
26-
classes.ingress,
27-
classes[size],
28-
{
29-
[classes.spacing]: !!spacing,
30-
},
31-
className,
32-
)}
33-
{...rest}
34-
/>
35-
),
28+
) => {
29+
const Component = asChild ? Slot : as;
30+
31+
return (
32+
<Component
33+
ref={ref}
34+
className={cl(
35+
classes.ingress,
36+
classes[size],
37+
{
38+
[classes.spacing]: !!spacing,
39+
},
40+
className,
41+
)}
42+
{...rest}
43+
/>
44+
);
45+
},
3646
);

0 commit comments

Comments
 (0)