-
-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(ds): Unify Paragraph with Text component (#14509)
- Loading branch information
Showing
3 changed files
with
21 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 5 additions & 58 deletions
63
packages/components/src/components/typography/Paragraph/Paragraph.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,10 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import { Text, TextVariant, textVariants, allowedTextTextProps } from '../Text/Text'; | ||
import { | ||
FrameProps, | ||
FramePropsKeys, | ||
pickAndPrepareFrameProps, | ||
withFrameProps, | ||
} from '../../../utils/frameProps'; | ||
import { makePropsTransient, TransientProps } from '../../../utils/transientProps'; | ||
import { TextProps, TextPropsKeys, withTextProps } from '../utils'; | ||
|
||
export const allowedParagraphTextProps: TextPropsKeys[] = [...allowedTextTextProps, 'align']; | ||
type AllowedParagraphTextProps = Pick<TextProps, (typeof allowedParagraphTextProps)[number]>; | ||
|
||
export const allowedParagraphFrameProps = [ | ||
'margin', | ||
'maxWidth', | ||
] as const satisfies FramePropsKeys[]; | ||
type AllowedFrameProps = Pick<FrameProps, (typeof allowedParagraphFrameProps)[number]>; | ||
|
||
export const paragraphVariants = textVariants; | ||
|
||
export type ParagraphProps = AllowedFrameProps & | ||
AllowedParagraphTextProps & { | ||
variant?: TextVariant; | ||
className?: string; | ||
'data-testid'?: string; | ||
children: React.ReactNode; | ||
}; | ||
|
||
const P = styled.p< | ||
TransientProps<AllowedFrameProps> & TransientProps<Pick<AllowedParagraphTextProps, 'align'>> | ||
>` | ||
${withTextProps} | ||
${withFrameProps} | ||
`; | ||
|
||
export const Paragraph = ({ | ||
className, | ||
typographyStyle = 'body', | ||
textWrap, | ||
align, | ||
'data-testid': dataTest, | ||
children, | ||
variant, | ||
...rest | ||
}: ParagraphProps) => { | ||
const frameProps = pickAndPrepareFrameProps(rest, allowedParagraphFrameProps); | ||
import { Text, TextProps } from '../Text/Text'; | ||
|
||
export const Paragraph = ({ children, ...rest }: TextProps) => { | ||
return ( | ||
<P | ||
className={className} | ||
data-testid={dataTest} | ||
{...makePropsTransient({ align })} | ||
{...frameProps} | ||
> | ||
<Text typographyStyle={typographyStyle} textWrap={textWrap} variant={variant}> | ||
{children} | ||
</Text> | ||
</P> | ||
<Text {...rest} as="p"> | ||
{children} | ||
</Text> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters