@momo-kits/foundation 0.169.16-beta.14 → 0.169.16-beta.16

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.
@@ -0,0 +1,93 @@
1
+ import React from 'react';
2
+ import { StyleSheet, TouchableOpacity, View } from 'react-native';
3
+ import { Colors, Spacing, Styles } from '../Consts';
4
+ import { Image } from '../Image';
5
+ import { Text } from '../Text';
6
+ import { Typography } from '../Text/types';
7
+ import styles from './styles';
8
+
9
+ const FLAG_SIZE = 24;
10
+
11
+ type CountryCodeViewProps = {
12
+ countryCode: string;
13
+ countryFlag: string;
14
+ typography: Typography;
15
+ textColor: string;
16
+ dividerHeight: number;
17
+ componentId: string;
18
+ isDisabled: boolean;
19
+ onPress?: () => void;
20
+ };
21
+
22
+ /**
23
+ * Flag, dial code and divider ahead of a phone number. Only becomes a button
24
+ * when `onPress` is given, so the default render stays a plain view.
25
+ */
26
+ const CountryCodeView: React.FC<CountryCodeViewProps> = ({
27
+ countryCode,
28
+ countryFlag,
29
+ typography,
30
+ textColor,
31
+ dividerHeight,
32
+ componentId,
33
+ isDisabled,
34
+ onPress,
35
+ }) => {
36
+ const content = (
37
+ <>
38
+ <Image
39
+ source={{ uri: countryFlag }}
40
+ style={innerStyle.iconFlag}
41
+ resizeMode="contain"
42
+ accessibilityLabel={`${componentId}|leading-icon`}
43
+ />
44
+ <View style={{ width: Spacing.XS }} />
45
+ <Text typography={typography} color={textColor}>
46
+ {countryCode}
47
+ </Text>
48
+ </>
49
+ );
50
+
51
+ const renderContent = () => {
52
+ if (!onPress) {
53
+ return content;
54
+ }
55
+ return (
56
+ <TouchableOpacity
57
+ style={Styles.row}
58
+ onPress={onPress}
59
+ disabled={isDisabled}
60
+ accessibilityRole="button"
61
+ accessibilityLabel={`${componentId}|leading-icon-touch|${countryCode}`}
62
+ accessibilityState={{ disabled: isDisabled }}
63
+ >
64
+ {content}
65
+ </TouchableOpacity>
66
+ );
67
+ };
68
+
69
+ return (
70
+ <View style={[styles.leadingIconContainer, Styles.row]}>
71
+ {renderContent()}
72
+ <View
73
+ style={[
74
+ styles.phoneNumberDivider,
75
+ {
76
+ height: dividerHeight,
77
+ backgroundColor: Colors.black_04,
78
+ },
79
+ ]}
80
+ />
81
+ </View>
82
+ );
83
+ };
84
+
85
+ const innerStyle = StyleSheet.create({
86
+ iconFlag: {
87
+ width: FLAG_SIZE,
88
+ height: FLAG_SIZE,
89
+ marginHorizontal: Spacing.XXS,
90
+ },
91
+ });
92
+
93
+ export { CountryCodeView };
@@ -6,7 +6,6 @@ import React, {
6
6
  useState,
7
7
  } from 'react';
