@momo-kits/badge 0.81.8 → 0.81.9-beta.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/Badge.tsx CHANGED
@@ -1,12 +1,26 @@
1
1
  import React, {FC, useContext} from 'react';
2
2
  import {View} from 'react-native';
3
3
  import {ApplicationContext, Colors, Text} from '@momo-kits/foundation';
4
- import {BadgeProps, BadgeType} from './types';
4
+ import {BadgeProps} from './types';
5
5
  import styles from './styles';
6
6
 
7
- const Badge: FC<BadgeProps> = ({label = 'Label', style}) => {
7
+ const Badge: FC<BadgeProps> = ({label = 'Label', style, backgroundColor}) => {
8
8
  const {theme} = useContext(ApplicationContext);
9
9
 
10
+ const isValidatedColor = () => {
11
+ const colorKeys = Object.keys(Colors);
12
+ const colorValue = Object.values(Colors);
13
+ if (backgroundColor) {
14
+ const colorIndex = colorValue.indexOf(backgroundColor);
15
+ if (colorIndex !== -1) {
16
+ if (colorKeys[colorIndex].includes('_03')) {
17
+ return true;
18
+ }
19
+ }
20
+ }
21
+ return false;
22
+ };
23
+
10
24
  const isNumber = () => {
11
25
  const numberRegex = /^\d+$/;
12
26
  return numberRegex.test(String(label));
@@ -19,12 +33,16 @@ const Badge: FC<BadgeProps> = ({label = 'Label', style}) => {
19
33
  return label.toString();
20
34
  };
21
35
 
22
- const backgroundColor = isNumber()
36
+ let badgeColor = isNumber()
23
37
  ? theme.colors.error.primary
24
38
  : theme.colors.warning.primary;
25
39
 
40
+ if (backgroundColor && isValidatedColor()) {
41
+ badgeColor = backgroundColor;
42
+ }
43
+
26
44
  return (
27
- <View style={[style, styles.badge, {backgroundColor}]}>
45
+ <View style={[style, styles.badge, {backgroundColor: badgeColor}]}>
28
46
  <Text color={Colors.black_01} typography={'action_xxs'}>
29
47
  {formatTitle()}
30
48
  </Text>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/badge",
3
- "version": "0.81.8",
3
+ "version": "0.81.9-beta.1",
4
4
  "private": false,
5
5
  "main": "index.tsx",
6
6
  "peerDependencies": {
package/styles.ts CHANGED
@@ -47,11 +47,8 @@ export default StyleSheet.create({
47
47
  alignItems: 'center',
48
48
  },
49
49
  ribbonLabel: {
50
- fontSize: 10,
51
- lineHeight: 14,
52
50
  color: Colors.black_01,
53
- minWidth: 20,
54
- marginRight: 8,
51
+ marginRight: Spacing.S,
55
52
  fontWeight: 'bold',
56
53
  },
57
54
  });
package/types.ts CHANGED
@@ -18,6 +18,8 @@ export type BadgeProps = {
18
18
  * Optional. Custom styles to apply to the badge component. Can be a single style or an array of styles.
19
19
  */
20
20
  style?: ViewStyle | ViewStyle[];
21
+
22
+ backgroundColor?: string;
21
23
  };
22
24
 
23
25
  /**