|
| 1 | +import * as React from "react"; |
| 2 | +import { Image, Pressable, StyleSheet, Text, View } from "react-native"; |
| 3 | +import { colors, paddings, rounded, textStyles } from "../../style"; |
| 4 | + |
| 5 | +const CustomCard = ({ |
| 6 | + iconSource = {}, |
| 7 | + title, |
| 8 | + description, |
| 9 | + size = "md", // "md" oder "lg" |
| 10 | + state = "default", // State: "active", "default" oder "disabled" |
| 11 | + showDescription = true, // Standardmäßig aktiv |
| 12 | + onPress |
| 13 | +}) => { |
| 14 | + // Bestimme den Container-Stil: |
| 15 | + // Im active-Zustand wird der aktive Style genutzt, |
| 16 | + // In default und disabled wird der Container-Style wie bei disabled angewandt. |
| 17 | + const containerStyle = |
| 18 | + state === "active" |
| 19 | + ? size === "md" |
| 20 | + ? styles.cardMdContainer |
| 21 | + : [styles.cardLgContainer, !showDescription && { height: 92}] |
| 22 | + : size === "md" |
| 23 | + ? styles.cardMdDisabled |
| 24 | + : [styles.cardLgDisabled, !showDescription && { height: 92}]; |
| 25 | + |
| 26 | + // Beim Text: Nur im disabled-Zustand wird durchgestrichen. |
| 27 | + const titleStyle = [styles.title, state === "disabled" && styles.strikeThroughText]; |
| 28 | + const descriptionStyle = [styles.description, state === "disabled" && styles.strikeThroughText]; |
| 29 | + |
| 30 | + // Text-Wrapper (für md bzw. lg) |
| 31 | + const textWrapperStyle = size === "md" ? styles.textWrapperMd : styles.textWrapperLg; |
| 32 | + |
| 33 | + // Icon: Falls iconSource ein React-Element ist, setzen wir per cloneElement die Farbe auf Schwarz. |
| 34 | + const iconElement = React.isValidElement(iconSource) |
| 35 | + ? React.cloneElement(iconSource, { color: colors.black }) |
| 36 | + : iconSource; |
| 37 | + |
| 38 | + return ( |
| 39 | + <Pressable style={containerStyle} onPress={onPress}> |
| 40 | + <View style={[styles.iconContainer, size === "lg" && { alignSelf: "flex-start" }]}> |
| 41 | + {iconElement} |
| 42 | + </View> |
| 43 | + <View style={[textWrapperStyle, size === "lg" && { alignSelf: "flex-start" }]}> |
| 44 | + <Text style={[titleStyle, {ellipsizeMode: "tail"}]} numberOfLines={1}> |
| 45 | + {title} |
| 46 | + </Text> |
| 47 | + {showDescription && ( |
| 48 | + <Text style={descriptionStyle} numberOfLines={1}> |
| 49 | + {description} |
| 50 | + </Text> |
| 51 | + )} |
| 52 | + </View> |
| 53 | + </Pressable> |
| 54 | + );; |
| 55 | +}; |
| 56 | + |
| 57 | +const styles = StyleSheet.create({ |
| 58 | + // ------------------------------- |
| 59 | + // Active Styles (voll aktiv) |
| 60 | + // ------------------------------- |
| 61 | + cardMdContainer: { |
| 62 | + gap: paddings.p_12, |
| 63 | + padding: paddings.p_12, |
| 64 | + flexDirection: "row", |
| 65 | + alignItems: "center", |
| 66 | + backgroundColor: colors.white, |
| 67 | + borderStyle: "solid", |
| 68 | + borderRadius: rounded.rounded_lg, |
| 69 | + width: 160, |
| 70 | + height: 64, |
| 71 | + borderWidth: 2, |
| 72 | + borderColor: colors.black, |
| 73 | + }, |
| 74 | + cardLgContainer: { |
| 75 | + gap: paddings.p_16, |
| 76 | + padding: paddings.p_16, |
| 77 | + alignItems: "center", |
| 78 | + backgroundColor: colors.white, |
| 79 | + borderStyle: "solid", |
| 80 | + borderRadius: rounded.rounded_lg, |
| 81 | + width: 160, |
| 82 | + height: 112, |
| 83 | + borderWidth: 2, |
| 84 | + borderColor: colors.black, |
| 85 | + }, |
| 86 | + // ------------------------------- |
| 87 | + // Disabled Styles (wie bisher) |
| 88 | + // ------------------------------- |
| 89 | + // (Sowohl für default als auch disabled wird hier der Container-Stil genutzt – |
| 90 | + // der Unterschied zeigt sich nur beim Text: bei disabled wird der Text durchgestrichen.) |
| 91 | + cardMdDisabled: { |
| 92 | + gap: paddings.p_12, |
| 93 | + padding: paddings.p_12, |
| 94 | + flexDirection: "row", |
| 95 | + alignItems: "center", |
| 96 | + backgroundColor: colors.white, |
| 97 | + borderStyle: "solid", |
| 98 | + borderRadius: rounded.rounded_lg, |
| 99 | + width: 160, |
| 100 | + height: 64, |
| 101 | + borderWidth: 1, |
| 102 | + borderColor: colors.grey200, |
| 103 | + }, |
| 104 | + cardLgDisabled: { |
| 105 | + gap: paddings.p_16, |
| 106 | + padding: paddings.p_16, |
| 107 | + alignItems: "center", |
| 108 | + backgroundColor: colors.white, |
| 109 | + borderStyle: "solid", |
| 110 | + borderRadius: rounded.rounded_lg, |
| 111 | + width: 160, |
| 112 | + height: 112, |
| 113 | + borderWidth: 1, |
| 114 | + borderColor: colors.grey200, |
| 115 | + |
| 116 | + }, |
| 117 | + // ------------------------------- |
| 118 | + // Icon-Container |
| 119 | + // ------------------------------- |
| 120 | + iconContainer: { |
| 121 | + justifyContent: "center", |
| 122 | + alignItems: "center", |
| 123 | + }, |
| 124 | + // ------------------------------- |
| 125 | + // Text Wrapper |
| 126 | + // ------------------------------- |
| 127 | + textWrapperMd: { |
| 128 | + width: "100%", |
| 129 | + justifyContent: "center", |
| 130 | + }, |
| 131 | + textWrapperLg: { |
| 132 | + width: "100%", |
| 133 | + justifyContent: "center", |
| 134 | + }, |
| 135 | + // ------------------------------- |
| 136 | + // Text-Styles |
| 137 | + // ------------------------------- |
| 138 | + title: { |
| 139 | + ...textStyles.text_sm_semibold, |
| 140 | + textAlign: "left", |
| 141 | + overflow: "hidden", |
| 142 | + alignSelf: "stretch", |
| 143 | + }, |
| 144 | + description: { |
| 145 | + ...textStyles.text_sm_regular, |
| 146 | + color: colors.black, |
| 147 | + overflow: "hidden", |
| 148 | + alignSelf: "stretch", |
| 149 | + }, |
| 150 | + // Durchgestrichener Text (nur im disabled-Zustand angewandt) |
| 151 | + strikeThroughText: { |
| 152 | + textDecorationLine: "line-through", |
| 153 | + color: colors.grey500, |
| 154 | + }, |
| 155 | +}); |
| 156 | + |
| 157 | +export default CustomCard; |
0 commit comments