import React from "react"; import { View, ImageSourcePropType, Text, StyleProp, ViewStyle, } from "react-native"; import color from "color"; import Image from "./Image"; import Card from "./DeprecatedCardWrapper"; import Elevation from "./Elevation"; import Icon from "./Icon"; import { withTheme } from "../core/theming"; import { GROUPS, FORM_TYPES, PROP_TYPES, COMPONENT_TYPES, createElevationType, createNumColumnsType, } from "../core/component-types"; import Config from "./Config"; import theme from "../styles/DefaultTheme"; import { justificationType } from "./Justification"; const ICON_CONTAINER_SIZE = Config.cardIconSize * 2; const ICON_CONTAINER_PADDING = Config.cardIconSize / 2 - 1; type Props = { image?: string | ImageSourcePropType; title?: string; leftDescription?: string; rightDescription?: string; textCentered: boolean; icon?: string; aspectRatio?: number; elevation?: number; numColumns?: number; theme: typeof theme; style?: StyleProp; onPress: () => void; }; const CardContainer: React.FC = ({ image = Config.cardImageUrl, title, leftDescription, rightDescription, textCentered, icon, aspectRatio = 1.5, elevation = 2, numColumns = 3, theme: { colors, roundness, typography }, style, onPress, ...rest }) => { let textJustification: justificationType; let titleStyle; if (textCentered && !rightDescription) { textJustification = "center"; } else { textJustification = "space-between"; } switch (numColumns) { case 2: titleStyle = typography.headline6; break; case 3: titleStyle = typography.headline5; break; } return ( {title ? ( {title} ) : null} {leftDescription ? ( {leftDescription} {rightDescription ? ( {rightDescription} ) : null} ) : null} {icon ? ( ) : null} ); }; export default withTheme(CardContainer); const SEED_DATA_PROPS = { image: { label: "Image", description: "Image", formType: FORM_TYPES.image, propType: PROP_TYPES.ASSET, defaultValue: null, editable: true, required: true, group: GROUPS.data, }, title: { label: "Title", description: "Text to display", formType: FORM_TYPES.string, propType: PROP_TYPES.STRING, defaultValue: "Beautiful West Coast Villa", editable: true, required: false, group: GROUPS.data, }, leftDescription: { label: "Left description", description: "Text to display on the left", formType: FORM_TYPES.string, propType: PROP_TYPES.STRING, defaultValue: "San Diego", editable: true, required: false, group: GROUPS.data, }, rightDescription: { label: "Right description", description: "Text to display on the right", formType: FORM_TYPES.string, propType: PROP_TYPES.STRING, defaultValue: "$100", editable: true, required: false, group: GROUPS.data, }, icon: { label: "Icon", description: "Icon to display on the top right", formType: FORM_TYPES.icon, propType: PROP_TYPES.STRING /* OR ASSET TODO TEST ME */, defaultValue: null, editable: true, required: false, group: GROUPS.basic, }, aspectRatio: { label: "Aspect ratio", description: "Aspect ratio of the image", formType: FORM_TYPES.aspectRatio, propType: PROP_TYPES.NUMBER, defaultValue: 1.5, editable: true, required: false, group: GROUPS.basic, }, textCentered: { label: "Centered Text", description: "Whether to center the text", formType: FORM_TYPES.boolean, propType: PROP_TYPES.BOOLEAN, defaultValue: false, editable: true, required: false, group: GROUPS.basic, }, elevation: createElevationType(2), }; export const SEED_DATA = [ { name: "Medium Card", tag: "CardContainer", description: "An elevated card with a title and description, that takes up half of its container.", category: COMPONENT_TYPES.card, layout: null, props: { ...SEED_DATA_PROPS, numColumns: createNumColumnsType({ defaultValue: 2, }), }, }, { name: "Large Card", tag: "CardContainer", description: "An elevated card with a title and description, that takes up its full container.", category: COMPONENT_TYPES.card, layout: null, props: { ...SEED_DATA_PROPS, numColumns: createNumColumnsType({ defaultValue: 3, }), }, }, ];