Skip to content

Commit 39c3c64

Browse files
committed
adds TextNode
1 parent 3e778c0 commit 39c3c64

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React, { PropsWithChildren } from 'react';
2+
import { Polymorph, PolymorphicAs } from '@leafygreen-ui/polymorphic';
3+
4+
/**
5+
* Wraps a string in the provided `as` component,
6+
* or renders the provided `ReactNode`.
7+
*
8+
* Useful when rendering `children` props that can be any react node
9+
*
10+
* @example
11+
* ```
12+
* <TextNode as={h1}>Hello!</TextNode> // <h1>Hello!</h1>
13+
* ```
14+
*
15+
* @example
16+
* ```
17+
* <TextNode><h2>Hello!</h2></TextNode> // <h2>Hello!</h2>
18+
* ```
19+
*
20+
*/
21+
// TODO: Move to `Typography`
22+
export const TextNode = ({
23+
children,
24+
as,
25+
}: PropsWithChildren<{ as?: PolymorphicAs }>) => {
26+
return typeof children === 'string' || typeof children === 'number' ? (
27+
<Polymorph as={as}>{children}</Polymorph>
28+
) : (
29+
children
30+
);
31+
};
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import React from 'react';
22

3-
import { Description, H3 } from '@leafygreen-ui/typography';
3+
import { TextNode, Description, H3 } from '@leafygreen-ui/typography';
44

55
import { stepStyles } from './WizardStep.styles';
66
import { WizardStepProps } from './WizardStep.types';
7+
import { WizardSubComponentProperties } from '../constants';
78

89
export function WizardStep({ title, description, children }: WizardStepProps) {
910
return (
1011
<div className={stepStyles}>
11-
<H3>{title}</H3>
12-
{description && <Description>{description}</Description>}
12+
<TextNode as={H3}>{title}</TextNode>
13+
{description && <TextNode as={Description}>{description}</TextNode>}
1314
<div>{children}</div>
1415
</div>
1516
);
1617
}
1718

1819
WizardStep.displayName = 'WizardStep';
20+
WizardStep[WizardSubComponentProperties.Step] = true;

0 commit comments

Comments
 (0)