Skip to content

Commit d92f917

Browse files
author
Aqib Mirza
committed
feat: table number input added
1 parent 1252ad2 commit d92f917

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
@@ -1141,7 +1141,11 @@ export const en = {
11411141
auto: "Auto",
11421142
fixed: "Fixed",
11431143
columnType: "Column type",
1144+
float: "Float",
1145+
prefix: "Prefix",
1146+
suffix: "Suffix",
11441147
text: "Text",
1148+
number: "Number",
11451149
link: "Link",
11461150
links: "Links",
11471151
tag: "Tag",

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,11 @@ table: {
11221122
auto: "自动",
11231123
fixed: "固定",
11241124
columnType: "列类型",
1125+
float: "分数",
1126+
prefix: "字首",
1127+
suffix: "后缀",
11251128
text: "文本",
1129+
number: "数字",
11261130
link: "链接",
11271131
links: "链接",
11281132
tag: "标签",

0 commit comments

Comments
 (0)