@momo-kits/foundation 1.0.0 → 1.0.1

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.
Files changed (62) hide show
  1. package/ActivityIndicator.tsx +244 -0
  2. package/Button/index.tsx +94 -164
  3. package/Button/types.ts +12 -3
  4. package/CheckBox/index.tsx +57 -0
  5. package/CheckBox/styles.ts +14 -0
  6. package/CheckBox/types.ts +7 -0
  7. package/Consts/colors+spacing+radius.ts +6 -4
  8. package/Consts/index.ts +4 -73
  9. package/Consts/styles.ts +1 -1
  10. package/Consts/theme.ts +65 -0
  11. package/ContentLoader/index.tsx +8 -11
  12. package/Icon/index.tsx +11 -11
  13. package/Icon/types.ts +1 -4
  14. package/IconButton/index.tsx +52 -72
  15. package/IconButton/styles.ts +19 -0
  16. package/IconButton/types.ts +1 -2
  17. package/Image/index.tsx +19 -18
  18. package/Image/types.ts +0 -1
  19. package/Input/TextArea.tsx +202 -0
  20. package/Input/index.tsx +200 -0
  21. package/Input/styles.ts +92 -0
  22. package/Input/types.ts +23 -0
  23. package/Layout/GridSystem.tsx +109 -0
  24. package/Layout/ScreenContainer.tsx +78 -0
  25. package/Layout/ScreenSection.tsx +104 -0
  26. package/Layout/SectionItem.tsx +60 -0
  27. package/Layout/index.ts +11 -5
  28. package/Layout/types.ts +6 -33
  29. package/Layout/utils.ts +55 -23
  30. package/Navigation/Components.tsx +16 -8
  31. package/Navigation/ModalScreen.tsx +35 -25
  32. package/Navigation/Navigation.ts +2 -2
  33. package/Navigation/NavigationButton.tsx +5 -3
  34. package/Navigation/NavigationContainer.tsx +59 -17
  35. package/Navigation/StackScreen.tsx +8 -2
  36. package/Navigation/index.ts +5 -3
  37. package/Navigation/types.ts +53 -36
  38. package/Navigation/utils.tsx +20 -18
  39. package/Radio/index.tsx +34 -0
  40. package/Radio/styles.ts +11 -0
  41. package/Radio/types.ts +7 -0
  42. package/Switch/index.tsx +37 -0
  43. package/Switch/styles.ts +23 -0
  44. package/Switch/types.ts +5 -0
  45. package/Text/index.tsx +36 -120
  46. package/Text/styles.ts +24 -23
  47. package/Text/types.ts +2 -0
  48. package/index.ts +18 -1
  49. package/package.json +1 -1
  50. package/publish.sh +8 -6
  51. package/CheckBox/index.js +0 -74
  52. package/CheckBox/styles.js +0 -3
  53. package/Layout/Row.tsx +0 -42
  54. package/Layout/Screen.tsx +0 -68
  55. package/Layout/Section.tsx +0 -30
  56. package/Layout/View.tsx +0 -84
  57. package/Layout/styles.ts +0 -24
  58. package/Navigation/ScreenContainer.tsx +0 -38
  59. package/SizedBox/index.js +0 -23
  60. package/SizedBox/styles.js +0 -7
  61. package/TextInput/index.js +0 -225
  62. package/TextInput/styles.js +0 -55
@@ -0,0 +1,7 @@
1
+ export interface CheckBoxProps {
2
+ value: boolean;
3
+ disabled?: boolean;
4
+ label?: string;
5
+ onChange: (value: boolean) => void;
6
+ indeterminated: boolean;
7
+ }
@@ -144,16 +144,18 @@ const Colors = {
144
144
  red_11: '#fef8f8',
145
145
  };
146
146
  const Spacing = {
147
- XS: 2,
148
- S: 4,
147
+ XXS: 2,
148
+ XS: 4,
149
+ S: 8,
149
150
  M: 12,
150
151
  L: 16,
151
152
  XL: 24,
152
153
  };
153
154
 
