diff --git a/src/components/Card/Card.tsx b/src/components/Card/Card.tsx new file mode 100644 index 0000000..f09d1c9 --- /dev/null +++ b/src/components/Card/Card.tsx @@ -0,0 +1,73 @@ +import React from "react"; + +import { Image, StyleSheet, View } from "react-native"; + +import { styled } from "nativewind"; + +import { CardType } from "./Card.types"; + +const Card: React.FC = ({ type, cardColor, imageURL, children }) => { + let cardStyle = { + ...style.baseCard, + ...cardColor?.[0] + }; + + let outlinedCardStyle = { + ...style.baseCard, + borderColor: cardColor?.[0].backgroundColor + }; + + if (type === "elevated") + cardStyle = StyleSheet.compose(cardStyle, style.elevatedCard as any); + + if (type === "outlined") + cardStyle = StyleSheet.compose( + outlinedCardStyle, + style.outlinedCard as any + ); + + return ( + + {imageURL && } + {children && ( + {children} + )} + + ); +}; + +export default styled(Card, { + props: { + cardColor: true + } +}); + +const style = StyleSheet.create({ + baseCard: { + borderRadius: 8, + height: "100%", + width: "100%" + }, + elevatedCard: { + shadowColor: "#000", + shadowOffset: { + width: 0, + height: 5 + }, + shadowOpacity: 0.36, + shadowRadius: 6.68 + }, + outlinedCard: { + borderWidth: 2 + }, + cardImage: { + width: "100%", + height: "50%", + borderTopLeftRadius: 6, + borderTopRightRadius: 6 + }, + childrenContainer: { + paddingVertical: 8, + paddingHorizontal: 16 + } +}); diff --git a/src/components/Card/Card.types.ts b/src/components/Card/Card.types.ts new file mode 100644 index 0000000..4f7bef4 --- /dev/null +++ b/src/components/Card/Card.types.ts @@ -0,0 +1,8 @@ +import React from "react"; + +export interface CardType { + type?: "elevated" | "outlined" | undefined; + cardColor?: [{ backgroundColor?: string | undefined }]; + imageURL?: string; + children?: React.ReactNode; +} diff --git a/src/components/Card/index.ts b/src/components/Card/index.ts new file mode 100644 index 0000000..c0424cd --- /dev/null +++ b/src/components/Card/index.ts @@ -0,0 +1 @@ +export { default } from "./Card"; diff --git a/src/components/Text/Text.tsx b/src/components/Text/Text.tsx index a3ebecc..577eeba 100644 --- a/src/components/Text/Text.tsx +++ b/src/components/Text/Text.tsx @@ -7,22 +7,15 @@ import { styled } from "nativewind"; import { TextType } from "./Text.types"; const Text: React.FC = ({ text, textColor, type }) => { - const generateTextStyle = ( - color: { color?: string | undefined } | undefined, - type: string | undefined - ): object => { - if (type === "title") { - return { ...style.title, ...color }; - } - if (type === "subtitle") { - return { ...style.subtitle, ...color }; - } - return { ...style.default, ...color }; - }; - - const generatedStyle = generateTextStyle(textColor?.[0], type); - - return {text}; + let textStyle = {...style.default, ...textColor?.[0]} + + if (type === "title") + textStyle = StyleSheet.compose(textStyle, style.title as any) + + if (type === "subtitle") + textStyle = StyleSheet.compose(textStyle, style.subtitle as any) + + return {text}; }; export default styled(Text, { diff --git a/src/components/index.ts b/src/components/index.ts index 417416b..7204108 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -2,4 +2,5 @@ export { default as Button } from "./Button"; export { default as Loader } from "./Loader"; export { default as ItemSeparator } from "./ItemSeparator"; export { default as TextInput } from "./TextInput"; +export { default as Card } from "./Card"; export { default as Text } from "./Text"; diff --git a/storybook/stories/Card/Card.stories.tsx b/storybook/stories/Card/Card.stories.tsx new file mode 100644 index 0000000..b5e006e --- /dev/null +++ b/storybook/stories/Card/Card.stories.tsx @@ -0,0 +1,102 @@ +// Card.stories.js + +import React from "react"; + +import { text, select, number } from "@storybook/addon-knobs"; + +import { storiesOf } from "@storybook/react-native"; + +import { Text, View } from "react-native"; +import { Button, Card, ItemSeparator } from "../../../src"; +import { action } from "@storybook/addon-actions"; + +storiesOf("Cards", module) + .addDecorator((getStory) => ( + + {getStory()} + + )) + .add("Elevated Card", () => { + return ( + + + + Card Title + + It is a long established fact that a reader will be distracted by + the readable content. + + +