1+ import { getRTL } from '@ui5/webcomponents-base/dist/config/RTL' ;
12import '@ui5/webcomponents-icons/dist/icons/filter' ;
23import '@ui5/webcomponents-icons/dist/icons/group-2' ;
34import '@ui5/webcomponents-icons/dist/icons/sort-ascending' ;
45import '@ui5/webcomponents-icons/dist/icons/sort-descending' ;
56import { createComponentStyles } from '@ui5/webcomponents-react-base/lib/createComponentStyles' ;
67import { ThemingParameters } from '@ui5/webcomponents-react-base/lib/ThemingParameters' ;
78import { Icon } from '@ui5/webcomponents-react/lib/Icon' ;
8- import { TextAlign } from '@ui5/webcomponents-react/lib/TextAlign ' ;
9+ import { Text } from '@ui5/webcomponents-react/lib/Text ' ;
910import React , {
1011 CSSProperties ,
1112 DragEventHandler ,
@@ -60,17 +61,23 @@ const styles = {
6061 width : '100%' ,
6162 overflowX : 'hidden' ,
6263 padding : `0 0.5rem` ,
63- boxSizing : 'border-box'
64+ boxSizing : 'border-box' ,
65+ '&[data-h-align="End"]' : {
66+ '& $text' : {
67+ textAlign : 'end'
68+ }
69+ }
70+ } ,
71+ text : {
72+ width : '100%' ,
73+ textAlign : 'start'
6474 } ,
6575 iconContainer : {
6676 display : 'inline-block' ,
6777 position : 'absolute' ,
6878 color : ThemingParameters . sapContent_IconColor ,
69- right : '0' ,
70- marginRight : '0.5rem' ,
71- '& :last-child' : {
72- marginLeft : '0.25rem'
73- }
79+ right : getRTL ( ) === false ? '0.5rem' : undefined ,
80+ left : getRTL ( ) === true ? '0.5rem' : undefined
7481 } ,
7582 resizer : {
7683 display : 'inline-block' ,
@@ -81,9 +88,6 @@ const styles = {
8188 top : 0 ,
8289 transform : 'translateX(50%)' ,
8390 zIndex : 1
84- } ,
85- lastColumn : {
86- right : '8px'
8791 }
8892} ;
8993
@@ -114,32 +118,48 @@ export const ColumnHeader: FC<ColumnHeaderProps> = (props: ColumnHeaderProps) =>
114118 } = props ;
115119
116120 const isFiltered = column . filterValue && column . filterValue . length > 0 ;
117- const desc = column . isSortedDesc ;
118-
119- const sortingIcon = column . isSorted ? < Icon name = { desc ? 'sort-descending' : 'sort-ascending' } /> : null ;
121+ const sortingIcon = column . isSorted ? (
122+ < Icon name = { column . isSortedDesc ? 'sort-descending' : 'sort-ascending' } />
123+ ) : null ;
120124 const filterIcon = isFiltered ? < Icon name = "filter" /> : null ;
121125 const groupingIcon = column . isGrouped ? < Icon name = "group-2" /> : null ;
122126
127+ const textStyle = useMemo ( ( ) => {
128+ let margin = 0 ;
129+
130+ if ( column . isSorted ) margin ++ ;
131+ if ( column . isGrouped ) margin ++ ;
132+ if ( isFiltered ) margin ++ ;
133+
134+ if ( margin === 0 ) {
135+ return { } ;
136+ }
137+
138+ if ( margin > 0 ) margin += 0.5 ;
139+
140+ if ( getRTL ( ) ) {
141+ return {
142+ marginLeft : `${ margin } rem`
143+ } ;
144+ }
145+ return {
146+ marginRight : `${ margin } rem`
147+ } ;
148+ } , [ column . isSorted , column . isGrouped , isFiltered ] ) ;
149+
123150 const hasPopover = column . canGroupBy || column . canSort || column . canFilter ;
124151 const innerStyle : CSSProperties = useMemo ( ( ) => {
125152 const modifiedStyles : CSSProperties = {
126153 cursor : hasPopover ? 'pointer' : 'auto'
127154 } ;
128- if ( column . canResize ) {
129- modifiedStyles . maxWidth = `calc(100% - 16px)` ;
130- }
131155 if ( dragOver ) {
132156 modifiedStyles . borderLeft = `3px solid ${ ThemingParameters . sapSelectedColor } ` ;
133157 }
134158 if ( column . id === '__ui5wcr__internal_highlight_column' || column . id === '__ui5wcr__internal_selection_column' ) {
135159 modifiedStyles . padding = 0 ;
136160 }
137- if ( column . hAlign === TextAlign . End ) {
138- modifiedStyles . justifyContent = 'flex-end' ;
139- modifiedStyles . maxWidth = '' ;
140- }
141161 return modifiedStyles ;
142- } , [ column . canResize , dragOver , hasPopover ] ) ;
162+ } , [ dragOver , hasPopover ] ) ;
143163
144164 const popoverRef = useRef < Ui5PopoverDomRef > ( null ) ;
145165
@@ -168,13 +188,15 @@ export const ColumnHeader: FC<ColumnHeaderProps> = (props: ColumnHeaderProps) =>
168188 onDragEnd = { onDragEnd }
169189 data-column-id = { id }
170190 >
171- < div style = { innerStyle } onClick = { onOpenPopover } className = { classes . header } >
172- < span
173- title = { typeof children === 'string' ? children : null }
174- style = { { textOverflow : 'ellipsis' , overflowX : 'hidden' , whiteSpace : 'nowrap' } }
191+ < div style = { innerStyle } onClick = { onOpenPopover } className = { classes . header } data-h-align = { column . hAlign } >
192+ < Text
193+ tooltip = { typeof children === 'string' ? children : null }
194+ wrapping = { false }
195+ style = { textStyle }
196+ className = { classes . text }
175197 >
176198 { children }
177- </ span >
199+ </ Text >
178200 < div className = { classes . iconContainer } >
179201 { filterIcon }
180202 { sortingIcon }
@@ -183,7 +205,7 @@ export const ColumnHeader: FC<ColumnHeaderProps> = (props: ColumnHeaderProps) =>
183205 </ div >
184206 { hasPopover && < ColumnHeaderModal column = { column } onSort = { onSort } onGroupBy = { onGroupBy } ref = { popoverRef } /> }
185207 { column . canResize && column . getResizerProps && (
186- < div { ...column . getResizerProps ( ) } className = { `${ classes . resizer } ` } />
208+ < div { ...column . getResizerProps ( ) } data-resizer className = { `${ classes . resizer } ` } />
187209 ) }
188210 </ div >
189211 ) ;
0 commit comments