Skip to content

Commit 1974df2

Browse files
authored
Merge pull request #329 from aaron1604/feat-table-number-input
feat: table number input added
2 parents eaab1d4 + 3889547 commit 1974df2

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-0
lines changed

client/packages/lowcoder/src/comps/comps/tableComp/column/columnTypeComp.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@ import { RatingComp } from "./columnTypeComps/columnRatingComp";
1515
import { BadgeStatusComp } from "./columnTypeComps/columnStatusComp";
1616
import { ColumnTagsComp } from "./columnTypeComps/columnTagsComp";
1717
import { SimpleTextComp } from "./columnTypeComps/simpleTextComp";
18+
import { ColumnNumberComp } from "./columnTypeComps/ColumnNumberComp";
1819

1920
const actionOptions = [
2021
{
2122
label: trans("table.text"),
2223
value: "text",
2324
},
25+
{
26+
label: trans("table.number"),
27+
value: "number",
28+
},
2429
{
2530
label: trans("table.link"),
2631
value: "link",
@@ -73,6 +78,7 @@ const actionOptions = [
7378

7479
export const ColumnTypeCompMap = {
7580
text: SimpleTextComp,
81+
number: ColumnNumberComp,
7682
button: ButtonComp,
7783
badgeStatus: BadgeStatusComp,
7884
link: LinkComp,
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { Input } from "antd";
2+
import { NumberControl, StringControl } from "comps/controls/codeControl";
3+
import { BoolControl } from "comps/controls/boolControl";
4+
import { trans } from "i18n";
5+
import { ColumnTypeCompBuilder, ColumnTypeViewFn } from "../columnTypeCompBuilder";
6+
import { ColumnValueTooltip } from "../simpleColumnTypeComps";
7+
8+
const childrenMap = {
9+
text: NumberControl,
10+
float: BoolControl,
11+
prefix: StringControl,
12+
suffix: StringControl,
13+
};
14+
15+
let float = false;
16+
const getBaseValue: ColumnTypeViewFn<typeof childrenMap, number, number> = (
17+
props
18+
) => {
19+
return props.text
20+
};
21+
22+
export const ColumnNumberComp = (function () {
23+
return new ColumnTypeCompBuilder(
24+
childrenMap,
25+
(props, dispatch) => {
26+
float = props.float;
27+
const value = !float ? Math.floor(props.changeValue ?? getBaseValue(props, dispatch)) : props.changeValue ?? getBaseValue(props, dispatch);
28+
return props.prefix + value + props.suffix;
29+
},
30+
(nodeValue) => nodeValue.text.value,
31+
getBaseValue,
32+
)
33+
.setEditViewFn((props) => {
34+
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+
/>
47+
)})
48+
.setPropertyViewFn((children) => {
49+
return (
50+
<>
51+
{children.text.propertyView({
52+
label: trans("table.columnValue"),
53+
tooltip: ColumnValueTooltip,
54+
})}
55+
{children.prefix.propertyView({
56+
label: trans("table.prefix"),
57+
// tooltip: ColumnValueTooltip,
58+
})}
59+
{children.suffix.propertyView({
60+
label: trans("table.suffix"),
61+
// tooltip: ColumnValueTooltip,
62+
})}
63+
{children.float.propertyView({
64+
label: trans("table.float"),
65+
// tooltip: ColumnValueTooltip,
66+
})}
67+
</>
68+
);
69+
})
70+
.build();
71+
})();

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,11 @@ export const en = {
11491149
auto: "Auto",
11501150
fixed: "Fixed",
11511151
columnType: "Column type",
1152+
float: "Float",
1153+
prefix: "Prefix",
1154+
suffix: "Suffix",
11521155
text: "Text",
1156+
number: "Number",
11531157
link: "Link",
11541158
links: "Links",
11551159
tag: "Tag",

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,11 @@ table: {
11301130
auto: "自动",
11311131
fixed: "固定",
11321132
columnType: "列类型",
1133+
float: "分数",
1134+
prefix: "字首",
1135+
suffix: "后缀",
11331136
text: "文本",
1137+
number: "数字",
11341138
link: "链接",
11351139
links: "多链接",
11361140
tag: "标签",

0 commit comments

Comments
 (0)