Skip to content

Commit e03baa8

Browse files
committed
feat: create Cutout and Window components
1 parent f2d032d commit e03baa8

File tree

10 files changed

+154
-1
lines changed

10 files changed

+154
-1
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,7 @@ https://www.contributor-covenant.org/faq. Translations are available at https://
197197
#### TextInput
198198

199199
- [ ] Implement the TextInput component
200+
201+
#### Cutout
202+
203+
- [ ] Implement shadow
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React from 'react';
2+
import { Cutout, Text, Window } from 'react95-native';
3+
4+
import Container from '../util/Container';
5+
6+
const CutoutExample = () => {
7+
return (
8+
<Container>
9+
<Container.Section title='Usage:'>
10+
<Window style={{ padding: 12 }}>
11+
<Cutout style={{ height: 120 }}>
12+
<Text>
13+
React95 React95 React95 React95 React95 React95 React95 React95
14+
React95 React95
15+
</Text>
16+
<Text>
17+
React95 React95 React95 React95 React95 React95 React95 React95
18+
React95 React95
19+
</Text>
20+
<Text>
21+
React95 React95 React95 React95 React95 React95 React95 React95
22+
React95 React95
23+
</Text>
24+
<Text>
25+
React95 React95 React95 React95 React95 React95 React95 React95
26+
React95 React95
27+
</Text>
28+
</Cutout>
29+
</Window>
30+
</Container.Section>
31+
</Container>
32+
);
33+
};
34+
35+
export default CutoutExample;

example/src/util/examples.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import ButtonExample from '../examples/ButtonExample';
22
import TextInputExample from '../examples/TextInputExample';
33
import PanelExample from '../examples/PanelExample';
44
import AppBarExample from '../examples/AppBarExample';
5+
import CutoutExample from '../examples/CutoutExample';
56

67
export default [
78
{ name: 'ButtonExample', component: ButtonExample, title: 'Button' },
89
{ name: 'TextInputExample', component: TextInputExample, title: 'TextInput' },
910
{ name: 'PanelExample', component: PanelExample, title: 'Panel' },
10-
{ name: 'AppBarExample', component: AppBarExample, title: 'AppBar' }
11+
{ name: 'AppBarExample', component: AppBarExample, title: 'AppBar' },
12+
{ name: 'CutoutExample', component: CutoutExample, title: 'Cutout' }
1113
];

src/Cutout/Cutout.spec.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react';
2+
import { render } from '@testing-library/react-native';
3+
4+
import { testId } from './Cutout';
5+
import { Cutout, Text } from '..';
6+
7+
describe('<Cutout />', () => {
8+
it('should render children', () => {
9+
const { getByTestId } = render(
10+
<Cutout>
11+
<Text>This is a Cutout</Text>
12+
</Cutout>
13+
);
14+
15+
expect(getByTestId(testId)).toHaveTextContent('This is a Cutout');
16+
});
17+
18+
it('should render custom styles', () => {
19+
const style = { padding: 12 };
20+
21+
const { getByTestId } = render(
22+
<Cutout style={style}>
23+
<Text>Potatoe</Text>
24+
</Cutout>
25+
);
26+
27+
expect(getByTestId(testId)).toHaveStyle(style);
28+
});
29+
});

src/Cutout/Cutout.tsx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import React from 'react';
2+
import { StyleSheet, View, ScrollView } from 'react-native';
3+
4+
import { border } from '../common/styles';
5+
import { original as theme } from '../common/themes';
6+
7+
export const testId = 'cutout';
8+
9+
type Props = {
10+
children: React.ReactNode;
11+
// shadow?: boolean;
12+
style?: Object;
13+
};
14+
15+
const Cutout = ({ children, style = {} }: Props) => {
16+
return (
17+
<ScrollView style={[styles.container, style]} testID={testId}>
18+
<View style={styles.beforeContainer}>
19+
<View style={styles.content}>{children}</View>
20+
</View>
21+
</ScrollView>
22+
);
23+
};
24+
25+
const styles = StyleSheet.create({
26+
container: {
27+
...border.wellInverted,
28+
backgroundColor: theme.material,
29+
padding: 2,
30+
borderStyle: 'solid',
31+
lineHeight: 1.5
32+
},
33+
beforeContainer: {
34+
borderStyle: 'solid',
35+
borderWidth: 2,
36+
margin: -2,
37+
borderLeftColor: theme.borderDarkest,
38+
borderTopColor: theme.borderDarkest,
39+
borderRightColor: theme.borderLight,
40+
borderBottomColor: theme.borderLight
41+
// ${props => props.shadow && `box-shadow:${insetShadow};`}
42+
},
43+
content: {
44+
width: '100%',
45+
padding: 4
46+
}
47+
});
48+
49+
export default Cutout;

src/Cutout/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './Cutout';

src/Window/Window.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react';
2+
import { StyleSheet, View } from 'react-native';
3+
4+
import { border, box } from '../common/styles';
5+
6+
type Props = {
7+
children: React.ReactNode;
8+
style?: Object;
9+
};
10+
11+
const Window = ({ children, style = {} }: Props) => {
12+
return <View style={[styles.container, style]}>{children}</View>;
13+
};
14+
15+
const styles = StyleSheet.create({
16+
container: {
17+
padding: 4,
18+
...border.windowBorders,
19+
...box.default
20+
}
21+
});
22+
23+
export default Window;

src/Window/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './Window';

src/common/styles.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ export const border = StyleSheet.create({
4848
});
4949

5050
export const box = StyleSheet.create({
51+
/* createBoxStyles() */
52+
default: {
53+
flexDirection: 'row',
54+
backgroundColor: theme.material,
55+
color: theme.materialText
56+
},
57+
/* createFlatBoxStyles() */
5158
flat: {
5259
position: 'relative',
5360
flexDirection: 'row',

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ export { default as TextInput } from './TextInput';
33
export { default as Panel } from './Panel';
44
export { default as Text } from './Text';
55
export { default as AppBar } from './AppBar';
6+
export { default as Cutout } from './Cutout';
7+
export { default as Window } from './Window';
68

79
export * from './common/themes';

0 commit comments

Comments
 (0)