@momo-kits/foundation 1.0.3 → 1.0.5

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.
@@ -1,13 +1,104 @@
1
1
  import React, {FC, useContext, useEffect, useState} from 'react';
2
- import {View} from 'react-native';
2
+ import {FlatList, TouchableOpacity, View} from 'react-native';
3
3
  import {CheckBox, Input, Radio, Text} from '@momo-kits/foundation';
4
4
  import {PlaygroundProps, PropValue} from './types';
5
5
  import styles from './styles';
6
- import {Spacing} from '../Consts';
6
+ import {Colors, Radius, Spacing} from '../Consts';
7
7
  import {ApplicationContext} from '../Navigation';
8
+ import {ScreenSection, SectionItem} from '../Layout';
9
+ import {Icon, IconSources} from '../Icon';
10
+ import {SearchInput} from '../Input';
8
11
 
9
- const Playground: FC<PlaygroundProps> = ({params}) => {
12
+ const ChooseOptionScreen = (
13
+ data: string[] = [],
14
+ optionType: 'color' | 'icon' | 'text' = 'text',
15
+ onPress: (value: string) => void,
16
+ ) => {
10
17
  const {theme} = useContext(ApplicationContext);
18
+ const [searchTerm, setSearchTerm] = useState('');
19
+ const [filteredData, setFilteredData] = useState<string[]>([]);
20
+
21
+ useEffect(() => {
22
+ let mapData = data;
23
+ if (optionType === 'color') {
24
+ mapData = Object.values(Colors);
25
+ }
26
+ if (optionType === 'icon') {
27
+ mapData = Object.keys(IconSources);
28
+ }
29
+
30
+ setFilteredData(mapData);
31
+ return () => {};
32
+ }, [filteredData]);
33
+
34
+ const renderItemView = (item: string) => {
35
+ switch (optionType) {
36
+ case 'color': {
37
+ return (
38
+ <View
39
+ style={{
40
+ width: 36,
41
+ height: 36,
42
+ borderRadius: Radius.M,
43
+ backgroundColor: item,
44
+ marginRight: Spacing.S,
45
+ }}
46
+ />
47
+ );
48
+ }
49
+ case 'icon': {
50
+ return <Icon source={item} style={{marginRight: Spacing.S}} />;
51
+ }
52
+ }
53
+ };
54
+
55
+ const onSearch = (text: string) => {
56
+ let newData = filteredData.map(i => i.includes(text));
57
+ if (text === '') {
58
+ newData = mapData;
59
+ }
60
+ };
61
+
62
+ const renderItem = ({item, index}) => {
63
+ const iconSource: {[key: string]: {uri: string}} = IconSources;
64
+ let key = item;
65
+ let chosenItem = item;
66
+ if (optionType === 'color') key = Object.keys(Colors)[index];
67
+ if (optionType === 'icon') chosenItem = iconSource[key].uri;
68
+ return (
69
+ <TouchableOpacity
70
+ key={`${item.toString()} ${index}`}
71
+ onPress={() => onPress(chosenItem)}
72
+ style={{
73
+ flexDirection: 'row',
74
+ alignItems: 'center',
75
+ marginBottom: Spacing.M,
76
+ borderBottomWidth: index !== filteredData.length - 1 ? 1 : 0,
77
+ borderColor: theme.colors.border.default,
78
+ paddingBottom: Spacing.M,
79
+ }}>
80
+ {renderItemView(item)}
81
+ <Text typography={'description_default'}>{key}</Text>
82
+ </TouchableOpacity>
83
+ );
84
+ };
85
+ return (
86
+ <ScreenSection>
87
+ <SectionItem widthSpan={12}>
88
+ <SearchInput value={searchTerm} onChangeText={onSearch} />
89
+ <FlatList
90
+ data={filteredData}
91
+ renderItem={renderItem}
92
+ keyExtractor={(item, index) => `${item.toString()} ${index}`}
93
+ showsVerticalScrollIndicator={false}
94
+ />
95
+ </SectionItem>
96
+ </ScreenSection>
97
+ );
98
+ };
99
+
100
+ const Playground: FC<PlaygroundProps> = ({params}) => {
101
+ const {theme, navigator} = useContext(ApplicationContext);
11
102
  const {props} = params;
12
103
  const [compProps, setCompProps] = useState<{[key: string]: any}>({});
13
104
  useEffect(() => {
@@ -37,6 +128,19 @@ const Playground: FC<PlaygroundProps> = ({params}) => {
37
128
  setCompProps(newProps);
38
129
  };
39
130
 
131
+ const showOptions = (prop: any, key: string) => {
132
+ navigator?.showBottomSheet({
133
+ options: {
134
+ title: 'Choose option',
135
+ },
136
+ screen: () =>
137
+ ChooseOptionScreen(prop.data, prop.optionType, optionValue => {
138
+ onChangeOptions(optionValue, key);
139
+ navigator?.pop();
140
+ }),
141
+ });
142
+ };
143
+
40
144
  const generateView = (key: string, prop: PropValue) => {
41
145
  let PlayGroundView = <View />;
42
146
  switch (prop.type) {
@@ -50,6 +154,11 @@ const Playground: FC<PlaygroundProps> = ({params}) => {
50
154
  value={option}
51
155
  onChange={() => onChangeOptions(option, key)}
52
156
  groupValue={compProps?.[key]}
157
+ style={{
158
+ marginBottom: Spacing.S,
159
+ marginRight: Spacing.M,
160
+ width: '25%',
161
+ }}
53
162
  />
54
163
  );
55
164
  })}
@@ -62,6 +171,7 @@ const Playground: FC<PlaygroundProps> = ({params}) => {
62
171
  <Input
63
172
  size={'small'}
64
173
  floatingValue={key}
174
+ value={compProps?.[key]}
65
175
  onChangeText={text => onChangeOptions(text, key)}
66
176
  />
67
177
  );
@@ -79,6 +189,29 @@ const Playground: FC<PlaygroundProps> = ({params}) => {
79
189
  onChange={value => onChangeOptions(value, key)}
80
190
  />
81
191
  );
192
+ break;
193
+ }
194
+ case 'options': {
195
+ PlayGroundView = (
196
+ <TouchableOpacity
197
+ style={{
198
+ width: '100%',
199
+ height: 48,
200
+ borderRadius: Radius.M,
201
+ borderColor: theme.colors.border.default,
202
+ borderWidth: 1,
203
+ justifyContent: 'center',
204
+ alignItems: 'center',
205
+ flexDirection: 'row',
206
+ backgroundColor: theme.colors.background.surface,
207
+ }}
208
+ onPress={() => showOptions(prop, key)}>
209
+ <Text typography={'description_default'}>{compProps?.[key]}</Text>
210
+ <View style={{position: 'absolute', right: Spacing.M}}>
211
+ <Icon source={'arrow_chevron_down_small'} size={24} />
212
+ </View>
213
+ </TouchableOpacity>
214
+ );
82
215
  }
83
216
  }
84
217
 
@@ -106,6 +239,7 @@ const Playground: FC<PlaygroundProps> = ({params}) => {
106
239
 
107
240
  const Component = params.component ?? <View />;
108
241
  const propsKeys = Object.keys(props);
242
+
109
243
  return (
110
244
  <View>
111
245
  <Text style={{marginBottom: Spacing.M}} typography={'title_s'}>
@@ -114,9 +248,12 @@ const Playground: FC<PlaygroundProps> = ({params}) => {
114
248
  <View
115
249
  style={[
116
250
  styles.propView,
117
- {backgroundColor: theme.colors.background.surface},
251
+ {
252
+ backgroundColor: theme.colors.background.surface,
253
+ justifyContent: 'center',
254
+ alignItems: 'center',
255
+ },
118
256
  ]}>
119
- <Text typography={'header_default'}>{params.displayName}</Text>
120
257
  <Component {...compProps} />
121
258
  </View>
122
259
  <Text style={{marginBottom: Spacing.M}} typography={'title_s'}>
@@ -3,13 +3,14 @@ import {ReactElement} from 'react';
3
3
  export type PropValue = {
4
4
  value: any;
5
5
  options?: string[];
6
- type: 'string' | 'enum' | 'bool';
6
+ type: 'string' | 'options' | 'enum' | 'bool';
7
7
  description?: string;
8
+ data?: {[key: string]: string}[];
9
+ optionType?: 'icon' | 'color';
8
10
  };
9
11
  export type PlaygroundProps = {
10
12
  params: {
11
13
  component: ReactElement;
12
- displayName: string;
13
14
  props: {[key: string]: PropValue};
14
15
  };
15
16
  };
@@ -6,11 +6,7 @@ import {Image} from '../Image';
6
6
  import {Button} from '../Button';
7
7
  import {Spacing} from '../Consts';
8
8
 
9
- const PopupPromotion: React.FC<PopupPromotionProps> = ({
10
- image,
11
- primary,
12
- onIconClose,
13
- }) => {
9
+ const PopupPromotion: React.FC<PopupPromotionProps> = ({image, primary}) => {
14
10
  const {theme, navigator} = useContext(ApplicationContext);
15
11
 
16
12
  /**
package/Popup/types.ts CHANGED
@@ -12,7 +12,6 @@ export type PopupNotifyProps = {
12
12
  export type PopupPromotionProps = {
13
13
  image: string;
14
14
  primary: PopupAction;
15
- onIconClose?: () => void;
16
15
  };
17
16
 
18
17
  type PopupAction = {
package/Radio/index.tsx CHANGED
@@ -13,6 +13,7 @@ const Radio: FC<RadioProps> = ({
13
13
  disabled,
14
14
  onChange,
15
15
  label,
16
+ style,
16
17
  }) => {
17
18
  const {theme} = useContext(ApplicationContext);
18
19
  const selected = value === groupValue;
@@ -26,15 +27,22 @@ const Radio: FC<RadioProps> = ({
26
27
 
27
28
  return (
28
29
  <TouchableOpacity
29
- onPress={() => onChange?.(value)}
30
+ onPress={onChange}
30
31
  disabled={disabled}
31
- style={{
32
- flexDirection: 'row',
33
- alignItems: 'center',
34
- marginRight: Spacing.S,
35
- }}>
36
- <View style={[styles.radio, {borderWidth, borderColor}]} />
37
- <Text typography={'description_default'}>{label}</Text>
32
+ style={[
33
+ style,
34
+ {
35
+ flexDirection: 'row',
36
+ alignItems: 'center',
37
+ },
38
+ ]}>
39
+ <View
40
+ style={[
41
+ styles.radio,
42
+ {borderWidth, borderColor, marginRight: !!label ? Spacing.XS : 0},
43
+ ]}
44
+ />
45
+ {!!label && <Text typography={'description_default'}>{label}</Text>}
38
46
  </TouchableOpacity>
39
47
  );
40
48
  };
package/Radio/styles.ts CHANGED
@@ -6,7 +6,6 @@ export default StyleSheet.create({
6
6
  height: 20,
7
7
  width: 20,
8
8
  borderRadius: Radius.M,
9
- marginRight: Spacing.S,
10
9
  },
11
10
  container: {flex: 1, backgroundColor: 'red'},
12
11
  });
package/Radio/types.ts CHANGED
@@ -1,7 +1,10 @@
1
+ import {ViewStyle} from 'react-native';
2
+
1
3
  export type RadioProps = {
2
4
  value: string;
3
5
  disabled?: boolean;
4
6
  label?: string;
5
- onChange: (newValue?: string) => void;
7
+ onChange: () => void;
6
8
  groupValue: string;
9
+ style?: ViewStyle;
7
10
  };
package/Switch/index.tsx CHANGED
@@ -7,7 +7,7 @@ import {Colors} from '../Consts';
7
7
 
8
8
  const Switch: FC<SwitchProps> = props => {
9
9
  const {theme} = useContext(ApplicationContext);
10
- const {value, onChange, disabled} = props;
10
+ const {value, onChange, disabled, style} = props;
11
11
  const circleBackgroundColor = value ? Colors.black_01 : Colors.black_03;
12
12
  const circleAlign = value ? 'flex-end' : 'flex-start';
13
13
 
@@ -20,7 +20,11 @@ const Switch: FC<SwitchProps> = props => {
20
20
  <TouchableOpacity
21
21
  disabled={disabled}
22
22
  onPress={() => onChange?.(!value)}
23
- style={[styles.container, {backgroundColor, alignItems: circleAlign}]}>
23
+ style={[
24
+ style,
25
+ styles.container,
26
+ {backgroundColor, alignItems: circleAlign},
27
+ ]}>
24
28
  <View style={[styles.circle, {backgroundColor: circleBackgroundColor}]}>
25
29
  <View style={[styles.circleSmall, {backgroundColor}]} />
26
30
  </View>
package/Switch/types.ts CHANGED
@@ -1,5 +1,8 @@
1
+ import {ViewStyle} from 'react-native';
2
+
1
3
  export type SwitchProps = {
2
4
  value: boolean;
3
5
  onChange: (value: boolean) => void;
4
- disabled: boolean;
6
+ disabled?: boolean;
7
+ style?: ViewStyle;
5
8
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {
@@ -11,7 +11,8 @@
11
11
  ],
12
12
  "dependencies": {
13
13
  "react-native-safe-area-context": "3.1.4",
14
- "@react-navigation/bottom-tabs": "5.11.15",
14
+ "react-native-linear-gradient": "2.5.6",
15
+ "@react-navigation/bottom-tabs": "git+https://gitlab.com/dung.huynh1/react-navigation-bottom-tabs.git#main",
15
16
  "@react-navigation/core": "5.16.1",
16
17
  "@react-navigation/native": "5.9.8",
17
18
  "@react-navigation/routers": "5.7.4",