8
8
  import {
9
- StyleSheet,
10
9
  TextInput,
11
10
  TextInputFocusEvent,
12
11
  TouchableOpacity,
@@ -18,12 +17,11 @@ import {
18
17
  ComponentContext,
19
18
  MiniAppContext,
20
19
  } from '../Context';
21
- import { Colors, Spacing, Styles } from '../Consts';
22
20
  import { Icon } from '../Icon';
23
- import { Image } from '../Image';
24
- import { useScaleSize, Text, exportFontFamily } from '../Text';
21
+ import { useScaleSize, exportFontFamily } from '../Text';
25
22
  import { Typography } from '../Text/types';
26
23
  import { CLEAR_ICON_SIZE } from './constants';
24
+ import { CountryCodeView } from './CountryCodeView';
27
25
  import { ErrorView } from './ErrorView';
28
26
  import { InputPhoneNumberProps } from './index';
29
27
  import { RenderTrailing } from './RenderTrailing';
@@ -36,11 +34,13 @@ const LARGE_FONT_SIZE = 18;
36
34
  const SMALL_DIVIDER_HEIGHT = 24;
37
35
  const LARGE_DIVIDER_HEIGHT = 32;
38
36
  const FOCUSED_BORDER_WIDTH = 1.5;
39
- const FLAG_SIZE = 24;
37
+ const DEFAULT_COUNTRY_CODE = '+84';
38
+ const DEFAULT_COUNTRY_FLAG =
39
+ 'https://static.momocdn.net/app/img/icon/ic-qrcode-package/ic_vn_flag.png';
40
40
 
41
41
  /**
42
- * Vietnamese phone number input with a fixed flag and `+84` prefix, number pad
43
- * by default, plus clear and trailing icons.
42
+ * Phone number input behind a country flag and dial code (Vietnam `+84` by
43
+ * default), number pad by default, plus clear and trailing icons.
44
44
  */
45
45
  const InputPhoneNumber = forwardRef(
46
46
  (
@@ -66,6 +66,9 @@ const InputPhoneNumber = forwardRef(
66
66
  editable = true,
67
67
  showClearIcon = true,
68
68
  defaultValue,
69
+ countryCode = DEFAULT_COUNTRY_CODE,
70
+ countryFlag = DEFAULT_COUNTRY_FLAG,
71
+ onPressLeadingIcon,
69
72
  ...props
70
73
  }: InputPhoneNumberProps,
71
74
  ref,
@@ -182,29 +185,16 @@ const InputPhoneNumber = forwardRef(
182
185
  ]}
183
186
  >
184
187
  <View style={styles.inputView}>
185
- <View style={[styles.leadingIconContainer, Styles.row]}>
186
- <Image
187
- source={{
188
- uri: 'https://static.momocdn.net/app/img/icon/ic-qrcode-package/ic_vn_flag.png',
189
- }}
190
- style={innerStyle.iconFlag}
191
- resizeMode="contain"
192
- accessibilityLabel={`${componentId}|leading-icon`}
193
- />
194
- <View style={{ width: Spacing.XS }} />
195
- <Text typography={typography} color={textColor}>
196
- {'+84'}
197
- </Text>
198
- <View
199
- style={[
200
- styles.phoneNumberDivider,
201
- {
202
- height: dividerHeight,
203
- backgroundColor: Colors.black_04,
204
- },
205
- ]}
206
- />
207
- </View>
188
+ <CountryCodeView
189
+ countryCode={countryCode}
190
+ countryFlag={countryFlag}
191
+ typography={typography}
192
+ textColor={textColor}
193
+ dividerHeight={dividerHeight}
194
+ componentId={componentId}
195
+ isDisabled={disabled || !editable}
196
+ onPress={onPressLeadingIcon}
197
+ />
208
198
  <SystemTextInput
209
199
  {...props}
210
200
  accessibilityLabel={`${componentId}`}
@@ -302,12 +292,4 @@ const InputPhoneNumber = forwardRef(
302
292
  },
303
293
  );
304
294
 
305
- const innerStyle = StyleSheet.create({
306
- iconFlag: {
307
- width: FLAG_SIZE,
308
- height: FLAG_SIZE,
309
- marginHorizontal: Spacing.XXS,
310
- },
311
- });
312
-
313
295
  export default InputPhoneNumber;
package/Input/index.tsx CHANGED
@@ -351,9 +351,22 @@ export interface InputDropDownProps extends TouchableOpacityProps {
351
351
 
352
352
  export interface InputPhoneNumberProps extends InputProps {
353
353
  /**
354
- * Optional. Currently unused: the displayed prefix is always `+84`.
354
+ * Optional. Dial code shown verbatim before the number.
355
+ * Defaults to `+84` if not provided.
355
356
  */
356
357
  countryCode?: string;
358
+
359
+ /**
360
+ * Optional. URL of the flag image shown before the dial code.
361
+ * Defaults to the Vietnam flag if not provided.
362
+ */
363
+ countryFlag?: string;
364
+
365
+ /**
366
+ * Optional. Called when the flag or dial code is pressed (e.g. to pick a country),
367
+ * which then reads as a button. Ignored while `disabled` or `editable={false}`.
368
+ */
369
+ onPressLeadingIcon?: () => void;
357
370
  }
358
371
 
359
372
  export type InputRef = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.169.16-beta.14",
3
+ "version": "0.169.16-beta.16",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},