@momo-kits/badge 0.0.48-rc.2 → 0.0.48

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/Badge.tsx ADDED
@@ -0,0 +1,54 @@
1
+ import React, {FC, useContext} from 'react';
2
+ import {View} from 'react-native';
3
+
4
+ import {BadgeProps} from './types';
5
+ import styles from './styles';
6
+ import {ApplicationContext, Colors, Text} from '@momo-kits/foundation';
7
+
8
+ const Badge: FC<BadgeProps> = ({label = 'Label', style, backgroundColor}) => {
9
+ const {theme} = useContext(ApplicationContext);
10
+
11
+ const isValidatedColor = () => {
12
+ const colorKeys = Object.keys(Colors);
13
+ const colorValue = Object.values(Colors);
14
+ if (backgroundColor) {
15
+ const colorIndex = colorValue.indexOf(backgroundColor);
16
+ if (colorIndex !== -1) {
17
+ if (colorKeys[colorIndex]?.includes('_03')) {
18
+ return true;
19
+ }
20
+ }
21
+ }
22
+ return false;
23
+ };
24
+
25
+ const isNumber = () => {
26
+ const numberRegex = /^\d+$/;
27
+ return numberRegex.test(String(label));
28
+ };
29
+
30
+ const formatTitle = () => {
31
+ if (isNumber() && Number(label) > 99) {
32
+ return '99+';
33
+ }
34
+ return label.toString();
35
+ };
36
+
37
+ let badgeColor = isNumber()
38
+ ? theme.colors.error.primary
39
+ : theme.colors.warning.primary;
40
+
41
+ if (backgroundColor && isValidatedColor()) {
42
+ badgeColor = backgroundColor;
43
+ }
44
+
45
+ return (
46
+ <View style={[style, styles.badge, {backgroundColor: badgeColor}]}>
47
+ <Text color={Colors.black_01} typography={'action_xxs_bold'}>
48
+ {formatTitle()}
49
+ </Text>
50
+ </View>
51
+ );
52
+ };
53
+
54
+ export default Badge;
package/BadgeDot.tsx ADDED
@@ -0,0 +1,11 @@
1
+ import React, {FC} from 'react';
2
+ import {View} from 'react-native';
3
+ import {BadgeDotProps} from './types';
4
+ import styles from './styles';
5
+
6
+ const BadgeDot: FC<BadgeDotProps> = ({size = 'large', style}) => {
7
+ const dotStyle = size === 'small' ? styles.dotSmall : styles.dot;
8
+ return <View style={[style, dotStyle]} />;
9
+ };
10
+
11
+ export default BadgeDot;
@@ -0,0 +1,122 @@
1
+ import React, {FC, useContext} from 'react';
2
+ import {View} from 'react-native';
3
+ import {DownTail, UpTail} from './Shape';
4
+ import styles from './styles';
5
+ import {BadgeRibbonProps} from './types';
6
+ import {ApplicationContext, Colors, Image, Text} from '@momo-kits/foundation';
7
+
8
+ const BadgeRibbon: FC<BadgeRibbonProps> = ({
9
+ position = 'top_right',
10
+ label = 'Label',
11
+ isRound = false,
12
+ style = {},
13
+ }) => {
14
+ const {theme} = useContext(ApplicationContext);
15
+ let ribbonRotate = '0deg';
16
+ let textRotate = '0deg';
17
+ let ribbonTail = <DownTail />;
18
+ let textMargin = 0;
19
+ let skewMargin = 0;
20
+
21
+ if (position === 'top_right' || position === 'bottom_right') {
22
+ ribbonRotate = '180deg';
23
+ textRotate = '180deg';
24
+ }
25
+
26
+ if (position === 'bottom_left' || position === 'top_right') {
27
+ textMargin = 4;
28
+ ribbonTail = <UpTail />;
29
+ skewMargin = 4;
30
+ }
31
+
32
+ const renderRoundContent = () => {
33
+ return (
34
+ <View
35
+ style={[
36
+ styles.ribbonContent,
37
+ {
38
+ backgroundColor: theme.colors.warning.primary,
39
+ marginTop: textMargin,
40
+ },
41
+ ]}>
42
+ <Text
43
+ style={[
44
+ styles.ribbonLabel,
45
+ {
46
+ transform: [
47
+ {
48
+ rotate: textRotate,
49
+ },
50
+ ],
51
+ },
52
+ ]}
53
+ color={Colors.black_01}
54
+ typography={'label_xs_medium'}>
55
+ {label}
56
+ </Text>
57
+ </View>
58
+ );
59
+ };
60
+
61
+ const renderSkewContent = () => {
62
+ return (
63
+ <View
64
+ style={{
65
+ flexDirection: 'row',
66
+ marginTop: skewMargin,
67
+ }}>
68
+ <View
69
+ style={[
70
+ styles.ribbonSkewContent,
71
+ {
72
+ backgroundColor: theme.colors.warning.primary,
73
+ },
74
+ ]}>
75
+ <Text
76
+ style={[
77
+ styles.ribbonLabel,
78
+ {
79
+ transform: [
80
+ {
81
+ rotate: textRotate,
82
+ },
83
+ ],
84
+ },
85
+ ]}
86
+ color={Colors.black_01}
87
+ typography={'label_xs_medium'}>
88
+ {label}
89
+ </Text>
90
+ </View>
91
+ <Image
92
+ source={{
93
+ uri: 'https://static.momocdn.net/app/img/kits/utils/Tail_4x.png',
94
+ }}
95
+ style={styles.skew}
96
+ />
97
+ </View>
98
+ );
99
+ };
100
+
101
+ const content = isRound ? renderRoundContent() : renderSkewContent();
102
+
103
+ return (
104
+ <View
105
+ style={[
106
+ style,
107
+ styles.ribbon,
108
+ {
109
+ transform: [
110
+ {
111
+ rotate: ribbonRotate,
112
+ },
113
+ ],
114
+ },
115
+ ]}>
116
+ {ribbonTail}
117
+ {content}
118
+ </View>
119
+ );
120
+ };
121
+
122
+ export default BadgeRibbon;
package/Shape.tsx ADDED
@@ -0,0 +1,29 @@
1
+ import React from 'react';
2
+ import styles from './styles';
3
+ import {Image} from '@momo-kits/foundation';
4
+
5
+ const UpTail = () => {
6
+ return (
7
+ <Image
8
+ resizeMode={'stretch'}
9
+ source={{
10
+ uri: 'https://static.momocdn.net/app/img/kits/utils/Head_down_4x.png',
11
+ }}
12
+ style={[styles.tail, {transform: [{rotate: '180deg'}]}]}
13
+ />
14
+ );
15
+ };
16
+
17
+ const DownTail = () => {
18
+ return (
19
+ <Image
20
+ resizeMode={'stretch'}
21
+ source={{
22
+ uri: 'https://static.momocdn.net/app/img/kits/utils/Head_4x.png',
23
+ }}
24
+ style={styles.tail}
25
+ />
26
+ );
27
+ };
28
+
29
+ export {UpTail, DownTail};
package/index.tsx ADDED
@@ -0,0 +1,7 @@
1
+ import Badge from './Badge';
2
+ import BadgeDot from './BadgeDot';
3
+ import BadgeRibbon from './BadgeRibbon';
4
+ import {BadgeDotProps, BadgeProps, BadgeRibbonProps} from './types';
5
+
6
+ export {Badge, BadgeRibbon, BadgeDot};
7
+ export type {BadgeProps, BadgeDotProps, BadgeRibbonProps};
package/package.json CHANGED
@@ -1,14 +1,17 @@
1
1
  {
2
- "name": "@momo-kits/badge",
3
- "version": "0.0.48-rc.2",
4
- "private": false,
5
- "main": "index.js",
6
- "peerDependencies": {
7
- "react": "16.9.0",
8
- "react-native": ">=0.55",
9
- "prop-types": "^15.7.2",
10
- "@momo-kits/core": ">=0.0.5-beta"
11
- },
12
- "devDependencies": {},
13
- "license": "MoMo"
14
- }
2
+ "name": "@momo-kits/badge",
3
+ "version": "0.0.48",
4
+ "private": false,
5
+ "main": "index.tsx",
6
+ "peerDependencies": {
7
+ "@momo-kits/foundation": "latest",
8
+ "react": "16.9.0",
9
+ "react-native": ">=0.55",
10
+ "prop-types": "^15.7.2"
11
+ },
12
+ "devDependencies": {
13
+ "@momo-platform/versions": "4.1.11"
14
+ },
15
+ "license": "MoMo",
16
+ "dependencies": {}
17
+ }
package/publish.sh CHANGED
@@ -1,28 +1,23 @@
1
1
  #!/bin/bash
