Skip to content

Commit

Permalink
[C-4476] HarmonyNative MusicBadge component (#8765)
Browse files Browse the repository at this point in the history
  • Loading branch information
dharit-tan authored Jun 8, 2024
1 parent 0272472 commit 7811515
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/mobile/.storybook/storybook.requires.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const getStories = () => {
'../src/harmony-native/Paper.stories.tsx': require('../src/harmony-native/components/layout/Paper/Paper.stories.tsx'),
'../src/harmony-native/Avatar.stories.tsx': require('../src/harmony-native/components/Avatar/Avatar.stories.tsx'),
'../src/harmony-native/Hint.stories.tsx': require('../src/harmony-native/components/Hint/Hint.stories.tsx'),
'../src/harmony-native/MusicBadge.stories.tsx': require('../src/harmony-native/components/MusicBadge/MusicBadge.stories.tsx'),
'../src/harmony-native/SelectablePill.stories.tsx': require('../src/harmony-native/components/input/SelectablePill/SelectablePill.stories.tsx'),
'../src/harmony-native/TextInput.stories.tsx': require('../src/harmony-native/components/input/TextInput/TextInput.stories.tsx'),
'../src/harmony-native/PasswordInput.stories.tsx': require('../src/harmony-native/components/input/PasswordInput/PasswordInput.stories.tsx'),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import type { Meta, StoryObj } from '@storybook/react'

import { IconRobot } from '@audius/harmony-native'

import type { MusicBadgeProps } from './MusicBadge'
import { MusicBadge } from './MusicBadge'

const meta: Meta<MusicBadgeProps> = {
title: 'Components/MusicBadge',
component: MusicBadge,
argTypes: {
variant: {
description: 'Variant',
control: { type: 'radio' },
options: ['default', 'accent']
},
color: {
description: 'Color',
control: { type: 'radio' },
options: ['aiGreen', 'trendingBlue']
}
},
render: (props) => <MusicBadge {...props} />
}

export default meta

type Story = StoryObj<MusicBadgeProps>

export const Default: Story = {
args: {
icon: IconRobot,
children: 'Example Badge'
}
}

export const Accent: Story = {
args: {
variant: 'accent',
icon: IconRobot,
children: 'Example Badge'
}
}

export const Color: Story = {
args: {
color: 'aiGreen',
icon: IconRobot,
children: 'Example Badge'
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import type { ComponentPropsWithoutRef } from 'react'

import { css } from '@emotion/native'
import Color from 'color'

import type { SpecialColors, IconComponent } from '@audius/harmony-native'
import { useTheme } from 'app/harmony-native/foundations/theme'

import { Text } from '../Text/Text'
import { Flex } from '../layout/Flex/Flex'

export type MusicBadgeVariant = 'default' | 'accent'

export type MusicBadgeSize = 's' | 'm'

export type MusicBadgeProps = {
/**
* The type of the MusicBadge
*/
variant?: MusicBadgeVariant
/**
* The icon to display in the left of the MusicBadge
*/
icon?: IconComponent
/**
* Override the colors of the MusicBadge
*/
color?: SpecialColors
} & ComponentPropsWithoutRef<'div'>

export const MusicBadge = (props: MusicBadgeProps) => {
const { variant = 'default', icon: Icon, color: colorProp, children } = props
const { color } = useTheme()

const backgroundColor = colorProp
? color.special[colorProp]
: variant === 'default'
? color.background.default
: color.background.accent
const textColor = colorProp
? (color.special[colorProp] as string)
: variant === 'default'
? color.text.default
: color.text.accent
const iconColor = colorProp
? (color.special[colorProp] as string)
: variant === 'default'
? color.icon.default
: color.icon.accent
const borderColor = colorProp
? Color(color.special[colorProp]).fade(0.5).toString()
: variant === 'default'
? color.border.strong
: color.border.accent

return (
<Flex
direction='row'
alignItems='center'
justifyContent='center'
borderRadius='s'
border='strong'
gap='xs'
ph='s'
pv='xs'
style={css({
backgroundColor: Color(backgroundColor).fade(0.92).toString(),
borderColor
})}
>
{Icon ? <Icon size='s' fill={iconColor} /> : null}
<Text
variant='label'
size='s'
// Hack - should not have to explicitly set lineHeight, but there's a bug
// that adds extra margins to demibold + bold text variants.
style={css({ color: textColor, lineHeight: 16 })}
>
{children}
</Text>
</Flex>
)
}
1 change: 1 addition & 0 deletions packages/mobile/src/harmony-native/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export type { TextLinkProps } from './TextLink/types'
export * from './layout'
export * from './Avatar/Avatar'
export * from './Hint/Hint'
export * from './MusicBadge/MusicBadge'
export * from './input/SelectablePill/SelectablePill'
export * from './input/TextInput/TextInput'
export * from './input/TextInput/types'
Expand Down

0 comments on commit 7811515

Please sign in to comment.