From 7811515686cd7a0d606382132e47547a7fcb9d7c Mon Sep 17 00:00:00 2001 From: Reed <3893871+dharit-tan@users.noreply.github.com> Date: Fri, 7 Jun 2024 20:04:26 -0400 Subject: [PATCH] [C-4476] HarmonyNative MusicBadge component (#8765) --- .../mobile/.storybook/storybook.requires.ts | 1 + .../MusicBadge/MusicBadge.stories.tsx | 51 ++++++++++++ .../components/MusicBadge/MusicBadge.tsx | 83 +++++++++++++++++++ .../src/harmony-native/components/index.ts | 1 + 4 files changed, 136 insertions(+) create mode 100644 packages/mobile/src/harmony-native/components/MusicBadge/MusicBadge.stories.tsx create mode 100644 packages/mobile/src/harmony-native/components/MusicBadge/MusicBadge.tsx diff --git a/packages/mobile/.storybook/storybook.requires.ts b/packages/mobile/.storybook/storybook.requires.ts index 682747248b5..4017ab4b995 100644 --- a/packages/mobile/.storybook/storybook.requires.ts +++ b/packages/mobile/.storybook/storybook.requires.ts @@ -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'), diff --git a/packages/mobile/src/harmony-native/components/MusicBadge/MusicBadge.stories.tsx b/packages/mobile/src/harmony-native/components/MusicBadge/MusicBadge.stories.tsx new file mode 100644 index 00000000000..e1abc392a12 --- /dev/null +++ b/packages/mobile/src/harmony-native/components/MusicBadge/MusicBadge.stories.tsx @@ -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 = { + 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) => +} + +export default meta + +type Story = StoryObj + +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' + } +} diff --git a/packages/mobile/src/harmony-native/components/MusicBadge/MusicBadge.tsx b/packages/mobile/src/harmony-native/components/MusicBadge/MusicBadge.tsx new file mode 100644 index 00000000000..3b035bfde09 --- /dev/null +++ b/packages/mobile/src/harmony-native/components/MusicBadge/MusicBadge.tsx @@ -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 ( + + {Icon ? : null} + + {children} + + + ) +} diff --git a/packages/mobile/src/harmony-native/components/index.ts b/packages/mobile/src/harmony-native/components/index.ts index 2ee951cfd1c..baa32f77217 100644 --- a/packages/mobile/src/harmony-native/components/index.ts +++ b/packages/mobile/src/harmony-native/components/index.ts @@ -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'