@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 +22 -4
- package/package.json +1 -1
- package/styles.ts +1 -4
- package/types.ts +2 -0
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
|
|
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
|
-
|
|
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
package/styles.ts
CHANGED