File tree Expand file tree Collapse file tree 5 files changed +55
-9
lines changed
src/design-system/tooltip Expand file tree Collapse file tree 5 files changed +55
-9
lines changed Original file line number Diff line number Diff line change 11import React from 'react' ;
22import type { ReactNode } from 'react' ;
33
4+ import cn from 'classnames' ;
5+
46import { Text } from '../text' ;
57
68import * as cx from './tooltip-content.css' ;
79
810export interface TooltipContentProps {
911 label : ReactNode | string ;
12+ preventTextWrap ?: boolean ;
1013}
1114
1215export const TooltipContent = ( {
1316 label,
17+ preventTextWrap = false ,
1418} : Readonly < TooltipContentProps > ) : JSX . Element => {
1519 return (
16- < div className = { cx . tooltipContent } >
20+ < div
21+ className = { cn ( cx . tooltipContent , {
22+ [ cx . preventTextWrap ] : preventTextWrap ,
23+ } ) }
24+ >
1725 < Text . Body . Small color = "secondary" weight = "$medium" >
1826 { label }
1927 </ Text . Body . Small >
Original file line number Diff line number Diff line change @@ -15,3 +15,8 @@ export const tooltipContent = style([
1515 wordBreak : 'break-word' ,
1616 } ,
1717] ) ;
18+
19+ export const preventTextWrap = style ( {
20+ whiteSpace : 'nowrap' ,
21+ maxWidth : 'none' ,
22+ } ) ;
Original file line number Diff line number Diff line change @@ -4,14 +4,14 @@ import type { ReactNode } from 'react';
44import * as Tooltip from '@radix-ui/react-tooltip' ;
55
66import { TooltipContent } from './tooltip-content.component' ;
7- import * as cx from './tooltip-root.css' ;
87
98export type Props = typeof Tooltip . Root & {
10- align ?: Tooltip . PopperContentProps [ 'align' ] ;
11- children ?: Tooltip . PopperContentProps [ 'children' ] ;
12- side ?: Tooltip . PopperContentProps [ 'side' ] ;
9+ align ?: Tooltip . TooltipContentProps [ 'align' ] ;
10+ children ?: Tooltip . TooltipContentProps [ 'children' ] ;
11+ side ?: Tooltip . TooltipContentProps [ 'side' ] ;
1312 label : ReactNode | string ;
1413 zIndex ?: number ;
14+ preventTextWrap ?: boolean ;
1515} ;
1616
1717export const Root = ( {
@@ -20,6 +20,7 @@ export const Root = ({
2020 align = 'center' ,
2121 zIndex,
2222 children,
23+ preventTextWrap = false ,
2324} : Readonly < Props > ) : JSX . Element => {
2425 return (
2526 < Tooltip . Root >
@@ -29,10 +30,9 @@ export const Root = ({
2930 style = { { zIndex } }
3031 side = { side }
3132 align = { align }
32- className = { cx . root }
3333 data-testid = { 'tooltip-content' }
3434 >
35- < TooltipContent label = { label } />
35+ < TooltipContent label = { label } preventTextWrap = { preventTextWrap } />
3636 </ Tooltip . Content >
3737 </ Tooltip . Portal >
3838 </ Tooltip . Root >
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ export type Props = PropsWithChildren<
1313 delayDuration ?: number ;
1414 skipDelayDuration ?: number ;
1515 children : ReactNode ;
16+ preventTextWrap ?: boolean ;
1617 }
1718> ;
1819
@@ -22,14 +23,20 @@ export const Tooltip = ({
2223 label,
2324 children,
2425 side,
26+ preventTextWrap = false ,
2527 ...props
2628} : Readonly < Props > ) : JSX . Element => {
2729 return (
2830 < Provider
2931 skipDelayDuration = { skipDelayDuration }
3032 delayDuration = { delayDuration }
3133 >
32- < Root side = { side } label = { label } { ...props } >
34+ < Root
35+ side = { side }
36+ label = { label }
37+ preventTextWrap = { preventTextWrap }
38+ { ...props }
39+ >
3340 < Trigger asChild >
3441 < div > { children } </ div >
3542 </ Trigger >
Original file line number Diff line number Diff line change @@ -33,9 +33,10 @@ export default {
3333
3434const SampleTooltip = ( {
3535 label,
36+ preventTextWrap,
3637} : Readonly < TooltipContentProps > ) : JSX . Element => (
3738 < StorybookContentRenderer >
38- < TooltipContent label = { label } />
39+ < TooltipContent label = { label } preventTextWrap = { preventTextWrap } />
3940 </ StorybookContentRenderer >
4041) ;
4142
@@ -111,6 +112,22 @@ const VariantsTable = (): JSX.Element => (
111112 </ Section >
112113) ;
113114
115+ const LongTextComponents = ( ) : JSX . Element => (
116+ < Variants . Table headers = { [ 'Long text default' , 'Long text on single line' ] } >
117+ < Variants . Row >
118+ < Variants . Cell >
119+ < SampleTooltip label = "This is a very long tooltip text that will not wrap and will display on a single line no matter how long it gets" />
120+ </ Variants . Cell >
121+ < Variants . Cell >
122+ < SampleTooltip
123+ label = "This is a very long tooltip text that will not wrap and will display on a single line no matter how long it gets"
124+ preventTextWrap
125+ />
126+ </ Variants . Cell >
127+ </ Variants . Row >
128+ </ Variants . Table >
129+ ) ;
130+
114131export const Overview = ( ) : JSX . Element => (
115132 < Grid columns = "$1" >
116133 < Cell >
@@ -163,6 +180,15 @@ export const Overview = (): JSX.Element => (
163180 </ Variants . Table >
164181 </ LocalThemeProvider >
165182 </ Section >
183+
184+ < Divider my = "$64" />
185+
186+ < Section title = "Long Text Wrapping" >
187+ < LongTextComponents />
188+ < LocalThemeProvider colorScheme = { ThemeColorScheme . Dark } >
189+ < LongTextComponents />
190+ </ LocalThemeProvider >
191+ </ Section >
166192 </ Cell >
167193 </ Grid >
168194) ;
You can’t perform that action at this time.
0 commit comments