1
- import { default as Input } from "antd/es/input" ;
1
+ import { default as InputNumber } from "antd/es/input-number " ;
2
2
import { NumberControl , StringControl } from "comps/controls/codeControl" ;
3
3
import { BoolControl } from "comps/controls/boolControl" ;
4
4
import { trans } from "i18n" ;
5
5
import { ColumnTypeCompBuilder , ColumnTypeViewFn } from "../columnTypeCompBuilder" ;
6
6
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
+ ` ;
7
24
8
25
const childrenMap = {
9
26
text : NumberControl ,
27
+ step : withDefault ( NumberControl , 1 ) ,
10
28
float : BoolControl ,
11
29
prefix : StringControl ,
12
30
suffix : StringControl ,
13
31
} ;
14
32
15
33
let float = false ;
34
+ let step = 1 ;
16
35
const getBaseValue : ColumnTypeViewFn < typeof childrenMap , number , number > = (
17
36
props
18
37
) => {
@@ -24,6 +43,7 @@ export const ColumnNumberComp = (function () {
24
43
childrenMap ,
25
44
( props , dispatch ) => {
26
45
float = props . float ;
46
+ step = props . step ;
27
47
const value = ! float ? Math . floor ( props . changeValue ?? getBaseValue ( props , dispatch ) ) : props . changeValue ?? getBaseValue ( props , dispatch ) ;
28
48
return props . prefix + value + props . suffix ;
29
49
} ,
@@ -32,18 +52,20 @@ export const ColumnNumberComp = (function () {
32
52
)
33
53
. setEditViewFn ( ( props ) => {
34
54
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 >
47
69
) } )
48
70
. setPropertyViewFn ( ( children ) => {
49
71
return (
@@ -52,17 +74,31 @@ export const ColumnNumberComp = (function () {
52
74
label : trans ( "table.columnValue" ) ,
53
75
tooltip : ColumnValueTooltip ,
54
76
} ) }
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
+ } ) }
55
89
{ children . prefix . propertyView ( {
56
90
label : trans ( "table.prefix" ) ,
57
- // tooltip: ColumnValueTooltip,
58
91
} ) }
59
92
{ children . suffix . propertyView ( {
60
93
label : trans ( "table.suffix" ) ,
61
- // tooltip: ColumnValueTooltip,
62
94
} ) }
63
95
{ children . float . propertyView ( {
64
96
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
+ }
66
102
} ) }
67
103
</ >
68
104
) ;
0 commit comments