@janiscommerce/ui-native 1.14.0 → 1.14.2
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/dist/components/atoms/Typography/index.d.ts +2 -1
- package/dist/components/atoms/Typography/index.js +2 -2
- package/dist/components/atoms/Typography/utils/getStyleByTypography/index.d.ts +2 -11
- package/dist/components/atoms/Typography/utils/getStyleByTypography/index.js +15 -50
- package/dist/components/molecules/Button/utils/getButtonStyles/utils/styleConfigs/index.js +9 -9
- package/dist/components/molecules/Input/index.d.ts +1 -0
- package/dist/components/molecules/Input/index.js +27 -4
- package/dist/theme/typography.d.ts +6 -4
- package/dist/theme/typography.js +80 -15
- package/package.json +1 -1
|
@@ -7,6 +7,7 @@ interface TypographyProps extends TextProps {
|
|
|
7
7
|
style?: StyleProp<TextStyle>;
|
|
8
8
|
type?: TypographyType;
|
|
9
9
|
size?: TypographySize;
|
|
10
|
+
color?: string;
|
|
10
11
|
}
|
|
11
|
-
declare const Typography: ({ children, style, type, size, ...props }: TypographyProps) => React.JSX.Element | null;
|
|
12
|
+
declare const Typography: ({ children, style, type, size, color, ...props }: TypographyProps) => React.JSX.Element | null;
|
|
12
13
|
export default Typography;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Text } from 'react-native';
|
|
3
3
|
import getStyleByTypography from './utils/getStyleByTypography';
|
|
4
|
-
const Typography = ({ children, style, type, size, ...props }) => {
|
|
4
|
+
const Typography = ({ children, style, type, size, color, ...props }) => {
|
|
5
5
|
if (!children) {
|
|
6
6
|
return null;
|
|
7
7
|
}
|
|
8
|
-
const typographyStyles = getStyleByTypography(type, size);
|
|
8
|
+
const typographyStyles = getStyleByTypography(type, size, color);
|
|
9
9
|
return (<Text style={[style, typographyStyles.typography]} {...props}>
|
|
10
10
|
{children}
|
|
11
11
|
</Text>);
|
|
@@ -1,17 +1,8 @@
|
|
|
1
1
|
import { TextStyle } from 'react-native';
|
|
2
|
-
import { Typography } from '../../../../../theme/typography';
|
|
2
|
+
import typography, { Typography } from '../../../../../theme/typography';
|
|
3
3
|
type TypographyType = keyof Typography;
|
|
4
4
|
type TypographySize = 'large' | 'medium' | 'small';
|
|
5
|
-
|
|
5
|
+
declare const getStyleByTypography: (type?: TypographyType | string, size?: TypographySize | string, color?: string) => {
|
|
6
6
|
typography: TextStyle;
|
|
7
7
|
};
|
|
8
|
-
declare const getStyleByTypography: (type: TypographyType | string, size: TypographySize | string) => {
|
|
9
|
-
typography: TextStyle;
|
|
10
|
-
} | {
|
|
11
|
-
typography: {
|
|
12
|
-
fontWeight: "100" | "200" | "300" | "400" | "500" | "600" | "700" | "800" | "900";
|
|
13
|
-
fontSize: number;
|
|
14
|
-
lineHeight: number;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
8
|
export default getStyleByTypography;
|
|
@@ -1,54 +1,19 @@
|
|
|
1
1
|
import { StyleSheet } from 'react-native';
|
|
2
2
|
import typography from '../../../../../theme/typography';
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const typographySize = size;
|
|
19
|
-
if (typographyType === 'display') {
|
|
20
|
-
return StyleSheet.create({
|
|
21
|
-
typography: {
|
|
22
|
-
fontWeight: typography.display.weight,
|
|
23
|
-
fontSize: typography.display.size,
|
|
24
|
-
lineHeight: typography.display.lineHeight,
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
if (typographyType === 'overline' && typographySize === 'medium') {
|
|
29
|
-
return StyleSheet.create({
|
|
30
|
-
typography: {
|
|
31
|
-
fontWeight: typography.overline.large.weight,
|
|
32
|
-
fontSize: typography.overline.large.size,
|
|
33
|
-
lineHeight: typography.overline.large.lineHeight,
|
|
34
|
-
letterSpacing: typography.overline.large.spacing,
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
const typographyObject = typography[typographyType];
|
|
39
|
-
// istanbul ignore next
|
|
40
|
-
if (typographyObject && typographySize in typographyObject) {
|
|
41
|
-
const typographyStyle = typographyObject[typographySize];
|
|
42
|
-
return StyleSheet.create({
|
|
43
|
-
typography: {
|
|
44
|
-
fontWeight: typographyStyle.weight,
|
|
45
|
-
fontSize: typographyStyle.size,
|
|
46
|
-
lineHeight: typographyStyle.lineHeight,
|
|
47
|
-
letterSpacing: typographyStyle.spacing,
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
// istanbul ignore next
|
|
52
|
-
return defaultStyles;
|
|
3
|
+
const getStyleByTypography = (type = 'body', size = 'medium', color) => {
|
|
4
|
+
const validType = Object.keys(typography).includes(type)
|
|
5
|
+
? type
|
|
6
|
+
: 'body';
|
|
7
|
+
const typographyCategory = typography[validType];
|
|
8
|
+
const validSize = Object.keys(typographyCategory).includes(size)
|
|
9
|
+
? size
|
|
10
|
+
: 'medium';
|
|
11
|
+
const typographyStyle = typographyCategory[validSize];
|
|
12
|
+
return StyleSheet.create({
|
|
13
|
+
typography: {
|
|
14
|
+
...typographyStyle,
|
|
15
|
+
...(color && { color }),
|
|
16
|
+
},
|
|
17
|
+
});
|
|
53
18
|
};
|
|
54
19
|
export default getStyleByTypography;
|
|
@@ -53,31 +53,31 @@ export const colorConfig = (selectedColor) => {
|
|
|
53
53
|
disabled: {
|
|
54
54
|
background: {
|
|
55
55
|
contained: grey[200],
|
|
56
|
-
outlined:
|
|
56
|
+
outlined: base.white,
|
|
57
57
|
text: 'transparent',
|
|
58
58
|
},
|
|
59
59
|
border: {
|
|
60
60
|
main: {
|
|
61
61
|
contained: 'transparent',
|
|
62
|
-
outlined:
|
|
62
|
+
outlined: grey[200],
|
|
63
63
|
text: 'transparent',
|
|
64
64
|
},
|
|
65
65
|
secondary: {
|
|
66
66
|
contained: 'transparent',
|
|
67
|
-
outlined: grey[
|
|
67
|
+
outlined: grey[200],
|
|
68
68
|
text: 'transparent',
|
|
69
69
|
},
|
|
70
70
|
},
|
|
71
71
|
text: {
|
|
72
72
|
main: {
|
|
73
|
-
contained:
|
|
74
|
-
outlined: grey[
|
|
75
|
-
text: grey[
|
|
73
|
+
contained: base.white,
|
|
74
|
+
outlined: grey[200],
|
|
75
|
+
text: grey[200],
|
|
76
76
|
},
|
|
77
77
|
secondary: {
|
|
78
|
-
contained:
|
|
79
|
-
outlined: grey[
|
|
80
|
-
text: grey[
|
|
78
|
+
contained: base.white,
|
|
79
|
+
outlined: grey[200],
|
|
80
|
+
text: grey[200],
|
|
81
81
|
},
|
|
82
82
|
},
|
|
83
83
|
},
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React, { forwardRef, useState, useRef } from 'react';
|
|
2
|
-
import { StyleSheet, View, TouchableWithoutFeedback, Keyboard } from 'react-native';
|
|
2
|
+
import { StyleSheet, View, TouchableWithoutFeedback, Keyboard, Platform, } from 'react-native';
|
|
3
3
|
import BaseInput from '../../atoms/BaseInput';
|
|
4
4
|
import { palette } from '../../../theme/palette';
|
|
5
5
|
import { moderateScale, scaledForDevice } from '../../../scale';
|
|
6
6
|
import handleChangeText from './utils/handleChangeText';
|
|
7
7
|
import Typography from '../../atoms/Typography';
|
|
8
|
+
const isWeb = Platform.OS === 'web';
|
|
8
9
|
var InputType;
|
|
9
10
|
(function (InputType) {
|
|
10
11
|
InputType["currency"] = "numeric";
|
|
@@ -17,8 +18,9 @@ var InputType;
|
|
|
17
18
|
InputType["amountTotal"] = "numeric";
|
|
18
19
|
InputType["numeric"] = "numeric";
|
|
19
20
|
})(InputType || (InputType = {}));
|
|
20
|
-
const Input = forwardRef(({ style, type, variant = 'default', totalValue, onChangeText, ...props }, ref) => {
|
|
21
|
+
const Input = forwardRef(({ style, type, variant = 'default', totalValue, placeholder, onChangeText, ...props }, ref) => {
|
|
21
22
|
const [value, setValue] = useState('');
|
|
23
|
+
const isPlaceholderBeingShown = !value;
|
|
22
24
|
const isAmountTotalVariant = variant === 'amountTotal';
|
|
23
25
|
const internalRef = useRef(null);
|
|
24
26
|
const inputRef = ref ?? internalRef;
|
|
@@ -36,14 +38,26 @@ const Input = forwardRef(({ style, type, variant = 'default', totalValue, onChan
|
|
|
36
38
|
justifyContent: 'center',
|
|
37
39
|
alignItems: 'center',
|
|
38
40
|
flexDirection: 'row',
|
|
41
|
+
position: 'relative',
|
|
39
42
|
},
|
|
40
43
|
input: {
|
|
41
44
|
color: palette.black.main,
|
|
42
45
|
fontSize: scaledForDevice(42, moderateScale),
|
|
46
|
+
height: '100%',
|
|
47
|
+
textAlign: 'center',
|
|
48
|
+
textAlignVertical: 'center',
|
|
49
|
+
includeFontPadding: false,
|
|
50
|
+
paddingVertical: 0,
|
|
51
|
+
...(isPlaceholderBeingShown && { marginLeft: scaledForDevice(-12, moderateScale) }),
|
|
52
|
+
...(isWeb && { flex: 1, maxWidth: isPlaceholderBeingShown ? '1%' : undefined }),
|
|
43
53
|
},
|
|
44
54
|
totalValue: {
|
|
45
55
|
color: palette.primary.main,
|
|
46
56
|
},
|
|
57
|
+
placeholder: {
|
|
58
|
+
color: '#A8AAAC',
|
|
59
|
+
marginLeft: scaledForDevice(-12, moderateScale),
|
|
60
|
+
},
|
|
47
61
|
});
|
|
48
62
|
const changeTextCb = (text) => {
|
|
49
63
|
const transformedText = handleChangeText(text, variant);
|
|
@@ -68,10 +82,19 @@ const Input = forwardRef(({ style, type, variant = 'default', totalValue, onChan
|
|
|
68
82
|
}
|
|
69
83
|
return InputType.default;
|
|
70
84
|
})();
|
|
85
|
+
const renderPlaceholder = () => {
|
|
86
|
+
if (value.length > 0) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
return (<Typography type="display" style={styles.placeholder}>
|
|
90
|
+
{placeholder}
|
|
91
|
+
</Typography>);
|
|
92
|
+
};
|
|
71
93
|
return (<TouchableWithoutFeedback onPress={handlePress}>
|
|
72
94
|
<View style={styles.container}>
|
|
73
|
-
<BaseInput style={[styles.input, style]} ref={inputRef} value={value} keyboardType={resolvedKeyboardType} onChangeText={changeTextCb} {...props}/>
|
|
74
|
-
{
|
|
95
|
+
<BaseInput testID="input" style={[styles.input, style].filter(Boolean)} ref={inputRef} value={value} keyboardType={resolvedKeyboardType} onChangeText={changeTextCb} {...props}/>
|
|
96
|
+
{renderPlaceholder()}
|
|
97
|
+
{isAmountTotalVariant && (<Typography style={styles.totalValue} type="display">
|
|
75
98
|
{`/${totalValue?.toString()}`}
|
|
76
99
|
</Typography>)}
|
|
77
100
|
</View>
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
export type TypographyItem = {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
fontWeight: '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900';
|
|
3
|
+
fontSize: number;
|
|
4
4
|
lineHeight: number;
|
|
5
|
-
|
|
5
|
+
letterSpacing?: number;
|
|
6
6
|
};
|
|
7
7
|
export type Typography = {
|
|
8
|
-
display:
|
|
8
|
+
display: {
|
|
9
|
+
medium: TypographyItem;
|
|
10
|
+
};
|
|
9
11
|
heading: {
|
|
10
12
|
large: TypographyItem;
|
|
11
13
|
medium: TypographyItem;
|
package/dist/theme/typography.js
CHANGED
|
@@ -1,29 +1,94 @@
|
|
|
1
1
|
import { moderateScale, scaledForDevice } from '../scale';
|
|
2
|
+
const scaleSize = (size) => scaledForDevice(size, moderateScale);
|
|
2
3
|
const typography = {
|
|
3
|
-
display: {
|
|
4
|
+
display: {
|
|
5
|
+
medium: {
|
|
6
|
+
fontSize: scaleSize(42),
|
|
7
|
+
fontWeight: '400',
|
|
8
|
+
lineHeight: 50,
|
|
9
|
+
},
|
|
10
|
+
},
|
|
4
11
|
heading: {
|
|
5
|
-
large: {
|
|
6
|
-
|
|
7
|
-
|
|
12
|
+
large: {
|
|
13
|
+
fontSize: scaleSize(34),
|
|
14
|
+
fontWeight: '500',
|
|
15
|
+
lineHeight: 40,
|
|
16
|
+
},
|
|
17
|
+
medium: {
|
|
18
|
+
fontSize: scaleSize(26),
|
|
19
|
+
fontWeight: '500',
|
|
20
|
+
lineHeight: 32,
|
|
21
|
+
},
|
|
22
|
+
small: {
|
|
23
|
+
fontSize: scaleSize(24),
|
|
24
|
+
fontWeight: '400',
|
|
25
|
+
lineHeight: 28,
|
|
26
|
+
},
|
|
8
27
|
},
|
|
9
28
|
title: {
|
|
10
|
-
large: {
|
|
11
|
-
|
|
12
|
-
|
|
29
|
+
large: {
|
|
30
|
+
fontSize: scaleSize(20),
|
|
31
|
+
fontWeight: '400',
|
|
32
|
+
lineHeight: 24,
|
|
33
|
+
},
|
|
34
|
+
medium: {
|
|
35
|
+
fontSize: scaleSize(18),
|
|
36
|
+
fontWeight: '700',
|
|
37
|
+
lineHeight: 22,
|
|
38
|
+
},
|
|
39
|
+
small: {
|
|
40
|
+
fontSize: scaleSize(14),
|
|
41
|
+
fontWeight: '700',
|
|
42
|
+
lineHeight: 16,
|
|
43
|
+
},
|
|
13
44
|
},
|
|
14
45
|
label: {
|
|
15
|
-
large: {
|
|
16
|
-
|
|
17
|
-
|
|
46
|
+
large: {
|
|
47
|
+
fontSize: scaleSize(16),
|
|
48
|
+
fontWeight: '500',
|
|
49
|
+
lineHeight: 18,
|
|
50
|
+
},
|
|
51
|
+
medium: {
|
|
52
|
+
fontSize: scaleSize(14),
|
|
53
|
+
fontWeight: '500',
|
|
54
|
+
lineHeight: 16,
|
|
55
|
+
},
|
|
56
|
+
small: {
|
|
57
|
+
fontSize: scaleSize(12),
|
|
58
|
+
fontWeight: '500',
|
|
59
|
+
lineHeight: 14,
|
|
60
|
+
},
|
|
18
61
|
},
|
|
19
62
|
body: {
|
|
20
|
-
large: {
|
|
21
|
-
|
|
22
|
-
|
|
63
|
+
large: {
|
|
64
|
+
fontSize: scaleSize(16),
|
|
65
|
+
fontWeight: '400',
|
|
66
|
+
lineHeight: 20,
|
|
67
|
+
},
|
|
68
|
+
medium: {
|
|
69
|
+
fontSize: scaleSize(14),
|
|
70
|
+
fontWeight: '400',
|
|
71
|
+
lineHeight: 18,
|
|
72
|
+
},
|
|
73
|
+
small: {
|
|
74
|
+
fontSize: scaleSize(12),
|
|
75
|
+
fontWeight: '400',
|
|
76
|
+
lineHeight: 16,
|
|
77
|
+
},
|
|
23
78
|
},
|
|
24
79
|
overline: {
|
|
25
|
-
large: {
|
|
26
|
-
|
|
80
|
+
large: {
|
|
81
|
+
fontSize: scaleSize(14),
|
|
82
|
+
fontWeight: '500',
|
|
83
|
+
lineHeight: 16,
|
|
84
|
+
letterSpacing: 1,
|
|
85
|
+
},
|
|
86
|
+
small: {
|
|
87
|
+
fontSize: scaleSize(12),
|
|
88
|
+
fontWeight: '500',
|
|
89
|
+
lineHeight: 14,
|
|
90
|
+
letterSpacing: 0.7,
|
|
91
|
+
},
|
|
27
92
|
},
|
|
28
93
|
};
|
|
29
94
|
export default typography;
|