33
44import React , { useMemo } from 'react' ;
55import styled from 'styled-components' ;
6+ import truncate from 'lodash/truncate' ;
67import { CompareType , Field , Merge , TooltipField } from '@kepler.gl/types' ;
78import { CenterFlexbox } from '../common/styled-components' ;
89import { Layers } from '../common/icons' ;
@@ -66,12 +67,22 @@ interface RowProps {
6667 url ?: string ;
6768}
6869
70+ /** Max length before truncation is applied */
71+ const TOOLTIP_VALUE_MAX_LENGTH = 60 ;
72+ /** Length to truncate to (including ellipsis) */
73+ const TOOLTIP_VALUE_TRUNCATE_LENGTH = 30 ;
74+
6975const Row : React . FC < RowProps > = ( { name, value, deltaValue, url} ) => {
7076 // Set 'url' to 'value' if it looks like a url
7177 if ( ! url && value && typeof value === 'string' && value . match ( / ^ h t t p / ) ) {
7278 url = value ;
7379 }
7480
81+ const displayValue =
82+ typeof value === 'string' && value . length > TOOLTIP_VALUE_MAX_LENGTH
83+ ? truncate ( value , { length : TOOLTIP_VALUE_TRUNCATE_LENGTH } )
84+ : value ;
85+
7586 const asImg = / < i m g > / . test ( name ) ;
7687 return (
7788 < tr className = "layer-hover-info__row" key = { name } >
@@ -81,11 +92,11 @@ const Row: React.FC<RowProps> = ({name, value, deltaValue, url}) => {
8192 < img src = { value } />
8293 ) : url ? (
8394 < a target = "_blank" rel = "noopener noreferrer" href = { url } >
84- { value }
95+ { displayValue }
8596 </ a >
8697 ) : (
8798 < >
88- < span > { value } </ span >
99+ < span > { displayValue } </ span >
89100 { notNullorUndefined ( deltaValue ) ? (
90101 < span
91102 className = { `row__delta-value ${
0 commit comments