@mpxjs/webpack-plugin 2.9.59 → 2.9.64
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/lib/index.js +1 -3
- package/lib/platform/style/wx/index.js +344 -270
- package/lib/platform/template/wx/component-config/checkbox-group.js +8 -0
- package/lib/platform/template/wx/component-config/checkbox.js +8 -0
- package/lib/platform/template/wx/component-config/cover-image.js +15 -0
- package/lib/platform/template/wx/component-config/cover-view.js +9 -0
- package/lib/platform/template/wx/component-config/form.js +13 -1
- package/lib/platform/template/wx/component-config/icon.js +8 -0
- package/lib/platform/template/wx/component-config/index.js +5 -1
- package/lib/platform/template/wx/component-config/label.js +15 -0
- package/lib/platform/template/wx/component-config/movable-area.js +18 -1
- package/lib/platform/template/wx/component-config/movable-view.js +18 -1
- package/lib/platform/template/wx/component-config/navigator.js +8 -0
- package/lib/platform/template/wx/component-config/picker-view-column.js +8 -0
- package/lib/platform/template/wx/component-config/picker-view.js +18 -2
- package/lib/platform/template/wx/component-config/picker.js +14 -1
- package/lib/platform/template/wx/component-config/radio-group.js +8 -0
- package/lib/platform/template/wx/component-config/radio.js +8 -0
- package/lib/platform/template/wx/component-config/root-portal.js +15 -0
- package/lib/platform/template/wx/component-config/switch.js +8 -0
- package/lib/platform/template/wx/component-config/unsupported.js +1 -3
- package/lib/react/processScript.js +2 -0
- package/lib/react/processStyles.js +1 -0
- package/lib/react/processTemplate.js +2 -3
- package/lib/react/style-helper.js +12 -7
- package/lib/runtime/components/react/context.ts +40 -0
- package/lib/runtime/components/react/dist/context.js +8 -0
- package/lib/runtime/components/react/dist/getInnerListeners.js +34 -12
- package/lib/runtime/components/react/dist/mpx-button.jsx +88 -88
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +82 -0
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +139 -0
- package/lib/runtime/components/react/dist/mpx-form.jsx +61 -0
- package/lib/runtime/components/react/dist/mpx-icon.jsx +48 -0
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +39 -43
- package/lib/runtime/components/react/dist/mpx-image/svg.jsx +3 -2
- package/lib/runtime/components/react/dist/mpx-input.jsx +63 -37
- package/lib/runtime/components/react/dist/mpx-label.jsx +55 -0
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +41 -0
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +346 -0
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +35 -0
- package/lib/runtime/components/react/dist/mpx-picker/date.jsx +69 -0
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +138 -0
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +142 -0
- package/lib/runtime/components/react/dist/mpx-picker/region.jsx +94 -0
- package/lib/runtime/components/react/dist/mpx-picker/regionData.js +6099 -0
- package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +76 -0
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +244 -0
- package/lib/runtime/components/react/dist/mpx-picker/type.js +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +107 -0
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +162 -0
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +80 -0
- package/lib/runtime/components/react/dist/mpx-radio.jsx +154 -0
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +15 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +93 -70
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +281 -157
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +21 -11
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +19 -11
- package/lib/runtime/components/react/dist/mpx-switch.jsx +79 -0
- package/lib/runtime/components/react/dist/mpx-text.jsx +21 -49
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-view.jsx +451 -146
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +17 -20
- package/lib/runtime/components/react/dist/parser.js +218 -0
- package/lib/runtime/components/react/dist/types/common.js +1 -0
- package/lib/runtime/components/react/dist/useNodesRef.js +3 -8
- package/lib/runtime/components/react/dist/utils.jsx +433 -0
- package/lib/runtime/components/react/getInnerListeners.ts +43 -21
- package/lib/runtime/components/react/mpx-button.tsx +129 -119
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +152 -0
- package/lib/runtime/components/react/mpx-checkbox.tsx +234 -0
- package/lib/runtime/components/react/mpx-form.tsx +117 -0
- package/lib/runtime/components/react/mpx-icon.tsx +106 -0
- package/lib/runtime/components/react/mpx-image/index.tsx +62 -68
- package/lib/runtime/components/react/mpx-image/svg.tsx +7 -5
- package/lib/runtime/components/react/mpx-input.tsx +90 -42
- package/lib/runtime/components/react/mpx-label.tsx +110 -0
- package/lib/runtime/components/react/mpx-movable-area.tsx +81 -0
- package/lib/runtime/components/react/mpx-movable-view.tsx +424 -0
- package/lib/runtime/components/react/mpx-navigator.tsx +67 -0
- package/lib/runtime/components/react/mpx-picker/date.tsx +82 -0
- package/lib/runtime/components/react/mpx-picker/index.tsx +155 -0
- package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +156 -0
- package/lib/runtime/components/react/mpx-picker/region.tsx +107 -0
- package/lib/runtime/components/react/mpx-picker/regionData.ts +6101 -0
- package/lib/runtime/components/react/mpx-picker/selector.tsx +91 -0
- package/lib/runtime/components/react/mpx-picker/time.tsx +270 -0
- package/lib/runtime/components/react/mpx-picker/type.ts +107 -0
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +156 -0
- package/lib/runtime/components/react/mpx-picker-view.tsx +220 -0
- package/lib/runtime/components/react/mpx-radio-group.tsx +150 -0
- package/lib/runtime/components/react/mpx-radio.tsx +230 -0
- package/lib/runtime/components/react/mpx-root-portal.tsx +27 -0
- package/lib/runtime/components/react/mpx-scroll-view.tsx +184 -130
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +308 -183
- package/lib/runtime/components/react/mpx-swiper/index.tsx +27 -19
- package/lib/runtime/components/react/mpx-swiper/type.ts +23 -5
- package/lib/runtime/components/react/mpx-swiper-item.tsx +49 -14
- package/lib/runtime/components/react/mpx-switch.tsx +148 -0
- package/lib/runtime/components/react/mpx-text.tsx +53 -77
- package/lib/runtime/components/react/mpx-textarea.tsx +3 -3
- package/lib/runtime/components/react/mpx-view.tsx +576 -195
- package/lib/runtime/components/react/mpx-web-view.tsx +34 -39
- package/lib/runtime/components/react/parser.ts +245 -0
- package/lib/runtime/components/react/types/common.ts +12 -0
- package/lib/runtime/components/react/types/getInnerListeners.ts +2 -1
- package/lib/runtime/components/react/types/global.d.ts +17 -1
- package/lib/runtime/components/react/useNodesRef.ts +4 -10
- package/lib/runtime/components/react/utils.tsx +505 -0
- package/lib/runtime/optionProcessor.js +19 -17
- package/lib/template-compiler/compiler.js +84 -61
- package/lib/template-compiler/gen-node-react.js +7 -9
- package/lib/web/processStyles.js +2 -5
- package/package.json +8 -3
- package/lib/runtime/components/react/dist/utils.js +0 -80
- package/lib/runtime/components/react/utils.ts +0 -92
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* ✔ plain
|
|
5
5
|
* ✔ disabled
|
|
6
6
|
* ✔ loading
|
|
7
|
-
*
|
|
7
|
+
* ✔ form-type
|
|
8
8
|
* - open-type: Partially. Only support `share`、`getUserInfo`
|
|
9
9
|
* ✔ hover-class: Convert hoverClass to hoverStyle.
|
|
10
10
|
* ✔ hover-style
|
|
@@ -34,20 +34,22 @@
|
|
|
34
34
|
* ✘ bindagreeprivacyauthorization
|
|
35
35
|
* ✔ bindtap
|
|
36
36
|
*/
|
|
37
|
-
import
|
|
38
|
-
import { View,
|
|
39
|
-
import {
|
|
37
|
+
import { useEffect, useRef, useState, forwardRef, useContext } from 'react';
|
|
38
|
+
import { View, StyleSheet, Animated, Easing } from 'react-native';
|
|
39
|
+
import { warn } from '@mpxjs/utils';
|
|
40
|
+
import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren } from './utils';
|
|
40
41
|
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
41
42
|
import useNodesRef from './useNodesRef';
|
|
43
|
+
import { FormContext } from './context';
|
|
42
44
|
const LOADING_IMAGE_URI = 'data:image/png;base64,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';
|
|
43
45
|
const TypeColorMap = {
|
|
44
46
|
default: ['#F8F8F8', '#DEDEDE', '35,35,35', '#F7F7F7'],
|
|
45
47
|
primary: ['#1AAD19', '#179B16', '26,173,25', '#9ED99D'],
|
|
46
|
-
warn: ['#E64340', '#CE3C39', '230,67,64', '#EC8B89']
|
|
48
|
+
warn: ['#E64340', '#CE3C39', '230,67,64', '#EC8B89']
|
|
47
49
|
};
|
|
48
50
|
const OpenTypeEventsMap = new Map([
|
|
49
51
|
['share', 'onShareAppMessage'],
|
|
50
|
-
['getUserInfo', 'onUserInfo']
|
|
52
|
+
['getUserInfo', 'onUserInfo']
|
|
51
53
|
]);
|
|
52
54
|
const styles = StyleSheet.create({
|
|
53
55
|
button: {
|
|
@@ -61,35 +63,33 @@ const styles = StyleSheet.create({
|
|
|
61
63
|
marginHorizontal: 'auto' // 按钮默认居中
|
|
62
64
|
},
|
|
63
65
|
buttonMini: {
|
|
64
|
-
height: 30
|
|
66
|
+
height: 30
|
|
65
67
|
},
|
|
66
68
|
text: {
|
|
67
69
|
fontSize: 18,
|
|
68
|
-
color: '#000000'
|
|
70
|
+
color: '#000000'
|
|
69
71
|
},
|
|
70
72
|
textMini: {
|
|
71
|
-
fontSize: 13
|
|
73
|
+
fontSize: 13
|
|
72
74
|
},
|
|
73
75
|
loading: {
|
|
74
76
|
width: 20,
|
|
75
|
-
height: 20
|
|
76
|
-
}
|
|
77
|
+
height: 20
|
|
78
|
+
}
|
|
77
79
|
});
|
|
78
80
|
const getOpenTypeEvent = (openType) => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
console.warn('Environment not supported');
|
|
81
|
+
if (!global.__mpx?.config?.rnConfig) {
|
|
82
|
+
warn('Environment not supported');
|
|
82
83
|
return;
|
|
83
84
|
}
|
|
84
85
|
const eventName = OpenTypeEventsMap.get(openType);
|
|
85
86
|
if (!eventName) {
|
|
86
|
-
|
|
87
|
+
warn(`open-type not support ${openType}`);
|
|
87
88
|
return;
|
|
88
89
|
}
|
|
89
|
-
|
|
90
|
-
const event = global.__mpx.config.rnConfig?.openTypeHandler?.[eventName];
|
|
90
|
+
const event = global.__mpx.config.rnConfig.openTypeHandler?.[eventName];
|
|
91
91
|
if (!event) {
|
|
92
|
-
|
|
92
|
+
warn(`Unregistered ${eventName} event`);
|
|
93
93
|
return;
|
|
94
94
|
}
|
|
95
95
|
return event;
|
|
@@ -98,7 +98,7 @@ const Loading = ({ alone = false }) => {
|
|
|
98
98
|
const image = useRef(new Animated.Value(0)).current;
|
|
99
99
|
const rotate = image.interpolate({
|
|
100
100
|
inputRange: [0, 1],
|
|
101
|
-
outputRange: ['0deg', '360deg']
|
|
101
|
+
outputRange: ['0deg', '360deg']
|
|
102
102
|
});
|
|
103
103
|
useEffect(() => {
|
|
104
104
|
const animation = Animated.loop(Animated.timing(image, {
|
|
@@ -106,33 +106,37 @@ const Loading = ({ alone = false }) => {
|
|
|
106
106
|
duration: 1000,
|
|
107
107
|
easing: Easing.linear,
|
|
108
108
|
useNativeDriver: true,
|
|
109
|
-
isInteraction: false
|
|
109
|
+
isInteraction: false
|
|
110
110
|
}));
|
|
111
111
|
animation.start();
|
|
112
112
|
return () => {
|
|
113
113
|
animation.stop();
|
|
114
114
|
};
|
|
115
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
116
115
|
}, []);
|
|
117
116
|
const loadingStyle = {
|
|
118
117
|
...styles.loading,
|
|
119
118
|
transform: [{ rotate }],
|
|
120
|
-
marginRight: alone ? 0 : 5
|
|
119
|
+
marginRight: alone ? 0 : 5
|
|
121
120
|
};
|
|
122
121
|
return <Animated.Image testID="loading" style={loadingStyle} source={{ uri: LOADING_IMAGE_URI }}/>;
|
|
123
122
|
};
|
|
124
|
-
const Button = forwardRef((
|
|
125
|
-
const {
|
|
123
|
+
const Button = forwardRef((buttonProps, ref) => {
|
|
124
|
+
const { textProps, innerProps: props = {} } = splitProps(buttonProps);
|
|
125
|
+
const { size = 'default', type = 'default', plain = false, disabled = false, loading = false, 'hover-class': hoverClass, 'hover-style': hoverStyle = {}, 'hover-start-time': hoverStartTime = 20, 'hover-stay-time': hoverStayTime = 70, 'open-type': openType, 'form-type': formType, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, style = {}, children, bindgetuserinfo, bindtap, bindtouchstart, bindtouchend } = props;
|
|
126
|
+
const formContext = useContext(FormContext);
|
|
127
|
+
let submitFn;
|
|
128
|
+
let resetFn;
|
|
129
|
+
if (formContext) {
|
|
130
|
+
submitFn = formContext.submit;
|
|
131
|
+
resetFn = formContext.reset;
|
|
132
|
+
}
|
|
126
133
|
const refs = useRef({
|
|
127
134
|
hoverStartTimer: undefined,
|
|
128
|
-
hoverStayTimer: undefined
|
|
135
|
+
hoverStayTimer: undefined
|
|
129
136
|
});
|
|
130
|
-
const layoutRef = useRef({});
|
|
131
137
|
const [isHover, setIsHover] = useState(false);
|
|
132
138
|
const isMiniSize = size === 'mini';
|
|
133
139
|
const applyHoverEffect = isHover && hoverClass !== 'none';
|
|
134
|
-
const inheritTextStyle = extractTextStyle(style);
|
|
135
|
-
const textHoverStyle = extractTextStyle(hoverStyle);
|
|
136
140
|
const [color, hoverColor, plainColor, disabledColor] = TypeColorMap[type];
|
|
137
141
|
const normalBackgroundColor = disabled ? disabledColor : applyHoverEffect || loading ? hoverColor : color;
|
|
138
142
|
const plainBorderColor = disabled
|
|
@@ -153,20 +157,34 @@ const Button = forwardRef((props, ref) => {
|
|
|
153
157
|
borderWidth: 1,
|
|
154
158
|
borderStyle: 'solid',
|
|
155
159
|
borderColor: plain ? plainBorderColor : normalBorderColor,
|
|
156
|
-
backgroundColor: plain ? 'transparent' : normalBackgroundColor
|
|
160
|
+
backgroundColor: plain ? 'transparent' : normalBackgroundColor
|
|
161
|
+
};
|
|
162
|
+
const defaultViewStyle = {
|
|
163
|
+
...styles.button,
|
|
164
|
+
...(isMiniSize && styles.buttonMini),
|
|
165
|
+
...viewStyle
|
|
166
|
+
};
|
|
167
|
+
const defaultTextStyle = {
|
|
168
|
+
...styles.text,
|
|
169
|
+
...(isMiniSize && styles.textMini),
|
|
170
|
+
color: plain ? plainTextColor : normalTextColor
|
|
157
171
|
};
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
...
|
|
172
|
+
const defaultStyle = {
|
|
173
|
+
...defaultViewStyle,
|
|
174
|
+
...defaultTextStyle
|
|
161
175
|
};
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
176
|
+
const styleObj = {
|
|
177
|
+
...defaultStyle,
|
|
178
|
+
...style,
|
|
179
|
+
...(applyHoverEffect && hoverStyle)
|
|
180
|
+
};
|
|
181
|
+
const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
|
|
182
|
+
const { nodeRef } = useNodesRef(props, ref, { defaultStyle });
|
|
183
|
+
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
|
|
184
|
+
const { textStyle, backgroundStyle, innerStyle } = splitStyle(normalStyle);
|
|
185
|
+
if (backgroundStyle) {
|
|
186
|
+
warn('Button does not support background image-related styles!');
|
|
187
|
+
}
|
|
170
188
|
const handleOpenTypeEvent = (evt) => {
|
|
171
189
|
if (!openType)
|
|
172
190
|
return;
|
|
@@ -174,14 +192,16 @@ const Button = forwardRef((props, ref) => {
|
|
|
174
192
|
if (openType === 'share') {
|
|
175
193
|
handleEvent && handleEvent({
|
|
176
194
|
from: 'button',
|
|
177
|
-
target: getCustomEvent('tap', evt, { layoutRef }, props).target
|
|
195
|
+
target: getCustomEvent('tap', evt, { layoutRef }, props).target
|
|
178
196
|
});
|
|
179
197
|
}
|
|
180
|
-
if (openType === 'getUserInfo') {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
198
|
+
if (openType === 'getUserInfo' && handleEvent && bindgetuserinfo) {
|
|
199
|
+
Promise.resolve(handleEvent)
|
|
200
|
+
.then((userInfo) => {
|
|
201
|
+
if (typeof userInfo === 'object') {
|
|
202
|
+
bindgetuserinfo(userInfo);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
185
205
|
}
|
|
186
206
|
};
|
|
187
207
|
const setStayTimer = () => {
|
|
@@ -210,60 +230,40 @@ const Button = forwardRef((props, ref) => {
|
|
|
210
230
|
return;
|
|
211
231
|
setStayTimer();
|
|
212
232
|
};
|
|
233
|
+
const handleFormTypeFn = () => {
|
|
234
|
+
if (formType === 'submit') {
|
|
235
|
+
submitFn && submitFn();
|
|
236
|
+
}
|
|
237
|
+
else if (formType === 'reset') {
|
|
238
|
+
resetFn && resetFn();
|
|
239
|
+
}
|
|
240
|
+
};
|
|
213
241
|
const onTap = (evt) => {
|
|
214
242
|
if (disabled)
|
|
215
243
|
return;
|
|
216
244
|
bindtap && bindtap(getCustomEvent('tap', evt, { layoutRef }, props));
|
|
217
245
|
handleOpenTypeEvent(evt);
|
|
218
|
-
|
|
219
|
-
const catchTap = (evt) => {
|
|
220
|
-
if (disabled)
|
|
221
|
-
return;
|
|
222
|
-
catchtap && catchtap(getCustomEvent('tap', evt, { layoutRef }, props));
|
|
223
|
-
};
|
|
224
|
-
function wrapChildren(children, textStyle) {
|
|
225
|
-
if (every(children, (child) => isText(child))) {
|
|
226
|
-
children = [<Text key='buttonTextWrap' style={textStyle}>{children}</Text>];
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
if (textStyle)
|
|
230
|
-
console.warn('Text style will be ignored unless every child of the Button is Text node!');
|
|
231
|
-
}
|
|
232
|
-
return children;
|
|
233
|
-
}
|
|
234
|
-
const { nodeRef } = useNodesRef(props, ref, {
|
|
235
|
-
defaultStyle: StyleSheet.flatten([
|
|
236
|
-
...defaultViewStyle,
|
|
237
|
-
...defaultTextStyle,
|
|
238
|
-
])
|
|
239
|
-
});
|
|
240
|
-
const onLayout = () => {
|
|
241
|
-
nodeRef.current?.measure((x, y, width, height, offsetLeft, offsetTop) => {
|
|
242
|
-
layoutRef.current = { x, y, width, height, offsetLeft, offsetTop };
|
|
243
|
-
});
|
|
246
|
+
handleFormTypeFn();
|
|
244
247
|
};
|
|
245
248
|
const innerProps = useInnerProps(props, {
|
|
246
249
|
ref: nodeRef,
|
|
250
|
+
style: { ...innerStyle, ...layoutStyle },
|
|
251
|
+
...layoutProps,
|
|
247
252
|
bindtouchstart: onTouchStart,
|
|
248
253
|
bindtouchend: onTouchEnd,
|
|
249
|
-
bindtap: onTap
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
'enable-offset'
|
|
254
|
-
], {
|
|
255
|
-
layoutRef
|
|
254
|
+
bindtap: onTap
|
|
255
|
+
}, [], {
|
|
256
|
+
layoutRef,
|
|
257
|
+
disableTap: disabled
|
|
256
258
|
});
|
|
257
|
-
return (<View {...innerProps}
|
|
258
|
-
...defaultViewStyle,
|
|
259
|
-
style,
|
|
260
|
-
applyHoverEffect && hoverStyle,
|
|
261
|
-
]}>
|
|
259
|
+
return (<View {...innerProps}>
|
|
262
260
|
{loading && <Loading alone={!children}/>}
|
|
263
|
-
{wrapChildren(
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
261
|
+
{wrapChildren(props, {
|
|
262
|
+
hasVarDec,
|
|
263
|
+
varContext: varContextRef.current,
|
|
264
|
+
textStyle,
|
|
265
|
+
textProps
|
|
266
|
+
})}
|
|
267
267
|
</View>);
|
|
268
268
|
});
|
|
269
269
|
Button.displayName = 'mpx-button';
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ✔ bindchange
|
|
3
|
+
*/
|
|
4
|
+
import { useRef, forwardRef, useContext } from 'react';
|
|
5
|
+
import { View } from 'react-native';
|
|
6
|
+
import { warn } from '@mpxjs/utils';
|
|
7
|
+
import { FormContext, CheckboxGroupContext } from './context';
|
|
8
|
+
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
9
|
+
import useNodesRef from './useNodesRef';
|
|
10
|
+
import { useLayout, useTransformStyle, wrapChildren } from './utils';
|
|
11
|
+
const CheckboxGroup = forwardRef((props, ref) => {
|
|
12
|
+
const { style = {}, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, bindchange } = props;
|
|
13
|
+
const formContext = useContext(FormContext);
|
|
14
|
+
let formValuesMap;
|
|
15
|
+
if (formContext) {
|
|
16
|
+
formValuesMap = formContext.formValuesMap;
|
|
17
|
+
}
|
|
18
|
+
const groupValue = useRef({}).current;
|
|
19
|
+
const defaultStyle = {
|
|
20
|
+
flexDirection: 'row',
|
|
21
|
+
flexWrap: 'wrap'
|
|
22
|
+
};
|
|
23
|
+
const styleObj = {
|
|
24
|
+
...defaultStyle,
|
|
25
|
+
...style
|
|
26
|
+
};
|
|
27
|
+
const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
|
|
28
|
+
const { nodeRef } = useNodesRef(props, ref, { defaultStyle });
|
|
29
|
+
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
|
|
30
|
+
const getSelectionValue = () => {
|
|
31
|
+
const arr = [];
|
|
32
|
+
for (const key in groupValue) {
|
|
33
|
+
if (groupValue[key].checked) {
|
|
34
|
+
arr.push(key);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return arr;
|
|
38
|
+
};
|
|
39
|
+
const getValue = () => {
|
|
40
|
+
return getSelectionValue();
|
|
41
|
+
};
|
|
42
|
+
const resetValue = () => {
|
|
43
|
+
Object.keys(groupValue).forEach((key) => {
|
|
44
|
+
groupValue[key].checked = false;
|
|
45
|
+
groupValue[key].setValue(false);
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
if (formValuesMap) {
|
|
49
|
+
if (!props.name) {
|
|
50
|
+
warn('If a form component is used, the name attribute is required.');
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
formValuesMap.set(props.name, { getValue, resetValue });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const notifyChange = (evt) => {
|
|
57
|
+
bindchange &&
|
|
58
|
+
bindchange(getCustomEvent('tap', evt, {
|
|
59
|
+
layoutRef,
|
|
60
|
+
detail: {
|
|
61
|
+
value: getSelectionValue()
|
|
62
|
+
}
|
|
63
|
+
}, props));
|
|
64
|
+
};
|
|
65
|
+
const innerProps = useInnerProps(props, {
|
|
66
|
+
ref: nodeRef,
|
|
67
|
+
style: { ...normalStyle, ...layoutStyle },
|
|
68
|
+
...layoutProps
|
|
69
|
+
}, [], {
|
|
70
|
+
layoutRef
|
|
71
|
+
});
|
|
72
|
+
return (<View {...innerProps}>
|
|
73
|
+
<CheckboxGroupContext.Provider value={{ groupValue, notifyChange }}>
|
|
74
|
+
{wrapChildren(props, {
|
|
75
|
+
hasVarDec,
|
|
76
|
+
varContext: varContextRef.current
|
|
77
|
+
})}
|
|
78
|
+
</CheckboxGroupContext.Provider>
|
|
79
|
+
</View>);
|
|
80
|
+
});
|
|
81
|
+
CheckboxGroup.displayName = 'mpx-checkbox-group';
|
|
82
|
+
export default CheckboxGroup;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ✔ value
|
|
3
|
+
* ✔ disabled
|
|
4
|
+
* ✔ checked
|
|
5
|
+
* ✔ color
|
|
6
|
+
*/
|
|
7
|
+
import { useState, forwardRef, useEffect, useContext } from 'react';
|
|
8
|
+
import { View, StyleSheet } from 'react-native';
|
|
9
|
+
import { warn } from '@mpxjs/utils';
|
|
10
|
+
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
11
|
+
import useNodesRef from './useNodesRef';
|
|
12
|
+
import Icon from './mpx-icon';
|
|
13
|
+
import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren } from './utils';
|
|
14
|
+
import { CheckboxGroupContext, LabelContext } from './context';
|
|
15
|
+
const styles = StyleSheet.create({
|
|
16
|
+
container: {
|
|
17
|
+
flexDirection: 'row',
|
|
18
|
+
alignItems: 'center'
|
|
19
|
+
},
|
|
20
|
+
wrapper: {
|
|
21
|
+
alignItems: 'center',
|
|
22
|
+
justifyContent: 'center',
|
|
23
|
+
width: 24,
|
|
24
|
+
height: 24,
|
|
25
|
+
borderColor: '#D1D1D1',
|
|
26
|
+
borderWidth: 1,
|
|
27
|
+
borderRadius: 3,
|
|
28
|
+
backgroundColor: '#ffffff',
|
|
29
|
+
marginRight: 5
|
|
30
|
+
},
|
|
31
|
+
wrapperDisabled: {
|
|
32
|
+
backgroundColor: '#E1E1E1'
|
|
33
|
+
},
|
|
34
|
+
icon: {
|
|
35
|
+
opacity: 0
|
|
36
|
+
},
|
|
37
|
+
iconChecked: {
|
|
38
|
+
opacity: 1
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
const Checkbox = forwardRef((checkboxProps, ref) => {
|
|
42
|
+
const { textProps, innerProps: props = {} } = splitProps(checkboxProps);
|
|
43
|
+
const { value = '', disabled = false, checked = false, color = '#09BB07', style = {}, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, bindtap, catchtap } = props;
|
|
44
|
+
const [isChecked, setIsChecked] = useState(!!checked);
|
|
45
|
+
const groupContext = useContext(CheckboxGroupContext);
|
|
46
|
+
let groupValue;
|
|
47
|
+
let notifyChange;
|
|
48
|
+
const defaultStyle = {
|
|
49
|
+
...styles.wrapper,
|
|
50
|
+
...(disabled && styles.wrapperDisabled)
|
|
51
|
+
};
|
|
52
|
+
const styleObj = {
|
|
53
|
+
...styles.container,
|
|
54
|
+
...style
|
|
55
|
+
};
|
|
56
|
+
const onChange = (evt) => {
|
|
57
|
+
if (disabled)
|
|
58
|
+
return;
|
|
59
|
+
const checked = !isChecked;
|
|
60
|
+
setIsChecked(checked);
|
|
61
|
+
if (groupValue) {
|
|
62
|
+
groupValue[value].checked = checked;
|
|
63
|
+
}
|
|
64
|
+
notifyChange && notifyChange(evt);
|
|
65
|
+
};
|
|
66
|
+
const onTap = (evt) => {
|
|
67
|
+
if (disabled)
|
|
68
|
+
return;
|
|
69
|
+
bindtap && bindtap(getCustomEvent('tap', evt, { layoutRef }, props));
|
|
70
|
+
onChange(evt);
|
|
71
|
+
};
|
|
72
|
+
const catchTap = (evt) => {
|
|
73
|
+
if (disabled)
|
|
74
|
+
return;
|
|
75
|
+
catchtap && catchtap(getCustomEvent('tap', evt, { layoutRef }, props));
|
|
76
|
+
onChange(evt);
|
|
77
|
+
};
|
|
78
|
+
const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
|
|
79
|
+
const { nodeRef } = useNodesRef(props, ref, {
|
|
80
|
+
defaultStyle,
|
|
81
|
+
change: onChange
|
|
82
|
+
});
|
|
83
|
+
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
|
|
84
|
+
const { textStyle, backgroundStyle, innerStyle } = splitStyle(normalStyle);
|
|
85
|
+
if (backgroundStyle) {
|
|
86
|
+
warn('Checkbox does not support background image-related styles!');
|
|
87
|
+
}
|
|
88
|
+
const labelContext = useContext(LabelContext);
|
|
89
|
+
if (groupContext) {
|
|
90
|
+
groupValue = groupContext.groupValue;
|
|
91
|
+
notifyChange = groupContext.notifyChange;
|
|
92
|
+
}
|
|
93
|
+
if (labelContext) {
|
|
94
|
+
labelContext.current.triggerChange = onChange;
|
|
95
|
+
}
|
|
96
|
+
const innerProps = useInnerProps(props, {
|
|
97
|
+
ref: nodeRef,
|
|
98
|
+
style: { ...innerStyle, ...layoutStyle },
|
|
99
|
+
...layoutProps,
|
|
100
|
+
bindtap: onTap,
|
|
101
|
+
catchtap: catchTap
|
|
102
|
+
}, [], {
|
|
103
|
+
layoutRef
|
|
104
|
+
});
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
if (groupValue) {
|
|
107
|
+
groupValue[value] = {
|
|
108
|
+
checked: checked,
|
|
109
|
+
setValue: setIsChecked
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
return () => {
|
|
113
|
+
if (groupValue) {
|
|
114
|
+
delete groupValue[value];
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}, []);
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
if (checked !== isChecked) {
|
|
120
|
+
setIsChecked(checked);
|
|
121
|
+
if (groupValue) {
|
|
122
|
+
groupValue[value].checked = checked;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}, [checked]);
|
|
126
|
+
return (<View {...innerProps}>
|
|
127
|
+
<View style={defaultStyle}>
|
|
128
|
+
<Icon type='success_no_circle' size={18} color={disabled ? '#ADADAD' : color} style={isChecked ? styles.iconChecked : styles.icon}/>
|
|
129
|
+
</View>
|
|
130
|
+
{wrapChildren(props, {
|
|
131
|
+
hasVarDec,
|
|
132
|
+
varContext: varContextRef.current,
|
|
133
|
+
textStyle,
|
|
134
|
+
textProps
|
|
135
|
+
})}
|
|
136
|
+
</View>);
|
|
137
|
+
});
|
|
138
|
+
Checkbox.displayName = 'mpx-checkbox';
|
|
139
|
+
export default Checkbox;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ✘ report-submit
|
|
3
|
+
* ✘ report-submit-timeout
|
|
4
|
+
* ✔ bindsubmit
|
|
5
|
+
* ✔ bindreset
|
|
6
|
+
*/
|
|
7
|
+
import { View } from 'react-native';
|
|
8
|
+
import { useRef, forwardRef } from 'react';
|
|
9
|
+
import useNodesRef from './useNodesRef';
|
|
10
|
+
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
11
|
+
import { FormContext } from './context';
|
|
12
|
+
import { useTransformStyle, splitProps, splitStyle, useLayout, wrapChildren } from './utils';
|
|
13
|
+
const _Form = forwardRef((fromProps, ref) => {
|
|
14
|
+
const { textProps, innerProps: props = {} } = splitProps(fromProps);
|
|
15
|
+
const formValuesMap = useRef(new Map()).current;
|
|
16
|
+
const { style, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props;
|
|
17
|
+
const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
|
|
18
|
+
const { textStyle, innerStyle } = splitStyle(normalStyle);
|
|
19
|
+
const { nodeRef: formRef } = useNodesRef(props, ref);
|
|
20
|
+
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: formRef });
|
|
21
|
+
const submit = () => {
|
|
22
|
+
const { bindsubmit } = props;
|
|
23
|
+
const formValue = {};
|
|
24
|
+
for (const name of formValuesMap.keys()) {
|
|
25
|
+
if (formValuesMap.get(name).getValue) {
|
|
26
|
+
formValue[name] = formValuesMap.get(name).getValue();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
bindsubmit && bindsubmit(getCustomEvent('submit', {}, {
|
|
30
|
+
detail: {
|
|
31
|
+
value: formValue
|
|
32
|
+
},
|
|
33
|
+
layoutRef
|
|
34
|
+
}, props));
|
|
35
|
+
};
|
|
36
|
+
const reset = () => {
|
|
37
|
+
const { bindreset } = props;
|
|
38
|
+
bindreset && bindreset();
|
|
39
|
+
formValuesMap.forEach(item => item.resetValue());
|
|
40
|
+
};
|
|
41
|
+
const innerProps = useInnerProps(props, {
|
|
42
|
+
style: { ...innerStyle, ...layoutStyle },
|
|
43
|
+
ref: formRef,
|
|
44
|
+
...layoutProps
|
|
45
|
+
}, [
|
|
46
|
+
'bindsubmit',
|
|
47
|
+
'bindreset'
|
|
48
|
+
], { layoutRef });
|
|
49
|
+
return (<View {...innerProps}>
|
|
50
|
+
<FormContext.Provider value={{ formValuesMap, submit, reset }}>
|
|
51
|
+
{wrapChildren(props, {
|
|
52
|
+
hasVarDec,
|
|
53
|
+
varContext: varContextRef.current,
|
|
54
|
+
textStyle,
|
|
55
|
+
textProps
|
|
56
|
+
})}
|
|
57
|
+
</FormContext.Provider>
|
|
58
|
+
</View>);
|
|
59
|
+
});
|
|
60
|
+
_Form.displayName = 'mpx-form';
|
|
61
|
+
export default _Form;
|