|
| 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 | +})(); |
0 commit comments