@momo-kits/stepper 0.102.3-beta.0 → 0.102.3-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.tsx +102 -77
- package/package.json +16 -16
- package/publish.sh +2 -11
- package/types.ts +4 -0
package/index.tsx
CHANGED
|
@@ -1,95 +1,120 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
forwardRef,
|
|
3
|
+
useEffect,
|
|
4
|
+
useImperativeHandle,
|
|
5
|
+
useState,
|
|
6
|
+
} from 'react';
|
|
2
7
|
import {View} from 'react-native';
|
|
3
8
|
import StepperButton from './StepperButton';
|
|
4
9
|
import {DisabledStatus, StepperProps} from './types';
|
|
5
10
|
import styles from './styles';
|
|
6
11
|
import NumberView from './NumberView';
|
|
7
12
|
|
|
8
|
-
const Stepper
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
const Stepper = forwardRef(
|
|
14
|
+
(
|
|
15
|
+
{
|
|
16
|
+
size = 'large',
|
|
17
|
+
defaultValue = 0,
|
|
18
|
+
min = 0,
|
|
19
|
+
max = 100,
|
|
20
|
+
disabled = false,
|
|
21
|
+
step = 1,
|
|
22
|
+
editable = false,
|
|
23
|
+
onValueChange,
|
|
24
|
+
}: StepperProps,
|
|
25
|
+
ref
|
|
26
|
+
) => {
|
|
27
|
+
const [value, setValue] = useState(defaultValue);
|
|
19
28
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
_onValueChange(newValue.toString());
|
|
27
|
-
};
|
|
28
|
-
const _onValueChange = (num: string) => {
|
|
29
|
-
let newValue = parseInt(num);
|
|
29
|
+
useImperativeHandle(ref, () => ({
|
|
30
|
+
setStepValue: (value: React.SetStateAction<number>) => {
|
|
31
|
+
setValue(value);
|
|
32
|
+
_onValueChange(value.toString());
|
|
33
|
+
},
|
|
34
|
+
}));
|
|
30
35
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
setValue(defaultValue);
|
|
38
|
+
}, [defaultValue]);
|
|
34
39
|
|
|
35
|
-
|
|
36
|
-
newValue =
|
|
37
|
-
|
|
40
|
+
const onPlus = () => {
|
|
41
|
+
let newValue = value + step;
|
|
42
|
+
_onValueChange(newValue.toString());
|
|
43
|
+
};
|
|
44
|
+
const onMinus = () => {
|
|
45
|
+
let newValue = value - step;
|
|
46
|
+
_onValueChange(newValue.toString());
|
|
47
|
+
};
|
|
48
|
+
const _onValueChange = (num: string) => {
|
|
49
|
+
let newValue = parseInt(num);
|
|
38
50
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
51
|
+
if (isNaN(newValue)) {
|
|
52
|
+
newValue = 0;
|
|
53
|
+
}
|
|
42
54
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const getViewDisabledStatus = () => {
|
|
47
|
-
let disabledStatus: DisabledStatus;
|
|
55
|
+
if (newValue > max) {
|
|
56
|
+
newValue = max;
|
|
57
|
+
}
|
|
48
58
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
minus: disabled[0],
|
|
53
|
-
number: disabled[0] && disabled[1],
|
|
54
|
-
};
|
|
55
|
-
} else {
|
|
56
|
-
disabledStatus = {
|
|
57
|
-
plus: disabled,
|
|
58
|
-
minus: disabled,
|
|
59
|
-
number: disabled,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
59
|
+
if (newValue < min) {
|
|
60
|
+
newValue = min;
|
|
61
|
+
}
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
disabledStatus
|
|
68
|
-
}
|
|
69
|
-
return disabledStatus;
|
|
70
|
-
};
|
|
63
|
+
setValue(newValue);
|
|
64
|
+
onValueChange?.(newValue);
|
|
65
|
+
};
|
|
66
|
+
const getViewDisabledStatus = () => {
|
|
67
|
+
let disabledStatus: DisabledStatus;
|
|
71
68
|
|
|
72
|
-
|
|
69
|
+
if (Array.isArray(disabled)) {
|
|
70
|
+
disabledStatus = {
|
|
71
|
+
plus: disabled[1],
|
|
72
|
+
minus: disabled[0],
|
|
73
|
+
number: disabled[0] && disabled[1],
|
|
74
|
+
};
|
|
75
|
+
} else {
|
|
76
|
+
disabledStatus = {
|
|
77
|
+
plus: disabled,
|
|
78
|
+
minus: disabled,
|
|
79
|
+
number: disabled,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
73
82
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
83
|
+
if (value === min) {
|
|
84
|
+
disabledStatus.minus = true;
|
|
85
|
+
}
|
|
86
|
+
if (value === max) {
|
|
87
|
+
disabledStatus.plus = true;
|
|
88
|
+
}
|
|
89
|
+
return disabledStatus;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const viewStatus = getViewDisabledStatus();
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<View style={styles.stepper}>
|
|
96
|
+
<StepperButton
|
|
97
|
+
onPress={onMinus}
|
|
98
|
+
sign={'-'}
|
|
99
|
+
size={size}
|
|
100
|
+
disabled={viewStatus.minus}
|
|
101
|
+
/>
|
|
102
|
+
<NumberView
|
|
103
|
+
onValueChange={_onValueChange}
|
|
104
|
+
size={size}
|
|
105
|
+
value={value}
|
|
106
|
+
disabled={viewStatus.number}
|
|
107
|
+
editable={editable}
|
|
108
|
+
/>
|
|
109
|
+
<StepperButton
|
|
110
|
+
onPress={onPlus}
|
|
111
|
+
size={size}
|
|
112
|
+
disabled={viewStatus.plus}
|
|
113
|
+
/>
|
|
114
|
+
</View>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
);
|
|
93
118
|
|
|
94
119
|
export {Stepper};
|
|
95
120
|
export type {StepperProps};
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
2
|
+
"name": "@momo-kits/stepper",
|
|
3
|
+
"version": "0.102.3-beta.2",
|
|
4
|
+
"private": false,
|
|
5
|
+
"main": "index.tsx",
|
|
6
|
+
"dependencies": {},
|
|
7
|
+
"peerDependencies": {
|
|
8
|
+
"@momo-kits/foundation": "latest",
|
|
9
|
+
"prop-types": "^15.7.2",
|
|
10
|
+
"react": "16.9.0",
|
|
11
|
+
"react-native": ">=0.55"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@momo-platform/versions": "4.1.11"
|
|
15
|
+
},
|
|
16
|
+
"license": "MoMo"
|
|
17
|
+
}
|
package/publish.sh
CHANGED
|
@@ -6,18 +6,9 @@ mkdir dist
|
|
|
6
6
|
rsync -r --exclude=/dist ./* dist
|
|
7
7
|
cd dist
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
#npm version patch
|
|
12
|
-
npm publish --tag stable --access=public
|
|
13
|
-
elif [ "$1" == "latest" ]; then
|
|
14
|
-
#npm version $(npm view @momo-kits/foundation@latest version)
|
|
15
|
-
npm publish --tag latest --access=public
|
|
16
|
-
else
|
|
17
|
-
#npm version $(npm view @momo-kits/stepper@beta version)
|
|
18
|
-
#npm version prerelease --preid=beta
|
|
9
|
+
npm version $(npm view @momo-kits/stepper@beta version)
|
|
10
|
+
npm version prerelease --preid=beta
|
|
19
11
|
npm publish --tag beta --access=public
|
|
20
|
-
fi
|
|
21
12
|
|
|
22
13
|
PACKAGE_NAME=$(npm pkg get name)
|
|
23
14
|
NEW_PACKAGE_VERSION=$(npm pkg get version)
|