From 61c6fef2640a622aa43fe54833fbcd8d5e592480 Mon Sep 17 00:00:00 2001 From: Satyajit Sahoo Date: Sun, 2 Sep 2018 03:46:33 +0200 Subject: [PATCH] BREAKING: replace ListSection.* and DrawerSection.* with List.* and Drawer.* (#524) --- docs/index.js | 22 +++++++----- example/DrawerItems.js | 12 +++---- example/src/ButtonExample.js | 18 +++++----- example/src/ChipExample.js | 10 +++--- example/src/DividerExample.js | 4 +-- example/src/ExampleList.js | 4 +-- example/src/ListAccordionExample.js | 48 +++++++++++++------------- example/src/ListSectionExample.js | 38 +++++++++----------- src/components/Drawer/Drawer.js | 7 ++++ src/components/Drawer/DrawerItem.js | 6 ++-- src/components/Drawer/DrawerSection.js | 16 ++++----- src/components/List/List.js | 13 +++++++ src/components/List/ListAccordion.js | 14 ++++---- src/components/List/ListIcon.js | 6 ++-- src/components/List/ListItem.js | 8 ++--- src/components/List/ListSection.js | 24 +++++-------- src/index.js | 7 ++-- 17 files changed, 135 insertions(+), 122 deletions(-) create mode 100644 src/components/Drawer/Drawer.js create mode 100644 src/components/List/List.js diff --git a/docs/index.js b/docs/index.js index d2ed52a..7767982 100644 --- a/docs/index.js +++ b/docs/index.js @@ -48,12 +48,16 @@ function getPages() { return file; }) .reduce((acc, file) => { - const matches = fs - .readFileSync(file) - .toString() - .match(/\/\/ @component (.\/\w+\.js)/gm); - if (matches && matches.length) { - const componentFiles = matches.map(line => { + const content = fs.readFileSync(file).toString(); + + if (/import \* as React/.test(content)) { + acc.push(file); + } + + const match = content.match(/\/\/ @component (.\/\w+\.js)/gm); + + if (match && match.length) { + const componentFiles = match.map(line => { const fileName = line.split(' ')[2]; return require.resolve( path.join( @@ -65,9 +69,11 @@ function getPages() { ) ); }); - return [...acc, file, ...componentFiles]; + + acc.push(...componentFiles); } - return [...acc, file]; + + return acc; }, []) .filter((name, index, self) => self.indexOf(name) === index) .sort((a, b) => { diff --git a/example/DrawerItems.js b/example/DrawerItems.js index 9d603c4..97cf679 100644 --- a/example/DrawerItems.js +++ b/example/DrawerItems.js @@ -3,7 +3,7 @@ import * as React from 'react'; import { View, StyleSheet, Platform } from 'react-native'; import { - DrawerSection, + Drawer, withTheme, Switch, TouchableRipple, @@ -46,9 +46,9 @@ class DrawerItems extends React.Component { return ( - + {DrawerItemsData.map((props, index) => ( - { onPress={() => this._setDrawerItem(index)} /> ))} - + - + Dark Theme @@ -79,7 +79,7 @@ class DrawerItems extends React.Component { - + ); } diff --git a/example/src/ButtonExample.js b/example/src/ButtonExample.js index 3b3ef78..699c2bc 100644 --- a/example/src/ButtonExample.js +++ b/example/src/ButtonExample.js @@ -2,7 +2,7 @@ import * as React from 'react'; import { View, ScrollView, StyleSheet, Image } from 'react-native'; -import { Button, ListSection, withTheme } from 'react-native-paper'; +import { Button, List, withTheme } from 'react-native-paper'; import type { Theme } from 'react-native-paper/types'; type Props = { @@ -23,7 +23,7 @@ class ButtonExample extends React.Component { - + - - + + - - + + - - + + - + ); } diff --git a/example/src/ChipExample.js b/example/src/ChipExample.js index 041de34..b1be708 100644 --- a/example/src/ChipExample.js +++ b/example/src/ChipExample.js @@ -2,7 +2,7 @@ import * as React from 'react'; import { View, ScrollView, StyleSheet, Image } from 'react-native'; -import { Chip, ListSection, withTheme } from 'react-native-paper'; +import { Chip, List, withTheme } from 'react-native-paper'; import type { Theme } from 'react-native-paper/types'; type Props = { @@ -19,7 +19,7 @@ class ChipExample extends React.Component { - + {}} style={styles.chip}> Simple @@ -67,8 +67,8 @@ class ChipExample extends React.Component { Avatar (disabled) - - + + {}} style={styles.chip}> Simple @@ -125,7 +125,7 @@ class ChipExample extends React.Component { Avatar (disabled) - + ); } diff --git a/example/src/DividerExample.js b/example/src/DividerExample.js index 42d69ad..3430902 100644 --- a/example/src/DividerExample.js +++ b/example/src/DividerExample.js @@ -2,7 +2,7 @@ import * as React from 'react'; import { FlatList } from 'react-native'; -import { Divider, ListSection, withTheme } from 'react-native-paper'; +import { Divider, List, withTheme } from 'react-native-paper'; import type { Theme } from 'react-native-paper/types'; type Props = { @@ -21,7 +21,7 @@ const DividerExample = (props: Props) => { return ( } + renderItem={({ item }) => } keyExtractor={item => item} ItemSeparatorComponent={Divider} data={items} diff --git a/example/src/ExampleList.js b/example/src/ExampleList.js index b18af09..e506865 100644 --- a/example/src/ExampleList.js +++ b/example/src/ExampleList.js @@ -2,7 +2,7 @@ import * as React from 'react'; import { FlatList } from 'react-native'; -import { ListSection, Divider, withTheme } from 'react-native-paper'; +import { List, Divider, withTheme } from 'react-native-paper'; import BottomNavigationExample from './BottomNavigationExample'; import ButtonExample from './ButtonExample'; import CardExample from './CardExample'; @@ -63,7 +63,7 @@ class ExampleList extends React.Component { }; _renderItem = ({ item }) => ( - this.props.navigation.navigate(item.id)} /> diff --git a/example/src/ListAccordionExample.js b/example/src/ListAccordionExample.js index 2df915c..2a1c458 100644 --- a/example/src/ListAccordionExample.js +++ b/example/src/ListAccordionExample.js @@ -2,7 +2,7 @@ import * as React from 'react'; import { ScrollView, StyleSheet } from 'react-native'; -import { ListSection, Divider, withTheme } from 'react-native-paper'; +import { List, Divider, withTheme } from 'react-native-paper'; import type { Theme } from 'react-native-paper/types'; type Props = { @@ -10,7 +10,7 @@ type Props = { }; class ListAccordionExample extends React.Component { - static title = 'ListSection.Accordion'; + static title = 'List.Accordion'; render() { const { @@ -20,41 +20,41 @@ class ListAccordionExample extends React.Component { } = this.props; return ( - - } + + } title="Expandable list item" > - - - - + + + + - - + - - - - + + + + - - } + + } title="Accordion item 1" > - } + } title="List item 1" /> - } + } title="List item 2" /> - - + + ); } diff --git a/example/src/ListSectionExample.js b/example/src/ListSectionExample.js index 41896b1..352254d 100644 --- a/example/src/ListSectionExample.js +++ b/example/src/ListSectionExample.js @@ -2,7 +2,7 @@ import * as React from 'react'; import { ScrollView, StyleSheet, Image } from 'react-native'; -import { ListSection, Divider, withTheme } from 'react-native-paper'; +import { List, Divider, withTheme } from 'react-native-paper'; import type { Theme } from 'react-native-paper/types'; type Props = { @@ -10,7 +10,7 @@ type Props = { }; class ListSectionExample extends React.Component { - static title = 'ListSection'; + static title = 'List.Section'; render() { const { @@ -20,19 +20,13 @@ class ListSectionExample extends React.Component { } = this.props; return ( - - } - title="List item 1" - /> - } - title="List item 2" - /> - + + } title="List item 1" /> + } title="List item 2" /> + - - + { title="List item 1" description="Describes item 1" /> - } - right={} + right={} title="List item 2" description="Describes item 2" /> - + - - + { title="List item 1" description="Describes item 1. Example of a very very long description." /> - } - right={} + right={} title="List item 2" description="Describes item 2. Example of a very very long description." /> - + ); } diff --git a/src/components/Drawer/Drawer.js b/src/components/Drawer/Drawer.js new file mode 100644 index 0000000..f24ec71 --- /dev/null +++ b/src/components/Drawer/Drawer.js @@ -0,0 +1,7 @@ +/* @flow */ + +// @component ./DrawerItem.js +export { default as Item } from './DrawerItem'; + +// @component ./DrawerSection.js +export { default as Section } from './DrawerSection'; diff --git a/src/components/Drawer/DrawerItem.js b/src/components/Drawer/DrawerItem.js index ec42691..a9a70cd 100644 --- a/src/components/Drawer/DrawerItem.js +++ b/src/components/Drawer/DrawerItem.js @@ -40,15 +40,15 @@ type Props = { * ## Usage * ```js * import * as React from 'react'; - * import { DrawerSection } from 'react-native-paper'; + * import { Drawer } from 'react-native-paper'; * * const MyComponent = () => ( - * + * * ); * ``` */ class DrawerItem extends React.Component { - static displayName = 'DrawerSection.Item'; + static displayName = 'Drawer.Item'; render() { const { icon, label, active, theme, style, onPress, ...rest } = this.props; diff --git a/src/components/Drawer/DrawerSection.js b/src/components/Drawer/DrawerSection.js index a7f4541..7aeaf2d 100644 --- a/src/components/Drawer/DrawerSection.js +++ b/src/components/Drawer/DrawerSection.js @@ -3,7 +3,6 @@ import color from 'color'; import * as React from 'react'; import { View } from 'react-native'; -import DrawerItem from './DrawerItem'; import Text from '../Typography/Text'; import Divider from '../Divider'; import { withTheme } from '../../core/theming'; @@ -15,7 +14,7 @@ type Props = { */ title?: string, /** - * Content of the `DrawerSection`. + * Content of the `Drawer.Section`. */ children: React.Node, /** @@ -30,7 +29,7 @@ type Props = { * ## Usage * ```js * import * as React from 'react'; - * import { DrawerSection } from 'react-native-paper'; + * import { Drawer } from 'react-native-paper'; * * export default class MyComponent extends React.Component { * state = { @@ -41,26 +40,25 @@ type Props = { * const { active } = this.state; * * return ( - * - * + * { this.setState({ active: 'first' }); }} * /> - * { this.setState({ active: 'second' }); }} * /> - * + * * ); * } * } * ``` */ class DrawerSection extends React.Component { - // @component ./DrawerItem.js - static Item = DrawerItem; + static displayName = 'Drawer.Section'; render() { const { children, title, theme, ...rest } = this.props; diff --git a/src/components/List/List.js b/src/components/List/List.js new file mode 100644 index 0000000..921e556 --- /dev/null +++ b/src/components/List/List.js @@ -0,0 +1,13 @@ +/* @flow */ + +// @component ./ListAccordion.js +export { default as Accordion } from './ListAccordion'; + +// @component ./ListIcon.js +export { default as Icon } from './ListIcon'; + +// @component ./ListItem.js +export { default as Item } from './ListItem'; + +// @component ./ListSection.js +export { default as Section } from './ListSection'; diff --git a/src/components/List/ListAccordion.js b/src/components/List/ListAccordion.js index fd89bb7..ed5f7e3 100644 --- a/src/components/List/ListAccordion.js +++ b/src/components/List/ListAccordion.js @@ -49,21 +49,21 @@ type State = { * ## Usage * ```js * import * as React from 'react'; - * import { ListSection, Checkbox } from 'react-native-paper'; + * import { List, Checkbox } from 'react-native-paper'; * * const MyComponent = () => ( - * } + * left={} * > - * - * - * + * + * + * * ); * ``` */ class ListAccordion extends React.Component { - static displayName = 'ListSection.Accordion'; + static displayName = 'List.Accordion'; state = { expanded: false, diff --git a/src/components/List/ListIcon.js b/src/components/List/ListIcon.js index 6445203..4162fcd 100644 --- a/src/components/List/ListIcon.js +++ b/src/components/List/ListIcon.js @@ -25,15 +25,15 @@ type Props = { * ## Usage * ```js * import * as React from 'react'; - * import { ListSection } from 'react-native-paper'; + * import { List } from 'react-native-paper'; * * const MyComponent = () => ( - * + * * ); * ``` */ class ListIcon extends React.Component { - static displayName = 'ListSection.Icon'; + static displayName = 'List.Icon'; render() { const { icon, theme, style } = this.props; diff --git a/src/components/List/ListItem.js b/src/components/List/ListItem.js index 563db7e..385868e 100644 --- a/src/components/List/ListItem.js +++ b/src/components/List/ListItem.js @@ -48,19 +48,19 @@ type Props = { * ## Usage * ```js * import * as React from 'react'; - * import { ListSection } from 'react-native-paper'; + * import { List } from 'react-native-paper'; * * const MyComponent = () => ( - * } + * left={} * /> * ); * ``` */ class ListItem extends React.Component { - static displayName = 'ListSection.Item'; + static displayName = 'List.Item'; render() { const { diff --git a/src/components/List/ListSection.js b/src/components/List/ListSection.js index 4adfbdd..f720556 100644 --- a/src/components/List/ListSection.js +++ b/src/components/List/ListSection.js @@ -3,9 +3,6 @@ import color from 'color'; import * as React from 'react'; import { View, StyleSheet } from 'react-native'; -import ListItem from './ListItem'; -import ListAccordion from './ListAccordion'; -import ListIcon from './ListIcon'; import Text from '../Typography/Text'; import { withTheme } from '../../core/theming'; import type { Theme } from '../../types'; @@ -36,33 +33,28 @@ type Props = { * ## Usage * ```js * import * as React from 'react'; - * import { ListSection } from 'react-native-paper'; + * import { List } from 'react-native-paper'; * * export default class MyComponent extends React.Component { * render() { * return ( - * - * + * } + * left={} * /> - * } + * left={} * /> - * + * * ); * } * } * ``` */ class ListSection extends React.Component { - // @component ./ListItem.js - static Item = ListItem; - // @component ./ListAccordion.js - static Accordion = ListAccordion; - // @component ./ListIcon.js - static Icon = ListIcon; + static displayName = 'List.Section'; render() { const { children, title, theme, style, ...rest } = this.props; diff --git a/src/index.js b/src/index.js index 59c9ba3..021e135 100644 --- a/src/index.js +++ b/src/index.js @@ -10,6 +10,11 @@ export { default as Provider } from './core/Provider'; export { default as DefaultTheme } from './styles/DefaultTheme'; export { default as DarkTheme } from './styles/DarkTheme'; +import * as List from './components/List/List'; +import * as Drawer from './components/Drawer/Drawer'; + +export { List, Drawer }; + export { default as BottomNavigation } from './components/BottomNavigation'; export { default as Button } from './components/Button'; export { default as Card } from './components/Card/Card'; @@ -17,11 +22,9 @@ export { default as Checkbox } from './components/Checkbox'; export { default as Chip } from './components/Chip'; export { default as Dialog } from './components/Dialog/Dialog'; export { default as Divider } from './components/Divider'; -export { default as DrawerSection } from './components/Drawer/DrawerSection'; export { default as FAB } from './components/FAB/FAB'; export { default as HelperText } from './components/HelperText'; export { default as IconButton } from './components/IconButton'; -export { default as ListSection } from './components/List/ListSection'; export { default as Modal } from './components/Modal'; export { default as Portal } from './components/Portal/Portal'; export { default as ProgressBar } from './components/ProgressBar/ProgressBar';