Skip to content

Commit

Permalink
feat(card): add Card component
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur Bien committed Dec 13, 2020
1 parent 10089c5 commit d6910f4
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 4 deletions.
3 changes: 1 addition & 2 deletions example/src/ExamplesScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const ExamplesScreen = () => {
</ScrollPanel>
<Panel variant='outside' style={styles.panel}>
<Divider />
<Cutout style={styles.cutout}>
<Cutout style={[styles.cutout, {backgroundColor: currentTheme.canvas}]}>
<ScrollView
style={styles.scrollView}
contentContainerStyle={styles.content}
Expand Down Expand Up @@ -91,7 +91,6 @@ const styles = StyleSheet.create({
paddingTop: 12,
},
cutout: {
backgroundColor: 'white',
flexGrow: 1,
marginTop: 8,
},
Expand Down
38 changes: 38 additions & 0 deletions example/src/examples/CardExample.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React, { useContext } from 'react';
import { Card, Text } from 'react95-native';

import Container from '../util/Container';
import { LocalThemeContext } from '../util/LocalThemeContext';

const TextExample = () => {
const { theme } = useContext(LocalThemeContext);
return (
<Container style={[{ backgroundColor: theme.materialDark }]}>
<Container.Section title='Default:'>
<Card style={[{ height: 300 }]}>
<Card.Content>
<Text>Simple text</Text>
</Card.Content>
</Card>
</Container.Section>

<Container.Section title='High elevation:'>
<Card elevation={8} style={[{ height: 100 }]}>
<Card.Content>
<Text>Simple text</Text>
</Card.Content>
</Card>
</Container.Section>

<Container.Section title='No elevation:'>
<Card elevation={0} style={[{ height: 100 }]}>
<Card.Content>
<Text linkUrl='https://react95.io'>React95 website</Text>
</Card.Content>
</Card>
</Container.Section>
</Container>
);
};

export default TextExample;
2 changes: 2 additions & 0 deletions example/src/examples/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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',
Expand Down
5 changes: 3 additions & 2 deletions example/src/util/Container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ const styles = StyleSheet.create({

type ContainerProps = {
children: React.ReactNode;
style: any
};

const Container = ({ children }: ContainerProps) => (
<ScrollView style={styles.container} contentContainerStyle={styles.content}>
const Container = ({ children, style }: ContainerProps) => (
<ScrollView style={[styles.container, style]} contentContainerStyle={styles.content}>
{children}
</ScrollView>
);
Expand Down
75 changes: 75 additions & 0 deletions src/Card/Card.tsx
Original file line number Diff line number Diff line change
@@ -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<ViewStyle>;
elevation?: number;
};

const Card = ({ children, style = {}, elevation = 2 }: Props) => {
const theme = useContext(ThemeContext);
return (
<View style={[styles.wrapper, style]}>
<View
style={[
styles.inner,
{
marginRight: elevation,
marginBottom: elevation,
},
]}
>
{elevation !== 0 && (
<View
style={[
styles.shadow,
{
top: elevation,
left: elevation,
width: '100%',
height: '100%',
backgroundColor: theme.borderDarkest,
},
]}
/>
)}
<View
style={[
styles.card,
{
backgroundColor: theme.canvas,
borderColor: theme.borderDarkest,
},
]}
>
{children}
</View>
</View>
</View>
);
};

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;
25 changes: 25 additions & 0 deletions src/Card/CardContent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import { StyleProp, StyleSheet, ViewStyle, View } from 'react-native';

type Props = {
children?: React.ReactNode;
style?: StyleProp<ViewStyle>;
};

const CardContent = ({ children, style = {} }: Props) => {
return (
<View style={[styles.wrapper, style]}>
{children}
</View>
);
};



const styles = StyleSheet.create({
wrapper: {
padding: 8,
},
});

export default CardContent;
1 change: 1 addition & 0 deletions src/Card/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default from './Card';
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

0 comments on commit d6910f4

Please sign in to comment.