-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
193 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,4 +68,7 @@ dist/ | |
|
||
# Static storybook page | ||
.storybook_static | ||
.docs | ||
.docs | ||
|
||
# env.json | ||
env.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const fs = require('fs'); | ||
|
||
const mode = process.argv[2]; | ||
|
||
const modes = { | ||
app: 0, | ||
storybook: 1, | ||
}; | ||
|
||
fs.writeFileSync('env.json', `{LOAD_STORYBOOK:${!!modes[mode]}}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from 'react'; | ||
import {create} from 'react-test-renderer'; | ||
import {Text, View} from 'react-native'; | ||
import List, {TypeList} from './'; | ||
|
||
const data = [ | ||
{id: 1, nombre: 'nombre1'}, | ||
{id: 2, nombre: 'nombre2'}, | ||
]; | ||
|
||
const renderComponent = ({item}) => ( | ||
<View key={item.id}> | ||
<Text>{item.nombre}</Text> | ||
</View> | ||
); | ||
|
||
describe('List component', () => { | ||
describe('returns null when ', () => { | ||
it('data is not correct', () => { | ||
const {toJSON} = create(<List data={undefined} renderComponent={renderComponent} />); | ||
expect(toJSON()).toBeNull(); | ||
}); | ||
}); | ||
|
||
describe('render correctlt when', () => { | ||
it('data is array type and type is flatList per default', () => { | ||
const {toJSON} = create(<List data={data} renderComponent={renderComponent} />); | ||
expect(toJSON()).toBeTruthy(); | ||
}); | ||
|
||
it('data is array type and type is scrollView', () => { | ||
const {toJSON} = create( | ||
<List data={data} type={TypeList.ScrollView} renderComponent={renderComponent} /> | ||
); | ||
expect(toJSON()).toBeTruthy(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React, {FC} from 'react'; | ||
import {FlatList, ScrollView, FlatListProps, ScrollViewProps} from 'react-native'; | ||
|
||
type TypeData = string | number | object | [] | React.ReactElement; | ||
type RCProps = { | ||
item: TypeData; | ||
index: number; | ||
}; | ||
type TypeRenderComponent = ({item, index}: RCProps) => React.ReactElement; | ||
export enum TypeList { | ||
FlatList = 'flatList', | ||
ScrollView = 'scrollView', | ||
} | ||
|
||
interface ListProps { | ||
data: TypeData[] | undefined; | ||
renderComponent: TypeRenderComponent; | ||
type?: TypeList; | ||
} | ||
type MergedProps = ListProps & (FlatListProps<TypeData> | ScrollViewProps); | ||
|
||
const List: FC<MergedProps> = ({data, renderComponent, type = TypeList.FlatList, ...props}) => { | ||
if (!data?.length) { | ||
return null; | ||
} | ||
|
||
const FlatListComponent = () => <FlatList data={data} renderItem={renderComponent} {...props} />; | ||
const ScrollViewComponent = () => ( | ||
<ScrollView {...props}>{data.map((item, index) => renderComponent({item, index}))}</ScrollView> | ||
); | ||
|
||
return type === TypeList.FlatList ? <FlatListComponent /> : <ScrollViewComponent />; | ||
}; | ||
|
||
export default List; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import React from 'react'; | ||
import List from '../../../src/components/List'; | ||
import {StyleSheet, Text, View} from 'react-native'; | ||
import {white} from '../../../src/theme/palette'; | ||
|
||
export default { | ||
title: 'Components/List', | ||
argTypes: { | ||
type: { | ||
options: ['flatList', 'scrollView'], | ||
control: {type: 'select'}, | ||
}, | ||
}, | ||
}; | ||
|
||
const fakeData = [ | ||
{ | ||
id: 'bd7acbea-c1b1-46c2-aed5-3ad53abb28ba', | ||
title: 'First Item', | ||
}, | ||
{ | ||
id: '3ac68afc-c605-48d3-a4f8-fbd91aa97f63', | ||
title: 'Second Item', | ||
}, | ||
{ | ||
id: '58694a0f-3da1-471f-bd96-145571e29d72', | ||
title: 'Third Item', | ||
}, | ||
{ | ||
id: '4e8372e6-5c86-4b0c-9f17-1a1d56b9a0e1', | ||
title: 'Fourth Item', | ||
}, | ||
{ | ||
id: '8f4c57e8-2763-498d-9c99-720a1f4eae03', | ||
title: 'Fifth Item', | ||
}, | ||
{ | ||
id: 'f6fe346e-80b8-4f91-8f27-2a3d49d18e9b', | ||
title: 'Sixth Item', | ||
}, | ||
{ | ||
id: '9c2ec5bb-89b1-4a7d-9759-2f7d3187b3a2', | ||
title: 'Seventh Item', | ||
}, | ||
{ | ||
id: '2d8c54fb-1a7b-4e5a-946d-789864cf05c3', | ||
title: 'Eighth Item', | ||
}, | ||
{ | ||
id: '7e1e9e6d-586b-4b2e-90a2-21f20c1b6b9e', | ||
title: 'Ninth Item', | ||
}, | ||
{ | ||
id: 'b4962f5f-e7e1-4d0f-923a-7941e86c7c90', | ||
title: 'Tenth Item', | ||
}, | ||
]; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
height: 400, | ||
borderRadius: 6, | ||
overflow: 'scroll', | ||
}, | ||
wrapperChildren: { | ||
padding: 20, | ||
backgroundColor: white.main, | ||
marginBottom: 2, | ||
}, | ||
}); | ||
|
||
const renderComponent = ({item}) => ( | ||
<View key={item.id} style={styles.wrapperChildren}> | ||
<Text>{item.title}</Text> | ||
</View> | ||
); | ||
|
||
export const DefaultProps = (props) => ( | ||
<List {...props} style={styles.container} keyExtractor={(item) => item.id} /> | ||
); | ||
|
||
DefaultProps.storyName = 'Default List'; | ||
|
||
DefaultProps.args = { | ||
data: fakeData, | ||
type: 'flatList', | ||
renderComponent, | ||
}; |