|
| 1 | +import React from 'react' |
| 2 | +import { StyleSheet, View, ImageBackground } from 'react-native' |
| 3 | +import { Text, Space, Button } from '../index' |
| 4 | +import { DARK, GRAY, WHITE, RED, BLACK } from '../../constants' |
| 5 | +import { s, vs } from 'react-native-size-matters' |
| 6 | +import { ButtonApply } from './buttons' |
| 7 | + |
| 8 | +const styles = StyleSheet.create({ |
| 9 | + container: { |
| 10 | + width: '90%', |
| 11 | + height: vs(80), |
| 12 | + borderRadius: 8, |
| 13 | + backgroundColor: DARK, |
| 14 | + flexDirection: 'row', |
| 15 | + overflow: 'hidden' |
| 16 | + }, |
| 17 | + percentContainer: { |
| 18 | + width: s(80), |
| 19 | + backgroundColor: RED, |
| 20 | + flexDirection: 'row', |
| 21 | + alignItems: 'center', |
| 22 | + justifyContent: 'center' |
| 23 | + }, |
| 24 | + percentImageContainer: { |
| 25 | + color: BLACK, |
| 26 | + width: s(80), |
| 27 | + flexDirection: 'row', |
| 28 | + alignItems: 'center', |
| 29 | + justifyContent: 'center' |
| 30 | + }, |
| 31 | + infoPercentAdded: { |
| 32 | + flexDirection: 'column' |
| 33 | + }, |
| 34 | + infoContainer: { |
| 35 | + flex: 1, |
| 36 | + marginHorizontal: s(5), |
| 37 | + flexDirection: 'row', |
| 38 | + justifyContent: 'space-around' |
| 39 | + }, |
| 40 | + containerMid: { |
| 41 | + flex: 1.3, |
| 42 | + flexDirection: 'column', |
| 43 | + justifyContent: 'center' |
| 44 | + }, |
| 45 | + containerRight: { |
| 46 | + flex: 1, |
| 47 | + flexDirection: 'column', |
| 48 | + alignItems: 'center', |
| 49 | + justifyContent: 'center' |
| 50 | + }, |
| 51 | + percentNumberStyle: { |
| 52 | + color: WHITE, |
| 53 | + fontSize: 34 |
| 54 | + }, |
| 55 | + percentTextStyle: { |
| 56 | + color: WHITE, |
| 57 | + fontSize: 14 |
| 58 | + }, |
| 59 | + personalTextStyle: { |
| 60 | + color: WHITE, |
| 61 | + fontSize: 14, |
| 62 | + fontWeight: 'bold' |
| 63 | + }, |
| 64 | + prmocodeTextStyle: { |
| 65 | + color: WHITE, |
| 66 | + fontSize: 11 |
| 67 | + }, |
| 68 | + remainTextStyle: { |
| 69 | + color: GRAY, |
| 70 | + fontSize: 11 |
| 71 | + }, |
| 72 | + imageContainer: { |
| 73 | + width: 80, |
| 74 | + height: 80, |
| 75 | + justifyContent: 'center' |
| 76 | + }, |
| 77 | + text: { |
| 78 | + color: 'white', |
| 79 | + fontSize: 12, |
| 80 | + fontWeight: 'bold', |
| 81 | + textAlign: 'center' |
| 82 | + }, |
| 83 | + blackTextStyle: { |
| 84 | + color: BLACK |
| 85 | + } |
| 86 | +}) |
| 87 | +interface CardProductBagT { |
| 88 | + percentNumber: string |
| 89 | + promocodeText: string |
| 90 | + daysRemainNumber: string |
| 91 | + imagePromo: string |
| 92 | +} |
| 93 | + |
| 94 | +const { |
| 95 | + container, |
| 96 | + percentContainer, |
| 97 | + infoContainer, |
| 98 | + containerMid, |
| 99 | + containerRight, |
| 100 | + percentNumberStyle, |
| 101 | + percentTextStyle, |
| 102 | + infoPercentAdded, |
| 103 | + personalTextStyle, |
| 104 | + prmocodeTextStyle, |
| 105 | + remainTextStyle, |
| 106 | + imageContainer, |
| 107 | + percentImageContainer, |
| 108 | + blackTextStyle |
| 109 | +} = styles |
| 110 | + |
| 111 | +function CardPromo({ |
| 112 | + percentNumber = '10', |
| 113 | + promocodeText = 'mypromocode2020', |
| 114 | + daysRemainNumber = '6', |
| 115 | + imagePromo |
| 116 | +}: CardProductBagT) { |
| 117 | + // imagePromo = 'https://demotivation.ru/wp-content/uploads/2020/05/255095-Sepik-2048x1383.jpg' |
| 118 | + const image = { uri: imagePromo } |
| 119 | + |
| 120 | + return ( |
| 121 | + <View style={container}> |
| 122 | + {imagePromo ? ( |
| 123 | + <ImageBackground source={image} resizeMode="cover" style={imageContainer}> |
| 124 | + <View style={percentImageContainer}> |
| 125 | + <Text title={`${percentNumber}`} textStyle={[percentNumberStyle, blackTextStyle]} /> |
| 126 | + <View style={infoPercentAdded}> |
| 127 | + <Text title={'%'} textStyle={[percentTextStyle, blackTextStyle]} /> |
| 128 | + <Text title={'off'} textStyle={[percentTextStyle, blackTextStyle]} /> |
| 129 | + </View> |
| 130 | + </View> |
| 131 | + </ImageBackground> |
| 132 | + ) : ( |
| 133 | + <View style={percentContainer}> |
| 134 | + <Text title={`${percentNumber}`} textStyle={percentNumberStyle} /> |
| 135 | + <View style={infoPercentAdded}> |
| 136 | + <Text title={'%'} textStyle={percentTextStyle} /> |
| 137 | + <Text title={'off'} textStyle={percentTextStyle} /> |
| 138 | + </View> |
| 139 | + </View> |
| 140 | + )} |
| 141 | + <Space width={11} height={0} /> |
| 142 | + <View style={infoContainer}> |
| 143 | + <View style={containerMid}> |
| 144 | + <Text title={'Personal offer'} numberOfLines={1} textStyle={personalTextStyle} /> |
| 145 | + <Space height={4} /> |
| 146 | + <Text title={promocodeText} textStyle={prmocodeTextStyle} /> |
| 147 | + </View> |
| 148 | + <Space width={20} height={0} /> |
| 149 | + <View style={containerRight}> |
| 150 | + <Text title={`${daysRemainNumber} days remaining`} textStyle={remainTextStyle} /> |
| 151 | + <Space height={10} /> |
| 152 | + <ButtonApply onPress={() => {}} title={'Apply'} /> |
| 153 | + </View> |
| 154 | + </View> |
| 155 | + </View> |
| 156 | + ) |
| 157 | +} |
| 158 | + |
| 159 | +export { CardPromo } |
0 commit comments