react-native-umui 1.3.65 → 1.3.87
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/commonjs/Accordion.js +46 -0
- package/lib/commonjs/Accordion.js.map +1 -0
- package/lib/commonjs/Badge.js +1 -1
- package/lib/commonjs/Badge.js.map +1 -1
- package/lib/commonjs/Button.js +10 -7
- package/lib/commonjs/Button.js.map +1 -1
- package/lib/commonjs/Checkbox.js +0 -1
- package/lib/commonjs/Checkbox.js.map +1 -1
- package/lib/commonjs/Divider.js.map +1 -1
- package/lib/commonjs/EasyIn.js +43 -0
- package/lib/commonjs/EasyIn.js.map +1 -1
- package/lib/commonjs/FlatList.js +2 -1
- package/lib/commonjs/FlatList.js.map +1 -1
- package/lib/commonjs/FlatPanel.js.map +1 -1
- package/lib/commonjs/Grid.js.map +1 -1
- package/lib/commonjs/InputField.js +2 -0
- package/lib/commonjs/InputField.js.map +1 -1
- package/lib/commonjs/Line.js +0 -1
- package/lib/commonjs/Line.js.map +1 -1
- package/lib/commonjs/Load.js +1 -2
- package/lib/commonjs/Load.js.map +1 -1
- package/lib/commonjs/Numeral.js +6 -1
- package/lib/commonjs/Numeral.js.map +1 -1
- package/lib/commonjs/PanelRK.js +1 -1
- package/lib/commonjs/PanelRK.js.map +1 -1
- package/lib/commonjs/Phone.js +12 -5
- package/lib/commonjs/Phone.js.map +1 -1
- package/lib/commonjs/Press.js.map +1 -1
- package/lib/commonjs/Radio.js +0 -1
- package/lib/commonjs/Radio.js.map +1 -1
- package/lib/commonjs/Scroll.js +2 -2
- package/lib/commonjs/Scroll.js.map +1 -1
- package/lib/commonjs/Tab.js +3 -12
- package/lib/commonjs/Tab.js.map +1 -1
- package/lib/commonjs/Text.js +22 -2
- package/lib/commonjs/Text.js.map +1 -1
- package/lib/commonjs/TextInput.js +69 -1
- package/lib/commonjs/TextInput.js.map +1 -1
- package/lib/commonjs/regions.js +8 -2
- package/lib/commonjs/regions.js.map +1 -1
- package/lib/commonjs/shadows.js +3 -2
- package/lib/commonjs/shadows.js.map +1 -1
- package/lib/module/Accordion.js +37 -0
- package/lib/module/Accordion.js.map +1 -0
- package/lib/module/Badge.js +1 -1
- package/lib/module/Badge.js.map +1 -1
- package/lib/module/Button.js +10 -7
- package/lib/module/Button.js.map +1 -1
- package/lib/module/Checkbox.js +0 -1
- package/lib/module/Checkbox.js.map +1 -1
- package/lib/module/Divider.js.map +1 -1
- package/lib/module/EasyIn.js +40 -0
- package/lib/module/EasyIn.js.map +1 -1
- package/lib/module/FlatList.js +2 -1
- package/lib/module/FlatList.js.map +1 -1
- package/lib/module/FlatPanel.js.map +1 -1
- package/lib/module/Grid.js.map +1 -1
- package/lib/module/InputField.js +2 -0
- package/lib/module/InputField.js.map +1 -1
- package/lib/module/Line.js +0 -1
- package/lib/module/Line.js.map +1 -1
- package/lib/module/Load.js +1 -2
- package/lib/module/Load.js.map +1 -1
- package/lib/module/Numeral.js +6 -1
- package/lib/module/Numeral.js.map +1 -1
- package/lib/module/PanelRK.js +2 -2
- package/lib/module/PanelRK.js.map +1 -1
- package/lib/module/Phone.js +12 -5
- package/lib/module/Phone.js.map +1 -1
- package/lib/module/Press.js.map +1 -1
- package/lib/module/Radio.js +0 -1
- package/lib/module/Radio.js.map +1 -1
- package/lib/module/Scroll.js +2 -2
- package/lib/module/Scroll.js.map +1 -1
- package/lib/module/Tab.js +3 -12
- package/lib/module/Tab.js.map +1 -1
- package/lib/module/Text.js +21 -2
- package/lib/module/Text.js.map +1 -1
- package/lib/module/TextInput.js +69 -2
- package/lib/module/TextInput.js.map +1 -1
- package/lib/module/regions.js +8 -2
- package/lib/module/regions.js.map +1 -1
- package/lib/module/shadows.js +3 -2
- package/lib/module/shadows.js.map +1 -1
- package/lib/typescript/src/Accordion.d.ts +12 -0
- package/lib/typescript/src/Accordion.d.ts.map +1 -0
- package/lib/typescript/src/Badge.d.ts.map +1 -1
- package/lib/typescript/src/Button.d.ts +1 -1
- package/lib/typescript/src/Button.d.ts.map +1 -1
- package/lib/typescript/src/Checkbox.d.ts.map +1 -1
- package/lib/typescript/src/Divider.d.ts.map +1 -1
- package/lib/typescript/src/EasyIn.d.ts +3 -0
- package/lib/typescript/src/EasyIn.d.ts.map +1 -1
- package/lib/typescript/src/FlatList.d.ts.map +1 -1
- package/lib/typescript/src/FlatPanel.d.ts.map +1 -1
- package/lib/typescript/src/Grid.d.ts.map +1 -1
- package/lib/typescript/src/InputField.d.ts +1 -2
- package/lib/typescript/src/InputField.d.ts.map +1 -1
- package/lib/typescript/src/Line.d.ts.map +1 -1
- package/lib/typescript/src/Load.d.ts.map +1 -1
- package/lib/typescript/src/Numeral.d.ts.map +1 -1
- package/lib/typescript/src/PanelRK.d.ts +2 -2
- package/lib/typescript/src/PanelRK.d.ts.map +1 -1
- package/lib/typescript/src/Phone.d.ts +2 -1
- package/lib/typescript/src/Phone.d.ts.map +1 -1
- package/lib/typescript/src/Press.d.ts.map +1 -1
- package/lib/typescript/src/Radio.d.ts.map +1 -1
- package/lib/typescript/src/Scroll.d.ts.map +1 -1
- package/lib/typescript/src/Tab.d.ts.map +1 -1
- package/lib/typescript/src/Text.d.ts.map +1 -1
- package/lib/typescript/src/TextInput.d.ts +8 -1
- package/lib/typescript/src/TextInput.d.ts.map +1 -1
- package/lib/typescript/src/regions.d.ts +7 -1
- package/lib/typescript/src/regions.d.ts.map +1 -1
- package/lib/typescript/src/shadows.d.ts +2 -2
- package/lib/typescript/src/shadows.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Accordion.tsx +1 -0
- package/src/Badge.tsx +1 -1
- package/src/Button.tsx +81 -7
- package/src/Checkbox.tsx +1 -13
- package/src/Divider.tsx +1 -11
- package/src/EasyIn.tsx +1 -22
- package/src/FlatList.tsx +1 -6
- package/src/FlatPanel.tsx +1 -9
- package/src/Grid.tsx +1 -18
- package/src/InputField.tsx +1 -14
- package/src/Line.tsx +13 -5
- package/src/Load.tsx +59 -2
- package/src/Numeral.tsx +115 -31
- package/src/PanelRK.tsx +1 -6
- package/src/Phone.tsx +100 -73
- package/src/Press.tsx +1 -6
- package/src/Radio.tsx +1 -15
- package/src/Scroll.tsx +1 -13
- package/src/Tab.tsx +223 -23
- package/src/Text.tsx +21 -8
- package/src/TextInput.tsx +1 -24
- package/src/regions.ts +13 -5
- package/src/shadows.ts +1 -24
package/src/Numeral.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React from "react"
|
|
2
|
-
import { cts, stc } from "./common"
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { cts, stc } from "./common";
|
|
3
3
|
/**
|
|
4
4
|
* @param fraction default 2
|
|
5
5
|
* @param thousandSeperator default true
|
|
@@ -25,32 +25,37 @@ export interface NumeralUtil {
|
|
|
25
25
|
* @param code country iat code or currency symbol, if it is empty set it geves from global
|
|
26
26
|
* @returns
|
|
27
27
|
*/
|
|
28
|
-
setCode: (code?: string) => void
|
|
28
|
+
setCode: (code?: string) => void;
|
|
29
|
+
|
|
29
30
|
/**
|
|
30
31
|
* @param code country iat code or currency symbol, if it is empty set it geves from global
|
|
31
32
|
* @returns
|
|
32
33
|
*/
|
|
33
|
-
currency: (value: number, code?: string | null, thousandSeperator?: boolean | null, fraction?: number, direction?: "ltr" | "rtl") => string
|
|
34
|
+
currency: (value: number, code?: string | null, thousandSeperator?: boolean | null, fraction?: number, direction?: "ltr" | "rtl") => string;
|
|
35
|
+
|
|
34
36
|
/**
|
|
35
37
|
* @param code country iat code or currency symbol, if it is empty set it geves from global
|
|
36
38
|
* @returns
|
|
37
39
|
*/
|
|
38
|
-
format: (value: number, code?: string | null, thousandSeperator?: boolean | null, fraction?: number) => string
|
|
40
|
+
format: (value: number, code?: string | null, thousandSeperator?: boolean | null, fraction?: number) => string;
|
|
41
|
+
|
|
39
42
|
/**
|
|
40
43
|
* @param code country iat code or currency symbol, if it is empty set it geves from global
|
|
41
44
|
* @returns
|
|
42
45
|
*/
|
|
43
|
-
parseRaw: (value: string, code?: string | null, fraction?: number) => string
|
|
46
|
+
parseRaw: (value: string, code?: string | null, fraction?: number) => string;
|
|
47
|
+
|
|
44
48
|
/**
|
|
45
49
|
*
|
|
46
50
|
* @returns
|
|
47
51
|
*/
|
|
48
|
-
toNumber: (value: string | number, fraction?: number) => number
|
|
52
|
+
toNumber: (value: string | number, fraction?: number) => number;
|
|
53
|
+
|
|
49
54
|
/**
|
|
50
55
|
*
|
|
51
56
|
* @returns
|
|
52
57
|
*/
|
|
53
|
-
toFloat: (value: string | number, fraction?: number) => number
|
|
58
|
+
toFloat: (value: string | number, fraction?: number) => number;
|
|
54
59
|
}
|
|
55
60
|
/**
|
|
56
61
|
* @param code country iat code or currency symbol, if it is empty set it geves from global
|
|
@@ -71,11 +76,15 @@ export interface NumeralSlotProps {
|
|
|
71
76
|
thousandSeperator?: boolean | null;
|
|
72
77
|
fraction?: number;
|
|
73
78
|
};
|
|
74
|
-
|
|
75
|
-
const
|
|
76
|
-
const
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
+
|
|
80
|
+
const fractionDefault: number = 2;
|
|
81
|
+
const isopt = (k: any) => k == undefined || k === null;
|
|
82
|
+
const setFraction = (defaultval: number, fraction?: number) => isopt(fraction) ? defaultval : fraction;
|
|
83
|
+
const decOptions = (fraction?: number) => {
|
|
84
|
+
const value = setFraction(fractionDefault, fraction)
|
|
85
|
+
return { minimumFractionDigits: value, maximumFractionDigits: value };
|
|
86
|
+
}
|
|
87
|
+
const fraction = (value: number, fraction: number) => fraction === 0 ? Math.floor(value) : value;
|
|
79
88
|
const cache = {
|
|
80
89
|
code: "",
|
|
81
90
|
countryCode: null,
|
|
@@ -84,75 +93,150 @@ const cache = {
|
|
|
84
93
|
separatorDecimal: "",
|
|
85
94
|
regexThousands: /[]/g,
|
|
86
95
|
regexDecimal: /[]/g
|
|
87
|
-
}
|
|
96
|
+
};
|
|
88
97
|
class Numeral {
|
|
89
98
|
private fraction?: number;
|
|
90
99
|
private thousandSeperator: boolean = false;
|
|
91
|
-
|
|
92
|
-
static
|
|
100
|
+
|
|
101
|
+
static new() {
|
|
102
|
+
return new Numeral();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
static convert(value: number | string, fraction?: number): number {
|
|
106
|
+
if (isopt(fraction)) {
|
|
107
|
+
return Number(value);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return Number(Number((value || "").toString().replace(",", ".")).toFixed(fraction));
|
|
111
|
+
}
|
|
112
|
+
|
|
93
113
|
init(code?: string) {
|
|
94
|
-
if (code !== cache.code) {
|
|
114
|
+
if (code !== cache.code) {
|
|
115
|
+
cache.code = code;
|
|
116
|
+
cache.countryCode = stc[code] || cts[code];
|
|
117
|
+
if (stc[code]) {
|
|
118
|
+
cache.countryCode = stc[code];
|
|
119
|
+
} else if (cts[code]) {
|
|
120
|
+
cache.countryCode = code;
|
|
121
|
+
}
|
|
122
|
+
cache.symbol = cts[cache.countryCode] || "?";
|
|
123
|
+
cache.separatorThousands = new Intl.NumberFormat(cache.countryCode, { style: "decimal" }).format(1111).replace(/\d/g, "");
|
|
124
|
+
cache.separatorDecimal = new Intl.NumberFormat(cache.countryCode, { style: "decimal" }).format(11.11).replace(/\d/g, "");
|
|
125
|
+
|
|
126
|
+
cache.regexThousands = new RegExp(`[${cache.separatorThousands}]`, "g");
|
|
127
|
+
cache.regexDecimal = new RegExp(`[${cache.separatorDecimal}]`, "g");
|
|
128
|
+
}
|
|
129
|
+
|
|
95
130
|
return this;
|
|
96
131
|
}
|
|
97
|
-
|
|
98
|
-
|
|
132
|
+
|
|
133
|
+
setFraction(val?: number) {
|
|
134
|
+
this.fraction = val;
|
|
135
|
+
return this;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
setThousandSeperator(val: boolean = false) {
|
|
139
|
+
this.thousandSeperator = val;
|
|
140
|
+
return this;
|
|
141
|
+
}
|
|
142
|
+
|
|
99
143
|
format(value: number): string {
|
|
100
144
|
try {
|
|
101
|
-
const amount = fraction(Number(value), this.fraction);
|
|
145
|
+
const amount = fraction(Number(value), this.fraction);
|
|
146
|
+
const stt = decOptions(this.fraction);
|
|
147
|
+
const amountformat = new Intl.NumberFormat(cache.countryCode, stt).format(amount);
|
|
148
|
+
return this.thousandSeperator ? amountformat.replace(cache.regexThousands, "") : amountformat;
|
|
102
149
|
} catch (error) {
|
|
103
150
|
return "";
|
|
104
151
|
}
|
|
105
152
|
}
|
|
153
|
+
|
|
106
154
|
inputFormat(value: number): string {
|
|
107
155
|
try {
|
|
108
|
-
const amountformat = this.format(value);
|
|
156
|
+
const amountformat = this.format(value);
|
|
157
|
+
return amountformat.replace(cache.regexThousands, "");
|
|
109
158
|
} catch (error) {
|
|
110
159
|
return "";
|
|
111
160
|
}
|
|
112
161
|
}
|
|
162
|
+
|
|
113
163
|
currency(value: number, direction: "ltr" | "rtl" = "ltr") {
|
|
114
164
|
try {
|
|
115
|
-
const amountformat = this.format(value);
|
|
165
|
+
const amountformat = this.format(value);
|
|
166
|
+
return direction === "ltr" ? `${amountformat}${cache.symbol}` : `${cache.symbol}${amountformat}`;
|
|
116
167
|
} catch (error) {
|
|
117
168
|
return "";
|
|
118
169
|
}
|
|
119
170
|
}
|
|
171
|
+
|
|
120
172
|
parseRawFormat(value: string) {
|
|
121
|
-
const stringNumber = (value || "")
|
|
173
|
+
const stringNumber = (value || "")
|
|
174
|
+
.replace(cache.regexThousands, "")
|
|
175
|
+
.replace(cache.regexDecimal, ".")
|
|
176
|
+
.replace(new RegExp(`[${cache.symbol}]`, "g"), "");
|
|
177
|
+
|
|
178
|
+
const amount = fraction(parseFloat(stringNumber), this.fraction);
|
|
179
|
+
|
|
180
|
+
return stringNumber ? amount.toFixed(setFraction(fractionDefault, this.fraction)) : stringNumber;
|
|
122
181
|
}
|
|
123
182
|
}
|
|
124
183
|
export const numeral: NumeralUtil = (() => {
|
|
125
|
-
let _code: string = null
|
|
184
|
+
let _code: string = null;
|
|
185
|
+
|
|
126
186
|
/**
|
|
127
187
|
* @param code country iat code or currency symbol, if it is empty set it geves from global
|
|
128
188
|
* @returns
|
|
129
189
|
*/
|
|
130
|
-
function setCode(code?: string) {
|
|
190
|
+
function setCode(code?: string) {
|
|
191
|
+
_code = code;
|
|
192
|
+
}
|
|
193
|
+
|
|
131
194
|
/**
|
|
132
195
|
* @param code country iat code or currency symbol, if it is empty set it geves from global
|
|
133
196
|
*/
|
|
134
|
-
function currency(value: number, code?: string | null, thousandSeperator?: boolean | null, fraction?: number, direction: "ltr" | "rtl" = "ltr") {
|
|
197
|
+
function currency(value: number, code?: string | null, thousandSeperator?: boolean | null, fraction?: number, direction: "ltr" | "rtl" = "ltr") {
|
|
198
|
+
return Numeral.new().init(code || _code).setFraction(fraction).setThousandSeperator(thousandSeperator).currency(value, direction);
|
|
199
|
+
}
|
|
200
|
+
|
|
135
201
|
/**
|
|
136
202
|
* @param code country iat code or currency symbol, if it is empty set it geves from global
|
|
137
203
|
*/
|
|
138
|
-
function format(value: number, code?: string | null, thousandSeperator?: boolean | null, fraction?: number) {
|
|
204
|
+
function format(value: number, code?: string | null, thousandSeperator?: boolean | null, fraction?: number) {
|
|
205
|
+
return Numeral.new().init(code || _code).setFraction(fraction).setThousandSeperator(thousandSeperator).format(value);
|
|
206
|
+
}
|
|
207
|
+
|
|
139
208
|
/**
|
|
140
209
|
* @param code country iat code or currency symbol, if it is empty set it geves from global
|
|
141
210
|
*/
|
|
142
|
-
function parseRaw(value: string, code?: string | null, fraction?: number) {
|
|
211
|
+
function parseRaw(value: string, code?: string | null, fraction?: number) {
|
|
212
|
+
return Numeral.new().init(code || _code).setFraction(fraction).parseRawFormat(value);
|
|
213
|
+
}
|
|
214
|
+
|
|
143
215
|
/**
|
|
144
216
|
*
|
|
145
217
|
* @param value
|
|
146
218
|
* @param fraction
|
|
147
219
|
* @returns
|
|
148
220
|
*/
|
|
149
|
-
function toNumber(value: string | number, fraction?: number): number {
|
|
221
|
+
function toNumber(value: string | number, fraction?: number): number {
|
|
222
|
+
return Numeral.convert(value, fraction);
|
|
223
|
+
}
|
|
224
|
+
|
|
150
225
|
/**
|
|
151
226
|
*
|
|
152
227
|
* @param value
|
|
153
228
|
* @param fraction
|
|
154
229
|
* @returns
|
|
155
230
|
*/
|
|
156
|
-
function toFloat(value: string | number, fraction: number = 2): number {
|
|
231
|
+
function toFloat(value: string | number, fraction: number = 2): number {
|
|
232
|
+
return Numeral.convert(value, fraction);
|
|
233
|
+
}
|
|
234
|
+
|
|
157
235
|
return { setCode, currency, format, parseRaw, toNumber, toFloat };
|
|
158
|
-
})();
|
|
236
|
+
})();
|
|
237
|
+
export function CurrencySlot(props: ICurrencySlotProps) {
|
|
238
|
+
return (<React.Fragment>{numeral.currency(props.value, props.code, props.thousandSeperator, props.fraction)}</React.Fragment>)
|
|
239
|
+
}
|
|
240
|
+
export function NumeralSlot(props: NumeralSlotProps) {
|
|
241
|
+
return (<React.Fragment>{numeral.format(props.value, props.code, props.thousandSeperator, props.fraction)}</React.Fragment>)
|
|
242
|
+
}
|
package/src/PanelRK.tsx
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { View, ViewProps } from "react-native";
|
|
3
|
-
interface MPanelRkProps extends ViewProps {
|
|
4
|
-
children?: React.ReactNode;
|
|
5
|
-
};
|
|
6
|
-
export function MPanelRK({ style, children, ...props }: MPanelRkProps) { return (<View style={[{ backgroundColor: "white", height: 53, borderWidth: 1, borderColor: "gray", marginTop: 7, marginBottom: 7, padding: 11, paddingHorizontal: 9, display: "flex", flexDirection: "row", alignItems: "center" }, style]} {...props}>{children}</View>) }
|
|
1
|
+
import React from "react"; import { TouchableOpacity, TouchableOpacityProps } from "react-native"; interface MPanelRkProps extends TouchableOpacityProps { children?: React.ReactNode; }; export function MPanelRK({ style, children, ...props }: MPanelRkProps) { return (<TouchableOpacity style={[ { backgroundColor: "white", height: 53, borderWidth: 1, borderColor: "gray", marginTop: 7, marginBottom: 7, padding: 11, paddingHorizontal: 9, display: "flex", flexDirection: "row", alignItems: "center" }, style ]} {...props}>{children}</TouchableOpacity>); }
|
package/src/Phone.tsx
CHANGED
|
@@ -4,96 +4,124 @@ import { MText } from "./Text";
|
|
|
4
4
|
import { aa3phone } from "./common";
|
|
5
5
|
import { MTextInput } from "./TextInput";
|
|
6
6
|
import { codesMap } from "./regions";
|
|
7
|
+
|
|
7
8
|
export enum PhoneType {
|
|
8
9
|
ANY = "ANY",
|
|
9
10
|
MOBILE = "MOBILE",
|
|
10
11
|
LAND = "LAND"
|
|
11
|
-
}
|
|
12
|
+
};
|
|
13
|
+
|
|
12
14
|
export interface PhoneRaw {
|
|
13
|
-
aa2: string
|
|
14
|
-
code: number
|
|
15
|
-
nn: string
|
|
16
|
-
example?: string
|
|
17
|
-
}
|
|
15
|
+
aa2: string;
|
|
16
|
+
code: number;
|
|
17
|
+
nn: string;
|
|
18
|
+
example?: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
18
21
|
export interface PhoneUtil {
|
|
19
|
-
regisons: () => string[]
|
|
20
|
-
flag: (code: string) => string
|
|
22
|
+
regisons: () => string[];
|
|
23
|
+
flag: (code: string) => string;
|
|
21
24
|
/**
|
|
22
25
|
* @param phone
|
|
23
26
|
* @returns
|
|
24
27
|
*/
|
|
25
|
-
parseRaw: (phone: string) => PhoneRaw | null
|
|
28
|
+
parseRaw: (phone: string) => PhoneRaw | null;
|
|
29
|
+
|
|
26
30
|
/**
|
|
27
31
|
* @param code
|
|
28
32
|
* @param phone
|
|
29
33
|
* @returns
|
|
30
34
|
*/
|
|
31
|
-
parseRawByCountryCode: (code: string, phone: string) => PhoneRaw | null
|
|
35
|
+
parseRawByCountryCode: (code: string, phone: string) => PhoneRaw | null;
|
|
36
|
+
|
|
32
37
|
/**
|
|
33
38
|
* @param code
|
|
34
39
|
* @param phone
|
|
35
40
|
* @returns
|
|
36
41
|
*/
|
|
37
|
-
pretty: (phone: string, phoneType?: PhoneType) => string
|
|
42
|
+
pretty: (phone: string, phoneType?: PhoneType) => string;
|
|
38
43
|
}
|
|
44
|
+
|
|
39
45
|
function checkList(item: AA3, phoneType: PhoneType) {
|
|
40
|
-
const regexlist: RegExp[] = []
|
|
46
|
+
const regexlist: RegExp[] = []
|
|
47
|
+
const phonelenghts = item.phone_number_lengths
|
|
48
|
+
const beginwiths = item.mobile_begin_with
|
|
49
|
+
const isNotOnlyMobile = phoneType === PhoneType.MOBILE
|
|
50
|
+
|
|
41
51
|
if (phonelenghts.length && beginwiths.length) {
|
|
42
52
|
phonelenghts.forEach(pl => {
|
|
43
|
-
beginwiths.forEach(bw => {
|
|
53
|
+
beginwiths.forEach(bw => {
|
|
54
|
+
const r = new RegExp(`^${item.countryCode}${isNotOnlyMobile ? bw : `[0-9]{${bw.toString().length}}`}[0-9]{${pl - (bw as number).toString().length}}$`)
|
|
55
|
+
regexlist.push(r)
|
|
56
|
+
})
|
|
44
57
|
})
|
|
45
58
|
} else if (!phonelenghts.length && beginwiths.length) {
|
|
46
59
|
beginwiths.forEach(bw => {
|
|
47
|
-
const r = new RegExp(`^${item.countryCode}${isNotOnlyMobile ? bw : `[0-9]{${bw.toString().length}}`}[0-9]`)
|
|
60
|
+
const r = new RegExp(`^${item.countryCode}${isNotOnlyMobile ? bw : `[0-9]{${bw.toString().length}}`}[0-9]`)
|
|
61
|
+
regexlist.push(r)
|
|
48
62
|
})
|
|
49
63
|
} else if (phonelenghts.length && !beginwiths.length) {
|
|
50
64
|
phonelenghts.forEach(pl => {
|
|
51
|
-
const r = new RegExp(`^${item.countryCode}[0-9]{${pl}}$`)
|
|
65
|
+
const r = new RegExp(`^${item.countryCode}[0-9]{${pl}}$`)
|
|
66
|
+
regexlist.push(r)
|
|
52
67
|
})
|
|
53
68
|
} else {
|
|
54
|
-
const r = new RegExp(`^${item.countryCode}[0-9]`)
|
|
69
|
+
const r = new RegExp(`^${item.countryCode}[0-9]`)
|
|
70
|
+
regexlist.push(r)
|
|
55
71
|
}
|
|
56
72
|
return regexlist
|
|
57
73
|
}
|
|
74
|
+
|
|
58
75
|
interface AA3 {
|
|
59
76
|
countryCode: number;
|
|
60
77
|
mobile_begin_with?: number[];
|
|
61
78
|
phone_number_lengths?: number[];
|
|
62
79
|
flag: string;
|
|
63
|
-
}
|
|
80
|
+
};
|
|
81
|
+
|
|
64
82
|
interface AA2 {
|
|
65
83
|
aa2: string;
|
|
66
84
|
flag: string;
|
|
67
|
-
}
|
|
85
|
+
};
|
|
86
|
+
|
|
68
87
|
class Phone {
|
|
69
88
|
private supportAa2s: AA2[] = [];
|
|
70
|
-
|
|
89
|
+
|
|
90
|
+
static new() {
|
|
91
|
+
return new Phone();
|
|
92
|
+
}
|
|
93
|
+
|
|
71
94
|
setRegions(vals: string[] = []) {
|
|
72
95
|
try {
|
|
73
96
|
vals.forEach(k => {
|
|
74
97
|
if (aa3phone[k]) {
|
|
75
|
-
this.supportAa2s.push({ aa2: k, flag: this.itemAa3ByAa2(k).flag })
|
|
76
|
-
}
|
|
77
|
-
})
|
|
98
|
+
this.supportAa2s.push({ aa2: k, flag: this.itemAa3ByAa2(k).flag })
|
|
99
|
+
}
|
|
100
|
+
})
|
|
78
101
|
} catch (error) {
|
|
102
|
+
|
|
79
103
|
}
|
|
80
104
|
return this;
|
|
81
105
|
}
|
|
106
|
+
|
|
82
107
|
get supportsIat2(): AA2[] {
|
|
83
108
|
return this.supportAa2s;
|
|
84
109
|
}
|
|
110
|
+
|
|
85
111
|
formatRaw(raw: PhoneRaw, noPlusPrefix: boolean = false) {
|
|
86
|
-
return `${noPlusPrefix ? "" : "+"}${raw.code}${raw.nn}
|
|
112
|
+
return `${noPlusPrefix ? "" : "+"}${raw.code}${raw.nn}`;
|
|
87
113
|
}
|
|
114
|
+
|
|
88
115
|
private itemAa3ByAa2(aa2: string): AA3 | null {
|
|
89
116
|
const item: AA3 = aa3phone[aa2];
|
|
90
117
|
return item ? item : null;
|
|
91
118
|
}
|
|
119
|
+
|
|
92
120
|
private check(aa2: string, fullPn: string, phoneType: PhoneType = PhoneType.MOBILE): PhoneRaw | null {
|
|
93
|
-
const item: AA3 | null = this.itemAa3ByAa2(aa2)
|
|
94
|
-
const regexlist = checkList(item, phoneType)
|
|
121
|
+
const item: AA3 | null = this.itemAa3ByAa2(aa2)
|
|
122
|
+
const regexlist = checkList(item, phoneType)
|
|
95
123
|
if (regexlist.map(k => k.test(fullPn)).filter(k => k).length > 0) {
|
|
96
|
-
const line = `${item.mobile_begin_with.length ? item.mobile_begin_with[item.mobile_begin_with.length - 1] : ""}${"512312387612638131123"}
|
|
124
|
+
const line = `${item.mobile_begin_with.length ? item.mobile_begin_with[item.mobile_begin_with.length - 1] : ""}${"512312387612638131123"}`
|
|
97
125
|
return ({
|
|
98
126
|
aa2: aa2,
|
|
99
127
|
code: item.countryCode,
|
|
@@ -101,64 +129,80 @@ class Phone {
|
|
|
101
129
|
example: line.substring(0, item.phone_number_lengths.length ? item.phone_number_lengths[item.mobile_begin_with.length - 1] : line.length)
|
|
102
130
|
});
|
|
103
131
|
}
|
|
132
|
+
|
|
104
133
|
return null;
|
|
105
134
|
}
|
|
135
|
+
|
|
106
136
|
parseRaw(fullPn: string, phoneType?: PhoneType): PhoneRaw | null {
|
|
107
137
|
try {
|
|
108
138
|
const pn = (fullPn || "").replace(/\D/g, "").replace(/ /g, "");
|
|
109
139
|
const aa2s = Object.keys(aa3phone);
|
|
140
|
+
|
|
110
141
|
let index = 0;
|
|
111
142
|
let raw: PhoneRaw | null = null;
|
|
143
|
+
|
|
112
144
|
for (index = 0; index < aa2s.length; index++) {
|
|
113
145
|
raw = this.check(aa2s[index], pn, phoneType);
|
|
146
|
+
|
|
114
147
|
if (raw) {
|
|
115
148
|
break;
|
|
116
149
|
}
|
|
117
150
|
}
|
|
151
|
+
|
|
118
152
|
return raw;
|
|
119
153
|
} catch (error) {
|
|
120
154
|
return null;
|
|
121
155
|
}
|
|
122
156
|
}
|
|
157
|
+
|
|
123
158
|
parseRawInput(aa2: string, nn: string, phoneType?: PhoneType): PhoneRaw | null {
|
|
124
159
|
try {
|
|
125
160
|
const item: AA3 | null = this.itemAa3ByAa2(aa2);
|
|
126
161
|
if (!item) {
|
|
127
162
|
return null;
|
|
128
|
-
}
|
|
163
|
+
}
|
|
164
|
+
|
|
129
165
|
const fullPn = `${item.countryCode}${nn}`;
|
|
130
166
|
return this.check(aa2, fullPn, phoneType);
|
|
131
167
|
} catch (error) {
|
|
132
168
|
return null;
|
|
133
169
|
}
|
|
134
170
|
}
|
|
171
|
+
|
|
135
172
|
placeholder(aa2: string): string {
|
|
136
173
|
try {
|
|
137
174
|
const item: AA3 | null = this.itemAa3ByAa2(aa2);
|
|
138
175
|
if (!item) {
|
|
139
176
|
return "";
|
|
140
177
|
}
|
|
178
|
+
|
|
141
179
|
const line = `${item.mobile_begin_with.length ? item.mobile_begin_with[item.mobile_begin_with.length - 1] : ""}${"512312387612638131123"}`;
|
|
180
|
+
|
|
142
181
|
return line.substring(0, item.phone_number_lengths.length ? item.phone_number_lengths[item.phone_number_lengths.length - 1] : line.length);
|
|
143
182
|
} catch (error) {
|
|
144
183
|
return "";
|
|
145
184
|
}
|
|
146
185
|
}
|
|
186
|
+
|
|
147
187
|
private mask(lenght: number, pt: string, txt: string, rmt: string): string {
|
|
148
188
|
if (rmt.length === 0 || txt.length >= lenght) {
|
|
149
|
-
return txt
|
|
189
|
+
return txt;
|
|
150
190
|
}
|
|
151
191
|
const c = pt.at(0);
|
|
152
192
|
const v = rmt.at(0);
|
|
193
|
+
|
|
153
194
|
if (c != "#") {
|
|
154
195
|
txt += c;
|
|
155
196
|
} else {
|
|
156
197
|
txt += v;
|
|
157
198
|
rmt = rmt.split("").filter((_, i) => i != 0).join("");
|
|
158
199
|
}
|
|
200
|
+
|
|
159
201
|
pt = pt.split("").filter((_, i) => i != 0).join("");
|
|
160
|
-
|
|
202
|
+
|
|
203
|
+
return this.mask(lenght, pt, txt, rmt);
|
|
161
204
|
}
|
|
205
|
+
|
|
162
206
|
prettyMaskWoc(aa2: string, nn: string) {
|
|
163
207
|
try {
|
|
164
208
|
const item = aa3phone[aa2];
|
|
@@ -168,6 +212,7 @@ class Phone {
|
|
|
168
212
|
return "";
|
|
169
213
|
}
|
|
170
214
|
}
|
|
215
|
+
|
|
171
216
|
prettyMask(aa2: string, nn: string) {
|
|
172
217
|
try {
|
|
173
218
|
const item = aa3phone[aa2];
|
|
@@ -178,12 +223,13 @@ class Phone {
|
|
|
178
223
|
}
|
|
179
224
|
}
|
|
180
225
|
}
|
|
226
|
+
|
|
181
227
|
export const phoneUtil: PhoneUtil = (() => {
|
|
182
228
|
function regisons() {
|
|
183
|
-
return Object.keys(codesMap)
|
|
229
|
+
return Object.keys(codesMap);
|
|
184
230
|
}
|
|
185
231
|
function flag(code: string) {
|
|
186
|
-
return aa3phone[code]?.flag
|
|
232
|
+
return aa3phone[code]?.flag;
|
|
187
233
|
}
|
|
188
234
|
/**
|
|
189
235
|
* @param phone
|
|
@@ -191,9 +237,9 @@ export const phoneUtil: PhoneUtil = (() => {
|
|
|
191
237
|
*/
|
|
192
238
|
function parseRaw(phone: string, phoneType?: PhoneType): PhoneRaw | null {
|
|
193
239
|
try {
|
|
194
|
-
return Phone.new().parseRaw(phone, phoneType)
|
|
240
|
+
return Phone.new().parseRaw(phone, phoneType);
|
|
195
241
|
} catch (error) {
|
|
196
|
-
return null
|
|
242
|
+
return null;
|
|
197
243
|
}
|
|
198
244
|
}
|
|
199
245
|
/**
|
|
@@ -203,55 +249,36 @@ export const phoneUtil: PhoneUtil = (() => {
|
|
|
203
249
|
*/
|
|
204
250
|
function parseRawByCountryCode(code: string, phone: string, phoneType?: PhoneType): PhoneRaw | null {
|
|
205
251
|
try {
|
|
206
|
-
return Phone.new().parseRawInput(code, phone, phoneType)
|
|
252
|
+
return Phone.new().parseRawInput(code, phone, phoneType);
|
|
207
253
|
} catch (error) {
|
|
208
|
-
return null
|
|
254
|
+
return null;
|
|
209
255
|
}
|
|
210
256
|
}
|
|
211
257
|
function pretty(phone: string, phoneType?: PhoneType): string {
|
|
212
258
|
try {
|
|
213
|
-
const raw = Phone.new().parseRaw(phone.replace(/\D/g, ""), phoneType || PhoneType.ANY)
|
|
214
|
-
return Phone.new().prettyMask(raw.aa2, raw.nn)
|
|
259
|
+
const raw = Phone.new().parseRaw(phone.replace(/\D/g, ""), phoneType || PhoneType.ANY);
|
|
260
|
+
return Phone.new().prettyMask(raw.aa2, raw.nn);
|
|
215
261
|
} catch (error) {
|
|
216
|
-
return ""
|
|
262
|
+
return "";
|
|
217
263
|
}
|
|
218
264
|
}
|
|
219
265
|
return { regisons, flag, parseRaw, parseRawByCountryCode, pretty };
|
|
220
266
|
})();
|
|
267
|
+
|
|
221
268
|
interface MPhoneInputProps {
|
|
222
|
-
containerStyle?: StyleProp<ViewStyle
|
|
223
|
-
phoneStyle?: StyleProp<TextStyle
|
|
224
|
-
placeholder?: string
|
|
225
|
-
disabled?: boolean
|
|
226
|
-
noPlusPrefix?: boolean
|
|
227
|
-
regions?: Array<keyof typeof codesMap
|
|
228
|
-
phoneType?: PhoneType
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
const [init, setInit] = React.useState<boolean>(false);
|
|
237
|
-
const [focus, setFocus] = React.useState<boolean>(false);
|
|
238
|
-
const [raw, setRaw] = React.useState<PhoneRaw & { pretty: string, flag: any }>({ aa2: "", nn: "", code: 0, pretty: "", flag: "" });
|
|
239
|
-
function onChangeCountryCode(v: string, isReset?: boolean) {
|
|
240
|
-
try {
|
|
241
|
-
setRaw(vals => { const item = ({ ...vals, aa2: v, nn: isReset ? "" : vals.nn, code: aa3phone[props.code]?.countryCode, flag: aa3phone[props.code]?.flag, example: Phone.new().setRegions(props.regions).placeholder(v) }); item.pretty = Phone.new().prettyMaskWoc(item.aa2, item.nn); return item; });
|
|
242
|
-
} catch (error) {
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
function onChangeNn(v: string) {
|
|
246
|
-
try {
|
|
247
|
-
const value = String(v).replace(/\D/g, "");
|
|
248
|
-
setRaw(vals => { const item = { ...vals, nn: value }; item.pretty = Phone.new().prettyMaskWoc(item.aa2, item.nn); return item; });
|
|
249
|
-
} catch (error) {
|
|
269
|
+
containerStyle?: StyleProp<ViewStyle>;
|
|
270
|
+
phoneStyle?: StyleProp<TextStyle>;
|
|
271
|
+
placeholder?: string;
|
|
272
|
+
disabled?: boolean;
|
|
273
|
+
noPlusPrefix?: boolean;
|
|
274
|
+
regions?: Array<keyof typeof codesMap>;
|
|
275
|
+
phoneType?: PhoneType;
|
|
276
|
+
keyboardType?: 'default' | 'number-pad' | 'decimal-pad' | 'numeric' | 'email-address' | 'phone-pad' | 'url';
|
|
277
|
+
code: string;
|
|
278
|
+
value: any;
|
|
279
|
+
onChangeCountry: (regions: string[], active?: string) => void;
|
|
280
|
+
onChange: (value: string) => void;
|
|
281
|
+
onBlur: () => void;
|
|
282
|
+
};
|
|
250
283
|
|
|
251
|
-
|
|
252
|
-
}
|
|
253
|
-
React.useEffect(() => { if (init) { const instance = Phone.new().setRegions(props.regions); const rawResponse = instance.parseRawInput(raw.aa2, raw.nn, props.phoneType); if (rawResponse) { const a = instance.formatRaw(rawResponse, props.noPlusPrefix); props.onChange(a); } else if (props.onChange) { props.onChange(""); } } }, [init, focus, raw, props.regions?.length]);
|
|
254
|
-
React.useEffect(() => { if (init && !focus) { const rawResponse = Phone.new().setRegions(props.regions).parseRaw(props.value, props.phoneType); if (rawResponse) { const item: PhoneRaw & { pretty: string, flag: any } = { ...rawResponse, pretty: "", flag: aa3phone[rawResponse.aa2]?.flag }; item.pretty = Phone.new().prettyMaskWoc(rawResponse.aa2, raw.nn); setRaw(item); } else { onChangeCountryCode(props.code); } if (rawResponse?.nn == raw?.nn && props.code !== raw.aa2) { onChangeCountryCode(props.code, true); } } }, [init, focus, props.code, props.value]);
|
|
255
|
-
React.useEffect(() => { setInit(true); }, []);
|
|
256
|
-
return (<View style={[{ flex: 1, height: 45, maxHeight: 45, display: "flex", flexDirection: "row", borderWidth: 1, borderColor: "#dadce0" }, props.containerStyle]}><TouchableHighlight style={{ flex: 1, maxWidth: 55, display: "flex", justifyContent: "center", alignItems: "center", borderRightWidth: 1, borderRightColor: "#dadce0", backgroundColor: "white" }} onPress={() => props.onChangeCountry(Phone.new().setRegions(props.regions).supportsIat2.map(k => k.aa2), raw.aa2)}><MText style={{ textAlign: "center", fontSize: 23 }}>{raw.flag || "🏁"}</MText></TouchableHighlight><View style={{ flex: 1, maxWidth: 55, padding: 5, display: "flex", justifyContent: "center", alignItems: "center", backgroundColor: "white", borderRightWidth: 1, borderRightColor: "#dadce0" }}><MText style={{ color: "black", textAlign: "center", padding: 5, fontWeight: "500" }}>+{raw?.code}</MText></View><MTextInput style={[{ flex: 1, color: "black", borderWidth: 0, borderRadius: 0, minHeight: 43, height: 43 }, props.phoneStyle]} value={raw.pretty} autoFocus={false} maxLength={Phone.new().prettyMaskWoc(raw.aa2, raw.example)?.length} placeholder={props.placeholder} onChangeText={onChangeNn} onFocus={() => setFocus(true)} onBlur={() => setFocus(false)} /></View>);
|
|
257
|
-
}
|
|
284
|
+
export function MPhoneInput({ keyboardType = "phone-pad", ...props }: MPhoneInputProps) { const [init, setInit] = React.useState<boolean>(false); const [focus, setFocus] = React.useState<boolean>(false); const [raw, setRaw] = React.useState<PhoneRaw & { pretty: string, flag: any }>({ aa2: "", nn: "", code: 0, pretty: "", flag: "" }); function onChangeCountryCode(v: string, isReset?: boolean) { try { setRaw(vals => { const item = ({ ...vals, aa2: v, nn: isReset ? "" : vals.nn, code: aa3phone[props.code]?.countryCode, flag: aa3phone[props.code]?.flag, example: Phone.new().setRegions(props.regions).placeholder(v) }); item.pretty = Phone.new().prettyMaskWoc(item.aa2, item.nn); return item; }); } catch (error) { } } function onChangeNn(v: string) { try { const value = String(v).replace(/\D/g, ""); setRaw(vals => { const item = { ...vals, nn: value }; item.pretty = Phone.new().prettyMaskWoc(item.aa2, item.nn); return item; }); } catch (error) { } } React.useEffect(() => { if (init) { const instance = Phone.new().setRegions(props.regions); const rawResponse = instance.parseRawInput(raw.aa2, raw.nn, props.phoneType); if (rawResponse) { const a = instance.formatRaw(rawResponse, props.noPlusPrefix); props.onChange(a); } else if (props.onChange) { props.onChange(""); } } }, [init, focus, raw, props.regions?.length]); React.useEffect(() => { if (init && !focus) { const rawResponse = Phone.new().setRegions(props.regions).parseRaw(props.value, props.phoneType); if (rawResponse) { const item: PhoneRaw & { pretty: string, flag: any } = { ...rawResponse, pretty: "", flag: aa3phone[rawResponse.aa2]?.flag }; item.pretty = Phone.new().prettyMaskWoc(rawResponse.aa2, raw.nn); setRaw(item); } else { onChangeCountryCode(props.code); } if (rawResponse?.nn == raw?.nn && props.code !== raw.aa2) { onChangeCountryCode(props.code, true); } } }, [init, focus, props.code, props.value]); React.useEffect(() => { setInit(true); }, []); return (<View style={[{ flex: 1, height: 45, maxHeight: 45, display: "flex", flexDirection: "row", borderWidth: 1, borderColor: "#dadce0" }, props.containerStyle]}><TouchableHighlight style={{ flex: 1, maxWidth: 55, display: "flex", justifyContent: "center", alignItems: "center", borderRightWidth: 1, borderRightColor: "#dadce0", backgroundColor: "white" }} onPress={() => props.onChangeCountry(Phone.new().setRegions(props.regions).supportsIat2.map(k => k.aa2), raw.aa2)}><MText style={{ textAlign: "center", fontSize: 23 }}>{raw.flag || "🏁"}</MText></TouchableHighlight><View style={{ flex: 1, maxWidth: 55, padding: 5, display: "flex", justifyContent: "center", alignItems: "center", backgroundColor: "white", borderRightWidth: 1, borderRightColor: "#dadce0" }}><MText style={{ color: "black", textAlign: "center", padding: 5, fontWeight: "500" }}>+{raw?.code}</MText></View><MTextInput style={[{ flex: 1, color: "black", borderWidth: 0, borderRadius: 0, minHeight: 43, height: 43 }, props.phoneStyle]} value={raw.pretty} keyboardType={keyboardType} placeholder={props.placeholder} maxLength={Phone.new().prettyMaskWoc(raw.aa2, raw.example)?.length} onChangeText={onChangeNn} onFocus={() => setFocus(true)} onBlur={() => setFocus(false)} /></View>) }
|
package/src/Press.tsx
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
import React, { ReactNode } from "react";
|
|
2
|
-
import { Pressable, PressableProps } from "react-native";
|
|
3
|
-
interface MPressProps extends PressableProps {
|
|
4
|
-
children: ReactNode;
|
|
5
|
-
};
|
|
6
|
-
export function MPress({ children, ...props }: MPressProps) {return (<Pressable {...props}>{children}</Pressable>)}
|
|
1
|
+
import React, { ReactNode } from "react"; import { Pressable, PressableProps } from "react-native"; interface MPressProps extends PressableProps { children: ReactNode; }; export function MPress({ children, ...props }: MPressProps) { return (<Pressable {...props}>{children}</Pressable>); }
|
package/src/Radio.tsx
CHANGED
|
@@ -1,15 +1 @@
|
|
|
1
|
-
import React, { ReactNode } from "react";
|
|
2
|
-
import { TextStyle, TouchableHighlight, TouchableHighlightProps, View } from "react-native";
|
|
3
|
-
import { MText } from "./Text";
|
|
4
|
-
interface MRadioProps extends TouchableHighlightProps {
|
|
5
|
-
name?: string;
|
|
6
|
-
activeValue?: string | number | boolean;
|
|
7
|
-
value: string | number | boolean;
|
|
8
|
-
size?: number;
|
|
9
|
-
color: string;
|
|
10
|
-
label?: string;
|
|
11
|
-
labelStyle?: TextStyle;
|
|
12
|
-
onChange?: (values: string | number | boolean, checked: boolean, name?: string) => void;
|
|
13
|
-
children?: ReactNode;
|
|
14
|
-
};
|
|
15
|
-
export function MRadio({ name = "", activeValue, value, color, label, size = 26, labelStyle, style, onChange, ...props }: MRadioProps) { const checked = value == activeValue; return (<TouchableHighlight activeOpacity={0.85}{...props} onPress={() => { if (onChange) { onChange(checked ? "" : value, !checked, name); }; }} underlayColor="transparent" style={[{ flex: 1 }, style]}><View style={{ display: "flex", flexDirection: "row", alignItems: "center", minHeight: size }}><View style={{ padding: 4, width: size, height: size, borderRadius: size, borderWidth: 1, borderColor: color, backgroundColor: "white", display: "flex", justifyContent: "center", alignItems: "center" }} ><View style={{ width: size - 8, height: size - 8, backgroundColor: checked ? color : "white", borderRadius: size }} /></View><MText style={[{ flex: 1, fontSize: 15, paddingLeft: 5 }, labelStyle]}>{label}</MText></View></TouchableHighlight>) }
|
|
1
|
+
import React, { ReactNode } from "react"; import { TextStyle, TouchableHighlight, TouchableHighlightProps, View } from "react-native"; import { MText } from "./Text"; interface MRadioProps extends TouchableHighlightProps { name?: string; activeValue?: string | number | boolean; value: string | number | boolean; size?: number; color: string; label?: string; labelStyle?: TextStyle; onChange?: (values: string | number | boolean, checked: boolean, name?: string) => void; children?: ReactNode; }; export function MRadio({ name = "", activeValue, value, color, label, size = 26, labelStyle, style, onChange, ...props }: MRadioProps) { const checked = value == activeValue; return (<TouchableHighlight activeOpacity={0.85} {...props} onPress={() => { if (onChange) { onChange(checked ? "" : value, !checked, name); } }} underlayColor="transparent" style={[{ flex: 1 }, style]}><View style={{ display: "flex", flexDirection: "row", alignItems: "center", minHeight: size }}><View style={{ padding: 4, width: size, height: size, borderRadius: size, borderWidth: 1, borderColor: color, backgroundColor: "white", display: "flex", justifyContent: "center", alignItems: "center" }}><View style={{ width: size - 8, height: size - 8, backgroundColor: checked ? color : "white", borderRadius: size }} /></View><MText style={[{ flex: 1, fontSize: 15, paddingLeft: 5 }, labelStyle]}>{label}</MText></View></TouchableHighlight>) }
|
package/src/Scroll.tsx
CHANGED
|
@@ -1,13 +1 @@
|
|
|
1
|
-
import React, { forwardRef, ReactNode } from "react";
|
|
2
|
-
import { RefreshControl, ScrollView, StyleProp, ViewStyle, ScrollViewProps } from "react-native";
|
|
3
|
-
export const styleMSVerticalCenter = {
|
|
4
|
-
justifyContent: "center"
|
|
5
|
-
} as any;
|
|
6
|
-
interface MScrollProps extends ScrollViewProps {
|
|
7
|
-
name?: string;
|
|
8
|
-
contentContainerStyle?: StyleProp<ViewStyle>;
|
|
9
|
-
isRefreshing?: boolean;
|
|
10
|
-
onRefresh?: () => void;
|
|
11
|
-
children?: ReactNode;
|
|
12
|
-
};
|
|
13
|
-
export const MScroll = forwardRef<ScrollView, MScrollProps>((props, ref) => { return (<ScrollView ref={ref} contentInsetAdjustmentBehavior="automatic" contentContainerStyle={{ flexGrow: 1, backgroundColor: "transparent", paddingBottom: 175, padding: 9, ...(props.contentContainerStyle || {}) as any }} refreshControl={(props.onRefresh ? <RefreshControl refreshing={Boolean(props.isRefreshing)} onRefresh={props.onRefresh} /> : <React.Fragment></React.Fragment>)}>{props.children}</ScrollView>); })
|
|
1
|
+
import React, { forwardRef, ReactNode } from "react"; import { RefreshControl, ScrollView, StyleProp, ViewStyle, ScrollViewProps } from "react-native"; export const styleMSVerticalCenter = { justifyContent: "center" } as any; interface MScrollProps extends ScrollViewProps { name?: string; contentContainerStyle?: StyleProp<ViewStyle>; isRefreshing?: boolean; onRefresh?: () => void; children?: ReactNode; }; export const MScroll = forwardRef<ScrollView, MScrollProps>((props, ref) => { return (<ScrollView ref={ref} contentInsetAdjustmentBehavior="automatic" contentContainerStyle={{ flexGrow: 1, backgroundColor: "transparent", paddingBottom: 175, padding: 9, ...(props.contentContainerStyle || {}) as any }} refreshControl={(props.onRefresh && (<RefreshControl refreshing={Boolean(props.isRefreshing)} onRefresh={props.onRefresh} /> ))}>{props.children}</ScrollView> ) })
|