1
-
2
- import { default as AntdSteps } from "antd/es/steps" ;
1
+ import { ConfigProvider , Steps } from "antd" ;
3
2
import { BoolCodeControl } from "comps/controls/codeControl" ;
4
- import { stringExposingStateControl } from "comps/controls/codeStateControl" ;
3
+ import { BoolControl } from "comps/controls/boolControl" ;
4
+ import { stringExposingStateControl , numberExposingStateControl } from "comps/controls/codeStateControl" ;
5
5
import { ChangeEventHandlerControl } from "comps/controls/eventHandlerControl" ;
6
6
import { LabelControl } from "comps/controls/labelControl" ;
7
7
import { StepOptionControl } from "comps/controls/optionsControl" ;
@@ -16,63 +16,79 @@ import { hiddenPropertyView, disabledPropertyView } from "comps/utils/propertyUt
16
16
import { trans } from "i18n" ;
17
17
import { hasIcon } from "comps/utils" ;
18
18
import { RefControl } from "comps/controls/refControl" ;
19
+ import { dropdownControl } from "comps/controls/dropdownControl" ;
19
20
20
- import { useContext , useState } from "react" ;
21
+ import { useContext , useState , useEffect } from "react" ;
21
22
import { EditorContext } from "comps/editorState" ;
22
23
23
24
24
- /* const getStyle = (style: StepsStyleType) => {
25
- return css`
26
- &.ant-segmented:not(.ant-segmented-disabled) {
27
- background-color: ${style.background};
28
-
29
- &,
30
- .ant-segmented-item-selected,
31
- .ant-segmented-thumb,
32
- .ant-segmented-item:hover,
33
- .ant-segmented-item:focus {
34
- color: ${style.text};
35
- border-radius: ${style.radius};
36
- }
37
- .ant-segmented-item {
38
- padding: ${style.padding};
39
- }
40
- .ant-segmented-item-selected,
41
- .ant-segmented-thumb {
42
- background-color: ${style.indicatorBackground};
43
- }
44
- }
45
-
46
- &.ant-segmented,
47
- .ant-segmented-item-selected {
48
- border-radius: ${style.radius};
49
- }
50
- &.ant-segmented, .ant-segmented-item-label {
51
- font-family:${style.fontFamily};
52
- font-style:${style.fontStyle};
53
- font-size:${style.textSize};
54
- font-weight:${style.textWeight};
55
- text-transform:${style.textTransform};
56
- text-decoration:${style.textDecoration};
57
- }
58
- `;
59
- }; */
60
-
61
- // ${(props) => props.$style && getStyle(props.$style)}
62
- const Segmented = styled ( AntdSteps ) < { $style : StepsStyleType } > `
63
- width: 100%;
64
- min-height: 24px;
65
- ` ;
66
-
67
- const SegmentedWrapper = styled . div `
68
- width: 100%;
69
- min-height: 24px;
70
- ` ;
25
+ const sizeOptions = [
26
+ {
27
+ label : trans ( "step.sizeSmall" ) ,
28
+ value : "small" ,
29
+ } ,
30
+ {
31
+ label : trans ( "step.sizeDefault" ) ,
32
+ value : "default" ,
33
+ }
34
+ ] as const ;
35
+
36
+ const typeOptions = [
37
+ {
38
+ label : trans ( "step.typeDefault" ) ,
39
+ value : "default" ,
40
+ } ,
41
+ {
42
+ label : trans ( "step.typeNavigation" ) ,
43
+ value : "navigation" ,
44
+ } ,
45
+ {
46
+ label : trans ( "step.typeInline" ) ,
47
+ value : "inline" ,
48
+ }
49
+ ] as const ;
50
+
51
+ const directionOptions = [
52
+ {
53
+ label : trans ( "step.directionHorizontal" ) ,
54
+ value : "horizontal" ,
55
+ } ,
56
+ {
57
+ label : trans ( "step.directionVertical" ) ,
58
+ value : "vertical" ,
59
+ }
60
+ ] as const ;
61
+
62
+ const statusOptions = [
63
+ {
64
+ label : trans ( "step.statusProcess" ) ,
65
+ value : "process"
66
+ } ,
67
+ {
68
+ label : trans ( "step.statusWait" ) ,
69
+ value : "wait"
70
+ } ,
71
+ {
72
+ label : trans ( "step.statusFinish" ) ,
73
+ value : "finish"
74
+ } ,
75
+ {
76
+ label : trans ( "step.statusError" ) ,
77
+ value : "error"
78
+ } ,
79
+ ]
71
80
72
81
const StepsChildrenMap = {
73
- defaultValue : stringExposingStateControl ( "value ") ,
82
+ initialValue : numberExposingStateControl ( "0 ") ,
74
83
value : stringExposingStateControl ( "value" ) ,
84
+ stepsStatus : stringExposingStateControl ( "process" ) ,
85
+ size : dropdownControl ( sizeOptions , "default" ) ,
86
+ displayType : dropdownControl ( typeOptions , "default" ) ,
87
+ direction : dropdownControl ( directionOptions , "horizontal" ) ,
88
+ showDots : BoolControl ,
89
+ showIcons : BoolControl ,
75
90
label : LabelControl ,
91
+ labelPlacement : dropdownControl ( directionOptions , "horizontal" ) ,
76
92
disabled : BoolCodeControl ,
77
93
onEvent : ChangeEventHandlerControl ,
78
94
options : StepOptionControl ,
@@ -83,42 +99,83 @@ const StepsChildrenMap = {
83
99
let StepControlBasicComp = ( function ( ) {
84
100
return new UICompBuilder ( StepsChildrenMap , ( props ) => {
85
101
102
+ // enabling user interaction to change the current step
86
103
const [ current , setCurrent ] = useState ( 0 ) ;
87
104
88
- const onChange = ( value : number ) => {
89
- console . log ( 'onChange:' , value ) ;
90
- setCurrent ( value ) ;
105
+ // updating the state of current by the expose value
106
+ useEffect ( ( ) => {
107
+ setCurrent ( Number ( props . value . value ) ) ;
108
+ } , [ props . value . value ] ) ;
109
+
110
+
111
+ const onChange = ( current : number ) => {
112
+ setCurrent ( current ) ;
113
+ if ( props . options [ current ] ?. value !== undefined ) {
114
+ props . value . onChange ( props . options [ current ] . value + "" ) ;
115
+ props . onEvent ( "change" ) ;
116
+ }
91
117
} ;
92
118
93
- return props . label ( {
94
-
95
- style : props . style ,
119
+ // margin-top: 17px; is important cause the dots where placed wrong.
120
+ /*
121
+ .ant-steps.ant-steps-small .ant-steps-item-icon {
122
+ margin-top: 17px;
123
+ }
124
+ */
125
+ const StepsWrapper = styled . div `
126
+ width: 100%;
127
+ min-height: 24px;
128
+
129
+ ` ;
96
130
131
+ return props . label ( {
97
132
children : (
98
- < SegmentedWrapper ref = { props . viewRef } >
99
- < AntdSteps
100
- type = "navigation"
101
- size = "default"
102
- current = { current }
103
- onChange = { onChange }
104
- items = { props . options . map ( ( option ) => ( {
105
- label : option . label ,
106
- subTitle : option . subTitle ,
107
- description : option . description ,
108
- status : option . status as "error" | "finish" | "wait" | "process" ,
109
- disabled : option . disabled ,
110
- icon : hasIcon ( option . icon ) && option . icon ,
111
- } ) ) }
112
- />
113
- </ SegmentedWrapper >
133
+ < StepsWrapper ref = { props . viewRef } >
134
+ < ConfigProvider
135
+ theme = { {
136
+ components : {
137
+ Steps : {
138
+ colorPrimary : '#00b96b' ,
139
+ algorithm : true ,
140
+ }
141
+ } ,
142
+ } }
143
+ >
144
+ < Steps
145
+ initial = { Number ( props . initialValue . value ) - 1 }
146
+ current = { current }
147
+ onChange = { ( current ) => {
148
+ onChange ( current ) ;
149
+ } }
150
+ percent = { 60 }
151
+ status = { props . stepsStatus . value as "error" | "finish" | "process" | "wait" }
152
+ type = { props . displayType }
153
+ size = { props . size }
154
+ labelPlacement = { props . labelPlacement }
155
+ progressDot = { props . showDots }
156
+ direction = { props . direction }
157
+ >
158
+ { props . options . map ( ( option , index ) => (
159
+ < Steps . Step
160
+ key = { index }
161
+ title = { option . label }
162
+ subTitle = { option . subTitle }
163
+ description = { option . description }
164
+ status = { option . status as "error" | "finish" | "wait" | "process" | undefined }
165
+ icon = { props . showIcons && hasIcon ( option . icon ) && option . icon || undefined }
166
+ />
167
+ ) ) }
168
+ </ Steps >
169
+ </ ConfigProvider >
170
+ </ StepsWrapper >
114
171
) ,
115
172
} ) ;
116
173
} )
117
174
. setPropertyViewFn ( ( children ) => (
118
175
< >
119
176
< Section name = { sectionNames . basic } >
120
177
{ children . options . propertyView ( { } ) }
121
- { children . defaultValue . propertyView ( { label : trans ( "prop.defaultValue " ) } ) }
178
+ { children . initialValue . propertyView ( { label : trans ( "step.initialValue " ) } ) }
122
179
</ Section >
123
180
124
181
{ [ "logic" , "both" ] . includes ( useContext ( EditorContext ) . editorModeStatus ) && (
@@ -127,13 +184,37 @@ let StepControlBasicComp = (function () {
127
184
{ children . onEvent . getPropertyView ( ) }
128
185
{ disabledPropertyView ( children ) }
129
186
{ hiddenPropertyView ( children ) }
187
+ { children . stepsStatus . propertyView ( { label : trans ( "step.status" ) } ) }
130
188
</ Section > </ >
131
189
) }
132
190
133
191
{ [ "layout" , "both" ] . includes ( useContext ( EditorContext ) . editorModeStatus ) && (
134
192
children . label . getPropertyView ( )
135
193
) }
136
194
195
+ { [ "layout" , "both" ] . includes ( useContext ( EditorContext ) . editorModeStatus ) && (
196
+ < Section name = { sectionNames . layout } >
197
+ { children . size . propertyView ( {
198
+ label : trans ( "step.size" ) ,
199
+ radioButton : true ,
200
+ } ) }
201
+ { children . displayType . propertyView ( {
202
+ label : trans ( "step.type" ) ,
203
+ radioButton : false ,
204
+ } ) }
205
+ { children . direction . propertyView ( {
206
+ label : trans ( "step.direction" ) ,
207
+ radioButton : true ,
208
+ } ) }
209
+ { children . labelPlacement . propertyView ( {
210
+ label : trans ( "step.labelPlacement" ) ,
211
+ radioButton : true ,
212
+ } ) }
213
+ { children . showDots . propertyView ( { label : trans ( "step.showDots" ) } ) }
214
+ { children . showIcons . propertyView ( { label : trans ( "step.showIcons" ) } ) }
215
+ </ Section >
216
+ ) }
217
+
137
218
{ [ "layout" , "both" ] . includes ( useContext ( EditorContext ) . editorModeStatus ) && (
138
219
< Section name = { sectionNames . style } >
139
220
{ children . style . getPropertyView ( ) }
@@ -146,6 +227,6 @@ let StepControlBasicComp = (function () {
146
227
} ) ( ) ;
147
228
148
229
export const StepComp = withExposingConfigs ( StepControlBasicComp , [
149
- // new NameConfig("label ", trans("selectInput .valueDesc")),
230
+ new NameConfig ( "value " , trans ( "step .valueDesc" ) ) ,
150
231
...CommonNameConfig ,
151
232
] ) ;
0 commit comments