Skip to content

Commit 2d76ceb

Browse files
added step control for number type columns
1 parent 8d485a2 commit 2d76ceb

File tree

5 files changed

+63
-18
lines changed

5 files changed

+63
-18
lines changed

client/packages/lowcoder/src/comps/comps/tableComp/column/columnTypeComps/ColumnNumberComp.tsx

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,37 @@
1-
import { default as Input } from "antd/es/input";
1+
import { default as InputNumber } from "antd/es/input-number";
22
import { NumberControl, StringControl } from "comps/controls/codeControl";
33
import { BoolControl } from "comps/controls/boolControl";
44
import { trans } from "i18n";
55
import { ColumnTypeCompBuilder, ColumnTypeViewFn } from "../columnTypeCompBuilder";
66
import { ColumnValueTooltip } from "../simpleColumnTypeComps";
7+
import { withDefault } from "comps/generators";
8+
import styled from "styled-components";
9+
10+
const InputNumberWrapper = styled.div`
11+
.ant-input-number {
12+
width: 100%;
13+
border-radius: 0;
14+
background: transparent !important;
15+
padding: 0 !important;
16+
box-shadow: none;
17+
18+
input {
19+
padding: 0;
20+
border-radius: 0;
21+
}
22+
}
23+
`;
724

825
const childrenMap = {
926
text: NumberControl,
27+
step: withDefault(NumberControl, 1),
1028
float: BoolControl,
1129
prefix: StringControl,
1230
suffix: StringControl,
1331
};
1432

1533
let float = false;
34+
let step = 1;
1635
const getBaseValue: ColumnTypeViewFn<typeof childrenMap, number, number> = (
1736
props
1837
) => {
@@ -24,6 +43,7 @@ export const ColumnNumberComp = (function () {
2443
childrenMap,
2544
(props, dispatch) => {
2645
float = props.float;
46+
step = props.step;
2747
const value = !float ? Math.floor(props.changeValue ?? getBaseValue(props, dispatch)) : props.changeValue ?? getBaseValue(props, dispatch);
2848
return props.prefix + value + props.suffix;
2949
},
@@ -32,18 +52,20 @@ export const ColumnNumberComp = (function () {
3252
)
3353
.setEditViewFn((props) => {
3454
return (
35-
<Input
36-
type="number"
37-
step={float?"0.01": "1"}
38-
defaultValue={props.value}
39-
autoFocus
40-
bordered={false}
41-
onChange={(e) => {
42-
props.onChange(!float ? Math.floor(e.target.valueAsNumber) : e.target.valueAsNumber);
43-
}}
44-
onBlur={props.onChangeEnd}
45-
onPressEnter={props.onChangeEnd}
46-
/>
55+
<InputNumberWrapper>
56+
<InputNumber
57+
step={step}
58+
defaultValue={props.value}
59+
autoFocus
60+
bordered={false}
61+
onChange={(value) => {
62+
value = value ?? 0;
63+
props.onChange(!float ? Math.floor(value) : value);
64+
}}
65+
onBlur={props.onChangeEnd}
66+
onPressEnter={props.onChangeEnd}
67+
/>
68+
</InputNumberWrapper>
4769
)})
4870
.setPropertyViewFn((children) => {
4971
return (
@@ -52,17 +74,31 @@ export const ColumnNumberComp = (function () {
5274
label: trans("table.columnValue"),
5375
tooltip: ColumnValueTooltip,
5476
})}
77+
{children.step.propertyView({
78+
label: trans("table.numberStep"),
79+
tooltip: trans("table.numberStepTooltip"),
80+
onFocus: (focused) => {
81+
if(!focused) {
82+
const value = children.step.getView();
83+
const isFloat = children.float.getView();
84+
const newValue = !isFloat ? Math.floor(value) : value;
85+
children.step.dispatchChangeValueAction(String(newValue));
86+
}
87+
}
88+
})}
5589
{children.prefix.propertyView({
5690
label: trans("table.prefix"),
57-
// tooltip: ColumnValueTooltip,
5891
})}
5992
{children.suffix.propertyView({
6093
label: trans("table.suffix"),
61-
// tooltip: ColumnValueTooltip,
6294
})}
6395
{children.float.propertyView({
6496
label: trans("table.float"),
65-
// tooltip: ColumnValueTooltip,
97+
onChange: (isFloat) => {
98+
const value = children.step.getView();
99+
const newValue = !isFloat ? Math.floor(value) : value;
100+
children.step.dispatchChangeValueAction(String(newValue));
101+
}
66102
})}
67103
</>
68104
);

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class BoolControl extends AbstractComp<boolean, DataType, Node<ValueAndMsg<boole
106106
return customAction<ChangeModeAction>({ useCodeEditor: !this.useCodeEditor }, true);
107107
}
108108

109-
propertyView(params: ControlParams) {
109+
propertyView(params: ControlParams & {onChange?: (changed: boolean) => void}) {
110110
const changeModeIcon = (
111111
<SwitchJsIcon
112112
checked={this.useCodeEditor}
@@ -127,7 +127,10 @@ class BoolControl extends AbstractComp<boolean, DataType, Node<ValueAndMsg<boole
127127
{!this.useCodeEditor && (
128128
<Switch
129129
value={this.getView()}
130-
onChange={(x) => this.dispatchChangeValueAction(x)}
130+
onChange={(x) => {
131+
this.dispatchChangeValueAction(x);
132+
params?.onChange?.(x);
133+
}}
131134
></Switch>
132135
)}
133136
</SwitchWrapper>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,8 @@ export const de = {
11351135
"auto": "Auto",
11361136
"fixed": "Festgelegt",
11371137
"columnType": "Säule Typ",
1138+
"numberStep": "Schritt",
1139+
"numberStepTooltip": "Die Zahl, auf die der aktuelle Wert erhöht oder verringert wird. Es kann eine ganze Zahl oder eine Dezimalzahl sein",
11381140
"float": "Schwimmer",
11391141
"prefix": "Präfix",
11401142
"suffix": "Nachsilbe",

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,8 @@ export const en = {
12391239
"auto": "Auto",
12401240
"fixed": "Fixed",
12411241
"columnType": "Column Type",
1242+
"numberStep": "Step",
1243+
"numberStepTooltip": "The number to which the current value is increased or decreased. It can be an integer or decimal",
12421244
"float": "Float",
12431245
"prefix": "Prefix",
12441246
"suffix": "Suffix",

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,8 @@ table: {
12101210
auto: "自动",
12111211
fixed: "固定",
12121212
columnType: "列类型",
1213+
numberStep: "步",
1214+
numberStepTooltip: "当前值增加或减少的数量。它可以是整数或小数",
12131215
float: "分数",
12141216
prefix: "字首",
12151217
suffix: "后缀",

0 commit comments

Comments
 (0)