6
6
} from "~/assets/icons/EnvironmentIcons" ;
7
7
import type { RuntimeEnvironment } from "~/models/runtimeEnvironment.server" ;
8
8
import { cn } from "~/utils/cn" ;
9
+ import { SimpleTooltip } from "~/components/primitives/Tooltip" ;
10
+ import { useEffect , useRef , useState } from "react" ;
9
11
10
12
type Environment = Pick < RuntimeEnvironment , "type" > & { branchName ?: string | null } ;
11
13
@@ -56,7 +58,10 @@ export function EnvironmentCombo({
56
58
} ) {
57
59
return (
58
60
< span className = { cn ( "flex items-center gap-1.5 text-sm text-text-bright" , className ) } >
59
- < EnvironmentIcon environment = { environment } className = { cn ( "size-4.5" , iconClassName ) } />
61
+ < EnvironmentIcon
62
+ environment = { environment }
63
+ className = { cn ( "size-4.5 shrink-0" , iconClassName ) }
64
+ />
60
65
< EnvironmentLabel environment = { environment } />
61
66
</ span >
62
67
) ;
@@ -69,11 +74,61 @@ export function EnvironmentLabel({
69
74
environment : Environment ;
70
75
className ?: string ;
71
76
} ) {
72
- return (
73
- < span className = { cn ( environmentTextClassName ( environment ) , className ) } >
74
- { environment . branchName ? environment . branchName : environmentFullTitle ( environment ) }
77
+ const spanRef = useRef < HTMLSpanElement > ( null ) ;
78
+ const [ isTruncated , setIsTruncated ] = useState ( false ) ;
79
+ const text = environment . branchName ? environment . branchName : environmentFullTitle ( environment ) ;
80
+
81
+ useEffect ( ( ) => {
82
+ const checkTruncation = ( ) => {
83
+ if ( spanRef . current ) {
84
+ const isTruncated = spanRef . current . scrollWidth > spanRef . current . clientWidth ;
85
+ console . log (
86
+ "isTruncated" ,
87
+ isTruncated ,
88
+ spanRef . current . scrollWidth ,
89
+ spanRef . current . clientWidth
90
+ ) ;
91
+ setIsTruncated ( isTruncated ) ;
92
+ }
93
+ } ;
94
+
95
+ checkTruncation ( ) ;
96
+ // Add resize observer to recheck on window resize
97
+ const resizeObserver = new ResizeObserver ( checkTruncation ) ;
98
+ if ( spanRef . current ) {
99
+ resizeObserver . observe ( spanRef . current ) ;
100
+ }
101
+
102
+ return ( ) => resizeObserver . disconnect ( ) ;
103
+ } , [ text ] ) ;
104
+
105
+ const content = (
106
+ < span
107
+ ref = { spanRef }
108
+ className = { cn ( "truncate text-left" , environmentTextClassName ( environment ) , className ) }
109
+ >
110
+ { text }
75
111
</ span >
76
112
) ;
113
+
114
+ if ( isTruncated ) {
115
+ return (
116
+ < SimpleTooltip
117
+ asChild
118
+ button = { content }
119
+ content = {
120
+ < span ref = { spanRef } className = { cn ( "text-left" , environmentTextClassName ( environment ) ) } >
121
+ { text }
122
+ </ span >
123
+ }
124
+ side = "right"
125
+ variant = "dark"
126
+ sideOffset = { 34 }
127
+ />
128
+ ) ;
129
+ }
130
+
131
+ return content ;
77
132
}
78
133
79
134
export function environmentTitle ( environment : Environment , username ?: string ) {
0 commit comments