-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(foundation): added Badge component
- Loading branch information
Showing
8 changed files
with
149 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
packages/uikit-react-native-foundation/src/ui/Badge/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React from 'react'; | ||
import { Platform, StyleProp, View, ViewStyle } from 'react-native'; | ||
|
||
import { truncatedBadgeCount } from '@sendbird/uikit-utils'; | ||
|
||
import createStyleSheet from '../../styles/createStyleSheet'; | ||
import useUIKitTheme from '../../theme/useUIKitTheme'; | ||
import Text from '../Text'; | ||
|
||
type Props = { | ||
count: number; | ||
maxCount?: number; | ||
badgeColor?: string; | ||
textColor?: string; | ||
style?: StyleProp<ViewStyle>; | ||
size?: 'small' | 'default'; | ||
}; | ||
|
||
const Badge: React.FC<Props> = ({ count, maxCount, badgeColor, textColor, style, size = 'default' }) => { | ||
const { colors } = useUIKitTheme(); | ||
const isSmall = size === 'small'; | ||
return ( | ||
<View | ||
style={[ | ||
isSmall ? styles.badgeSmall : styles.badgeDefault, | ||
{ backgroundColor: badgeColor ?? colors.ui.badge.default.none.background }, | ||
count >= 10 && (isSmall ? styles.badgeSmallPadding : styles.badgeDefaultPadding), | ||
style, | ||
]} | ||
> | ||
<Text caption1 color={textColor ?? colors.ui.badge.default.none.text}> | ||
{truncatedBadgeCount(count, maxCount)} | ||
</Text> | ||
</View> | ||
); | ||
}; | ||
|
||
const styles = createStyleSheet({ | ||
badgeDefault: { | ||
paddingTop: Platform.select({ ios: 2, android: 2 }), | ||
minWidth: 20, | ||
minHeight: 20, | ||
borderRadius: 99, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}, | ||
badgeDefaultPadding: { | ||
paddingHorizontal: 8, | ||
}, | ||
badgeSmall: { | ||
paddingTop: Platform.select({ ios: 3, android: 2 }), | ||
minWidth: 16, | ||
minHeight: 16, | ||
borderRadius: 99, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}, | ||
badgeSmallPadding: { | ||
paddingHorizontal: 4, | ||
}, | ||
}); | ||
|
||
export default Badge; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type { ComponentMeta, ComponentStory } from '@storybook/react-native'; | ||
import React from 'react'; | ||
import { View } from 'react-native'; | ||
|
||
import { Badge as BadgeComponent } from '@sendbird/uikit-react-native-foundation'; | ||
|
||
const BadgeMeta: ComponentMeta<typeof BadgeComponent> = { | ||
title: 'Badge', | ||
component: BadgeComponent, | ||
argTypes: { | ||
maxCount: { | ||
name: 'Max Count', | ||
control: { type: 'number' }, | ||
}, | ||
badgeColor: { | ||
name: 'Badge Color', | ||
control: { type: 'color' }, | ||
}, | ||
textColor: { | ||
name: 'Text Color', | ||
control: { type: 'color' }, | ||
}, | ||
}, | ||
args: { | ||
maxCount: 99, | ||
badgeColor: undefined, | ||
textColor: undefined, | ||
}, | ||
}; | ||
|
||
export default BadgeMeta; | ||
|
||
type BadgeStory = ComponentStory<typeof BadgeComponent>; | ||
export const Default: BadgeStory = (args) => ( | ||
<> | ||
<View style={{ flexDirection: 'row', width: '100%', justifyContent: 'space-evenly', marginBottom: 12 }}> | ||
<BadgeComponent {...args} count={1} /> | ||
<BadgeComponent {...args} count={30} /> | ||
<BadgeComponent {...args} count={60} /> | ||
<BadgeComponent {...args} count={90} /> | ||
<BadgeComponent {...args} count={120} /> | ||
</View> | ||
<View style={{ flexDirection: 'row', width: '100%', justifyContent: 'space-evenly' }}> | ||
<BadgeComponent {...args} size={'small'} count={1} /> | ||
<BadgeComponent {...args} size={'small'} count={30} /> | ||
<BadgeComponent {...args} size={'small'} count={60} /> | ||
<BadgeComponent {...args} size={'small'} count={90} /> | ||
<BadgeComponent {...args} size={'small'} count={120} /> | ||
</View> | ||
</> | ||
); |