Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C-3435] Add CompletionCheck to native harmony #6947

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/mobile/.storybook/storybook.requires.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const getStories = () => {
'../src/harmony-native/Hint.stories.tsx': require('../src/harmony-native/components/Hint/Hint.stories.tsx'),
'../src/harmony-native/SelectablePill.stories.tsx': require('../src/harmony-native/components/input/SelectablePill/SelectablePill.stories.tsx'),
'../src/harmony-native/FollowButton.stories.tsx': require('../src/harmony-native/components/Button/FollowButton/FollowButton.stories.tsx'),
'../src/harmony-native/CompletionCheck.stories.tsx': require('../src/harmony-native/components/CompletionCheck/CompletionCheck.stories.tsx'),
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { CompletionCheckProps } from '@audius/harmony'
import type { Meta, StoryObj } from '@storybook/react-native'

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

import { CompletionCheck } from './CompletionCheck'

const meta: Meta<CompletionCheckProps> = {
title: 'Components/Input/CompletionCheck',
component: CompletionCheck,
argTypes: {
value: {
description: 'Value',
control: { type: 'radio' },
options: ['incomplete', 'complete', 'error']
}
},
render: (props) => (
<Flex p='l'>
<CompletionCheck {...props} />
</Flex>
)
}

export default meta

type Story = StoryObj<CompletionCheckProps>

export const Default: Story = {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import type { CompletionCheckProps } from '@audius/harmony'
import styled, { css } from '@emotion/native'
import Animated, {
Easing,
interpolate,
useAnimatedStyle,
useDerivedValue,
withTiming
} from 'react-native-reanimated'

import { IconValidationCheck, IconValidationX } from 'app/harmony-native/icons'

import { Flex } from '../layout'

const CompletionIconBase = styled(Animated.View)({
position: 'absolute',
justifyContent: 'center',
alignItems: 'center',
height: 16,
width: 16,
borderRadius: 9999
})

const CompletionDefault = styled(CompletionIconBase)(({ theme }) => ({
borderWidth: 1,
borderStyle: 'solid',
borderColor: theme.color.neutral.neutral
}))

const useIconAnimation = (
value: CompletionCheckProps['value'],
iconValue: CompletionCheckProps['value']
) => {
const animationValue = useDerivedValue(() => {
return withTiming(value === iconValue ? 1 : 0, {
duration: 180,
easing: Easing.inOut(Easing.ease)
})
})

return useAnimatedStyle(() => {
const scale = interpolate(animationValue.value, [0, 0.75, 1], [0, 1.2, 1])
const opacity = interpolate(animationValue.value, [0, 1], [0.3, 1])
const zIndex = interpolate(animationValue.value, [0, 1], [0, 2])

return { zIndex, opacity, transform: [{ scale }] }
})
}

const CompletionError = ({ value }: CompletionCheckProps) => {
const animationStyle = useIconAnimation(value, 'error')

return (
<CompletionIconBase style={[animationStyle]}>
<IconValidationX />
</CompletionIconBase>
)
}

const CompletionSuccess = ({ value }: CompletionCheckProps) => {
const animationStyle = useIconAnimation(value, 'complete')

return (
<CompletionIconBase style={[animationStyle]}>
<IconValidationCheck />
</CompletionIconBase>
)
}

export const CompletionCheck = (props: CompletionCheckProps) => {
return (
<Flex
alignItems='center'
style={css({
position: 'relative',
width: 16,
height: 16
})}
>
<CompletionDefault />
<CompletionSuccess {...props} />
<CompletionError {...props} />
</Flex>
)
}