-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
0272472
commit 7811515
Showing
4 changed files
with
136 additions
and
0 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
51 changes: 51 additions & 0 deletions
51
packages/mobile/src/harmony-native/components/MusicBadge/MusicBadge.stories.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,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' | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
packages/mobile/src/harmony-native/components/MusicBadge/MusicBadge.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,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> | ||
) | ||
} |
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