1-
2- import { default as AntdSteps } from "antd/es/steps" ;
1+ import { ConfigProvider , Steps } from "antd" ;
32import { 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" ;
55import { ChangeEventHandlerControl } from "comps/controls/eventHandlerControl" ;
66import { LabelControl } from "comps/controls/labelControl" ;
77import { StepOptionControl } from "comps/controls/optionsControl" ;
@@ -16,63 +16,79 @@ import { hiddenPropertyView, disabledPropertyView } from "comps/utils/propertyUt
1616import { trans } from "i18n" ;
1717import { hasIcon } from "comps/utils" ;
1818import { RefControl } from "comps/controls/refControl" ;
19+ import { dropdownControl } from "comps/controls/dropdownControl" ;
1920
20- import { useContext , useState } from "react" ;
21+ import { useContext , useState , useEffect } from "react" ;
2122import { EditorContext } from "comps/editorState" ;
2223
2324
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+ ]
7180
7281const StepsChildrenMap = {
73- defaultValue : stringExposingStateControl ( "value ") ,
82+ initialValue : numberExposingStateControl ( "0 ") ,
7483 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 ,
7590 label : LabelControl ,
91+ labelPlacement : dropdownControl ( directionOptions , "horizontal" ) ,
7692 disabled : BoolCodeControl ,
7793 onEvent : ChangeEventHandlerControl ,
7894 options : StepOptionControl ,
@@ -83,42 +99,83 @@ const StepsChildrenMap = {
8399let StepControlBasicComp = ( function ( ) {
84100 return new UICompBuilder ( StepsChildrenMap , ( props ) => {
85101
102+ // enabling user interaction to change the current step
86103 const [ current , setCurrent ] = useState ( 0 ) ;
87104
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+ }
91117 } ;
92118
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+ ` ;
96130
131+ return props . label ( {
97132 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 >
114171 ) ,
115172 } ) ;
116173 } )
117174 . setPropertyViewFn ( ( children ) => (
118175 < >
119176 < Section name = { sectionNames . basic } >
120177 { children . options . propertyView ( { } ) }
121- { children . defaultValue . propertyView ( { label : trans ( "prop.defaultValue " ) } ) }
178+ { children . initialValue . propertyView ( { label : trans ( "step.initialValue " ) } ) }
122179 </ Section >
123180
124181 { [ "logic" , "both" ] . includes ( useContext ( EditorContext ) . editorModeStatus ) && (
@@ -127,13 +184,37 @@ let StepControlBasicComp = (function () {
127184 { children . onEvent . getPropertyView ( ) }
128185 { disabledPropertyView ( children ) }
129186 { hiddenPropertyView ( children ) }
187+ { children . stepsStatus . propertyView ( { label : trans ( "step.status" ) } ) }
130188 </ Section > </ >
131189 ) }
132190
133191 { [ "layout" , "both" ] . includes ( useContext ( EditorContext ) . editorModeStatus ) && (
134192 children . label . getPropertyView ( )
135193 ) }
136194
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+
137218 { [ "layout" , "both" ] . includes ( useContext ( EditorContext ) . editorModeStatus ) && (
138219 < Section name = { sectionNames . style } >
139220 { children . style . getPropertyView ( ) }
@@ -146,6 +227,6 @@ let StepControlBasicComp = (function () {
146227} ) ( ) ;
147228
148229export const StepComp = withExposingConfigs ( StepControlBasicComp , [
149- // new NameConfig("label ", trans("selectInput .valueDesc")),
230+ new NameConfig ( "value " , trans ( "step .valueDesc" ) ) ,
150231 ...CommonNameConfig ,
151232] ) ;
0 commit comments