Skip to content

feat: table number input added #329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ import { RatingComp } from "./columnTypeComps/columnRatingComp";
import { BadgeStatusComp } from "./columnTypeComps/columnStatusComp";
import { ColumnTagsComp } from "./columnTypeComps/columnTagsComp";
import { SimpleTextComp } from "./columnTypeComps/simpleTextComp";
import { ColumnNumberComp } from "./columnTypeComps/ColumnNumberComp";

const actionOptions = [
{
label: trans("table.text"),
value: "text",
},
{
label: trans("table.number"),
value: "number",
},
{
label: trans("table.link"),
value: "link",
Expand Down Expand Up @@ -73,6 +78,7 @@ const actionOptions = [

export const ColumnTypeCompMap = {
text: SimpleTextComp,
number: ColumnNumberComp,
button: ButtonComp,
badgeStatus: BadgeStatusComp,
link: LinkComp,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { Input } from "antd";
import { NumberControl, StringControl } from "comps/controls/codeControl";
import { BoolControl } from "comps/controls/boolControl";
import { trans } from "i18n";
import { ColumnTypeCompBuilder, ColumnTypeViewFn } from "../columnTypeCompBuilder";
import { ColumnValueTooltip } from "../simpleColumnTypeComps";

const childrenMap = {
text: NumberControl,
float: BoolControl,
prefix: StringControl,
suffix: StringControl,
};

let float = false;
const getBaseValue: ColumnTypeViewFn<typeof childrenMap, number, number> = (
props
) => {
return props.text
};

export const ColumnNumberComp = (function () {
return new ColumnTypeCompBuilder(
childrenMap,
(props, dispatch) => {
float = props.float;
const value = !float ? Math.floor(props.changeValue ?? getBaseValue(props, dispatch)) : props.changeValue ?? getBaseValue(props, dispatch);
return props.prefix + value + props.suffix;
},
(nodeValue) => nodeValue.text.value,
getBaseValue,
)
.setEditViewFn((props) => {
return (
<Input
type="number"
step={float?"0.01": "1"}
defaultValue={props.value}
autoFocus
bordered={false}
onChange={(e) => {
props.onChange(!float ? Math.floor(e.target.valueAsNumber) : e.target.valueAsNumber);
}}
onBlur={props.onChangeEnd}
onPressEnter={props.onChangeEnd}
/>
)})
.setPropertyViewFn((children) => {
return (
<>
{children.text.propertyView({
label: trans("table.columnValue"),
tooltip: ColumnValueTooltip,
})}
{children.prefix.propertyView({
label: trans("table.prefix"),
// tooltip: ColumnValueTooltip,
})}
{children.suffix.propertyView({
label: trans("table.suffix"),
// tooltip: ColumnValueTooltip,
})}
{children.float.propertyView({
label: trans("table.float"),
// tooltip: ColumnValueTooltip,
})}
</>
);
})
.build();
})();
4 changes: 4 additions & 0 deletions client/packages/lowcoder/src/i18n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,11 @@ export const en = {
auto: "Auto",
fixed: "Fixed",
columnType: "Column type",
float: "Float",
prefix: "Prefix",
suffix: "Suffix",
text: "Text",
number: "Number",
link: "Link",
links: "Links",
tag: "Tag",
Expand Down
4 changes: 4 additions & 0 deletions client/packages/lowcoder/src/i18n/locales/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,11 @@ table: {
auto: "自动",
fixed: "固定",
columnType: "列类型",
float: "分数",
prefix: "字首",
suffix: "后缀",
text: "文本",
number: "数字",
link: "链接",
links: "多链接",
tag: "标签",
Expand Down