You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

108 lines
3.5 KiB

import React from "react"
import { View, TouchableOpacity, Text, StyleSheet } from "react-native"
import { colors } from "../components/Variables"
const styles = StyleSheet.create({
button: {
backgroundColor: colors.white_alpha,
borderWidth: 4,
borderColor: 'transparent',
borderRadius: 10,
paddingHorizontal: 20,
paddingVertical: 15,
alignItems: "center",
justifyContent: "center",
width: "100%",
marginTop: 15
},
text: {
color: colors.white,
fontSize: 20,
textAlign: "center"
},
subtitle: {
color: colors.white,
fontSize: 15,
textAlign: "center"
},
shadow: {
textShadowColor: 'rgba(0, 0, 0, 0.45)',
textShadowOffset: {width: -1, height: 1},
textShadowRadius: 2
},
buttonContainer: {
flexDirection: "row",
flexWrap: "wrap",
marginTop: 20,
justifyContent: "space-between",
overflow: "hidden",
borderRadius: 10
}
})
export const Button = ({ text, subtitle = null, isBig = false, colorize = false, color = false, noPadding = false, noBorder = false, halfSize = false, hasShadow = false, onPress = false }) => {
const buttonBig = isBig ? {fontSize: 25} : {}
const isClicked = colorize.clicked == colorize.id
let buttonColor = {backgroundColor: colors.white_alpha}
let planeButton = noPadding ? { borderRadius: 0, marginTop: 0, borderWidth: 0, borderBottomWidth: 1, borderColor: colors.white_alpha} : {}
let noBorderButton = noBorder ? { borderWidth: 0, borderBottomWidth: 0} : {}
let isHalf = halfSize ? { width: "48%", marginHorizontal: "1%"} : {}
if(colorize && colorize.answered) {
if(colorize.isCorrect) {
buttonColor = {backgroundColor: colors.green_light, borderColor: isClicked ? colors.white_alpha : 'transparent'}
} else {
if(isClicked) {
buttonColor = {backgroundColor: colors.red_light, borderColor: isClicked ? colors.white_alpha : 'transparent'}
}
}
}
if(color) {
buttonColor = {backgroundColor: color, borderColor: 'transparent'}
}
if(onPress) {
if(subtitle) {
return (
<TouchableOpacity onPress={onPress} style={[styles.button, buttonColor, planeButton, noBorderButton, isHalf]}>
<Text style={[styles.text, buttonBig, hasShadow ? styles.shadow : '', {fontWeight: "500"}]}>{text}</Text>
<Text style={[styles.subtitle, hasShadow ? styles.shadow : '']}>{subtitle}</Text>
</TouchableOpacity>
)
} else {
return (
<TouchableOpacity onPress={onPress} style={[styles.button, buttonColor, planeButton, noBorderButton, isHalf]}>
<Text style={[styles.text, buttonBig, hasShadow ? styles.shadow : '']}>{text}</Text>
</TouchableOpacity>
)
}
} else {
if(subtitle) {
return (
<View style={[styles.button, buttonColor, planeButton, noBorderButton, isHalf]}>
<Text style={[styles.text, buttonBig, hasShadow ? styles.shadow : ''], {fontWeight: "500"}}>{text}</Text>
<Text style={[styles.subtitle, hasShadow ? styles.shadow : '']}>{subtitle}</Text>
</View>
)
} else {
return (
<View style={[styles.button, buttonColor, planeButton, noBorderButton, isHalf]}>
<Text style={[styles.text, buttonBig, hasShadow ? styles.shadow : '']}>{text}</Text>
</View>
)
}
}
}
export const ButtonContainer = ({ children, isBoxed = false}) => {
let boxedStyle = isBoxed ? {borderWidth: 3, borderColor: colors.white_alpha2} : {}
return (
<View style={[styles.buttonContainer, boxedStyle]}>{children}</View>
)
}