From d6910f4106746f482635cba78278f00475584912 Mon Sep 17 00:00:00 2001 From: Artur Bien Date: Sun, 13 Dec 2020 12:34:35 +0100 Subject: [PATCH] feat(card): add Card component --- example/src/ExamplesScreen.tsx | 3 +- example/src/examples/CardExample.tsx | 38 ++++++++++++++ example/src/examples/index.tsx | 2 + example/src/util/Container.tsx | 5 +- src/Card/Card.tsx | 75 ++++++++++++++++++++++++++++ src/Card/CardContent.tsx | 25 ++++++++++ src/Card/index.ts | 1 + src/index.ts | 1 + 8 files changed, 146 insertions(+), 4 deletions(-) create mode 100644 example/src/examples/CardExample.tsx create mode 100644 src/Card/Card.tsx create mode 100644 src/Card/CardContent.tsx create mode 100644 src/Card/index.ts diff --git a/example/src/ExamplesScreen.tsx b/example/src/ExamplesScreen.tsx index 1804ed6..5959ca0 100644 --- a/example/src/ExamplesScreen.tsx +++ b/example/src/ExamplesScreen.tsx @@ -34,7 +34,7 @@ const ExamplesScreen = () => { - + { + const { theme } = useContext(LocalThemeContext); + return ( + + + + + Simple text + + + + + + + + Simple text + + + + + + + + React95 website + + + + + ); +}; + +export default TextExample; diff --git a/example/src/examples/index.tsx b/example/src/examples/index.tsx index c027b7c..92cbc97 100644 --- a/example/src/examples/index.tsx +++ b/example/src/examples/index.tsx @@ -1,5 +1,6 @@ import AppBarExample from './AppBarExample'; import ButtonExample from './ButtonExample'; +import CardExample from './CardExample'; import CheckboxExample from './CheckboxExample'; import CutoutExample from './CutoutExample'; import DesktopExample from './DesktopExample'; @@ -52,6 +53,7 @@ export default [ title: 'Layout', items: [ { name: 'AppBarExample', component: AppBarExample, title: 'AppBar' }, + { name: 'CardExample', component: CardExample, title: 'Card' }, { name: 'CutoutExample', component: CutoutExample, title: 'Cutout' }, { name: 'DividerExample', diff --git a/example/src/util/Container.tsx b/example/src/util/Container.tsx index 56cb17d..590aa49 100644 --- a/example/src/util/Container.tsx +++ b/example/src/util/Container.tsx @@ -23,10 +23,11 @@ const styles = StyleSheet.create({ type ContainerProps = { children: React.ReactNode; + style: any }; -const Container = ({ children }: ContainerProps) => ( - +const Container = ({ children, style }: ContainerProps) => ( + {children} ); diff --git a/src/Card/Card.tsx b/src/Card/Card.tsx new file mode 100644 index 0000000..5292063 --- /dev/null +++ b/src/Card/Card.tsx @@ -0,0 +1,75 @@ +import React, { useContext } from 'react'; +import { StyleProp, StyleSheet, ViewStyle, View } from 'react-native'; +import { ThemeContext } from '../common/theming/Theme'; + +import CardContent from './CardContent'; + +type Props = { + children?: React.ReactNode; + style?: StyleProp; + elevation?: number; +}; + +const Card = ({ children, style = {}, elevation = 2 }: Props) => { + const theme = useContext(ThemeContext); + return ( + + + {elevation !== 0 && ( + + )} + + {children} + + + + ); +}; + +const styles = StyleSheet.create({ + wrapper: { + flex: 1, + position: 'relative', + }, + inner: { + flexGrow: 1, + }, + card: { + borderWidth: 2, + flexGrow: 1, + }, + shadow: { + position: 'absolute', + }, +}); + +Card.Content = CardContent; + +export default Card; diff --git a/src/Card/CardContent.tsx b/src/Card/CardContent.tsx new file mode 100644 index 0000000..2d7e29a --- /dev/null +++ b/src/Card/CardContent.tsx @@ -0,0 +1,25 @@ +import React from 'react'; +import { StyleProp, StyleSheet, ViewStyle, View } from 'react-native'; + +type Props = { + children?: React.ReactNode; + style?: StyleProp; +}; + +const CardContent = ({ children, style = {} }: Props) => { + return ( + + {children} + + ); +}; + + + +const styles = StyleSheet.create({ + wrapper: { + padding: 8, + }, +}); + +export default CardContent; diff --git a/src/Card/index.ts b/src/Card/index.ts new file mode 100644 index 0000000..375fa91 --- /dev/null +++ b/src/Card/index.ts @@ -0,0 +1 @@ +export default from './Card'; \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 3bbab60..c42437f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,5 +18,6 @@ export { default as ScrollView } from './ScrollView'; export { default as Hourglass } from './Hourglass'; export { default as List } from './List'; export { default as ScrollPanel } from './ScrollPanel'; +export { default as Card } from './Card'; export * from './common/theming';