2
+
3
+ # Prepare dist files
2
4
  rm -rf dist
3
5
  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
6
+ rsync -r --exclude=/dist ./* dist
23
7
  cd dist
24
- npm publish --tag beta --access=public
8
+
9
+ if [ "$1" == "beta" ]; then # Publish beta
10
+ npm version $(npm view @momo-kits/badge@beta version)
11
+ npm version prepatch --preid=beta
12
+ npm publish --tag beta --access=public
13
+ else # Publish latest
14
+ npm version $(npm view @momo-kits/badge version)
15
+ npm version patch
16
+ npm publish --tag latest --access=public
17
+ fi
18
+ PACKAGE_NAME=$(npm pkg get name)
19
+ NEW_PACKAGE_VERSION=$(npm pkg get version)
20
+
21
+ # Clean up
25
22
  cd ..
26
23
  rm -rf dist
27
-
28
- #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/bank new version release: '*"$VERSION"*' `https://www.npmjs.com/package/@momo-kits/bank`"}'
package/styles.ts ADDED
@@ -0,0 +1,57 @@
1
+ import {StyleSheet} from 'react-native';
2
+ import {Colors, Radius, scaleSize, Spacing} from '@momo-kits/foundation';
3
+
4
+ export default StyleSheet.create({
5
+ badge: {
6
+ paddingHorizontal: Spacing.XS,
7
+ borderRadius: Radius.M,
8
+ justifyContent: 'center',
9
+ alignItems: 'center',
10
+ height: scaleSize(16),
11
+ minWidth: scaleSize(16),
12
+ flexDirection: 'row',
13
+ borderWidth: 1,
14
+ borderColor: Colors.black_01,
15
+ alignSelf: 'baseline',
16
+ },
17
+ dot: {
18
+ width: 16,
19
+ height: 16,
20
+ borderWidth: 2,
21
+ borderColor: Colors.black_01,
22
+ backgroundColor: Colors.red_03,
23
+ borderRadius: 8,
24
+ },
25
+ dotSmall: {
26
+ width: 10,
27
+ height: 10,
28
+ borderWidth: 1,
29
+ borderColor: Colors.black_01,
30
+ backgroundColor: Colors.red_03,
31
+ borderRadius: 5,
32
+ },
33
+ ribbon: {
34
+ alignSelf: 'baseline',
35
+ flexDirection: 'row',
36
+ height: 20,
37
+ overflow: 'hidden',
38
+ },
39
+ ribbonContent: {
40
+ height: 16,
41
+ justifyContent: 'center',
42
+ alignItems: 'center',
43
+ borderBottomRightRadius: 12,
44
+ borderTopRightRadius: 12,
45
+ paddingRight: 6,
46
+ },
47
+ ribbonSkewContent: {
48
+ height: 16,
49
+ justifyContent: 'center',
50
+ alignItems: 'center',
51
+ },
52
+ ribbonLabel: {
53
+ color: Colors.black_01,
54
+ },
55
+ skew: {width: 8, height: 16},
56
+ tail: {width: 5, height: 20},
57
+ });
package/types.ts ADDED
@@ -0,0 +1,63 @@
1
+ import {ViewStyle} from 'react-native';
2
+
3
+ /**
4
+ * Props for a general Badge component. It can display a wide range of badges including simple labels, numbers, or dots.
5
+ */
6
+ export type BadgeProps = {
7
+ /**
8
+ * Optional. The text to display on the badge. This could be a number or string, depending on the badge's purpose.
9
+ */
10
+ label?: string | number;
11
+
12
+ /**
13
+ * Optional. Custom styles to apply to the badge component. Can be a single style or an array of styles.
14
+ */
15
+ style?: ViewStyle | ViewStyle[];
16
+
17
+ /**
18
+ * Optional. Custom background badge.
19
+ */
20
+ backgroundColor?: string;
21
+ };
22
+
23
+ /**
24
+ * Props for a BadgeDot component. It specifically represents a dot-style badge, typically used for notification indicators.
25
+ */
26
+ export type BadgeDotProps = {
27
+ /**
28
+ * Optional. The size of the dot, either 'small' or 'large'. This allows for better visual alignment with different UI elements.
29
+ */
30
+ size?: 'small' | 'large';
31
+
32
+ /**
33
+ * Optional. Custom styles to apply to the badge dot component. Can be a single style or an array of styles.
34
+ */
35
+ style?: ViewStyle | ViewStyle[];
36
+ };
37
+
38
+ /**
39
+ * Props for a BadgeRibbon component. It represents a more specialized badge in the shape of a ribbon, allowing for placement around containers.
40
+ */
41
+ export type BadgeRibbonProps = {
42
+ /**
43
+ * The text to display on the ribbon-style badge. Unlike other badges, ribbons typically carry more descriptive text.
44
+ */
45
+ label: string;
46
+
47
+ /**
48
+ * Optional. Determines the placement of the ribbon on its parent container. The position can be any corner of the container.
49
+ * Defaults to 'top_right' if not specified.
50
+ */
51
+ position?: 'top_right' | 'top_left' | 'bottom_right' | 'bottom_left';
52
+
53
+ /**
54
+ * Optional. If true, the edges of the ribbon badge will be rounded. This is purely a stylistic choice.
55
+ * Defaults to `false` if not provided, resulting in a flat-edged ribbon.
56
+ */
57
+ isRound?: boolean;
58
+
59
+ /**
60
+ * Optional. Custom styles to apply to the ribbon badge component. Can be a single style or an array of styles.
61
+ */
62
+ style?: ViewStyle | ViewStyle[];
63
+ };
package/index.js DELETED
@@ -1,83 +0,0 @@
1
- import React from 'react';
2
- import { StyleSheet, View } from 'react-native';
3
- import { Colors, Radius, Spacing, Text } from '@momo-kits/core';
4
- import { isNumber } from 'lodash';
5
-
6
- const Badge = ({ type, title, style, textStyle, containerWidth }) => {
7
- const getStyle = (type) => {
8
- switch (type) {
9
- case 'badge':
10
- return [
11
- styles.container,
12
- {
13
- minWidth: 16,
14
- height: 16,
15
- left: containerWidth ? containerWidth - 12 : null,
16
- },
17
- ];
18
- case 'dot':
19
- return styles.dot;
20
- case 'dot-small':
21
- return styles.dotSmall;
22
- }
23
- };
24
-
25
- const formatTitle = (title) => {
26
- if (isNumber(title) && title > 99) {
27
- return '99+';
28
- }
29
- return title;
30
- };
31
-
32
- return (
33
- <View style={[getStyle(type), style]}>
34
- {type === 'badge' && (
35
- <Text
36
- weight="medium"
37
- style={[{ fontSize: 10, color: Colors.white }, textStyle]}>
38
- {formatTitle(title)}
39
- </Text>
40
- )}
41
- </View>
42
- );
43
- };
44
-
45
- const styles = StyleSheet.create({
46
- container: {
47
- paddingHorizontal: Spacing.XS,
48
- backgroundColor: Colors.error,
49
- borderRadius: Radius.M,
50
- justifyContent: 'center',
51
- alignItems: 'center',
52
- position: 'absolute',
53
- top: -4,
54
- },
55
- dot: {
56
- width: 16,
57
- height: 16,
58
- borderWidth: 1,
59
- borderColor: Colors.white,
60
- backgroundColor: Colors.error,
61
- borderRadius: 8,
62
- position: 'absolute',
63
- right: -8,
64
- top: -8,
65
- },
66
- dotSmall: {
67
- width: 10,
68
- height: 10,
69
- borderWidth: 1,
70
- borderColor: Colors.white,
71
- backgroundColor: Colors.error,
72
- borderRadius: 5,
73
- position: 'absolute',
74
- right: -5,
75
- top: -5,
76
- },
77
- });
78
-
79
- Badge.defaultProps = {
80
- type: 'badge',
81
- };
82
-
83
- export default Badge;