1
+ import { getRTL } from '@ui5/webcomponents-base/dist/config/RTL' ;
1
2
import '@ui5/webcomponents-icons/dist/icons/filter' ;
2
3
import '@ui5/webcomponents-icons/dist/icons/group-2' ;
3
4
import '@ui5/webcomponents-icons/dist/icons/sort-ascending' ;
4
5
import '@ui5/webcomponents-icons/dist/icons/sort-descending' ;
5
6
import { createComponentStyles } from '@ui5/webcomponents-react-base/lib/createComponentStyles' ;
6
7
import { ThemingParameters } from '@ui5/webcomponents-react-base/lib/ThemingParameters' ;
7
8
import { 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 ' ;
9
10
import React , {
10
11
CSSProperties ,
11
12
DragEventHandler ,
@@ -60,17 +61,23 @@ const styles = {
60
61
width : '100%' ,
61
62
overflowX : 'hidden' ,
62
63
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'
64
74
} ,
65
75
iconContainer : {
66
76
display : 'inline-block' ,
67
77
position : 'absolute' ,
68
78
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
74
81
} ,
75
82
resizer : {
76
83
display : 'inline-block' ,
@@ -81,9 +88,6 @@ const styles = {
81
88
top : 0 ,
82
89
transform : 'translateX(50%)' ,
83
90
zIndex : 1
84
- } ,
85
- lastColumn : {
86
- right : '8px'
87
91
}
88
92
} ;
89
93
@@ -114,32 +118,48 @@ export const ColumnHeader: FC<ColumnHeaderProps> = (props: ColumnHeaderProps) =>
114
118
} = props ;
115
119
116
120
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 ;
120
124
const filterIcon = isFiltered ? < Icon name = "filter" /> : null ;
121
125
const groupingIcon = column . isGrouped ? < Icon name = "group-2" /> : null ;
122
126
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
+
123
150
const hasPopover = column . canGroupBy || column . canSort || column . canFilter ;
124
151
const innerStyle : CSSProperties = useMemo ( ( ) => {
125
152
const modifiedStyles : CSSProperties = {
126
153
cursor : hasPopover ? 'pointer' : 'auto'
127
154
} ;
128
- if ( column . canResize ) {
129
- modifiedStyles . maxWidth = `calc(100% - 16px)` ;
130
- }
131
155
if ( dragOver ) {
132
156
modifiedStyles . borderLeft = `3px solid ${ ThemingParameters . sapSelectedColor } ` ;
133
157
}
134
158
if ( column . id === '__ui5wcr__internal_highlight_column' || column . id === '__ui5wcr__internal_selection_column' ) {
135
159
modifiedStyles . padding = 0 ;
136
160
}
137
- if ( column . hAlign === TextAlign . End ) {
138
- modifiedStyles . justifyContent = 'flex-end' ;
139
- modifiedStyles . maxWidth = '' ;
140
- }
141
161
return modifiedStyles ;
142
- } , [ column . canResize , dragOver , hasPopover ] ) ;
162
+ } , [ dragOver , hasPopover ] ) ;
143
163
144
164
const popoverRef = useRef < Ui5PopoverDomRef > ( null ) ;
145
165
@@ -168,13 +188,15 @@ export const ColumnHeader: FC<ColumnHeaderProps> = (props: ColumnHeaderProps) =>
168
188
onDragEnd = { onDragEnd }
169
189
data-column-id = { id }
170
190
>
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 }
175
197
>
176
198
{ children }
177
- </ span >
199
+ </ Text >
178
200
< div className = { classes . iconContainer } >
179
201
{ filterIcon }
180
202
{ sortingIcon }
@@ -183,7 +205,7 @@ export const ColumnHeader: FC<ColumnHeaderProps> = (props: ColumnHeaderProps) =>
183
205
</ div >
184
206
{ hasPopover && < ColumnHeaderModal column = { column } onSort = { onSort } onGroupBy = { onGroupBy } ref = { popoverRef } /> }
185
207
{ column . canResize && column . getResizerProps && (
186
- < div { ...column . getResizerProps ( ) } className = { `${ classes . resizer } ` } />
208
+ < div { ...column . getResizerProps ( ) } data-resizer className = { `${ classes . resizer } ` } />
187
209
) }
188
210
</ div >
189
211
) ;
0 commit comments