react-native-styled-badges 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Lachlan Crawford
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # React Native Badges
2
+
3
+ `BadgeStack` is a customizable React Native component that allows you to stack multiple badges in any corner of a child view. It supports animation and styling options.
4
+
5
+ ## ✨ Features
6
+
7
+ - Display multiple badges in a corner of any wrapped component.
8
+ - Customize badge colors and text colors.
9
+ - Optional fade-in animation.
10
+ - Supports positioning in all four corners.
11
+
12
+ ## 📦 Installation
13
+
14
+ Copy the `BadgeStack.tsx` component into your project. It uses only built-in React Native libraries and requires no external dependencies.
15
+
16
+ ## 🔧 Props
17
+
18
+ | Prop | Type | Default | Description |
19
+ |--------------|------------------|-------------|-------------|
20
+ | `badges` | `Badge[]` | **Required**| Array of badge objects (`label`, `color`, `labelColor`) |
21
+ | `position` | `'top-right' \| 'top-left' \| 'bottom-right' \| 'bottom-left'` | `'top-right'` | Corner in which badges should appear |
22
+ | `animate` | `boolean` | `false` | Whether badges should fade in |
23
+ | `badgeStyle` | `ViewStyle` | `undefined` | Style override for badge container |
24
+ | `textStyle` | `TextStyle` | `undefined` | Style override for badge text |
25
+ | `children` | `ReactNode` | **Required**| Child component to wrap |
26
+
27
+ ## 🧩 Badge Type
28
+
29
+ ```ts
30
+ type Badge = {
31
+ label: string;
32
+ color?: string; // Background color of badge
33
+ labelColor?: string; // Text color of badge
34
+ };
35
+ ```
36
+
37
+
38
+ ## 🚀 Usage
39
+ ```
40
+ import React from 'react';
41
+ import { View, Text } from 'react-native';
42
+ import BadgeStack from './BadgeStack';
43
+
44
+ const MyComponent = () => {
45
+ const badges = [
46
+ { label: 'New', color: '#28a745' },
47
+ { label: 'Hot', color: '#dc3545', labelColor: '#fff' },
48
+ ];
49
+
50
+ return (
51
+ <BadgeStack badges={badges} position="top-left" animate>
52
+ <View style={{ width: 100, height: 100, backgroundColor: '#ddd' }}>
53
+ <Text>Content</Text>
54
+ </View>
55
+ </BadgeStack>
56
+ );
57
+ };
58
+
59
+ export default MyComponent;
60
+ ```
61
+ ## 🖌️ Customization
62
+ You can customize the badges by using the badgeStyle and textStyle props to override padding, font size, border radius, etc.
63
+
64
+ ## 🎬 Animation
65
+ When the animate prop is set to true, each badge fades into view using Animated.View.
66
+
67
+ ## 📄 License
68
+ This component is open for modification and use in any React Native project. No specific license is applied. Add your own if needed.
@@ -0,0 +1,85 @@
1
+ import React from 'react';
2
+ import { View, Text, StyleSheet, Animated } from 'react-native';
3
+ const BadgeStack = ({
4
+ badges,
5
+ position = 'top-right',
6
+ animate = false,
7
+ badgeStyle,
8
+ textStyle,
9
+ children
10
+ }) => {
11
+ const positionStyle = getPositionStyle(position);
12
+ const renderBadges = () => {
13
+ return badges.map((badge, index) => {
14
+ const offset = index * 22;
15
+ const animStyle = animate ? {
16
+ opacity: fadeInAnim
17
+ } : {};
18
+ return /*#__PURE__*/React.createElement(Animated.View, {
19
+ key: badge.label + index,
20
+ style: [styles.badge, {
21
+ top: position.includes('top') ? offset : undefined,
22
+ bottom: position.includes('bottom') ? offset : undefined,
23
+ backgroundColor: badge.color || '#007AFF'
24
+ }, badgeStyle, animStyle]
25
+ }, /*#__PURE__*/React.createElement(Text, {
26
+ style: [styles.badgeText, textStyle, {
27
+ color: badge.labelColor || "#fff",
28
+ textDecorationStyle: 'dotted'
29
+ }]
30
+ }, badge.label));
31
+ });
32
+ };
33
+
34
+ // Animation (optional)
35
+ const fadeInAnim = React.useRef(new Animated.Value(0)).current;
36
+ React.useEffect(() => {
37
+ if (animate) {
38
+ Animated.timing(fadeInAnim, {
39
+ toValue: 1,
40
+ duration: 500,
41
+ useNativeDriver: true
42
+ }).start();
43
+ }
44
+ }, [animate]);
45
+ const styles = StyleSheet.create({
46
+ container: {
47
+ position: 'relative'
48
+ },
49
+ stackContainer: {
50
+ position: 'absolute',
51
+ zIndex: 10,
52
+ elevation: 5
53
+ },
54
+ badge: {
55
+ paddingHorizontal: 8,
56
+ paddingVertical: 3,
57
+ borderRadius: 12,
58
+ marginVertical: 1,
59
+ alignSelf: 'flex-start',
60
+ elevation: 5
61
+ },
62
+ badgeText: {
63
+ color: '#fff',
64
+ fontSize: 10,
65
+ fontWeight: '600'
66
+ }
67
+ });
68
+ return /*#__PURE__*/React.createElement(View, {
69
+ style: styles.container
70
+ }, children, /*#__PURE__*/React.createElement(View, {
71
+ style: [styles.stackContainer, positionStyle]
72
+ }, renderBadges()));
73
+ };
74
+ function getPositionStyle(position) {
75
+ const style = {
76
+ position: 'absolute'
77
+ };
78
+ if (position.includes('top')) style.top = 0;
79
+ if (position.includes('bottom')) style.bottom = 0;
80
+ if (position.includes('left')) style.left = 0;
81
+ if (position.includes('right')) style.right = 0;
82
+ return style;
83
+ }
84
+ export default BadgeStack;
85
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","View","Text","StyleSheet","Animated","BadgeStack","badges","position","animate","badgeStyle","textStyle","children","positionStyle","getPositionStyle","renderBadges","map","badge","index","offset","animStyle","opacity","fadeInAnim","createElement","key","label","style","styles","top","includes","undefined","bottom","backgroundColor","color","badgeText","labelColor","textDecorationStyle","useRef","Value","current","useEffect","timing","toValue","duration","useNativeDriver","start","create","container","stackContainer","zIndex","elevation","paddingHorizontal","paddingVertical","borderRadius","marginVertical","alignSelf","fontSize","fontWeight","left","right"],"sources":["index.tsx"],"sourcesContent":["import React from 'react';\r\nimport {\r\n View,\r\n Text,\r\n StyleSheet,\r\n Animated,\r\n} from 'react-native';\r\n\r\nimport type { ViewStyle, TextStyle } from 'react-native';\r\ntype Badge = {\r\n label: string;\r\n color?: string; // Named color or hex\r\n labelColor?: string; // Named color or hex\r\n};\r\n\r\ntype Position =\r\n | 'top-right'\r\n | 'top-left'\r\n | 'bottom-right'\r\n | 'bottom-left';\r\n\r\ntype Props = {\r\n badges: Badge[];\r\n position?: Position;\r\n animate?: boolean;\r\n badgeStyle?: ViewStyle;\r\n textStyle?: TextStyle;\r\n children: React.ReactNode;\r\n};\r\n\r\nconst BadgeStack: React.FC<Props> = ({\r\n badges,\r\n position = 'top-right',\r\n animate = false,\r\n badgeStyle,\r\n textStyle,\r\n children,\r\n}) => {\r\n const positionStyle = getPositionStyle(position);\r\n\r\n const renderBadges = () => {\r\n return badges.map((badge, index) => {\r\n const offset = index * 22;\r\n const animStyle = animate ? { opacity: fadeInAnim } : {};\r\n return (\r\n <Animated.View\r\n key={badge.label + index}\r\n style={[\r\n styles.badge,\r\n {\r\n top: position.includes('top') ? offset : undefined,\r\n bottom: position.includes('bottom') ? offset : undefined,\r\n backgroundColor: badge.color || '#007AFF',\r\n \r\n },\r\n badgeStyle,\r\n animStyle,\r\n ]}\r\n >\r\n <Text style={[styles.badgeText, textStyle,{color:badge.labelColor ||\"#fff\",textDecorationStyle:'dotted'}]}>{badge.label}</Text>\r\n </Animated.View>\r\n );\r\n });\r\n };\r\n\r\n // Animation (optional)\r\n const fadeInAnim = React.useRef(new Animated.Value(0)).current;\r\n React.useEffect(() => {\r\n if (animate) {\r\n Animated.timing(fadeInAnim, {\r\n toValue: 1,\r\n duration: 500,\r\n useNativeDriver: true,\r\n }).start();\r\n }\r\n }, [animate]);\r\n\r\n\r\nconst styles = StyleSheet.create({\r\n container: {\r\n position: 'relative',\r\n },\r\n stackContainer: {\r\n position: 'absolute',\r\n zIndex: 10,\r\n elevation: 5,\r\n },\r\n badge: {\r\n paddingHorizontal: 8,\r\n paddingVertical: 3,\r\n borderRadius: 12,\r\n marginVertical: 1,\r\n alignSelf: 'flex-start',\r\n elevation: 5,\r\n },\r\n badgeText: {\r\n color: '#fff',\r\n fontSize: 10,\r\n fontWeight: '600',\r\n },\r\n});\r\n\r\n\r\n\r\n return (\r\n <View style={styles.container}>\r\n {children}\r\n <View style={[styles.stackContainer, positionStyle]}>\r\n {renderBadges()}\r\n </View>\r\n </View>\r\n );\r\n};\r\n\r\nfunction getPositionStyle(position: Position): ViewStyle {\r\n const style: ViewStyle = { position: 'absolute' };\r\n if (position.includes('top')) style.top = 0;\r\n if (position.includes('bottom')) style.bottom = 0;\r\n if (position.includes('left')) style.left = 0;\r\n if (position.includes('right')) style.right = 0;\r\n return style;\r\n}\r\n\r\n\r\n\r\nexport default BadgeStack;\r\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SACEC,IAAI,EACJC,IAAI,EACJC,UAAU,EACVC,QAAQ,QACH,cAAc;AAwBrB,MAAMC,UAA2B,GAAGA,CAAC;EACnCC,MAAM;EACNC,QAAQ,GAAG,WAAW;EACtBC,OAAO,GAAG,KAAK;EACfC,UAAU;EACVC,SAAS;EACTC;AACF,CAAC,KAAK;EACJ,MAAMC,aAAa,GAAGC,gBAAgB,CAACN,QAAQ,CAAC;EAEhD,MAAMO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,QAAQ,CAACqB,QAAQ,CAAC,OAAO,CAAC,EAAEH,KAAK,CAACiC,KAAK,GAAG,CAAC;EAC/C,OAAOjC,KAAK;AACd;AAIA,eAAepB,UAAU","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ export { default as BadgeStack } from '../src/BadgeStack/index';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["default","BadgeStack"],"sources":["index.tsx"],"sourcesContent":["export {default as BadgeStack} from '../src/BadgeStack/index';"],"mappings":"AAAA,SAAQA,OAAO,IAAIC,UAAU,QAAO,yBAAyB","ignoreList":[]}
package/package.json ADDED
@@ -0,0 +1,152 @@
1
+ {
2
+ "name": "react-native-styled-badges",
3
+ "version": "0.1.0",
4
+ "description": "A clean badge system without layout bugs",
5
+ "source": "./src/index.tsx",
6
+ "main": "./lib/module/index.js",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./lib/typescript/src/index.d.ts",
10
+ "default": "./lib/module/index.js"
11
+ },
12
+ "./package.json": "./package.json"
13
+ },
14
+ "files": [
15
+ "src",
16
+ "lib",
17
+ "android",
18
+ "ios",
19
+ "cpp",
20
+ "*.podspec",
21
+ "react-native.config.js",
22
+ "!ios/build",
23
+ "!android/build",
24
+ "!android/gradle",
25
+ "!android/gradlew",
26
+ "!android/gradlew.bat",
27
+ "!android/local.properties",
28
+ "!**/__tests__",
29
+ "!**/__fixtures__",
30
+ "!**/__mocks__",
31
+ "!**/.*"
32
+ ],
33
+ "scripts": {
34
+ "example": "yarn workspace react-native-badges-example",
35
+ "test": "jest",
36
+ "typecheck": "tsc",
37
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
38
+ "clean": "del-cli lib",
39
+ "prepare": "bob build",
40
+ "release": "release-it"
41
+ },
42
+ "keywords": [
43
+ "react-native",
44
+ "ios",
45
+ "android"
46
+ ],
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "git+https://github.com/InDataStar/react-native-badges.git"
50
+ },
51
+ "author": "Lachlan Crawford <crawfordlp1@gmail.com> (https://github.com/InDataStar)",
52
+ "license": "MIT",
53
+ "bugs": {
54
+ "url": "https://github.com/InDataStar/react-native-badges/issues"
55
+ },
56
+ "homepage": "https://github.com/InDataStar/react-native-badges#readme",
57
+ "publishConfig": {
58
+ "registry": "https://registry.npmjs.org/"
59
+ },
60
+ "devDependencies": {
61
+ "@commitlint/config-conventional": "^19.6.0",
62
+ "@eslint/compat": "^1.2.7",
63
+ "@eslint/eslintrc": "^3.3.0",
64
+ "@eslint/js": "^9.22.0",
65
+ "@evilmartians/lefthook": "^1.5.0",
66
+ "@react-native/eslint-config": "^0.78.0",
67
+ "@release-it/conventional-changelog": "^9.0.2",
68
+ "@types/jest": "^29.5.5",
69
+ "@types/react": "^19.0.12",
70
+ "commitlint": "^19.6.1",
71
+ "del-cli": "^5.1.0",
72
+ "eslint": "^9.22.0",
73
+ "eslint-config-prettier": "^10.1.1",
74
+ "eslint-plugin-prettier": "^5.2.3",
75
+ "jest": "^29.7.0",
76
+ "prettier": "^3.0.3",
77
+ "react": "19.0.0",
78
+ "react-native": "0.79.4",
79
+ "react-native-builder-bob": "^0.18.3",
80
+ "release-it": "^17.10.0",
81
+ "typescript": "^5.2.2"
82
+ },
83
+ "peerDependencies": {
84
+ "react": "*",
85
+ "react-native": "*"
86
+ },
87
+ "workspaces": [
88
+ "example"
89
+ ],
90
+ "packageManager": "yarn@3.6.1",
91
+ "jest": {
92
+ "preset": "react-native",
93
+ "modulePathIgnorePatterns": [
94
+ "<rootDir>/example/node_modules",
95
+ "<rootDir>/lib/"
96
+ ]
97
+ },
98
+ "commitlint": {
99
+ "extends": [
100
+ "@commitlint/config-conventional"
101
+ ]
102
+ },
103
+ "release-it": {
104
+ "git": {
105
+ "commitMessage": "chore: release ${version}",
106
+ "tagName": "v${version}"
107
+ },
108
+ "npm": {
109
+ "publish": true
110
+ },
111
+ "github": {
112
+ "release": true
113
+ },
114
+ "plugins": {
115
+ "@release-it/conventional-changelog": {
116
+ "preset": {
117
+ "name": "angular"
118
+ }
119
+ }
120
+ }
121
+ },
122
+ "prettier": {
123
+ "quoteProps": "consistent",
124
+ "singleQuote": true,
125
+ "tabWidth": 2,
126
+ "trailingComma": "es5",
127
+ "useTabs": false
128
+ },
129
+ "react-native-builder-bob": {
130
+ "source": "src",
131
+ "output": "lib",
132
+ "targets": [
133
+ [
134
+ "module",
135
+ {
136
+ "esm": true
137
+ }
138
+ ],
139
+ [
140
+ "typescript",
141
+ {
142
+ "project": "tsconfig.build.json"
143
+ }
144
+ ]
145
+ ]
146
+ },
147
+ "create-react-native-library": {
148
+ "languages": "js",
149
+ "type": "library",
150
+ "version": "0.49.3"
151
+ }
152
+ }
@@ -0,0 +1,126 @@
1
+ import React from 'react';
2
+ import {
3
+ View,
4
+ Text,
5
+ StyleSheet,
6
+ Animated,
7
+ } from 'react-native';
8
+
9
+ import type { ViewStyle, TextStyle } from 'react-native';
10
+ type Badge = {
11
+ label: string;
12
+ color?: string; // Named color or hex
13
+ labelColor?: string; // Named color or hex
14
+ };
15
+
16
+ type Position =
17
+ | 'top-right'
18
+ | 'top-left'
19
+ | 'bottom-right'
20
+ | 'bottom-left';
21
+
22
+ type Props = {
23
+ badges: Badge[];
24
+ position?: Position;
25
+ animate?: boolean;
26
+ badgeStyle?: ViewStyle;
27
+ textStyle?: TextStyle;
28
+ children: React.ReactNode;
29
+ };
30
+
31
+ const BadgeStack: React.FC<Props> = ({
32
+ badges,
33
+ position = 'top-right',
34
+ animate = false,
35
+ badgeStyle,
36
+ textStyle,
37
+ children,
38
+ }) => {
39
+ const positionStyle = getPositionStyle(position);
40
+
41
+ const renderBadges = () => {
42
+ return badges.map((badge, index) => {
43
+ const offset = index * 22;
44
+ const animStyle = animate ? { opacity: fadeInAnim } : {};
45
+ return (
46
+ <Animated.View
47
+ key={badge.label + index}
48
+ style={[
49
+ styles.badge,
50
+ {
51
+ top: position.includes('top') ? offset : undefined,
52
+ bottom: position.includes('bottom') ? offset : undefined,
53
+ backgroundColor: badge.color || '#007AFF',
54
+
55
+ },
56
+ badgeStyle,
57
+ animStyle,
58
+ ]}
59
+ >
60
+ <Text style={[styles.badgeText, textStyle,{color:badge.labelColor ||"#fff",textDecorationStyle:'dotted'}]}>{badge.label}</Text>
61
+ </Animated.View>
62
+ );
63
+ });
64
+ };
65
+
66
+ // Animation (optional)
67
+ const fadeInAnim = React.useRef(new Animated.Value(0)).current;
68
+ React.useEffect(() => {
69
+ if (animate) {
70
+ Animated.timing(fadeInAnim, {
71
+ toValue: 1,
72
+ duration: 500,
73
+ useNativeDriver: true,
74
+ }).start();
75
+ }
76
+ }, [animate]);
77
+
78
+
79
+ const styles = StyleSheet.create({
80
+ container: {
81
+ position: 'relative',
82
+ },
83
+ stackContainer: {
84
+ position: 'absolute',
85
+ zIndex: 10,
86
+ elevation: 5,
87
+ },
88
+ badge: {
89
+ paddingHorizontal: 8,
90
+ paddingVertical: 3,
91
+ borderRadius: 12,
92
+ marginVertical: 1,
93
+ alignSelf: 'flex-start',
94
+ elevation: 5,
95
+ },
96
+ badgeText: {
97
+ color: '#fff',
98
+ fontSize: 10,
99
+ fontWeight: '600',
100
+ },
101
+ });
102
+
103
+
104
+
105
+ return (
106
+ <View style={styles.container}>
107
+ {children}
108
+ <View style={[styles.stackContainer, positionStyle]}>
109
+ {renderBadges()}
110
+ </View>
111
+ </View>
112
+ );
113
+ };
114
+
115
+ function getPositionStyle(position: Position): ViewStyle {
116
+ const style: ViewStyle = { position: 'absolute' };
117
+ if (position.includes('top')) style.top = 0;
118
+ if (position.includes('bottom')) style.bottom = 0;
119
+ if (position.includes('left')) style.left = 0;
120
+ if (position.includes('right')) style.right = 0;
121
+ return style;
122
+ }
123
+
124
+
125
+
126
+ export default BadgeStack;
package/src/index.tsx ADDED
@@ -0,0 +1 @@
1
+ export {default as BadgeStack} from '../src/BadgeStack/index';