@momo-kits/foundation 1.0.0 → 1.0.3
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/Button/index.tsx +118 -171
- package/CheckBox/index.tsx +63 -0
- package/CheckBox/styles.ts +14 -0
- package/CheckBox/types.ts +10 -0
- package/Consts/colors+spacing+radius.ts +6 -4
- package/Consts/index.ts +4 -73
- package/Consts/styles.ts +1 -1
- package/Consts/theme.ts +121 -0
- package/ContentLoader/index.tsx +9 -13
- package/Icon/index.tsx +14 -11
- package/Icon/types.ts +1 -4
- package/IconButton/index.tsx +67 -67
- package/IconButton/styles.ts +19 -0
- package/Image/index.tsx +22 -21
- package/Image/types.ts +0 -1
- package/Input/Input.tsx +161 -0
- package/Input/TextArea.tsx +162 -0
- package/Input/common.tsx +70 -0
- package/Input/index.tsx +26 -0
- package/Input/styles.ts +92 -0
- package/Layout/GridSystem.tsx +109 -0
- package/Layout/ScreenContainer.tsx +84 -0
- package/Layout/ScreenSection.tsx +117 -0
- package/Layout/SectionItem.tsx +63 -0
- package/Layout/index.ts +11 -5
- package/Layout/types.ts +6 -33
- package/Layout/utils.ts +69 -23
- package/Navigation/Components.tsx +42 -9
- package/Navigation/ModalScreen.tsx +65 -40
- package/Navigation/Navigation.ts +5 -2
- package/Navigation/NavigationButton.tsx +10 -5
- package/Navigation/NavigationContainer.tsx +17 -13
- package/Navigation/StackScreen.tsx +8 -2
- package/Navigation/index.ts +5 -3
- package/Navigation/types.ts +72 -38
- package/Navigation/utils.tsx +37 -14
- package/Playground/index.tsx +132 -0
- package/Playground/styles.ts +16 -0
- package/Playground/types.ts +15 -0
- package/Popup/PopupNotify.tsx +210 -0
- package/Popup/PopupPromotion.tsx +66 -0
- package/Popup/index.tsx +4 -0
- package/Popup/types.ts +23 -0
- package/Radio/index.tsx +42 -0
- package/Radio/styles.ts +12 -0
- package/Radio/types.ts +7 -0
- package/Switch/index.tsx +35 -0
- package/Switch/styles.ts +23 -0
- package/Switch/types.ts +5 -0
- package/Text/index.tsx +36 -118
- package/Text/styles.ts +24 -23
- package/Text/types.ts +5 -12
- package/index.ts +21 -4
- package/package.json +3 -4
- package/Button/types.ts +0 -18
- package/CheckBox/index.js +0 -74
- package/CheckBox/styles.js +0 -3
- package/IconButton/types.ts +0 -17
- package/Layout/Row.tsx +0 -42
- package/Layout/Screen.tsx +0 -68
- package/Layout/Section.tsx +0 -30
- package/Layout/View.tsx +0 -84
- package/Layout/styles.ts +0 -24
- package/Navigation/ScreenContainer.tsx +0 -38
- package/SizedBox/index.js +0 -23
- package/SizedBox/styles.js +0 -7
- package/TextInput/index.js +0 -225
- package/TextInput/styles.js +0 -55
package/Navigation/types.ts
CHANGED
|
@@ -1,42 +1,61 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import React
|
|
1
|
+
import {ViewProps} from 'react-native';
|
|
2
|
+
import React from 'react';
|
|
3
3
|
import Navigator from './Navigator';
|
|
4
|
-
import {Source} from 'react-native-fast-image';
|
|
5
4
|
import Navigation from './Navigation';
|
|
5
|
+
import {StackNavigationOptions} from '@react-navigation/stack';
|
|
6
6
|
|
|
7
7
|
export type Theme = {
|
|
8
8
|
dark: boolean;
|
|
9
9
|
colors: {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
10
|
+
primary: string;
|
|
11
|
+
secondary: string;
|
|
12
|
+
background: {
|
|
13
|
+
default: string;
|
|
14
|
+
surface: string;
|
|
15
|
+
tonal: string;
|
|
16
|
+
pressed: string;
|
|
17
|
+
selected: string;
|
|
18
|
+
disable: string;
|
|
19
|
+
};
|
|
20
|
+
text: {
|
|
21
|
+
default: string;
|
|
22
|
+
secondary: string;
|
|
23
|
+
hint: string;
|
|
24
|
+
disable: string;
|
|
25
|
+
};
|
|
26
|
+
border: {
|
|
27
|
+
default: string;
|
|
28
|
+
disable: string;
|
|
29
|
+
};
|
|
30
|
+
success: {
|
|
31
|
+
primary: string;
|
|
32
|
+
secondary: string;
|
|
33
|
+
container: string;
|
|
34
|
+
};
|
|
35
|
+
warning: {
|
|
36
|
+
primary: string;
|
|
37
|
+
secondary: string;
|
|
38
|
+
container: string;
|
|
39
|
+
};
|
|
40
|
+
error: {
|
|
41
|
+
primary: string;
|
|
42
|
+
secondary: string;
|
|
43
|
+
container: string;
|
|
44
|
+
};
|
|
45
|
+
highlight: {
|
|
46
|
+
primary: string;
|
|
47
|
+
secondary: string;
|
|
48
|
+
container: string;
|
|
49
|
+
};
|
|
50
|
+
interactive: {
|
|
51
|
+
primary: string;
|
|
52
|
+
secondary: string;
|
|
53
|
+
container: string;
|
|
54
|
+
};
|
|
36
55
|
};
|
|
37
56
|
font: string;
|
|
38
57
|
assets?: {
|
|
39
|
-
headerBackground?:
|
|
58
|
+
headerBackground?: string;
|
|
40
59
|
};
|
|
41
60
|
};
|
|
42
61
|
|
|
@@ -46,20 +65,20 @@ export type Context = {
|
|
|
46
65
|
};
|
|
47
66
|
|
|
48
67
|
export type NavigationContainerProps = {
|
|
49
|
-
useNative?: boolean;
|
|
50
68
|
screen: React.ElementType;
|
|
69
|
+
screenOptions?: StackNavigationOptions;
|
|
70
|
+
hideBackFirst?: boolean;
|
|
51
71
|
theme: Theme;
|
|
52
|
-
onDismiss
|
|
72
|
+
onDismiss?: () => void;
|
|
53
73
|
};
|
|
54
74
|
|
|
55
|
-
export
|
|
56
|
-
style?: ViewStyle;
|
|
57
|
-
children: ReactNode;
|
|
75
|
+
export interface ScreenContainerProps extends ViewProps {
|
|
58
76
|
navigation: Navigation;
|
|
59
77
|
options?: NavigationOptions;
|
|
60
78
|
edges?: any[];
|
|
61
79
|
enableKeyboardAvoidingView?: boolean;
|
|
62
|
-
|
|
80
|
+
scrollable: boolean;
|
|
81
|
+
}
|
|
63
82
|
|
|
64
83
|
export type ScreenParams = {
|
|
65
84
|
[key: string]: any;
|
|
@@ -71,7 +90,8 @@ export interface ModalParams extends ScreenParams {
|
|
|
71
90
|
[key: string]: any;
|
|
72
91
|
screen: React.ElementType;
|
|
73
92
|
onDismiss?: (mounted?: boolean) => void;
|
|
74
|
-
|
|
93
|
+
barrierDismissible?: boolean;
|
|
94
|
+
backgroundColor?: string;
|
|
75
95
|
}
|
|
76
96
|
|
|
77
97
|
export type NavigationButtonProps = {
|
|
@@ -81,7 +101,21 @@ export type NavigationButtonProps = {
|
|
|
81
101
|
};
|
|
82
102
|
|
|
83
103
|
export type NavigationOptions = {
|
|
104
|
+
surface?: boolean;
|
|
84
105
|
title?: string;
|
|
85
|
-
|
|
106
|
+
headerTitleAlign?: 'left' | 'center';
|
|
107
|
+
customTitle?: TitleCustomProps;
|
|
86
108
|
headerRight?: (props?: any) => React.ReactElement;
|
|
87
109
|
};
|
|
110
|
+
|
|
111
|
+
export type HeaderBackgroundProps = {
|
|
112
|
+
surface?: boolean;
|
|
113
|
+
image?: string;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export type TitleCustomProps = {
|
|
117
|
+
title?: string;
|
|
118
|
+
subTitle?: string;
|
|
119
|
+
image?: string;
|
|
120
|
+
content?: React.ReactNode;
|
|
121
|
+
};
|
package/Navigation/utils.tsx
CHANGED
|
@@ -1,28 +1,34 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {Colors, NavigationButton, Text, Theme} from '../index';
|
|
3
|
-
import {HeaderBackground} from './Components';
|
|
4
2
|
import {
|
|
5
3
|
StackNavigationOptions,
|
|
6
4
|
TransitionPresets,
|
|
7
5
|
} from '@react-navigation/stack';
|
|
6
|
+
import {HeaderBackground, HeaderCustom} from './Components';
|
|
7
|
+
import {NavigationOptions, Theme} from './types';
|
|
8
|
+
import {Colors} from '../Consts';
|
|
9
|
+
import {Text} from '../Text';
|
|
10
|
+
import {NavigationButton} from './index';
|
|
8
11
|
|
|
9
12
|
const renderTitle = (props: any) => {
|
|
10
13
|
return (
|
|
11
14
|
<Text
|
|
12
15
|
{...props}
|
|
13
|
-
typography="
|
|
16
|
+
typography="header_default"
|
|
14
17
|
weight="bold"
|
|
15
|
-
|
|
18
|
+
color={props.tintColor}
|
|
16
19
|
/>
|
|
17
20
|
);
|
|
18
21
|
};
|
|
19
22
|
|
|
20
|
-
const
|
|
23
|
+
const getTintColor = (theme: Theme): any => {
|
|
21
24
|
if (theme.assets?.headerBackground) {
|
|
22
25
|
return {
|
|
23
|
-
|
|
26
|
+
headerTintColor: Colors.black_01,
|
|
24
27
|
};
|
|
25
28
|
}
|
|
29
|
+
return {
|
|
30
|
+
headerTintColor: theme.colors.text.default,
|
|
31
|
+
};
|
|
26
32
|
};
|
|
27
33
|
|
|
28
34
|
const getStackOptions = (
|
|
@@ -30,13 +36,13 @@ const getStackOptions = (
|
|
|
30
36
|
goBack: () => void,
|
|
31
37
|
): StackNavigationOptions => {
|
|
32
38
|
return {
|
|
33
|
-
headerTintColor: Colors.black_01,
|
|
34
39
|
headerTitleAlign: 'center',
|
|
35
40
|
headerTitle: renderTitle,
|
|
36
|
-
|
|
41
|
+
headerBackground: HeaderBackground,
|
|
42
|
+
headerLeft: (props: any) => (
|
|
37
43
|
<NavigationButton icon="ic_back" {...props} onPress={goBack} />
|
|
38
44
|
),
|
|
39
|
-
...
|
|
45
|
+
...getTintColor(theme),
|
|
40
46
|
};
|
|
41
47
|
};
|
|
42
48
|
|
|
@@ -45,14 +51,14 @@ const getDialogOptions = (
|
|
|
45
51
|
goBack: () => void,
|
|
46
52
|
): StackNavigationOptions => {
|
|
47
53
|
return {
|
|
48
|
-
headerTintColor: Colors.black_01,
|
|
49
54
|
headerTitleAlign: 'center',
|
|
50
55
|
headerTitle: renderTitle,
|
|
51
|
-
headerLeft: props => (
|
|
52
|
-
<NavigationButton icon="
|
|
56
|
+
headerLeft: (props: any) => (
|
|
57
|
+
<NavigationButton icon="ic_back" {...props} onPress={goBack} />
|
|
53
58
|
),
|
|
59
|
+
headerBackground: HeaderBackground,
|
|
60
|
+
...getTintColor(theme),
|
|
54
61
|
...TransitionPresets.ModalTransition,
|
|
55
|
-
...getHeaderBackground(theme),
|
|
56
62
|
};
|
|
57
63
|
};
|
|
58
64
|
|
|
@@ -81,4 +87,21 @@ const getModalOptions = (): StackNavigationOptions => {
|
|
|
81
87
|
};
|
|
82
88
|
};
|
|
83
89
|
|
|
84
|
-
|
|
90
|
+
const getOptions = (params: NavigationOptions) => {
|
|
91
|
+
let surfaceTheme = {};
|
|
92
|
+
let titleTheme = {};
|
|
93
|
+
if (params.surface) {
|
|
94
|
+
surfaceTheme = {
|
|
95
|
+
headerBackground: () => <HeaderBackground surface={true} />,
|
|
96
|
+
headerTintColor: undefined,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
if (params.customTitle) {
|
|
100
|
+
titleTheme = {
|
|
101
|
+
headerTitle: () => <HeaderCustom {...params.customTitle} />,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return {...params, ...surfaceTheme, ...titleTheme};
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export {getStackOptions, getDialogOptions, getModalOptions, getOptions};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import React, {FC, useContext, useEffect, useState} from 'react';
|
|
2
|
+
import {View} from 'react-native';
|
|
3
|
+
import {CheckBox, Input, Radio, Text} from '@momo-kits/foundation';
|
|
4
|
+
import {PlaygroundProps, PropValue} from './types';
|
|
5
|
+
import styles from './styles';
|
|
6
|
+
import {Spacing} from '../Consts';
|
|
7
|
+
import {ApplicationContext} from '../Navigation';
|
|
8
|
+
|
|
9
|
+
const Playground: FC<PlaygroundProps> = ({params}) => {
|
|
10
|
+
const {theme} = useContext(ApplicationContext);
|
|
11
|
+
const {props} = params;
|
|
12
|
+
const [compProps, setCompProps] = useState<{[key: string]: any}>({});
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
initProps();
|
|
15
|
+
return () => {};
|
|
16
|
+
}, [props]);
|
|
17
|
+
|
|
18
|
+
const initProps = () => {
|
|
19
|
+
let newProps = {};
|
|
20
|
+
Object.keys(props).forEach(i => {
|
|
21
|
+
newProps = {...newProps, [i]: props[i].value};
|
|
22
|
+
});
|
|
23
|
+
setCompProps(newProps);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const onChangeOptions = (
|
|
27
|
+
value: string | boolean | undefined,
|
|
28
|
+
key: string,
|
|
29
|
+
) => {
|
|
30
|
+
const newProps = {...compProps, [key]: value};
|
|
31
|
+
setCompProps(newProps);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const onCheckUndefined = (value: boolean, key: string) => {
|
|
35
|
+
let newValue = !value ? undefined : props?.[key]?.value;
|
|
36
|
+
const newProps = {...compProps, [key]: newValue};
|
|
37
|
+
setCompProps(newProps);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const generateView = (key: string, prop: PropValue) => {
|
|
41
|
+
let PlayGroundView = <View />;
|
|
42
|
+
switch (prop.type) {
|
|
43
|
+
case 'enum': {
|
|
44
|
+
PlayGroundView = (
|
|
45
|
+
<View style={styles.radioView}>
|
|
46
|
+
{prop?.options?.map(option => {
|
|
47
|
+
return (
|
|
48
|
+
<Radio
|
|
49
|
+
label={option}
|
|
50
|
+
value={option}
|
|
51
|
+
onChange={() => onChangeOptions(option, key)}
|
|
52
|
+
groupValue={compProps?.[key]}
|
|
53
|
+
/>
|
|
54
|
+
);
|
|
55
|
+
})}
|
|
56
|
+
</View>
|
|
57
|
+
);
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
case 'string': {
|
|
61
|
+
PlayGroundView = (
|
|
62
|
+
<Input
|
|
63
|
+
size={'small'}
|
|
64
|
+
floatingValue={key}
|
|
65
|
+
onChangeText={text => onChangeOptions(text, key)}
|
|
66
|
+
/>
|
|
67
|
+
);
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
case 'bool': {
|
|
71
|
+
let label = compProps?.[key] === true ? 'True' : 'False';
|
|
72
|
+
if (compProps?.[key] === undefined) {
|
|
73
|
+
label = 'undefined';
|
|
74
|
+
}
|
|
75
|
+
PlayGroundView = (
|
|
76
|
+
<CheckBox
|
|
77
|
+
label={label}
|
|
78
|
+
value={compProps?.[key]}
|
|
79
|
+
onChange={value => onChangeOptions(value, key)}
|
|
80
|
+
/>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<View
|
|
87
|
+
style={[
|
|
88
|
+
styles.propView,
|
|
89
|
+
{backgroundColor: theme.colors.background.surface},
|
|
90
|
+
]}>
|
|
91
|
+
<Text style={styles.propTitle} typography={'header_default'}>
|
|
92
|
+
{key}
|
|
93
|
+
</Text>
|
|
94
|
+
{PlayGroundView}
|
|
95
|
+
{typeof compProps?.[key] !== 'boolean' && (
|
|
96
|
+
<CheckBox
|
|
97
|
+
style={{marginTop: Spacing.M}}
|
|
98
|
+
label={'Is undefined'}
|
|
99
|
+
value={!compProps?.[key]}
|
|
100
|
+
onChange={value => onCheckUndefined(!value, key)}
|
|
101
|
+
/>
|
|
102
|
+
)}
|
|
103
|
+
</View>
|
|
104
|
+
);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const Component = params.component ?? <View />;
|
|
108
|
+
const propsKeys = Object.keys(props);
|
|
109
|
+
return (
|
|
110
|
+
<View>
|
|
111
|
+
<Text style={{marginBottom: Spacing.M}} typography={'title_s'}>
|
|
112
|
+
Component
|
|
113
|
+
</Text>
|
|
114
|
+
<View
|
|
115
|
+
style={[
|
|
116
|
+
styles.propView,
|
|
117
|
+
{backgroundColor: theme.colors.background.surface},
|
|
118
|
+
]}>
|
|
119
|
+
<Text typography={'header_default'}>{params.displayName}</Text>
|
|
120
|
+
<Component {...compProps} />
|
|
121
|
+
</View>
|
|
122
|
+
<Text style={{marginBottom: Spacing.M}} typography={'title_s'}>
|
|
123
|
+
Props
|
|
124
|
+
</Text>
|
|
125
|
+
{propsKeys.map(prop => {
|
|
126
|
+
return generateView(prop, props[prop]);
|
|
127
|
+
})}
|
|
128
|
+
</View>
|
|
129
|
+
);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export default Playground;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {StyleSheet} from 'react-native';
|
|
2
|
+
import {Colors, Radius, Spacing} from '../Consts';
|
|
3
|
+
|
|
4
|
+
export default StyleSheet.create({
|
|
5
|
+
radioView: {
|
|
6
|
+
flexDirection: 'row',
|
|
7
|
+
flexWrap: 'wrap',
|
|
8
|
+
alignItems: 'center',
|
|
9
|
+
},
|
|
10
|
+
propView: {
|
|
11
|
+
borderRadius: Radius.M,
|
|
12
|
+
padding: Spacing.M,
|
|
13
|
+
marginBottom: Spacing.M,
|
|
14
|
+
},
|
|
15
|
+
propTitle: {marginBottom: Spacing.S, textTransform: 'capitalize'},
|
|
16
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {ReactElement} from 'react';
|
|
2
|
+
|
|
3
|
+
export type PropValue = {
|
|
4
|
+
value: any;
|
|
5
|
+
options?: string[];
|
|
6
|
+
type: 'string' | 'enum' | 'bool';
|
|
7
|
+
description?: string;
|
|
8
|
+
};
|
|
9
|
+
export type PlaygroundProps = {
|
|
10
|
+
params: {
|
|
11
|
+
component: ReactElement;
|
|
12
|
+
displayName: string;
|
|
13
|
+
props: {[key: string]: PropValue};
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import React, {useContext} from 'react';
|
|
2
|
+
import {StyleSheet, TouchableOpacity, View} from 'react-native';
|
|
3
|
+
import {PopupNotifyProps} from './types';
|
|
4
|
+
import {Radius, Spacing, Styles} from '../Consts';
|
|
5
|
+
import {Image} from '../Image';
|
|
6
|
+
import {Text} from '../Text';
|
|
7
|
+
import {ApplicationContext} from '../Navigation';
|
|
8
|
+
import {Button} from '../Button';
|
|
9
|
+
import {Icon} from '../Icon';
|
|
10
|
+
|
|
11
|
+
const PopupNotify: React.FC<PopupNotifyProps> = ({
|
|
12
|
+
image,
|
|
13
|
+
title,
|
|
14
|
+
description,
|
|
15
|
+
information,
|
|
16
|
+
secondary,
|
|
17
|
+
primary,
|
|
18
|
+
buttonDirection,
|
|
19
|
+
onIconClose,
|
|
20
|
+
}) => {
|
|
21
|
+
const {theme, navigator} = useContext(ApplicationContext);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* on action popup
|
|
25
|
+
* @param callback
|
|
26
|
+
*/
|
|
27
|
+
const onAction = (callback?: () => void) => {
|
|
28
|
+
navigator?.pop();
|
|
29
|
+
callback?.();
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* build main action of popup
|
|
34
|
+
*/
|
|
35
|
+
const buildAction = () => {
|
|
36
|
+
const renderRow = () => {
|
|
37
|
+
return (
|
|
38
|
+
<View style={Styles.row}>
|
|
39
|
+
{secondary?.title && (
|
|
40
|
+
<>
|
|
41
|
+
<View style={Styles.flex}>
|
|
42
|
+
<Button
|
|
43
|
+
title={secondary.title}
|
|
44
|
+
type="text"
|
|
45
|
+
size="medium"
|
|
46
|
+
onPress={() => {
|
|
47
|
+
onAction(secondary?.onPress);
|
|
48
|
+
}}
|
|
49
|
+
/>
|
|
50
|
+
</View>
|
|
51
|
+
<View style={styles.buttonSpace} />
|
|
52
|
+
</>
|
|
53
|
+
)}
|
|
54
|
+
<View style={Styles.flex}>
|
|
55
|
+
<Button
|
|
56
|
+
title={primary.title}
|
|
57
|
+
size="medium"
|
|
58
|
+
onPress={() => {
|
|
59
|
+
onAction(primary.onPress);
|
|
60
|
+
}}
|
|
61
|
+
/>
|
|
62
|
+
</View>
|
|
63
|
+
</View>
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
const renderColumn = () => {
|
|
67
|
+
return (
|
|
68
|
+
<View style={Styles.columnCenter}>
|
|
69
|
+
<Button
|
|
70
|
+
title={primary.title}
|
|
71
|
+
size="medium"
|
|
72
|
+
onPress={() => {
|
|
73
|
+
onAction(primary.onPress);
|
|
74
|
+
}}
|
|
75
|
+
/>
|
|
76
|
+
{secondary?.title && (
|
|
77
|
+
<>
|
|
78
|
+
<View style={styles.buttonSpace} />
|
|
79
|
+
<Button
|
|
80
|
+
title={secondary.title}
|
|
81
|
+
type="text"
|
|
82
|
+
size="medium"
|
|
83
|
+
onPress={() => {
|
|
84
|
+
onAction(secondary?.onPress);
|
|
85
|
+
}}
|
|
86
|
+
/>
|
|
87
|
+
</>
|
|
88
|
+
)}
|
|
89
|
+
</View>
|
|
90
|
+
);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
if (buttonDirection == 'auto') {
|
|
94
|
+
if (
|
|
95
|
+
secondary?.title &&
|
|
96
|
+
(secondary.title.length > 12 || primary.title.length > 12)
|
|
97
|
+
) {
|
|
98
|
+
return renderColumn();
|
|
99
|
+
}
|
|
100
|
+
return renderRow();
|
|
101
|
+
}
|
|
102
|
+
if (buttonDirection == 'row') {
|
|
103
|
+
return renderRow();
|
|
104
|
+
}
|
|
105
|
+
return renderColumn();
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* build close action
|
|
110
|
+
*/
|
|
111
|
+
const buildCloseIcon = () => {
|
|
112
|
+
return (
|
|
113
|
+
<View style={styles.iconCloseContainer}>
|
|
114
|
+
<TouchableOpacity
|
|
115
|
+
onPress={() => onAction(onIconClose)}
|
|
116
|
+
style={[
|
|
117
|
+
styles.iconClose,
|
|
118
|
+
{
|
|
119
|
+
backgroundColor: theme.colors.text.default,
|
|
120
|
+
borderColor: theme.colors.background.surface,
|
|
121
|
+
},
|
|
122
|
+
]}>
|
|
123
|
+
<Icon
|
|
124
|
+
source="navigation_close"
|
|
125
|
+
color={theme.colors.background.surface}
|
|
126
|
+
size={14}
|
|
127
|
+
/>
|
|
128
|
+
</TouchableOpacity>
|
|
129
|
+
</View>
|
|
130
|
+
);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<View
|
|
135
|
+
style={[
|
|
136
|
+
styles.container,
|
|
137
|
+
{backgroundColor: theme.colors.background.surface},
|
|
138
|
+
]}>
|
|
139
|
+
{image && <Image source={{uri: image}} style={styles.image} />}
|
|
140
|
+
<View style={styles.content}>
|
|
141
|
+
<Text typography={'title_xs'} numberOfLines={1}>
|
|
142
|
+
{title}
|
|
143
|
+
</Text>
|
|
144
|
+
<View style={styles.description}>
|
|
145
|
+
<Text typography={'paragraph_default'} numberOfLines={3}>
|
|
146
|
+
{description}
|
|
147
|
+
</Text>
|
|
148
|
+
</View>
|
|
149
|
+
{information && (
|
|
150
|
+
<View style={styles.information}>
|
|
151
|
+
<Text typography={'description_xs'} numberOfLines={1}>
|
|
152
|
+
{information}
|
|
153
|
+
</Text>
|
|
154
|
+
</View>
|
|
155
|
+
)}
|
|
156
|
+
</View>
|
|
157
|
+
<View style={styles.contentAction}>{buildAction()}</View>
|
|
158
|
+
{buildCloseIcon()}
|
|
159
|
+
</View>
|
|
160
|
+
);
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const styles = StyleSheet.create({
|
|
164
|
+
container: {
|
|
165
|
+
borderRadius: Radius.L,
|
|
166
|
+
},
|
|
167
|
+
image: {
|
|
168
|
+
borderTopLeftRadius: Radius.L,
|
|
169
|
+
borderTopRightRadius: Radius.L,
|
|
170
|
+
aspectRatio: 1.7777,
|
|
171
|
+
},
|
|
172
|
+
content: {padding: Spacing.XL},
|
|
173
|
+
description: {
|
|
174
|
+
marginTop: Spacing.S,
|
|
175
|
+
},
|
|
176
|
+
information: {
|
|
177
|
+
marginTop: Spacing.S,
|
|
178
|
+
},
|
|
179
|
+
contentAction: {
|
|
180
|
+
paddingHorizontal: Spacing.XL,
|
|
181
|
+
paddingBottom: Spacing.L,
|
|
182
|
+
},
|
|
183
|
+
buttonSpace: {
|
|
184
|
+
width: Spacing.S,
|
|
185
|
+
height: Spacing.S,
|
|
186
|
+
},
|
|
187
|
+
iconCloseContainer: {
|
|
188
|
+
position: 'absolute',
|
|
189
|
+
top: -Spacing.S,
|
|
190
|
+
right: -Spacing.S,
|
|
191
|
+
},
|
|
192
|
+
iconClose: {
|
|
193
|
+
width: 20,
|
|
194
|
+
height: 20,
|
|
195
|
+
alignItems: 'center',
|
|
196
|
+
justifyContent: 'center',
|
|
197
|
+
borderRadius: Radius.M,
|
|
198
|
+
borderWidth: 2,
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
PopupNotify.defaultProps = {
|
|
203
|
+
title: 'Title',
|
|
204
|
+
primary: {
|
|
205
|
+
title: 'Primary',
|
|
206
|
+
onPress: () => {},
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
export default PopupNotify;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import React, {useContext} from 'react';
|
|
2
|
+
import {StyleSheet, View} from 'react-native';
|
|
3
|
+
import {PopupPromotionProps} from './types';
|
|
4
|
+
import {ApplicationContext} from '../Navigation';
|
|
5
|
+
import {Image} from '../Image';
|
|
6
|
+
import {Button} from '../Button';
|
|
7
|
+
import {Spacing} from '../Consts';
|
|
8
|
+
|
|
9
|
+
const PopupPromotion: React.FC<PopupPromotionProps> = ({
|
|
10
|
+
image,
|
|
11
|
+
primary,
|
|
12
|
+
onIconClose,
|
|
13
|
+
}) => {
|
|
14
|
+
const {theme, navigator} = useContext(ApplicationContext);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* on action popup
|
|
18
|
+
* @param callback
|
|
19
|
+
*/
|
|
20
|
+
const onAction = (callback?: () => void) => {
|
|
21
|
+
navigator?.pop();
|
|
22
|
+
callback?.();
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<>
|
|
27
|
+
<Image
|
|
28
|
+
style={styles.container}
|
|
29
|
+
source={{
|
|
30
|
+
uri: image,
|
|
31
|
+
}}
|
|
32
|
+
/>
|
|
33
|
+
<View style={styles.actionContainer}>
|
|
34
|
+
<Button
|
|
35
|
+
title={primary?.title}
|
|
36
|
+
onPress={() => {
|
|
37
|
+
onAction(primary?.onPress);
|
|
38
|
+
}}
|
|
39
|
+
/>
|
|
40
|
+
</View>
|
|
41
|
+
</>
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const styles = StyleSheet.create({
|
|
46
|
+
container: {
|
|
47
|
+
aspectRatio: 0.66,
|
|
48
|
+
},
|
|
49
|
+
actionContainer: {
|
|
50
|
+
position: 'absolute',
|
|
51
|
+
bottom: 0,
|
|
52
|
+
width: '100%',
|
|
53
|
+
paddingVertical: Spacing.XL,
|
|
54
|
+
paddingHorizontal: Spacing.L,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
PopupPromotion.defaultProps = {
|
|
59
|
+
image: 'https://google.com',
|
|
60
|
+
primary: {
|
|
61
|
+
title: 'Primary',
|
|
62
|
+
onPress: () => {},
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export default PopupPromotion;
|
package/Popup/index.tsx
ADDED