Skip to content

Commit b954525

Browse files
Merge branch 'badge' into 'main'
Badge See merge request react-native/react-native-material-components!15
2 parents 1a4746e + 3f0258c commit b954525

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,19 @@ export const AppBodyLargeText: React.FC<PropsWithChildren> = ({children}) => {
212212
![linear activity indicator gif](https://ik.imagekit.io/Computools/rn-material-components/linear-indicator-gif.gif?updatedAt=1705066319092)
213213
</details>
214214
</details>
215+
<details><summary>Badge</summary>
216+
<br />
217+
218+
**Properties**
219+
220+
| name | description | type | default |
221+
| ------ | ------ | ------ | ----|
222+
| value | required | string | - |
223+
| valueStyle | - | TextStyle | - |
224+
225+
![badge light theme](https://ik.imagekit.io/Computools/rn-material-components/badge_light.png?updatedAt=1733926687727)
226+
![badge dark theme](https://ik.imagekit.io/Computools/rn-material-components/badge_dark.png?updatedAt=1733926687741)
227+
</details>
215228
<details><summary>Buttons</summary>
216229
<br />
217230
<details><summary>Common buttons</summary>

src/badge/Badge.component.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react';
2+
import {View, Text, type ViewProps, type StyleProp, type TextStyle} from 'react-native';
3+
4+
import {styles} from './badge.styles';
5+
import {useTheme} from '../theme/useTheme.hook';
6+
import {useTypography} from '../typography/useTypography.component';
7+
8+
export interface BadgeProps extends ViewProps {
9+
value: string;
10+
11+
valueStyle?: StyleProp<TextStyle>;
12+
}
13+
14+
export const Badge: React.FC<BadgeProps> = ({value, style, valueStyle, ...props}) => {
15+
const {error} = useTheme();
16+
const {labelSmall} = useTypography();
17+
18+
return (
19+
<View style={[styles.container, {backgroundColor: error.background}, style]} {...props}>
20+
<Text style={[labelSmall, {color: error.text}, valueStyle]}>{value}</Text>
21+
</View>
22+
);
23+
};

src/badge/badge.styles.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {StyleSheet} from 'react-native';
2+
3+
export const styles = StyleSheet.create({
4+
container: {
5+
alignItems: 'center',
6+
justifyContent: 'center',
7+
8+
paddingHorizontal: 4,
9+
minWidth: 16,
10+
height: 16,
11+
borderRadius: 100,
12+
},
13+
});

src/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export {Badge, type BadgeProps} from './badge/Badge.component';
2+
13
export {Divider, type DividerProps} from './divider/Divider.component';
24

35
export {BottomSheet, type BottomSheetProps, type BottomSheetRef} from './sheets/bottom-sheet/BottomSheet.component';

0 commit comments

Comments
 (0)