Skip to content

Commit f17e542

Browse files
committed
chore: ✨ changed prop name to badgeValues, added some props to customise the badge
1 parent 219fb51 commit f17e542

File tree

1 file changed

+64
-8
lines changed

1 file changed

+64
-8
lines changed

src/index.tsx

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,63 @@ import Animated, {
1515
import { widthPercentageToDP } from 'react-native-responsive-screen';
1616

1717
interface SegmentedControlProps {
18+
/**
19+
* The Segments Text Array
20+
*/
1821
segments: Array<string>;
22+
/**
23+
* The Current Active Segment Index
24+
*/
1925
currentIndex: number;
26+
/**
27+
* A callback onPress of a Segment
28+
*/
2029
onChange: (index: number) => void;
21-
badgeCount?: Array<number | null>;
30+
/**
31+
* An array of Badge Values corresponding to the Segment
32+
*/
33+
badgeValues?: Array<number | null>;
34+
/**
35+
* Is right-to-left mode.
36+
*/
2237
isRTL?: boolean;
38+
/**
39+
* The container margin for the segmented control
40+
* Used to calculate the width of Segmented Control
41+
*/
2342
containerMargin?: number;
43+
/**
44+
* Active Segment Text Style
45+
*/
2446
activeTextStyle?: TextStyle;
47+
/**
48+
* InActive Segment Text Style
49+
*/
2550
inactiveTextStyle?: TextStyle;
51+
/**
52+
* Segment Container Styles
53+
*/
2654
segmentedControlWrapper?: ViewStyle;
55+
/**
56+
* Pressable Container Styles
57+
*/
2758
pressableWrapper?: ViewStyle;
59+
/**
60+
* The moving Tile Container Styles
61+
*/
2862
tileStyle?: ViewStyle;
63+
/**
64+
* Active Badge Styles
65+
*/
66+
activeBadgeStyle?: ViewStyle;
67+
/**
68+
* Inactive Badge Styles
69+
*/
70+
inactiveBadgeStyle?: ViewStyle;
71+
/**
72+
* Badge Text Styles
73+
*/
74+
badgeTextStyle?: TextStyle;
2975
}
3076

3177
const defaultShadowStyle = {
@@ -53,14 +99,17 @@ const SegmentedControl: React.FC<SegmentedControlProps> = ({
5399
segments,
54100
currentIndex,
55101
onChange,
56-
badgeCount = [],
102+
badgeValues = [],
57103
isRTL = false,
58104
containerMargin = 0,
59105
activeTextStyle,
60106
inactiveTextStyle,
61107
segmentedControlWrapper,
62108
pressableWrapper,
63109
tileStyle,
110+
activeBadgeStyle,
111+
inactiveBadgeStyle,
112+
badgeTextStyle,
64113
}: SegmentedControlProps) => {
65114
const width = widthPercentageToDP('100%') - containerMargin * 2;
66115
const translateValue = width / segments.length;
@@ -91,34 +140,41 @@ const SegmentedControl: React.FC<SegmentedControlProps> = ({
91140

92141
const finalisedActiveTextStyle: TextStyle = {
93142
fontSize: 15,
94-
fontWeight: '500',
143+
fontWeight: '600',
95144
textAlign: 'center',
96-
color: '#0ea5e9',
145+
color: '#111827',
97146
...activeTextStyle,
98147
};
99148

100149
const finalisedInActiveTextStyle: TextStyle = {
101150
fontSize: 15,
102151
textAlign: 'center',
103-
color: '#1f2937',
152+
color: '#4b5563',
104153
...inactiveTextStyle,
105154
};
106155

107156
const finalisedActiveBadgeStyle: ViewStyle = {
108-
backgroundColor: '#0ea5e9',
157+
backgroundColor: '#27272a',
109158
marginLeft: 4,
159+
alignItems: 'center',
160+
justifyContent: 'center',
161+
...activeBadgeStyle,
110162
};
111163

112164
const finalisedInActiveBadgeStyle: ViewStyle = {
113165
backgroundColor: '#6b7280',
114166
marginLeft: 4,
167+
justifyContent: 'center',
168+
alignItems: 'center',
169+
...inactiveBadgeStyle,
115170
};
116171

117172
const finalisedBadgeTextStyle: TextStyle = {
118173
fontSize: 11,
119174
fontWeight: '500',
120175
textAlign: 'center',
121176
color: '#FFFFFF',
177+
...badgeTextStyle,
122178
};
123179

124180
return (
@@ -154,7 +210,7 @@ const SegmentedControl: React.FC<SegmentedControlProps> = ({
154210
>
155211
{segment}
156212
</Text>
157-
{badgeCount[index] && (
213+
{badgeValues[index] && (
158214
<View
159215
style={[
160216
styles.defaultBadgeContainerStyle,
@@ -164,7 +220,7 @@ const SegmentedControl: React.FC<SegmentedControlProps> = ({
164220
]}
165221
>
166222
<Text style={finalisedBadgeTextStyle}>
167-
{badgeCount[index]}
223+
{badgeValues[index]}
168224
</Text>
169225
</View>
170226
)}

0 commit comments

Comments
 (0)