@momo-kits/title 0.92.1-rc.14

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/index.tsx ADDED
@@ -0,0 +1,178 @@
1
+ import React, {FC, useContext, useState} from 'react';
2
+ import {Text as RNText, TouchableOpacity, View, ViewStyle} from 'react-native';
3
+ import styles from './styles';
4
+ import {Icon} from '../Icon';
5
+ import {scaleSize, Text} from '../Text';
6
+ import {ApplicationContext} from '../Application';
7
+ import {Badge} from '../Badge';
8
+ import {Typography} from '../Text/types';
9
+ import {TitleProps} from './types';
10
+ import {Colors} from '../Consts';
11
+
12
+ const Title: FC<TitleProps> = ({
13
+ title = 'Title',
14
+ type = 'section',
15
+ size = 'medium',
16
+ icon,
17
+ description,
18
+ iconColor = null,
19
+ iconAlign = 'top',
20
+ showRightAction = false,
21
+ showTrailingAction = false,
22
+ badgeLabel,
23
+ buttonTitle,
24
+ onPressRightAction = () => {},
25
+ buttonSize = 'small',
26
+ textOnly = false,
27
+ }) => {
28
+ const {theme} = useContext(ApplicationContext);
29
+ const [badgeWidth, setBadgeWidth] = useState(0);
30
+ const [contentWidth, setContentWidth] = useState(0);
31
+ const styleSheet: {
32
+ [key: string]: any;
33
+ } = styles;
34
+ const typography = `${type}_${size}`;
35
+ const isSection = type === 'section';
36
+ const numberOfLines = showTrailingAction || !!badgeLabel ? 1 : 2;
37
+ const buttonTypo: Typography =
38
+ buttonSize === 'small' ? 'action_xs_bold' : 'action_s_bold';
39
+ const flexStyle = showTrailingAction && {maxWidth: '70%'};
40
+
41
+ const renderIcon = () => {
42
+ if (!icon) return null;
43
+
44
+ let iconStyle: ViewStyle = {
45
+ justifyContent: 'flex-start',
46
+ };
47
+
48
+ if (iconAlign === 'middle') {
49
+ iconStyle = {justifyContent: 'center'};
50
+ }
51
+
52
+ if (iconAlign === 'bottom') {
53
+ iconStyle = {justifyContent: 'flex-end'};
54
+ }
55
+
56
+ return (
57
+ <View style={[styles.iconView, iconStyle]}>
58
+ <Icon color={iconColor} source={icon} />
59
+ </View>
60
+ );
61
+ };
62
+
63
+ const renderContent = () => {
64
+ return (
65
+ <View style={styles.contentView}>
66
+ <View
67
+ onLayout={e => {
68
+ setContentWidth(e.nativeEvent.layout.width);
69
+ }}
70
+ style={[styles.iconLeftView, flexStyle]}>
71
+ <RNText
72
+ numberOfLines={numberOfLines}
73
+ style={[
74
+ styleSheet[typography],
75
+ styles.title,
76
+ {maxWidth: contentWidth - badgeWidth},
77
+ ]}>
78
+ {title}
79
+ </RNText>
80
+ {badgeLabel && (
81
+ <View
82
+ onLayout={e => {
83
+ setBadgeWidth(e.nativeEvent.layout.width);
84
+ }}
85
+ style={{
86
+ alignItems: 'center',
87
+ }}>
88
+ <Badge style={styles.badge} label={badgeLabel} />
89
+ </View>
90
+ )}
91
+ {renderActionLeft()}
92
+ </View>
93
+ <Text
94
+ color={theme.colors.text.secondary}
95
+ typography={'description_default_regular'}>
96
+ {description}
97
+ </Text>
98
+ </View>
99
+ );
100
+ };
101
+
102
+ const renderActionLeft = () => {
103
+ return (
104
+ <View style={styles.iconLeftView}>
105
+ {showTrailingAction && !showRightAction && (
106
+ <View
107
+ style={[
108
+ styles.iconLeft,
109
+ {
110
+ backgroundColor: isSection
111
+ ? Colors.black_06 + '99'
112
+ : Colors.black_06 + '4D',
113
+ },
114
+ ]}>
115
+ <Icon
116
+ source={'arrow_chevron_right_small'}
117
+ size={scaleSize(18)}
118
+ color={theme.colors.text.default}
119
+ />
120
+ </View>
121
+ )}
122
+ </View>
123
+ );
124
+ };
125
+
126
+ const renderActionRight = () => {
127
+ if (!showRightAction || showTrailingAction) return false;
128
+
129
+ return (
130
+ <View>
131
+ {!buttonTitle ? (
132
+ <View
133
+ style={[
134
+ styles.iconRight,
135
+ {
136
+ backgroundColor: theme.colors.primary + '0F',
137
+ },
138
+ ]}>
139
+ <Icon
140
+ source={'arrow_chevron_right_small'}
141
+ size={scaleSize(22)}
142
+ color={theme.colors.primary}
143
+ />
144
+ </View>
145
+ ) : (
146
+ <TouchableOpacity onPress={onPressRightAction}>
147
+ <Text color={theme.colors.primary} typography={buttonTypo}>
148
+ {buttonTitle}
149
+ </Text>
150
+ </TouchableOpacity>
151
+ )}
152
+ </View>
153
+ );
154
+ };
155
+
156
+ if (textOnly) {
157
+ return (
158
+ <View style={isSection && styles.margin}>
159
+ <RNText
160
+ numberOfLines={numberOfLines}
161
+ style={[styleSheet[typography], styles.title]}>
162
+ {title}
163
+ </RNText>
164
+ </View>
165
+ );
166
+ }
167
+
168
+ return (
169
+ <View style={[styles.wrapper, isSection && styles.margin]}>
170
+ {renderIcon()}
171
+ {renderContent()}
172
+ {renderActionRight()}
173
+ </View>
174
+ );
175
+ };
176
+
177
+ export {Title};
178
+ export type {TitleProps};
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@momo-kits/title",
3
+ "version": "0.92.1-rc.14",
4
+ "private": false,
5
+ "main": "index.tsx",
6
+ "dependencies": {},
7
+ "peerDependencies": {
8
+ "@momo-kits/foundation": "latest",
9
+ "prop-types": "^15.7.2",
10
+ "react": "16.9.0",
11
+ "react-native": ">=0.55"
12
+ },
13
+ "devDependencies": {
14
+ "@momo-platform/versions": "4.1.11"
15
+ },
16
+ "license": "MoMo"
17
+ }
package/publish.sh ADDED
@@ -0,0 +1,29 @@
1
+ #!/bin/bash
2
+ rm -rf dist
3
+ mkdir dist
4
+
5
+ cp . ./dist
6
+
7
+ # GET VERSION from mck_package.json
8
+ VERSIONSTRING=( v$(jq .version package.json) )
9
+ VERSION=(${VERSIONSTRING//[\"]/})
10
+ echo VERSION: $VERSION
11
+
12
+ rsync -r --verbose --exclude '*.mdx' --exclude '*Demo.js' --exclude 'props-type.js' --exclude 'prop-types.js' ./* dist
13
+
14
+ # #babel component to dist
15
+ #babel ./dist -d dist --copy-files
16
+
17
+ #copy option
18
+ #cp -r ./src/ dist
19
+
20
+
21
+ #npm login
22
+ #publish dist to npm
23
+ cd dist
24
+ npm publish --tag beta --access=public
25
+ cd ..
26
+ rm -rf dist
27
+
28
+
29
+ ##curl -X POST -H 'Content-Type: application/json' 'https://chat.googleapis.com/v1/spaces/AAAAbP8987c/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=UGSFRvk_oYb9uGsAgs31bVvMm6jDkmD8zihGm3eyaQA%3D&threadKey=JoaXTEYaNNkl' -d '{"text": "@momo-kits/stepper new version release: '*"$VERSION"*' https://www.npmjs.com/package/@momo-kits/stepper"}'
package/styles.ts ADDED
@@ -0,0 +1,76 @@
1
+ import {StyleSheet} from 'react-native';
2
+ import {scaleSize} from '../Text';
3
+ import {Colors, Radius, Spacing} from '../Consts';
4
+
5
+ export default StyleSheet.create({
6
+ card_small: {
7
+ fontSize: scaleSize(14),
8
+ lineHeight: scaleSize(20),
9
+ },
10
+ card_medium: {
11
+ fontSize: scaleSize(16),
12
+ lineHeight: scaleSize(22),
13
+ },
14
+ card_large: {
15
+ fontSize: scaleSize(18),
16
+ lineHeight: scaleSize(26),
17
+ },
18
+ section_medium: {
19
+ fontSize: scaleSize(20),
20
+ lineHeight: scaleSize(28),
21
+ },
22
+ section_small: {
23
+ fontSize: scaleSize(16),
24
+ lineHeight: scaleSize(22),
25
+ },
26
+ section_large: {
27
+ fontSize: scaleSize(24),
28
+ lineHeight: scaleSize(34),
29
+ },
30
+ actionIcon: {
31
+ borderRadius: Radius.M,
32
+ alignItems: 'center',
33
+ justifyContent: 'center',
34
+ },
35
+ icon: {
36
+ marginRight: Spacing.S,
37
+ borderRadius: Radius.XS,
38
+ },
39
+ wrapper: {
40
+ flexDirection: 'row',
41
+ },
42
+ margin: {
43
+ marginTop: Spacing.S,
44
+ },
45
+ iconView: {
46
+ marginRight: Spacing.S,
47
+ },
48
+ iconRight: {
49
+ width: scaleSize(22),
50
+ height: scaleSize(22),
51
+ borderRadius: Radius.M,
52
+ alignItems: 'center',
53
+ justifyContent: 'center',
54
+ marginLeft: Spacing.S,
55
+ },
56
+ iconLeft: {
57
+ width: scaleSize(18),
58
+ height: scaleSize(18),
59
+ borderRadius: Radius.M,
60
+ alignItems: 'center',
61
+ justifyContent: 'center',
62
+ marginHorizontal: Spacing.XS,
63
+ },
64
+ iconLeftView: {
65
+ flexDirection: 'row',
66
+ alignItems: 'center',
67
+ },
68
+ contentView: {marginRight: Spacing.S, flex: 1},
69
+ title: {
70
+ fontWeight: 'bold',
71
+ marginBottom: Spacing.XS,
72
+ },
73
+ badge: {
74
+ marginLeft: Spacing.XS,
75
+ },
76
+ });
package/types.ts ADDED
@@ -0,0 +1,16 @@
1
+ export type TitleProps = {
2
+ type?: 'card' | 'section';
3
+ size?: 'small' | 'medium' | 'large';
4
+ title: string;
5
+ icon?: string;
6
+ description?: string;
7
+ iconColor?: string;
8
+ iconAlign?: 'top' | 'middle' | 'bottom';
9
+ showRightAction?: boolean;
10
+ showTrailingAction?: boolean;
11
+ badgeLabel?: string;
12
+ buttonTitle?: string;
13
+ buttonSize?: 'small' | 'large';
14
+ onPressRightAction?: () => void;
15
+ textOnly?: boolean;
16
+ };