Skip to content

Commit b582763

Browse files
author
FalkWolsky
committed
WIP Introducing Step Component 2nd step
1 parent 1c8f1f6 commit b582763

File tree

4 files changed

+192
-83
lines changed

4 files changed

+192
-83
lines changed
Lines changed: 157 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
2-
import { default as AntdSteps } from "antd/es/steps";
1+
import { ConfigProvider, Steps} from "antd";
32
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";
55
import { ChangeEventHandlerControl } from "comps/controls/eventHandlerControl";
66
import { LabelControl } from "comps/controls/labelControl";
77
import { StepOptionControl } from "comps/controls/optionsControl";
@@ -16,63 +16,79 @@ import { hiddenPropertyView, disabledPropertyView } from "comps/utils/propertyUt
1616
import { trans } from "i18n";
1717
import { hasIcon } from "comps/utils";
1818
import { 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";
2122
import { 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

7281
const 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 = {
8399
let 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

148229
export const StepComp = withExposingConfigs(StepControlBasicComp, [
149-
// new NameConfig("label", trans("selectInput.valueDesc")),
230+
new NameConfig("value", trans("step.valueDesc")),
150231
...CommonNameConfig,
151232
]);

client/packages/lowcoder/src/comps/controls/optionsControl.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ViewDocIcon } from "assets/icons";
2-
import { ArrayControl, BoolCodeControl, RadiusControl, StringControl } from "comps/controls/codeControl";
2+
import { ArrayControl, BoolCodeControl, NumberControl, RadiusControl, StringControl } from "comps/controls/codeControl";
33
import { dropdownControl, LeftRightControl } from "comps/controls/dropdownControl";
44
import { IconControl } from "comps/controls/iconControl";
55
import { MultiCompBuilder, valueComp, withContext, withDefault } from "comps/generators";
@@ -636,6 +636,7 @@ export const ColumnOptionControl = manualOptionsControl(ColumnOption, {
636636

637637
let StepOption = new MultiCompBuilder(
638638
{
639+
value : NumberControl,
639640
label: StringControl,
640641
subTitle: StringControl,
641642
description: StringControl,
@@ -650,10 +651,11 @@ StepOption = class extends StepOption implements OptionCompProperty {
650651
propertyView(param: { autoMap?: boolean }) {
651652
return (
652653
<>
654+
{this.children.value.propertyView({ label: trans("stepOptionsControl.value") })}
653655
{this.children.label.propertyView({ label: trans("stepOptionsControl.title") })}
654656
{this.children.subTitle.propertyView({ label: trans("stepOptionsControl.subTitle") })}
655657
{this.children.description.propertyView({ label: trans("stepOptionsControl.description") })}
656-
{this.children.icon.propertyView({ label: trans("button.icon") })}
658+
{this.children.icon.propertyView({ label: trans("stepOptionsControl.icon") })}
657659
{this.children.status.propertyView({ label: trans("stepOptionsControl.status") })}
658660
{disabledPropertyView(this.children)}
659661
</>
@@ -663,10 +665,10 @@ StepOption = class extends StepOption implements OptionCompProperty {
663665

664666
export const StepOptionControl = optionsControl(StepOption, {
665667
initOptions: [
666-
{ label: "Step 1", subTitle: "Initialization", description: "Initial setup of parameters.", icon: "solid/play", status: "complete", disabled: "false" },
667-
{ label: "Step 2", subTitle: "Execution", description: "Execution of the main process.", icon: "solid/person-running", status: "in_progress", disabled: "false" },
668-
{ label: "Step 3", subTitle: "Finalization", description: "Final steps to complete the process.", icon: "solid/circle-check", status: "pending", disabled: "true" },
669-
{ label: "Step 4", subTitle: "Completion", description: "Process completed successfully.", icon: "solid/stamp", status: "complete", disabled: "true" },
668+
{ value: "1", label: "Step 1", subTitle: "Initialization", description: "Initial setup of parameters.", icon: "/icon:solid/play", status: "finish", disabled: "false" },
669+
{ value: "2", label: "Step 2", subTitle: "Execution", description: "Execution of the main process.", icon: "/icon:solid/person-running", status: "process", disabled: "false" },
670+
{ value: "3", label: "Step 3", subTitle: "Finalization", description: "Final steps to complete the process.", icon: "/icon:solid/circle-check", status: "wait", disabled: "true" },
671+
{ value: "4", label: "Step 4", subTitle: "Completion", description: "Process completed successfully.", status: "wait", disabled: "true" },
670672
],
671673
uniqField: "label",
672674
});

client/packages/lowcoder/src/comps/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ export var uiCompMap: Registry = {
908908
keywords: trans("uiComp.stepControlCompKeywords"),
909909
lazyLoad: true,
910910
compName: 'StepComp',
911-
compPath: 'comps/selectInputComp/stepsControl',
911+
compPath: 'comps/selectInputComp/stepControl',
912912
layoutInfo: {
913913
w: 6,
914914
h: 6,

client/packages/lowcoder/src/i18n/locales/en.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,10 +1255,36 @@ export const en = {
12551255
"tip": "The 'item' and 'i' Variables Represent the Value and Index of Each Item in the Data Array"
12561256
},
12571257
"stepOptionsControl": {
1258+
"value": "Value / Key",
12581259
"title": "Step Title",
12591260
"subTitle": "Step Subtitle",
12601261
"description": "Step Description",
12611262
"status": "Step Status",
1263+
"icon": "Step Icon",
1264+
},
1265+
"step" : {
1266+
"initialValue": "Start Numbers from",
1267+
"valueDesc": "Current Value",
1268+
"size" : "Steps Size",
1269+
"sizeSmall" : "Small",
1270+
"sizeDefault" : "Default",
1271+
"percent" : "Steps Percent",
1272+
"type" : "Steps Type",
1273+
"typeDefault" : "Standard",
1274+
"typeNavigation" : "Navigation",
1275+
"typeInline" : "Inline",
1276+
"direction" : "Steps Direction",
1277+
"directionVertical" : "Vertical",
1278+
"directionHorizontal" : "Horizontal",
1279+
"labelPlacement" : "Steps Label Placement",
1280+
"status" : "Steps Status",
1281+
"statusWait" : "Wait",
1282+
"statusProcess" : "Process",
1283+
"statusFinish" : "Finish",
1284+
"statusError" : "Error",
1285+
"showDots" : "Show Dots instead Symbols",
1286+
"showIcons" : "Show Icons instead Symbols",
1287+
"responsive" : "Responsive",
12621288
},
12631289
"radio": {
12641290
"options": "Options",

0 commit comments

Comments
 (0)