Skip to content

Commit

Permalink
feat: create Cutout and Window components
Browse files Browse the repository at this point in the history
  • Loading branch information
luizbaldi committed Nov 11, 2020
1 parent f2d032d commit e03baa8
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,7 @@ https://www.contributor-covenant.org/faq. Translations are available at https://
#### TextInput

- [ ] Implement the TextInput component

#### Cutout

- [ ] Implement shadow
35 changes: 35 additions & 0 deletions example/src/examples/CutoutExample.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react';
import { Cutout, Text, Window } from 'react95-native';

import Container from '../util/Container';

const CutoutExample = () => {
return (
<Container>
<Container.Section title='Usage:'>
<Window style={{ padding: 12 }}>
<Cutout style={{ height: 120 }}>
<Text>
React95 React95 React95 React95 React95 React95 React95 React95
React95 React95
</Text>
<Text>
React95 React95 React95 React95 React95 React95 React95 React95
React95 React95
</Text>
<Text>
React95 React95 React95 React95 React95 React95 React95 React95
React95 React95
</Text>
<Text>
React95 React95 React95 React95 React95 React95 React95 React95
React95 React95
</Text>
</Cutout>
</Window>
</Container.Section>
</Container>
);
};

export default CutoutExample;
4 changes: 3 additions & 1 deletion example/src/util/examples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import ButtonExample from '../examples/ButtonExample';
import TextInputExample from '../examples/TextInputExample';
import PanelExample from '../examples/PanelExample';
import AppBarExample from '../examples/AppBarExample';
import CutoutExample from '../examples/CutoutExample';

export default [
{ name: 'ButtonExample', component: ButtonExample, title: 'Button' },
{ name: 'TextInputExample', component: TextInputExample, title: 'TextInput' },
{ name: 'PanelExample', component: PanelExample, title: 'Panel' },
{ name: 'AppBarExample', component: AppBarExample, title: 'AppBar' }
{ name: 'AppBarExample', component: AppBarExample, title: 'AppBar' },
{ name: 'CutoutExample', component: CutoutExample, title: 'Cutout' }
];
29 changes: 29 additions & 0 deletions src/Cutout/Cutout.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import { render } from '@testing-library/react-native';

import { testId } from './Cutout';
import { Cutout, Text } from '..';

describe('<Cutout />', () => {
it('should render children', () => {
const { getByTestId } = render(
<Cutout>
<Text>This is a Cutout</Text>
</Cutout>
);

expect(getByTestId(testId)).toHaveTextContent('This is a Cutout');
});

it('should render custom styles', () => {
const style = { padding: 12 };

const { getByTestId } = render(
<Cutout style={style}>
<Text>Potatoe</Text>
</Cutout>
);

expect(getByTestId(testId)).toHaveStyle(style);
});
});
49 changes: 49 additions & 0 deletions src/Cutout/Cutout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React from 'react';
import { StyleSheet, View, ScrollView } from 'react-native';

import { border } from '../common/styles';
import { original as theme } from '../common/themes';

export const testId = 'cutout';

type Props = {
children: React.ReactNode;
// shadow?: boolean;
style?: Object;
};

const Cutout = ({ children, style = {} }: Props) => {
return (
<ScrollView style={[styles.container, style]} testID={testId}>
<View style={styles.beforeContainer}>
<View style={styles.content}>{children}</View>
</View>
</ScrollView>
);
};

const styles = StyleSheet.create({
container: {
...border.wellInverted,
backgroundColor: theme.material,
padding: 2,
borderStyle: 'solid',
lineHeight: 1.5
},
beforeContainer: {
borderStyle: 'solid',
borderWidth: 2,
margin: -2,
borderLeftColor: theme.borderDarkest,
borderTopColor: theme.borderDarkest,
borderRightColor: theme.borderLight,
borderBottomColor: theme.borderLight
// ${props => props.shadow && `box-shadow:${insetShadow};`}
},
content: {
width: '100%',
padding: 4
}
});

export default Cutout;
1 change: 1 addition & 0 deletions src/Cutout/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './Cutout';
23 changes: 23 additions & 0 deletions src/Window/Window.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import { StyleSheet, View } from 'react-native';

import { border, box } from '../common/styles';

type Props = {
children: React.ReactNode;
style?: Object;
};

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

const styles = StyleSheet.create({
container: {
padding: 4,
...border.windowBorders,
...box.default
}
});

export default Window;
1 change: 1 addition & 0 deletions src/Window/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './Window';
7 changes: 7 additions & 0 deletions src/common/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ export const border = StyleSheet.create({
});

export const box = StyleSheet.create({
/* createBoxStyles() */
default: {
flexDirection: 'row',
backgroundColor: theme.material,
color: theme.materialText
},
/* createFlatBoxStyles() */
flat: {
position: 'relative',
flexDirection: 'row',
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ export { default as TextInput } from './TextInput';
export { default as Panel } from './Panel';
export { default as Text } from './Text';
export { default as AppBar } from './AppBar';
export { default as Cutout } from './Cutout';
export { default as Window } from './Window';

export * from './common/themes';

0 comments on commit e03baa8

Please sign in to comment.