1
1
import { Component } from "@odoo/owl" ;
2
2
import { DEFAULT_VERTICAL_ALIGN , GRID_ICON_EDGE_LENGTH , GRID_ICON_MARGIN } from "../../constants" ;
3
3
import { positionToZone } from "../../helpers" ;
4
- import { Align , CellPosition , Rect , SpreadsheetChildEnv , VerticalAlign } from "../../types" ;
5
- import { css , cssPropertiesToCss } from "../helpers" ;
6
-
7
- css /* scss */ `
8
- .o-grid-cell-icon {
9
- width : ${ GRID_ICON_EDGE_LENGTH } px;
10
- height : ${ GRID_ICON_EDGE_LENGTH } px;
11
- }
12
- ` ;
4
+ import { GridIcon } from "../../registries/icons_on_cell_registry" ;
5
+ import { CellPosition , Rect , SpreadsheetChildEnv , VerticalAlign } from "../../types" ;
6
+ import { cssPropertiesToCss } from "../helpers" ;
13
7
14
8
export interface GridCellIconProps {
15
- cellPosition : CellPosition ;
16
- horizontalAlign ?: Align ;
9
+ icon : GridIcon ;
17
10
verticalAlign ?: VerticalAlign ;
18
11
}
19
12
20
13
export class GridCellIcon extends Component < GridCellIconProps , SpreadsheetChildEnv > {
21
14
static template = "o-spreadsheet-GridCellIcon" ;
22
15
static props = {
23
- cellPosition : Object ,
24
- horizontalAlign : { type : String , optional : true } ,
16
+ icon : Object ,
25
17
verticalAlign : { type : String , optional : true } ,
26
18
slots : Object ,
27
19
} ;
28
20
29
21
get iconStyle ( ) : string {
30
- const cellPosition = this . props . cellPosition ;
22
+ const cellPosition = this . props . icon . position ;
31
23
const merge = this . env . model . getters . getMerge ( cellPosition ) ;
32
24
const zone = merge || positionToZone ( cellPosition ) ;
33
25
const rect = this . env . model . getters . getVisibleRectWithoutHeaders ( zone ) ;
@@ -36,6 +28,8 @@ export class GridCellIcon extends Component<GridCellIconProps, SpreadsheetChildE
36
28
return cssPropertiesToCss ( {
37
29
top : `${ y } px` ,
38
30
left : `${ x } px` ,
31
+ width : `${ this . props . icon . size } px` ,
32
+ height : `${ this . props . icon . size } px` ,
39
33
} ) ;
40
34
}
41
35
@@ -63,16 +57,17 @@ export class GridCellIcon extends Component<GridCellIconProps, SpreadsheetChildE
63
57
64
58
const cell = this . env . model . getters . getCell ( cellPosition ) ;
65
59
const evaluatedCell = this . env . model . getters . getEvaluatedCell ( cellPosition ) ;
66
- const align = this . props . horizontalAlign || cell ?. style ?. align || evaluatedCell . defaultAlign ;
60
+ const align =
61
+ this . props . icon . horizontalAlign || cell ?. style ?. align || evaluatedCell . defaultAlign ;
67
62
68
63
switch ( align ) {
69
64
case "right" :
70
- return end - GRID_ICON_MARGIN - GRID_ICON_EDGE_LENGTH ;
65
+ return end - this . props . icon . size - this . props . icon . margin ;
71
66
case "left" :
72
- return start + GRID_ICON_MARGIN ;
67
+ return start + this . props . icon . margin ;
73
68
default :
74
- const centeringOffset = Math . floor ( ( end - start - GRID_ICON_EDGE_LENGTH ) / 2 ) ;
75
- return end - GRID_ICON_EDGE_LENGTH - centeringOffset ;
69
+ const centeringOffset = Math . floor ( ( end - start - this . props . icon . size ) / 2 ) ;
70
+ return end - this . props . icon . size - centeringOffset ;
76
71
}
77
72
}
78
73
0 commit comments