1
1
import { BoolControl } from "comps/controls/boolControl" ;
2
- import { NumberControl , StringControl } from "comps/controls/codeControl" ;
2
+ import { ColorOrBoolCodeControl , NumberControl , RadiusControl , StringControl } from "comps/controls/codeControl" ;
3
3
import { dropdownControl , HorizontalAlignmentControl } from "comps/controls/dropdownControl" ;
4
- import { MultiCompBuilder , stateComp , valueComp } from "comps/generators" ;
4
+ import { MultiCompBuilder , stateComp , valueComp , withContext , withDefault } from "comps/generators" ;
5
5
import { withSelectedMultiContext } from "comps/generators/withSelectedMultiContext" ;
6
6
import { genRandomKey } from "comps/utils/idGenerator" ;
7
7
import { trans } from "i18n" ;
8
8
import _ from "lodash" ;
9
9
import {
10
10
changeChildAction ,
11
11
changeValueAction ,
12
+ CompAction ,
13
+ CompActionTypes ,
12
14
ConstructorToComp ,
13
15
ConstructorToDataType ,
14
16
ConstructorToNodeType ,
@@ -19,8 +21,10 @@ import {
19
21
withFunction ,
20
22
wrapChildAction ,
21
23
} from "lowcoder-core" ;
22
- import { AlignClose , AlignLeft , AlignRight } from "lowcoder-design" ;
24
+ import { AlignClose , AlignLeft , AlignRight , controlItem } from "lowcoder-design" ;
23
25
import { ColumnTypeComp , ColumnTypeCompMap } from "./columnTypeComp" ;
26
+ import { ColorControl } from "comps/controls/colorControl" ;
27
+ import { JSONValue } from "util/jsonTypes" ;
24
28
25
29
export type Render = ReturnType < ConstructorToComp < typeof RenderComp > [ "getOriginalComp" ] > ;
26
30
export const RenderComp = withSelectedMultiContext ( ColumnTypeComp ) ;
@@ -51,6 +55,31 @@ const columnFixOptions = [
51
55
} ,
52
56
] as const ;
53
57
58
+ const cellColorLabel = trans ( "table.cellColor" ) ;
59
+ const CellColorTempComp = withContext (
60
+ new MultiCompBuilder ( { color : ColorOrBoolCodeControl } , ( props ) => props . color )
61
+ . setPropertyViewFn ( ( children ) =>
62
+ children . color . propertyView ( {
63
+ label : cellColorLabel ,
64
+ tooltip : trans ( "table.cellColorDesc" ) ,
65
+ } )
66
+ )
67
+ . build ( ) ,
68
+ [ "currentCell" ] as const
69
+ ) ;
70
+
71
+ // @ts -ignore
72
+ export class CellColorComp extends CellColorTempComp {
73
+ override getPropertyView ( ) {
74
+ return controlItem ( { filterText : cellColorLabel } , super . getPropertyView ( ) ) ;
75
+ }
76
+ }
77
+
78
+ // fixme, should be infer from RowColorComp, but withContext type incorrect
79
+ export type CellColorViewType = ( param : {
80
+ currentCell : JSONValue | undefined ; //number | string;
81
+ } ) => string ;
82
+
54
83
export const columnChildrenMap = {
55
84
// column title
56
85
title : StringControl ,
@@ -67,6 +96,11 @@ export const columnChildrenMap = {
67
96
tempHide : stateComp < boolean > ( false ) ,
68
97
fixed : dropdownControl ( columnFixOptions , "close" ) ,
69
98
editable : BoolControl ,
99
+ background : withDefault ( ColorControl , "" ) ,
100
+ text : withDefault ( ColorControl , "" ) ,
101
+ border : withDefault ( ColorControl , "" ) ,
102
+ radius : withDefault ( RadiusControl , "" ) ,
103
+ cellColor : CellColorComp ,
70
104
} ;
71
105
72
106
/**
@@ -90,6 +124,21 @@ const ColumnInitComp = new MultiCompBuilder(columnChildrenMap, (props, dispatch)
90
124
. build ( ) ;
91
125
92
126
export class ColumnComp extends ColumnInitComp {
127
+ override reduce ( action : CompAction ) {
128
+ let comp = super . reduce ( action ) ;
129
+ if ( action . type === CompActionTypes . UPDATE_NODES_V2 ) {
130
+ comp = comp . setChild (
131
+ "cellColor" ,
132
+ comp . children . cellColor . reduce (
133
+ CellColorComp . changeContextDataAction ( {
134
+ currentCell : undefined ,
135
+ } )
136
+ )
137
+ ) ;
138
+ }
139
+ return comp ;
140
+ }
141
+
93
142
override getView ( ) {
94
143
const superView = super . getView ( ) ;
95
144
const columnType = this . children . render . getSelectedComp ( ) . getComp ( ) . children . compType . getView ( ) ;
@@ -143,6 +192,26 @@ export class ColumnComp extends ColumnInitComp {
143
192
} ) }
144
193
{ this . children . autoWidth . getView ( ) === "fixed" &&
145
194
this . children . width . propertyView ( { label : trans ( "prop.width" ) } ) }
195
+ { controlItem ( { } , (
196
+ < div style = { { marginTop : '8px' } } >
197
+ < b > { "Style" } </ b >
198
+ </ div >
199
+ ) ) }
200
+ { this . children . background . propertyView ( {
201
+ label : trans ( 'style.background' ) ,
202
+ } ) }
203
+ { this . children . text . propertyView ( {
204
+ label : trans ( 'text' ) ,
205
+ } ) }
206
+ { this . children . border . propertyView ( {
207
+ label : trans ( 'style.border' )
208
+ } ) }
209
+ { this . children . radius . propertyView ( {
210
+ label : trans ( 'style.borderRadius' ) ,
211
+ // preInputNode: <StyledIcon as={IconRadius} title="" />,
212
+ placeholder : '3px' ,
213
+ } ) }
214
+ { this . children . cellColor . getPropertyView ( ) }
146
215
</ >
147
216
) ;
148
217
}
0 commit comments