Skip to content

Commit aa65736

Browse files
author
Kenneth
committed
#feature: Add nowrap and minRows props for Typography
1 parent 8984d99 commit aa65736

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

src/atomics/Typography/styles.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,30 @@ export const TypographyTitleStyles = styled(Typography.Title, {
2424
}}
2525
`;
2626

27-
export const TypographyTextStyles = styled(Typography.Text)<Pick<RdTypographyTextProps, 'size'>>`
27+
export const TypographyTextStyles = styled(Typography.Text, {
28+
shouldForwardProp: prop =>
29+
getExcludeForwardProps<RdTypographyTextProps>(
30+
['noWrap', 'size'] as (keyof RdTypographyTextProps)[],
31+
prop
32+
),
33+
})<Pick<RdTypographyTextProps, 'size' | 'noWrap'>>`
2834
${({ size }) => {
2935
switch (size) {
3036
case 'small':
3137
return `
3238
font-size: ${getComponentOrGlobalToken('Typography', 'fontSizeSM')}px;
3339
`;
34-
// Case normal is the default size
3540
}
3641
}}
42+
43+
${({ noWrap }) => {
44+
return (
45+
noWrap &&
46+
css`
47+
text-wrap: nowrap;
48+
`
49+
);
50+
}}
3751
`;
3852

3953
export const TypographyParagraphStyles = styled(Typography.Paragraph, {
@@ -47,7 +61,9 @@ export const TypographyParagraphStyles = styled(Typography.Paragraph, {
4761
return (
4862
minRows &&
4963
css`
50-
min-height: ${Number(getComponentOrGlobalToken('Typography', 'lineHeight')) * Number(getComponentOrGlobalToken('Typography', 'fontSize')) * minRows}px;
64+
min-height: ${Number(getComponentOrGlobalToken('Typography', 'lineHeight')) *
65+
Number(getComponentOrGlobalToken('Typography', 'fontSize')) *
66+
minRows}px;
5167
`
5268
);
5369
}}

src/atomics/Typography/types.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,20 @@ type TypographyParagraphPropsExtend = TypographyBaseProps & {
2727
};
2828
type TypographyTextPropsExtend = TypographyBaseProps & {
2929
/**
30-
* @description The size of the text.
30+
* If true, the text will not wrap to the next line and instead will be truncated with an ellipsis when it overflows.
31+
* This is useful when you want to keep the text in a single line.
32+
* @default false
33+
*/
34+
noWrap?: boolean;
35+
36+
/**
37+
* The size of the text.
3138
* @default "normal"
3239
*/
3340
size?: 'small' | 'normal';
3441

3542
/**
36-
* @description Callback function that is triggered when the text value changes.
43+
* Callback function that is triggered when the text value changes.
3744
* @param value The new value of the text.
3845
*/
3946
onChange?: (value: string) => void;

0 commit comments

Comments
 (0)