154
155
  const Radius = {
155
- XS: 2,
156
- S: 4,
156
+ XXS: 2,
157
+ XS: 4,
158
+ S: 8,
157
159
  M: 12,
158
160
  L: 16,
159
161
  XL: 24,
package/Consts/index.ts CHANGED
@@ -1,76 +1,7 @@
1
- import {Context, Theme} from '../Navigation/types';
1
+ export const GutterSize = 12;
2
+ export const ScreenPadding = 12;
3
+ export const NumberOfColumns = 12;
2
4
 
3
- const defaultTheme: Theme = {
4
- dark: false,
5
- colors: {
6
- background_default: '',
7
- background_surface: '',
8
- background_pressed: '',
9
- background_selected: '',
10
- background_disable: '',
11
- background_primary: '',
12
- background_tonal: '',
13
- text_default: '',
14
- text_secondary: '',
15
- text_hint: '',
16
- text_disable: '',
17
- text_white: '',
18
- text_primary: '',
19
- text_interactive: '',
20
- text_highlight: '',
21
- text_success: '',
22
- text_warning: '',
23
- text_error: '',
24
- border_default: '',
25
- border_disable: '',
26
- border_primary: '',
27
- border_primary_disable: '',
28
- border_error: '',
29
- border_error_disable: '',
30
- border_success: '',
31
- border_success_disable: '',
32
- },
33
- font: 'SFProText',
34
- };
35
-
36
- const defaultDarkTheme: Theme = {
37
- dark: true,
38
- colors: {
39
- background_default: '',
40
- background_surface: '',
41
- background_pressed: '',
42
- background_selected: '',
43
- background_disable: '',
44
- background_primary: '',
45
- background_tonal: '',
46
- text_default: '',
47
- text_secondary: '',
48
- text_hint: '',
49
- text_disable: '',
50
- text_white: '',
51
- text_primary: '',
52
- text_interactive: '',
53
- text_highlight: '',
54
- text_success: '',
55
- text_warning: '',
56
- text_error: '',
57
- border_default: '',
58
- border_disable: '',
59
- border_primary: '',
60
- border_primary_disable: '',
61
- border_error: '',
62
- border_error_disable: '',
63
- border_success: '',
64
- border_success_disable: '',
65
- },
66
- font: 'Raleway',
67
- };
68
-
69
- const defaultContext: Context = {
70
- theme: defaultTheme,
71
- navigator: undefined,
72
- };
73
-
74
- export {defaultContext, defaultTheme, defaultDarkTheme};
75
5
  export * from './colors+spacing+radius';
6
+ export * from './theme';
76
7
  export * from './styles';
package/Consts/styles.ts CHANGED
@@ -117,7 +117,7 @@ const Styles = StyleSheet.create({
117
117
  overflow: 'hidden',
118
118
  justifyContent: 'center',
119
119
  alignItems: 'center',
120
- paddingHorizontal: 8,
120
+ paddingHorizontal: 4,
121
121
  },
122
122
  //text
123
123
  textCenter: {textAlign: 'center'},
@@ -0,0 +1,65 @@
1
+ import {Context, Theme} from '../Navigation/types';
2
+ import {Colors} from './colors+spacing+radius';
3
+
4
+ const defaultTheme: Theme = {
5
+ dark: false,
6
+ colors: {
7
+ primary: Colors.pink_03,
8
+ secondary: Colors.pink_07,
9
+ background: {
10
+ default: '#f2f2f6',
11
+ surface: Colors.black_01,
12
+ tonal: Colors.pink_09,
13
+ pressed: '#fef4fa',
14
+ selected: Colors.pink_10,
15
+ disable: '#ebebf2',
16
+ },
17
+ text: {
18
+ default: Colors.black_17,
19
+ secondary: Colors.black_15,
20
+ hint: Colors.black_12,
21
+ disable: Colors.black_08,
22
+ },
23
+ border: {
24
+ default: Colors.black_04,
25
+ disable: Colors.black_02,
26
+ },
27
+ success: {
28
+ primary: Colors.green_03,
29
+ secondary: Colors.green_07,
30
+ container: Colors.green_08,
31
+ },
32
+ warning: {
33
+ primary: Colors.orange_03,
34
+ secondary: Colors.orange_07,
35
+ container: Colors.orange_08,
36
+ },
37
+ error: {
38
+ primary: Colors.red_03,
39
+ secondary: Colors.red_07,
40
+ container: Colors.red_08,
41
+ },
42
+ highlight: {
43
+ primary: Colors.mint_03,
44
+ secondary: Colors.mint_07,
45
+ container: Colors.mint_08,
46
+ },
47
+ interactive: {
48
+ primary: Colors.blue_03,
49
+ secondary: Colors.blue_07,
50
+ container: Colors.blue_08,
51
+ },
52
+ },
53
+ font: 'SFProText',
54
+ assets: {
55
+ headerBackground:
56
+ 'https://static.momocdn.net/app/img/app/img/header-background.png',
57
+ },
58
+ };
59
+
60
+ const defaultContext: Context = {
61
+ theme: defaultTheme,
62
+ navigator: undefined,
63
+ };
64
+
65
+ export {defaultContext, defaultTheme};
@@ -1,23 +1,20 @@
1
1
  import React, {useContext, useEffect, useMemo, useRef} from 'react';
2
2
  import {Animated, Platform, useWindowDimensions, View} from 'react-native';
3
- import {
4
- ContentLoaderTypes,
5
- LinearGradient,
6
- NavigationContext,
7
- Styles,
8
- } from '../index';
3
+ import {ContentLoaderTypes} from './types';
4
+ import {ApplicationContext} from '../Navigation';
5
+ import LinearGradient from 'react-native-linear-gradient';
6
+ import {Styles} from '../Consts';
9
7
  import styles from './styles';
10
-
11
8
  const ContentLoader: React.FC<ContentLoaderTypes> = props => {
12
9
  const {width} = useWindowDimensions();
13
- const {theme} = useContext(NavigationContext);
10
+ const {theme} = useContext(ApplicationContext);
14
11
  const beginShimmerPosition = useRef(new Animated.Value(-1)).current;
15
12
  const {style} = props;
16
13
 
17
14
  const shimmerColors = [
18
- theme.colors.border + '40',
19
- theme.colors.border + '80',
20
- theme.colors.border,
15
+ theme.colors.text.disable + '40',
16
+ theme.colors.text.disable + '80',
17
+ theme.colors.text.disable,
21
18
  ];
22
19
  const location = [0.3, 0.5, 0.7];
23
20
  const linearTranslate = beginShimmerPosition.interpolate({
package/Icon/index.tsx CHANGED
@@ -1,30 +1,30 @@
1
1
  import React, {useContext} from 'react';
2
- import {IconProps, Image, NavigationContext} from '../index';
3
- import SourceSets from './icon.json';
2
+ import {IconProps, Image, ApplicationContext} from '../index';
3
+ import IconSources from './icon.json';
4
4
 
5
- const Icon: React.FC<IconProps> = ({name, source, size, color}) => {
6
- const {theme} = useContext(NavigationContext);
5
+ const Icon: React.FC<IconProps> = ({source, size, color}) => {
6
+ const {theme} = useContext(ApplicationContext);
7
7
 
8
8
  const getIconSource = (): any => {
9
- if (name) {
10
- let icon: {[key: string]: object} = SourceSets;
11
- return icon[name] ?? icon.ic_warning;
9
+ if (source && !source.includes('http')) {
10
+ let icon: {[key: string]: object} = IconSources;
11
+ return icon[source] ?? icon.ic_warning;
12
12
  }
13
- return source;
13
+ return {uri: source};
14
14
  };
15
15
 
16
16
  return (
17
17
  <Image
18
18
  source={getIconSource()}
19
19
  style={{width: size, height: size}}
20
- tintColor={color ?? theme.colors.text}
20
+ tintColor={color ?? theme.colors.text.default}
21
21
  />
22
22
  );
23
23
  };
24
24
 
25
25
  Icon.defaultProps = {
26
- name: 'ic_back',
26
+ source: 'ic_back',
27
27
  size: 24,
28
28
  };
29
29
 
30
- export {Icon};
30
+ export {Icon, IconSources};
package/Icon/types.ts CHANGED
@@ -1,8 +1,5 @@
1
- import {Source} from 'react-native-fast-image';
2
-
3
1
  export type IconProps = {
4
- name?: string;
5
- source?: Source | number | undefined;
2
+ source?: string;
6
3
  size?: number;
7
4
  color?: string;
8
5
  };
@@ -1,65 +1,58 @@
1
1
  import React, {useContext} from 'react';
2
- import {StyleSheet, TouchableOpacity, View} from 'react-native';
3
- import {NavigationContext, Colors, Icon, IconButtonProps} from '../index';
2
+ import {
3
+ GestureResponderEvent,
4
+ StyleSheet,
5
+ TouchableOpacity,
6
+ } from 'react-native';
7
+ import {IconButtonProps} from './types';
8
+ import {ApplicationContext} from '../Navigation';
9
+ import {Colors} from '../Consts';
10
+ import {Icon} from '../Icon';
11
+ import styles from './styles';
4
12
 
5
13
  const IconButton: React.FC<IconButtonProps> = ({
6
- style,
7
14
  type,
8
15
  icon,
9
16
  size,
10
- shape,
17
+ onPress,
11
18
  ...rest
12
19
  }) => {
13
- const {theme} = useContext(NavigationContext);
20
+ const {theme} = useContext(ApplicationContext);
14
21
 
15
- /**
16
- * export size style
17
- */
18
22
  const getSizeStyle = () => {
19
- switch (size) {
20
- case 'large':
21
- return styles.large;
22
- case 'small':
23
- return styles.small;
24
-
25
- default:
26
- return styles.small;
27
- }
28
- };
29
-
30
- /**
31
- * export size style
32
- */
33
- const getIconSize = () => {
34
- switch (size) {
35
- case 'large':
36
- return 24;
37
- case 'small':
38
- return 16;
39
-
40
- default:
41
- return 16;
23
+ if (size === 'small') {
24
+ return styles.small;
42
25
  }
26
+ return styles.large;
43
27
  };
44
-
45
- /**
46
- * export type style
47
- */
48
28
  const getTypeStyle = () => {
49
29
  switch (type) {
30
+ case 'disabled':
31
+ return {
32
+ backgroundColor: theme.colors.background.disable,
33
+ };
50
34
  case 'primary':
51
35
  return {backgroundColor: theme.colors.primary};
52
- case 'tonal':
53
- return {backgroundColor: theme.colors.primary + '33'};
54
36
  case 'secondary':
55
- return {borderColor: theme.colors.border, borderWidth: 1};
37
+ return {
38
+ backgroundColor: Colors.black_01,
39
+ borderWidth: 1,
40
+ borderColor: theme.colors.border.default,
41
+ };
56
42
  case 'outline':
57
43
  return {
44
+ backgroundColor: Colors.black_01,
58
45
  borderWidth: 1,
59
46
  borderColor: theme.colors.primary,
60
47
  };
61
- case 'disabled':
62
- return {backgroundColor: theme.colors.border};
48
+ case 'tonal':
49
+ return {
50
+ backgroundColor: theme.colors.background.tonal,
51
+ };
52
+ case 'danger':
53
+ return {
54
+ backgroundColor: theme.colors.error.primary,
55
+ };
63
56
  default:
64
57
  return {backgroundColor: theme.colors.primary};
65
58
  }
@@ -67,61 +60,48 @@ const IconButton: React.FC<IconButtonProps> = ({
67
60
 
68
61
  const getIconColor = () => {
69
62
  switch (type) {
63
+ case 'disabled':
64
+ return theme.colors.text.disable;
70
65
  case 'primary':
71
66
  return Colors.black_01;
67
+ case 'danger':
68
+ return Colors.black_01;
72
69
  case 'tonal':
73
70
  return theme.colors.primary;
74
71
  case 'secondary':
75
- return theme.colors.text;
72
+ return theme.colors.text.default;
76
73
  case 'outline':
77
74
  return theme.colors.primary;
78
- case 'disabled':
79
- return theme.colors.text + '4D';
80
75
  default:
81
76
  return Colors.black_01;
82
77
  }
83
78
  };
84
79
 
85
- const buttonStyle = StyleSheet.flatten([
86
- getSizeStyle(),
87
- getTypeStyle(),
88
- shape === 'rectangle' && {borderRadius: 8},
89
- style,
90
- ]);
80
+ const onPressButton = (e: GestureResponderEvent) => {
81
+ if (type === 'disabled') {
82
+ return () => {};
83
+ }
84
+ onPress?.(e);
85
+ };
86
+
87
+ const activeOpacity = type === 'disabled' ? 0.75 : 0.5;
91
88
 
89
+ const buttonStyle = StyleSheet.flatten([getTypeStyle(), getSizeStyle()]);
90
+ const iconSize = size === 'small' ? 16 : 24;
92
91
  return (
93
92
  <TouchableOpacity
94
93
  {...rest}
95
- disabled={type === 'disabled'}
94
+ activeOpacity={activeOpacity}
95
+ onPress={onPressButton}
96
96
  style={buttonStyle}>
97
- <Icon name={icon} size={getIconSize()} color={getIconColor()} />
97
+ <Icon size={iconSize} source={icon} color={getIconColor()} />
98
98
  </TouchableOpacity>
99
99
  );
100
100
  };
101
101
 
102
102
  IconButton.defaultProps = {
103
- icon: 'close',
104
103
  type: 'primary',
105
- size: 'small',
106
- shape: 'circle',
107
- children: <View />,
104
+ disabled: false,
108
105
  };
109
106
 
110
- const styles = StyleSheet.create({
111
- large: {
112
- height: 48,
113
- width: 48,
114
- borderRadius: 24,
115
- justifyContent: 'center',
116
- alignItems: 'center',
117
- },
118
- small: {
119
- height: 36,
120
- width: 36,
121
- borderRadius: 18,
122
- justifyContent: 'center',
123
- alignItems: 'center',
124
- },
125
- });
126
-
127
107
  export {IconButton};
@@ -0,0 +1,19 @@
1
+ import {StyleSheet} from 'react-native';
2
+ import {Radius} from '../Consts';
3
+
4
+ export default StyleSheet.create({
5
+ large: {
6
+ width: 48,
7
+ height: 48,
8
+ borderRadius: Radius.XL,
9
+ justifyContent: 'center',
10
+ alignItems: 'center',
11
+ },
12
+ small: {
13
+ width: 40,
14
+ height: 40,
15
+ borderRadius: Radius.XL,
16
+ justifyContent: 'center',
17
+ alignItems: 'center',
18
+ },
19
+ });
@@ -4,14 +4,13 @@ export type IconButtonType =
4
4
  | 'primary'
5
5
  | 'tonal'
6
6
  | 'secondary'
7
+ | 'danger'
7
8
  | 'outline'
8
9
  | 'disabled';
9
10
  export type IconButtonSize = 'large' | 'small';
10
- export type IconButtonShape = 'circle' | 'rectangle';
11
11
 
12
12
  export interface IconButtonProps extends TouchableOpacityProps {
13
13
  icon: string;
14
14
  type?: IconButtonType;
15
15
  size?: IconButtonSize;
16
- shape?: IconButtonShape;
17
16
  }
package/Image/index.tsx CHANGED
@@ -1,19 +1,17 @@
1
1
  import React, {useContext, useState} from 'react';
2
2
  import {StyleSheet, View} from 'react-native';
3
3
  import FastImage from 'react-native-fast-image';
4
- import {
5
- ContentLoader,
6
- Icon,
7
- ImageProps,
8
- NavigationContext,
9
- Styles,
10
- Text,
11
- } from '../index';
4
+
12
5
  import styles from './styles';
6
+ import {ImageProps} from './types';
7
+ import {ApplicationContext} from '../Navigation';
8
+ import {ContentLoader} from '../ContentLoader';
9
+ import {Icon} from '../Icon';
10
+ import {Styles} from '../Consts';
13
11
 
14
12
  const Image: React.FC<ImageProps> = props => {
15
- const {theme} = useContext(NavigationContext);
16
- const {style, placeholder, error, source} = props;
13
+ const {theme} = useContext(ApplicationContext);
14
+ const {style, placeholder, source} = props;
17
15
  const [loading, setLoading] = useState(typeof source === 'object');
18
16
  const [fail, setFail] = useState(false);
19
17
 
@@ -27,18 +25,21 @@ const Image: React.FC<ImageProps> = props => {
27
25
  <ContentLoader style={[StyleSheet.absoluteFill, styles.image]} />
28
26
  );
29
27
  if (fail) {
30
- content = error ?? (
31
- <View
32
- style={[Styles.flexCenter, {backgroundColor: theme.colors.border}]}>
33
- <Icon name="error-outline" />
34
- <Text typography="subtitle" style={Styles.textCenter}>
35
- Can't load image
36
- </Text>
28
+ content = (
29
+ <View style={Styles.flexCenter}>
30
+ <Icon source="error-outline" />
37
31
  </View>
38
32
  );
39
33
  }
40
34
  return (
41
- <View style={[StyleSheet.absoluteFill, styles.image]}>{content}</View>
35
+ <View
36
+ style={[
37
+ StyleSheet.absoluteFill,
38
+ styles.image,
39
+ {backgroundColor: theme.colors.background.disable},
40
+ ]}>
41
+ {content}
42
+ </View>
42
43
  );
43
44
  }
44
45
  };
package/Image/types.ts CHANGED
@@ -2,5 +2,4 @@ import {FastImageProps} from 'react-native-fast-image';
2
2
 
3
3
  export interface ImageProps extends FastImageProps {
4
4
  placeholder?: boolean;
5
- error?: boolean;
6
5
  }