11import React , { Children , Fragment , forwardRef } from 'react' ;
22
3- import { Icon , ColorPalette , ColorVariant , Typography } from '@lumx/react' ;
3+ import { Icon , ColorPalette , ColorVariant , Typography , WhiteSpace } from '@lumx/react' ;
44import { Comp , GenericProps , TextElement , isComponent } from '@lumx/react/utils/type' ;
55import {
66 getFontColorClassName ,
@@ -41,6 +41,12 @@ export interface TextProps extends GenericProps {
4141 * (automatically activated when single line text truncate is activated).
4242 */
4343 noWrap ?: boolean ;
44+ /**
45+ * WhiteSpace variant
46+ * Ignored when `noWrap` is set to true
47+ * Ignored when `truncate` is set to true or lines: 1
48+ * */
49+ whiteSpace ?: WhiteSpace ;
4450}
4551
4652/**
@@ -75,6 +81,7 @@ export const Text: Comp<TextProps> = forwardRef((props, ref) => {
7581 noWrap,
7682 typography,
7783 truncate,
84+ whiteSpace,
7885 style,
7986 ...forwardedProps
8087 } = props ;
@@ -88,6 +95,15 @@ export const Text: Comp<TextProps> = forwardRef((props, ref) => {
8895 const isTruncatedMultiline = ! ! truncateLinesStyle ;
8996 const isTruncated = ! ! truncate ;
9097
98+ /**
99+ * Add custom white-space style if specified
100+ * Disabled if noWrap is specified
101+ * Disabled if truncated on one-line
102+ * */
103+ const whiteSpaceStyle = ! noWrap &&
104+ ! ( isTruncated && ! isTruncatedMultiline ) &&
105+ whiteSpace && { '--lumx-text-white-space' : whiteSpace } ;
106+
91107 return (
92108 < Component
93109 ref = { ref as React . Ref < any > }
@@ -102,7 +118,7 @@ export const Text: Comp<TextProps> = forwardRef((props, ref) => {
102118 colorClass ,
103119 noWrap && `${ CLASSNAME } --no-wrap` ,
104120 ) }
105- style = { { ...truncateLinesStyle , ...style } }
121+ style = { { ...truncateLinesStyle , ...whiteSpaceStyle , ... style } }
106122 { ...forwardedProps }
107123 >
108124 { children &&
0 commit comments