@momo-kits/foundation 0.74.2-react-native.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.
- package/Application/BottomTab.tsx +120 -0
- package/Application/Components.tsx +534 -0
- package/Application/ModalScreen.tsx +268 -0
- package/Application/Navigation.ts +50 -0
- package/Application/NavigationContainer.tsx +120 -0
- package/Application/Navigator.ts +131 -0
- package/Application/StackScreen.tsx +71 -0
- package/Application/index.ts +41 -0
- package/Application/types.ts +216 -0
- package/Application/utils.tsx +151 -0
- package/Assets/DotAnimation.json +256 -0
- package/Assets/SpinnerAnimation.json +1027 -0
- package/Assets/icon.json +4031 -0
- package/Assets/icon_bank.json +506 -0
- package/Assets/language.json +202 -0
- package/Badge/Badge.tsx +56 -0
- package/Badge/BadgeDot.tsx +11 -0
- package/Badge/BadgeRibbon.tsx +125 -0
- package/Badge/Shape.tsx +29 -0
- package/Badge/index.tsx +7 -0
- package/Badge/styles.ts +58 -0
- package/Badge/types.ts +63 -0
- package/Button/index.tsx +310 -0
- package/Button/styles.ts +60 -0
- package/CheckBox/index.tsx +65 -0
- package/CheckBox/styles.ts +15 -0
- package/CheckBox/types.ts +38 -0
- package/Consts/colors+spacing+radius.ts +218 -0
- package/Consts/index.ts +4 -0
- package/Consts/styles.ts +52 -0
- package/Consts/theme.ts +125 -0
- package/Divider/index.tsx +21 -0
- package/Icon/index.tsx +41 -0
- package/Icon/types.ts +27 -0
- package/IconButton/index.tsx +139 -0
- package/IconButton/styles.ts +19 -0
- package/Image/index.tsx +83 -0
- package/Image/styles.ts +5 -0
- package/Image/types.ts +5 -0
- package/Input/Input.tsx +192 -0
- package/Input/InputDropDown.tsx +114 -0
- package/Input/InputMoney.tsx +163 -0
- package/Input/InputOTP.tsx +235 -0
- package/Input/InputSearch.tsx +151 -0
- package/Input/InputTextArea.tsx +159 -0
- package/Input/common.tsx +129 -0
- package/Input/index.tsx +251 -0
- package/Input/styles.ts +160 -0
- package/Input/utils.ts +69 -0
- package/Layout/Card.tsx +180 -0
- package/Layout/GridSystem.tsx +136 -0
- package/Layout/Item.tsx +56 -0
- package/Layout/ItemList.tsx +55 -0
- package/Layout/ItemSectionList.tsx +39 -0
- package/Layout/Screen.tsx +355 -0
- package/Layout/Section.tsx +179 -0
- package/Layout/index.ts +29 -0
- package/Layout/styles.ts +97 -0
- package/Layout/types.ts +23 -0
- package/Layout/utils.ts +55 -0
- package/Loader/DotLoader.tsx +37 -0
- package/Loader/Loader.tsx +13 -0
- package/Loader/ProgressBar.tsx +44 -0
- package/Loader/Spinner.tsx +28 -0
- package/Loader/index.tsx +4 -0
- package/Loader/styles.ts +10 -0
- package/Loader/types.ts +35 -0
- package/Loader/utils.ts +25 -0
- package/Pagination/Dot.tsx +16 -0
- package/Pagination/PaginationDot.tsx +38 -0
- package/Pagination/PaginationNumber.tsx +24 -0
- package/Pagination/PaginationScroll.tsx +88 -0
- package/Pagination/PaginationWhiteDot.tsx +35 -0
- package/Pagination/index.tsx +25 -0
- package/Pagination/styles.ts +50 -0
- package/Pagination/types.ts +40 -0
- package/Popup/PopupNotify.tsx +266 -0
- package/Popup/PopupPromotion.tsx +120 -0
- package/Popup/index.tsx +4 -0
- package/Popup/types.ts +87 -0
- package/Radio/index.tsx +64 -0
- package/Radio/styles.ts +11 -0
- package/Radio/types.ts +38 -0
- package/Skeleton/index.tsx +72 -0
- package/Skeleton/styles.ts +5 -0
- package/Skeleton/types.ts +6 -0
- package/Switch/index.tsx +37 -0
- package/Switch/styles.ts +23 -0
- package/Switch/types.ts +26 -0
- package/Tag/index.tsx +79 -0
- package/Tag/styles.ts +24 -0
- package/Tag/types.ts +36 -0
- package/Text/index.tsx +110 -0
- package/Text/styles.ts +73 -0
- package/Text/types.ts +34 -0
- package/Text/utils.ts +14 -0
- package/Title/index.tsx +132 -0
- package/Title/styles.ts +52 -0
- package/Title/types.ts +52 -0
- package/code-scanner.js +51 -0
- package/index.ts +51 -0
- package/package.json +36 -0
- package/publish.sh +23 -0
- package/tsconfig.json +24 -0
- package/verify.js +44 -0
package/Input/styles.ts
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import {StyleSheet} from 'react-native';
|
|
2
|
+
import {Radius, Spacing} from '../Consts';
|
|
3
|
+
import {scaleSize} from '../Text';
|
|
4
|
+
|
|
5
|
+
export default StyleSheet.create({
|
|
6
|
+
//input style
|
|
7
|
+
input: {
|
|
8
|
+
flex: 1,
|
|
9
|
+
paddingLeft: Spacing.M,
|
|
10
|
+
fontSize: scaleSize(15),
|
|
11
|
+
},
|
|
12
|
+
wrapper: {
|
|
13
|
+
width: '100%',
|
|
14
|
+
},
|
|
15
|
+
container: {
|
|
16
|
+
borderWidth: 1,
|
|
17
|
+
borderRadius: Radius.S,
|
|
18
|
+
height: 56,
|
|
19
|
+
},
|
|
20
|
+
smallContainer: {
|
|
21
|
+
borderRadius: Radius.S,
|
|
22
|
+
borderWidth: 1,
|
|
23
|
+
height: 48,
|
|
24
|
+
},
|
|
25
|
+
floatingView: {
|
|
26
|
+
position: 'absolute',
|
|
27
|
+
top: -10,
|
|
28
|
+
left: Spacing.S,
|
|
29
|
+
paddingHorizontal: Spacing.S,
|
|
30
|
+
flexDirection: 'row',
|
|
31
|
+
},
|
|
32
|
+
floatingIcon: {marginLeft: Spacing.XS},
|
|
33
|
+
errorIcon: {marginRight: Spacing.XS},
|
|
34
|
+
errorView: {
|
|
35
|
+
flexDirection: 'row',
|
|
36
|
+
alignItems: 'center',
|
|
37
|
+
marginTop: Spacing.XS,
|
|
38
|
+
},
|
|
39
|
+
inputView: {
|
|
40
|
+
flex: 1,
|
|
41
|
+
flexDirection: 'row',
|
|
42
|
+
alignItems: 'center',
|
|
43
|
+
},
|
|
44
|
+
leadingIconContainer: {
|
|
45
|
+
marginLeft: Spacing.M,
|
|
46
|
+
borderRadius: Radius.XS,
|
|
47
|
+
overflow: 'hidden',
|
|
48
|
+
},
|
|
49
|
+
iconView: {
|
|
50
|
+
flexDirection: 'row',
|
|
51
|
+
alignItems: 'center',
|
|
52
|
+
marginLeft: Spacing.XS,
|
|
53
|
+
marginRight: Spacing.M,
|
|
54
|
+
},
|
|
55
|
+
icon: {
|
|
56
|
+
marginLeft: Spacing.S
|
|
57
|
+
},
|
|
58
|
+
iconWrapper: {
|
|
59
|
+
width: 24,
|
|
60
|
+
height: 24,
|
|
61
|
+
justifyContent: 'center',
|
|
62
|
+
alignItems: 'center',
|
|
63
|
+
},
|
|
64
|
+
inputWrapper: {
|
|
65
|
+
flexDirection: 'row',
|
|
66
|
+
marginTop: Spacing.S,
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
//text area style
|
|
70
|
+
textAreaView: {
|
|
71
|
+
flex: 1,
|
|
72
|
+
},
|
|
73
|
+
textArea: {
|
|
74
|
+
width: '100%',
|
|
75
|
+
flex: 1,
|
|
76
|
+
paddingRight: Spacing.XS,
|
|
77
|
+
paddingVertical: Spacing.XS,
|
|
78
|
+
fontSize: scaleSize(15),
|
|
79
|
+
},
|
|
80
|
+
textAreaWrapper: {
|
|
81
|
+
borderWidth: 1,
|
|
82
|
+
borderRadius: Radius.S,
|
|
83
|
+
paddingVertical: Spacing.S,
|
|
84
|
+
paddingLeft: Spacing.M,
|
|
85
|
+
paddingRight: Spacing.S,
|
|
86
|
+
},
|
|
87
|
+
countingView: {
|
|
88
|
+
width: '100%',
|
|
89
|
+
alignItems: 'flex-end',
|
|
90
|
+
paddingRight: Spacing.XS,
|
|
91
|
+
},
|
|
92
|
+
rowArea: {
|
|
93
|
+
flexDirection: 'row',
|
|
94
|
+
width: '100%',
|
|
95
|
+
flex: 1,
|
|
96
|
+
marginBottom: Spacing.XS,
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
//searchInput
|
|
100
|
+
searchInputWrapper: {
|
|
101
|
+
flexDirection: 'row',
|
|
102
|
+
borderRadius: Radius.XL,
|
|
103
|
+
borderWidth: 1,
|
|
104
|
+
paddingHorizontal: Spacing.S,
|
|
105
|
+
alignItems: 'center',
|
|
106
|
+
flex: 1,
|
|
107
|
+
},
|
|
108
|
+
searchInput: {
|
|
109
|
+
height: 36,
|
|
110
|
+
marginLeft: Spacing.S,
|
|
111
|
+
flex: 1,
|
|
112
|
+
fontSize: scaleSize(15),
|
|
113
|
+
paddingVertical: Spacing.XS,
|
|
114
|
+
},
|
|
115
|
+
searchInputView: {
|
|
116
|
+
flexDirection: 'row',
|
|
117
|
+
alignItems: 'center',
|
|
118
|
+
},
|
|
119
|
+
iconSearchInput: {
|
|
120
|
+
marginLeft: Spacing.S,
|
|
121
|
+
},
|
|
122
|
+
searchInputContainer: {flexDirection: 'row', alignItems: 'center'},
|
|
123
|
+
textButton: {marginLeft: Spacing.L},
|
|
124
|
+
divider: {
|
|
125
|
+
width: 1,
|
|
126
|
+
marginLeft: Spacing.XS,
|
|
127
|
+
},
|
|
128
|
+
moneyInput: {
|
|
129
|
+
width: '100%',
|
|
130
|
+
paddingLeft: Spacing.M,
|
|
131
|
+
height: '100%',
|
|
132
|
+
fontSize: scaleSize(20),
|
|
133
|
+
paddingVertical: Spacing.S,
|
|
134
|
+
fontWeight: 'bold',
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
//OTP
|
|
138
|
+
otpWrapper: {
|
|
139
|
+
width: '100%',
|
|
140
|
+
marginTop: Spacing.M,
|
|
141
|
+
},
|
|
142
|
+
otpInput: {
|
|
143
|
+
height: scaleSize(56),
|
|
144
|
+
borderRadius: Radius.S,
|
|
145
|
+
borderWidth: 1,
|
|
146
|
+
},
|
|
147
|
+
otpFloatingView: {
|
|
148
|
+
position: 'absolute',
|
|
149
|
+
top: -Spacing.S,
|
|
150
|
+
alignSelf: 'center',
|
|
151
|
+
paddingHorizontal: Spacing.S,
|
|
152
|
+
},
|
|
153
|
+
otpInputsView: {
|
|
154
|
+
width: '100%',
|
|
155
|
+
height: '100%',
|
|
156
|
+
flexDirection: 'row',
|
|
157
|
+
alignItems: 'center',
|
|
158
|
+
justifyContent: 'center',
|
|
159
|
+
},
|
|
160
|
+
});
|
package/Input/utils.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const formatNumberToMoney = (number: number, currency = '') => {
|
|
2
|
+
if (!number || isNaN(number) || Number(number) === 0) {
|
|
3
|
+
return `0${currency}`;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const array: string[] = [];
|
|
7
|
+
let result = '';
|
|
8
|
+
let isNegative = false;
|
|
9
|
+
|
|
10
|
+
if (number < 0) {
|
|
11
|
+
isNegative = true;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const numberString = Math.abs(number).toString();
|
|
15
|
+
if (numberString.length < 3) {
|
|
16
|
+
return numberString + currency;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let count = 0;
|
|
20
|
+
for (let i = numberString.length - 1; i >= 0; i -= 1) {
|
|
21
|
+
count += 1;
|
|
22
|
+
if (numberString[i] === '.' || numberString[i] === ',') {
|
|
23
|
+
array.push(',');
|
|
24
|
+
count = 0;
|
|
25
|
+
} else {
|
|
26
|
+
array.push(numberString[i] as string);
|
|
27
|
+
}
|
|
28
|
+
if (count === 3 && i >= 1) {
|
|
29
|
+
array.push('.');
|
|
30
|
+
count = 0;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
for (let i = array.length - 1; i >= 0; i -= 1) {
|
|
35
|
+
result += array[i];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (isNegative) {
|
|
39
|
+
result = `-${result}`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return result + currency;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const formatMoneyToNumber = (money: string, currencyUnit: string) => {
|
|
46
|
+
if (money && money.length > 0) {
|
|
47
|
+
const moneyString = money
|
|
48
|
+
.replace(currencyUnit, '')
|
|
49
|
+
.replace(/,/g, '')
|
|
50
|
+
.replace(/đ/g, '')
|
|
51
|
+
.replace(/\./g, '')
|
|
52
|
+
.replace(/ /g, '');
|
|
53
|
+
const number = Number(moneyString);
|
|
54
|
+
if (isNaN(number)) {
|
|
55
|
+
return 0;
|
|
56
|
+
}
|
|
57
|
+
return number;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return Number(money);
|
|
61
|
+
};
|
|
62
|
+
const checkTyping = (text: string, value: boolean, setValue: any) => {
|
|
63
|
+
let typing = text?.length > 0;
|
|
64
|
+
if (typing != value) {
|
|
65
|
+
setValue(typing);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export {formatMoneyToNumber, formatNumberToMoney, checkTyping};
|
package/Layout/Card.tsx
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import React, {Fragment, useContext} from 'react';
|
|
2
|
+
import {Dimensions, View, ViewProps} from 'react-native';
|
|
3
|
+
import {useGridSystem, validateChildren} from './utils';
|
|
4
|
+
import {GridContextProps} from './types';
|
|
5
|
+
import {GridContext, GridSystem} from './index';
|
|
6
|
+
import Item from './Item';
|
|
7
|
+
import {Image} from '../Image';
|
|
8
|
+
import {ApplicationContext} from '../Application';
|
|
9
|
+
import styles from './styles';
|
|
10
|
+
import {Colors, Radius, Shadow, Spacing} from '../Consts';
|
|
11
|
+
import ItemList from './ItemList';
|
|
12
|
+
|
|
13
|
+
export interface CardProps extends ViewProps {
|
|
14
|
+
/**
|
|
15
|
+
* Optional. Background image for the card.
|
|
16
|
+
*/
|
|
17
|
+
backgroundImage?: string;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Optional. Use shadow for the card.
|
|
21
|
+
*/
|
|
22
|
+
useShadow?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const Card: React.FC<CardProps> = ({
|
|
26
|
+
children,
|
|
27
|
+
style,
|
|
28
|
+
backgroundImage,
|
|
29
|
+
useShadow = false,
|
|
30
|
+
...props
|
|
31
|
+
}) => {
|
|
32
|
+
const {showGrid, theme} = useContext(ApplicationContext);
|
|
33
|
+
const {numberOfColumns} = useGridSystem();
|
|
34
|
+
|
|
35
|
+
const gutterSize = 8;
|
|
36
|
+
const margin = 12;
|
|
37
|
+
|
|
38
|
+
const widthSection = Dimensions.get('window').width - margin * 2;
|
|
39
|
+
const totalGutterSize = gutterSize * (numberOfColumns - 1);
|
|
40
|
+
const sizePerSpan = (widthSection - totalGutterSize - 24) / numberOfColumns;
|
|
41
|
+
|
|
42
|
+
const gridContext: GridContextProps = {
|
|
43
|
+
numberOfColumns,
|
|
44
|
+
gutterSize,
|
|
45
|
+
sizePerSpan,
|
|
46
|
+
getSizeSpan: span => {
|
|
47
|
+
return span * sizePerSpan + (span - 1) * gutterSize;
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* render overlay only dev mode
|
|
53
|
+
*/
|
|
54
|
+
const renderOverlay = () => {
|
|
55
|
+
return (
|
|
56
|
+
<>
|
|
57
|
+
<GridSystem
|
|
58
|
+
width={widthSection}
|
|
59
|
+
gutterSize={Spacing.S}
|
|
60
|
+
screenGrid={false}
|
|
61
|
+
gridColor={Colors.red_01}
|
|
62
|
+
/>
|
|
63
|
+
<View pointerEvents={'none'} style={styles.boxGridCard} />
|
|
64
|
+
</>
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* build a row view in side session
|
|
70
|
+
* @param rows
|
|
71
|
+
* @param cursor
|
|
72
|
+
* @param endRow
|
|
73
|
+
*/
|
|
74
|
+
const addRowView = (
|
|
75
|
+
rows: any[],
|
|
76
|
+
cursor: number = 0,
|
|
77
|
+
endRow: boolean = false,
|
|
78
|
+
) => {
|
|
79
|
+
return (
|
|
80
|
+
<View
|
|
81
|
+
key={`Item${cursor}`}
|
|
82
|
+
style={{
|
|
83
|
+
flexDirection: 'row',
|
|
84
|
+
marginBottom: endRow ? 0 : gridContext.gutterSize,
|
|
85
|
+
}}>
|
|
86
|
+
{rows.map((i: React.ReactElement, index: number) => {
|
|
87
|
+
return (
|
|
88
|
+
<View key={`Item${cursor}${index}`} style={{flexDirection: 'row'}}>
|
|
89
|
+
{index != 0 && (
|
|
90
|
+
<View style={{width: gridContext.gutterSize}}></View>
|
|
91
|
+
)}
|
|
92
|
+
{i}
|
|
93
|
+
</View>
|
|
94
|
+
);
|
|
95
|
+
})}
|
|
96
|
+
</View>
|
|
97
|
+
);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* render children content for card
|
|
102
|
+
* @param children
|
|
103
|
+
*/
|
|
104
|
+
const renderView = (
|
|
105
|
+
children: any,
|
|
106
|
+
): React.ReactElement | React.ReactElement[] => {
|
|
107
|
+
const element: React.ReactElement | React.ReactElement[] = [];
|
|
108
|
+
if (Array.isArray(children)) {
|
|
109
|
+
let cursor = 0;
|
|
110
|
+
let rows: any[] = [];
|
|
111
|
+
const arrayChild = children.filter(item => !!item);
|
|
112
|
+
for (let i = 0; i < arrayChild.length; ++i) {
|
|
113
|
+
const item = arrayChild[i];
|
|
114
|
+
const totalSpan = rows
|
|
115
|
+
.concat([item])
|
|
116
|
+
.map(i => i.props?.widthSpan)
|
|
117
|
+
.reduce((previousValue, currentValue) => {
|
|
118
|
+
return previousValue + currentValue;
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
if (totalSpan <= gridContext.numberOfColumns) {
|
|
122
|
+
rows.push(item);
|
|
123
|
+
} else {
|
|
124
|
+
cursor += 1;
|
|
125
|
+
element.push(addRowView(rows, cursor));
|
|
126
|
+
rows = [item];
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (i == arrayChild.length - 1) {
|
|
130
|
+
cursor += 1;
|
|
131
|
+
element.push(addRowView(rows, cursor, true));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
} else {
|
|
135
|
+
element.push(children);
|
|
136
|
+
if (children?.type == Fragment) {
|
|
137
|
+
return renderView(children?.props.children);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return element;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
return (
|
|
144
|
+
<GridContext.Provider value={gridContext}>
|
|
145
|
+
<View
|
|
146
|
+
{...props}
|
|
147
|
+
style={[
|
|
148
|
+
{backgroundColor: theme.colors.background.surface},
|
|
149
|
+
style,
|
|
150
|
+
styles.protectedStyle,
|
|
151
|
+
styles.card,
|
|
152
|
+
{
|
|
153
|
+
width: widthSection,
|
|
154
|
+
marginHorizontal: margin,
|
|
155
|
+
},
|
|
156
|
+
!!backgroundImage && {backgroundColor: undefined},
|
|
157
|
+
useShadow && Shadow.Light,
|
|
158
|
+
]}>
|
|
159
|
+
{!!backgroundImage && (
|
|
160
|
+
<Image
|
|
161
|
+
source={{uri: backgroundImage}}
|
|
162
|
+
style={[
|
|
163
|
+
styles.imageBackground,
|
|
164
|
+
{
|
|
165
|
+
width: widthSection,
|
|
166
|
+
borderRadius: Radius.M,
|
|
167
|
+
},
|
|
168
|
+
]}
|
|
169
|
+
/>
|
|
170
|
+
)}
|
|
171
|
+
{renderView(validateChildren(children, [Item, ItemList]))}
|
|
172
|
+
{showGrid && renderOverlay()}
|
|
173
|
+
</View>
|
|
174
|
+
</GridContext.Provider>
|
|
175
|
+
);
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
Card.displayName = 'Card';
|
|
179
|
+
|
|
180
|
+
export default Card;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import React, {useContext} from 'react';
|
|
2
|
+
import {useSafeAreaInsets} from 'react-native-safe-area-context';
|
|
3
|
+
import {Dimensions, StyleSheet, View} from 'react-native';
|
|
4
|
+
import {ApplicationContext} from '../Application';
|
|
5
|
+
import {Colors, Spacing} from '../Consts';
|
|
6
|
+
import {GridContextProps} from './types';
|
|
7
|
+
import {useGridSystem} from './utils';
|
|
8
|
+
|
|
9
|
+
const GridSystem: React.FC<any> = ({
|
|
10
|
+
width = Dimensions.get('window').width,
|
|
11
|
+
useMargin = true,
|
|
12
|
+
gutterSize = Spacing.M,
|
|
13
|
+
screenGrid = true,
|
|
14
|
+
gridColor = Colors.blue_07,
|
|
15
|
+
}) => {
|
|
16
|
+
const {theme} = useContext(ApplicationContext);
|
|
17
|
+
const {numberOfColumns} = useGridSystem();
|
|
18
|
+
|
|
19
|
+
const margin = useMargin ? Spacing.M : 0;
|
|
20
|
+
const widthSection = width - margin * 2;
|
|
21
|
+
const totalGutterSize = gutterSize * (numberOfColumns - 1);
|
|
22
|
+
const sizePerSpan = (widthSection - totalGutterSize) / numberOfColumns;
|
|
23
|
+
|
|
24
|
+
const grid: GridContextProps = {
|
|
25
|
+
numberOfColumns,
|
|
26
|
+
gutterSize,
|
|
27
|
+
sizePerSpan,
|
|
28
|
+
getSizeSpan: span => {
|
|
29
|
+
return span * sizePerSpan + (span - 1) * gutterSize;
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
const insets = useSafeAreaInsets();
|
|
33
|
+
|
|
34
|
+
const list: number[] = [];
|
|
35
|
+
for (let i = 1; i <= grid.numberOfColumns; i++) {
|
|
36
|
+
list.push(i);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<>
|
|
41
|
+
<View
|
|
42
|
+
pointerEvents="none"
|
|
43
|
+
style={[
|
|
44
|
+
styles.gridContainer,
|
|
45
|
+
screenGrid && insets,
|
|
46
|
+
{
|
|
47
|
+
borderColor: theme.colors.error.primary,
|
|
48
|
+
marginHorizontal: margin,
|
|
49
|
+
top: Spacing.M,
|
|
50
|
+
bottom: Spacing.M,
|
|
51
|
+
},
|
|
52
|
+
]}>
|
|
53
|
+
{list.map((_, index) => {
|
|
54
|
+
return (
|
|
55
|
+
<View style={{flexDirection: 'row'}} key={index.toString()}>
|
|
56
|
+
{index != -0 && <View style={{width: grid.gutterSize}} />}
|
|
57
|
+
<View
|
|
58
|
+
key={`Grid${index.toString()}`}
|
|
59
|
+
pointerEvents="none"
|
|
60
|
+
style={[
|
|
61
|
+
styles.gridColumn,
|
|
62
|
+
{
|
|
63
|
+
width: grid.sizePerSpan,
|
|
64
|
+
backgroundColor: gridColor,
|
|
65
|
+
},
|
|
66
|
+
]}
|
|
67
|
+
/>
|
|
68
|
+
</View>
|
|
69
|
+
);
|
|
70
|
+
})}
|
|
71
|
+
</View>
|
|
72
|
+
{screenGrid && (
|
|
73
|
+
<>
|
|
74
|
+
<View pointerEvents="none" style={styles.dangerLeftContainer} />
|
|
75
|
+
<View pointerEvents="none" style={styles.dangerRightContainer} />
|
|
76
|
+
<View
|
|
77
|
+
pointerEvents="none"
|
|
78
|
+
style={[styles.dangerTopContainer, {height: Spacing.M}]}
|
|
79
|
+
/>
|
|
80
|
+
<View
|
|
81
|
+
pointerEvents="none"
|
|
82
|
+
style={[styles.dangerBottomContainer, {height: insets.bottom}]}
|
|
83
|
+
/>
|
|
84
|
+
</>
|
|
85
|
+
)}
|
|
86
|
+
</>
|
|
87
|
+
);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const styles = StyleSheet.create({
|
|
91
|
+
gridContainer: {
|
|
92
|
+
position: 'absolute',
|
|
93
|
+
top: 0,
|
|
94
|
+
bottom: 0,
|
|
95
|
+
left: 0,
|
|
96
|
+
right: 0,
|
|
97
|
+
flexDirection: 'row',
|
|
98
|
+
borderWidth: 1,
|
|
99
|
+
},
|
|
100
|
+
gridColumn: {
|
|
101
|
+
height: '100%',
|
|
102
|
+
opacity: 0.2,
|
|
103
|
+
},
|
|
104
|
+
dangerTopContainer: {
|
|
105
|
+
opacity: 0.2,
|
|
106
|
+
backgroundColor: Colors.red_03,
|
|
107
|
+
width: '100%',
|
|
108
|
+
top: 0,
|
|
109
|
+
position: 'absolute',
|
|
110
|
+
},
|
|
111
|
+
dangerBottomContainer: {
|
|
112
|
+
opacity: 0.2,
|
|
113
|
+
backgroundColor: Colors.red_03,
|
|
114
|
+
width: '100%',
|
|
115
|
+
bottom: 0,
|
|
116
|
+
position: 'absolute',
|
|
117
|
+
},
|
|
118
|
+
dangerLeftContainer: {
|
|
119
|
+
opacity: 0.2,
|
|
120
|
+
backgroundColor: Colors.red_03,
|
|
121
|
+
width: Spacing.M,
|
|
122
|
+
height: '100%',
|
|
123
|
+
left: 0,
|
|
124
|
+
position: 'absolute',
|
|
125
|
+
},
|
|
126
|
+
dangerRightContainer: {
|
|
127
|
+
opacity: 0.2,
|
|
128
|
+
backgroundColor: Colors.red_03,
|
|
129
|
+
width: Spacing.M,
|
|
130
|
+
height: '100%',
|
|
131
|
+
right: 0,
|
|
132
|
+
position: 'absolute',
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
export default GridSystem;
|
package/Layout/Item.tsx
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import React, {useContext} from 'react';
|
|
2
|
+
import {View, ViewProps} from 'react-native';
|
|
3
|
+
|
|
4
|
+
import {GridContext} from './index';
|
|
5
|
+
import {ApplicationContext} from '../Application';
|
|
6
|
+
import styles from './styles';
|
|
7
|
+
|
|
8
|
+
export type SpanNumber = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
|
|
9
|
+
|
|
10
|
+
export interface ItemProps extends ViewProps {
|
|
11
|
+
/**
|
|
12
|
+
* Represents the width of the Card component in terms of span numbers (1-12).
|
|
13
|
+
*/
|
|
14
|
+
widthSpan?: SpanNumber;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Optional. Represents the height of the Card component in terms of span numbers (1-12).
|
|
18
|
+
*/
|
|
19
|
+
heightSpan?: SpanNumber;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const Item: React.FC<ItemProps> = ({
|
|
23
|
+
widthSpan,
|
|
24
|
+
heightSpan,
|
|
25
|
+
children,
|
|
26
|
+
style,
|
|
27
|
+
}) => {
|
|
28
|
+
const {showGrid} = useContext(ApplicationContext);
|
|
29
|
+
const grid = useContext(GridContext);
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* render overlay view only dev mode
|
|
33
|
+
*/
|
|
34
|
+
const renderOverlay = () => {
|
|
35
|
+
return <View pointerEvents={'none'} style={styles.boxGrid} />;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<View
|
|
40
|
+
style={[
|
|
41
|
+
style,
|
|
42
|
+
styles.item,
|
|
43
|
+
{
|
|
44
|
+
width: grid.getSizeSpan(widthSpan ?? grid.numberOfColumns),
|
|
45
|
+
height: heightSpan ? grid.getSizeSpan(heightSpan) : undefined,
|
|
46
|
+
},
|
|
47
|
+
]}>
|
|
48
|
+
{children}
|
|
49
|
+
{showGrid && renderOverlay()}
|
|
50
|
+
</View>
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
Item.displayName = 'Item';
|
|
55
|
+
|
|
56
|
+
export default Item;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import React, {forwardRef, useContext} from 'react';
|
|
2
|
+
import {FlatList, FlatListProps, View} from 'react-native';
|
|
3
|
+
import Item, {SpanNumber} from './Item';
|
|
4
|
+
import {GridContext} from './index';
|
|
5
|
+
import styles from './styles';
|
|
6
|
+
|
|
7
|
+
export interface ItemListProps extends FlatListProps<any> {
|
|
8
|
+
/**
|
|
9
|
+
* Represents the width of the Card component in terms of span numbers (1-12).
|
|
10
|
+
*/
|
|
11
|
+
widthSpan?: SpanNumber;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const ItemList = forwardRef(
|
|
15
|
+
(
|
|
16
|
+
{
|
|
17
|
+
renderItem,
|
|
18
|
+
widthSpan,
|
|
19
|
+
style,
|
|
20
|
+
contentContainerStyle,
|
|
21
|
+
...props
|
|
22
|
+
}: ItemListProps,
|
|
23
|
+
ref,
|
|
24
|
+
) => {
|
|
25
|
+
const {gutterSize, numberOfColumns} = useContext(GridContext);
|
|
26
|
+
const widthItem = (widthSpan ?? numberOfColumns) as SpanNumber;
|
|
27
|
+
const numColumns = Math.floor(numberOfColumns / widthItem);
|
|
28
|
+
const indexBegin = props?.data?.map((_i, index) => index * numColumns);
|
|
29
|
+
const _renderItem = (item: any) => {
|
|
30
|
+
if (indexBegin?.includes(item?.index)) {
|
|
31
|
+
return <Item widthSpan={widthItem}>{renderItem?.(item)}</Item>;
|
|
32
|
+
}
|
|
33
|
+
return (
|
|
34
|
+
<View style={{paddingLeft: gutterSize}}>
|
|
35
|
+
<Item widthSpan={widthItem}>{renderItem?.(item)}</Item>
|
|
36
|
+
</View>
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<FlatList
|
|
42
|
+
ref={ref as React.RefObject<FlatList>}
|
|
43
|
+
{...props}
|
|
44
|
+
numColumns={numColumns}
|
|
45
|
+
renderItem={_renderItem}
|
|
46
|
+
horizontal={false}
|
|
47
|
+
ItemSeparatorComponent={() => <View style={{height: gutterSize}} />}
|
|
48
|
+
style={[style, styles.protectedStyle]}
|
|
49
|
+
contentContainerStyle={[contentContainerStyle, styles.protectedStyle]}
|
|
50
|
+
/>
|
|
51
|
+
);
|
|
52
|
+
},
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
export default ItemList;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React, {FC, useContext} from 'react';
|
|
2
|
+
import {SectionList, SectionListProps, View} from 'react-native';
|
|
3
|
+
import Item, {SpanNumber} from './Item';
|
|
4
|
+
import {GridContext} from './index';
|
|
5
|
+
import styles from './styles';
|
|
6
|
+
|
|
7
|
+
export interface ItemSectionListProps extends SectionListProps<any> {
|
|
8
|
+
/**
|
|
9
|
+
* Represents the width of the Card component in terms of span numbers (1-12).
|
|
10
|
+
*/
|
|
11
|
+
widthSpan?: SpanNumber;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const ItemSectionList: FC<ItemSectionListProps> = ({
|
|
15
|
+
renderItem,
|
|
16
|
+
widthSpan,
|
|
17
|
+
style,
|
|
18
|
+
contentContainerStyle,
|
|
19
|
+
...props
|
|
20
|
+
}) => {
|
|
21
|
+
const {gutterSize, numberOfColumns} = useContext(GridContext);
|
|
22
|
+
const widthItem = (widthSpan ?? numberOfColumns) as SpanNumber;
|
|
23
|
+
const _renderItem = (item: any) => {
|
|
24
|
+
return <Item widthSpan={widthItem}>{renderItem?.(item)}</Item>;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<SectionList
|
|
29
|
+
{...props}
|
|
30
|
+
renderItem={_renderItem}
|
|
31
|
+
horizontal={false}
|
|
32
|
+
ItemSeparatorComponent={() => <View style={{height: gutterSize}} />}
|
|
33
|
+
style={[style, styles.protectedStyle]}
|
|
34
|
+
contentContainerStyle={[contentContainerStyle, styles.protectedStyle]}
|
|
35
|
+
/>
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export default ItemSectionList;
|