Created
July 26, 2021 05:21
-
-
Save sturmenta/47a0d55a703c97c144558996bdf18ac3 to your computer and use it in GitHub Desktop.
hex percentage - cta with fading
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
/* eslint-disable react/no-array-index-key */ | |
import React, {ReactNode} from 'react'; | |
import {SafeAreaView, View} from 'react-native'; | |
import {withTheme} from '../../Elements'; | |
import {baseTheme, darkTheme, PuraMenteTheme} from '../../../styles/base'; | |
import {makeStyles} from '../../Utils/MakeStylesHoc'; | |
interface CTAWithFadingProps { | |
theme: PuraMenteTheme; | |
children: () => void; | |
bgColorDarkTheme?: string; | |
bgColorLightTheme?: string; | |
} | |
const CTAWithFading: React.FC<CTAWithFadingProps> = ({ | |
theme, | |
children, | |
bgColorDarkTheme, | |
bgColorLightTheme, | |
}: CTAWithFadingProps) => { | |
const styles = useStyles(); | |
return ( | |
<SafeAreaView> | |
<View style={styles.fadingContainer}> | |
{Array.from({length: 100}).map((e, i) => { | |
const preHexNumber = (i * 255) / 100; | |
const hexNumber = preHexNumber.toString(16).split('.')[0].padStart(2, '0').replace('f0', 'ff'); | |
return ( | |
<View | |
key={i} | |
style={{ | |
height: 1, | |
backgroundColor: `${theme.name === 'dark' ? bgColorDarkTheme : bgColorLightTheme}${hexNumber}`, | |
}} | |
/> | |
); | |
})} | |
</View> | |
<View style={styles.childrenContainer}>{children() as ReactNode}</View> | |
</SafeAreaView> | |
); | |
}; | |
CTAWithFading.defaultProps = { | |
bgColorDarkTheme: darkTheme.background, | |
bgColorLightTheme: baseTheme.background, | |
}; | |
const useStyles = makeStyles((theme: PuraMenteTheme) => ({ | |
fadingContainer: { | |
position: 'absolute', | |
marginTop: -100, | |
right: 0, | |
left: 0, | |
}, | |
childrenContainer: { | |
backgroundColor: theme.background, | |
}, | |
})); | |
export default withTheme(CTAWithFading); |
Author
sturmenta
commented
Jul 26, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment