-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
17 changed files
with
868 additions
and
27 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,63 @@ | ||
/* @flow */ | ||
|
||
import * as React from 'react'; | ||
import { ScrollView, StyleSheet } from 'react-native'; | ||
import { | ||
ListAccordion, | ||
ListSection, | ||
ListItem, | ||
Divider, | ||
withTheme, | ||
} from 'react-native-paper'; | ||
import type { Theme } from 'react-native-paper/types'; | ||
|
||
type Props = { | ||
theme: Theme, | ||
}; | ||
|
||
class ListAccordionExample extends React.Component<Props> { | ||
static title = 'ListAccordion'; | ||
|
||
render() { | ||
const { | ||
theme: { | ||
colors: { background }, | ||
}, | ||
} = this.props; | ||
return ( | ||
<ScrollView style={[styles.container, { backgroundColor: background }]}> | ||
<ListSection title="Expandable list item"> | ||
<ListAccordion icon="folder" title="Expandable list item"> | ||
<ListItem title="List item 1" /> | ||
<ListItem title="List item 2" /> | ||
</ListAccordion> | ||
</ListSection> | ||
<Divider /> | ||
<ListSection title="Expandable & multiline list item"> | ||
<ListAccordion | ||
title="Expandable list item" | ||
description="Describes the expandable list item" | ||
> | ||
<ListItem title="List item 1" /> | ||
<ListItem title="List item 2" /> | ||
</ListAccordion> | ||
</ListSection> | ||
<Divider /> | ||
<ListSection title="Expandable list with icons"> | ||
<ListAccordion icon="star" title="Accordion item 1"> | ||
<ListItem icon="thumb-up" title="List item 1" /> | ||
<ListItem icon="thumb-down" title="List item 2" /> | ||
</ListAccordion> | ||
</ListSection> | ||
</ScrollView> | ||
); | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
}, | ||
}); | ||
|
||
export default withTheme(ListAccordionExample); |
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
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,204 @@ | ||
/* @flow */ | ||
|
||
import color from 'color'; | ||
import * as React from 'react'; | ||
import { View, StyleSheet } from 'react-native'; | ||
import TouchableRipple from '../TouchableRipple'; | ||
import Icon from '../Icon'; | ||
import Text from '../Typography/Text'; | ||
import withTheme from '../../core/withTheme'; | ||
import type { Theme } from '../../types'; | ||
|
||
type Props = { | ||
/** | ||
* Title text for the list accordion. | ||
*/ | ||
title: React.Node, | ||
/** | ||
* Description text for the list accordion. | ||
*/ | ||
description?: React.Node, | ||
/** | ||
* Icon to display for the `ListAccordion`. | ||
*/ | ||
icon?: React.Node, | ||
|
||
/** | ||
* Content of the section. | ||
*/ | ||
children: React.Node, | ||
|
||
/** | ||
* @optional | ||
*/ | ||
theme: Theme, | ||
style?: any, | ||
}; | ||
|
||
type State = { | ||
expanded: boolean, | ||
}; | ||
|
||
/** | ||
* `ListAccordion` can be used to display an expandable list item. | ||
* | ||
* <div class="screenshots"> | ||
* <img class="medium" src="screenshots/list-accordion-1.png" /> | ||
* <img class="medium" src="screenshots/list-accordion-2.png" /> | ||
* <img class="medium" src="screenshots/list-accordion-3.png" /> | ||
* </div> | ||
* | ||
* ## Usage | ||
* ```js | ||
* import * as React from 'react'; | ||
* import { ListAccordion, ListItem, Checkbox } from 'react-native-paper'; | ||
* | ||
* const MyComponent = () => ( | ||
* <ListAccordion | ||
* title="Accordion" | ||
* icon="folder" | ||
* > | ||
* <ListItem title="First item" /> | ||
* <ListItem title="Second item" /> | ||
* </ListAccordion> | ||
* ); | ||
* ``` | ||
*/ | ||
class ListAccordion extends React.Component<Props, State> { | ||
state = { | ||
expanded: false, | ||
}; | ||
|
||
_handlePress = () => | ||
this.setState(state => ({ | ||
expanded: !state.expanded, | ||
})); | ||
|
||
render() { | ||
const { icon, title, description, children, theme, style } = this.props; | ||
const titleColor = color(theme.colors.text) | ||
.alpha(0.87) | ||
.rgb() | ||
.string(); | ||
const descriptionColor = color(theme.colors.text) | ||
.alpha(0.54) | ||
.rgb() | ||
.string(); | ||
|
||
return ( | ||
<View> | ||
<TouchableRipple | ||
style={[styles.container, style]} | ||
onPress={this._handlePress} | ||
> | ||
<View style={styles.row} pointerEvents="none"> | ||
{icon ? ( | ||
<View | ||
style={[ | ||
styles.item, | ||
styles.icon, | ||
description && styles.multiline, | ||
]} | ||
> | ||
<Icon | ||
name={icon} | ||
size={24} | ||
color={ | ||
this.state.expanded | ||
? theme.colors.primary | ||
: descriptionColor | ||
} | ||
/> | ||
</View> | ||
) : null} | ||
<View style={[styles.item, styles.content]}> | ||
<Text | ||
numberOfLines={1} | ||
style={[ | ||
styles.title, | ||
{ | ||
color: this.state.expanded | ||
? theme.colors.primary | ||
: titleColor, | ||
}, | ||
]} | ||
> | ||
{title} | ||
</Text> | ||
{description && ( | ||
<Text | ||
numberOfLines={2} | ||
style={[ | ||
styles.description, | ||
{ | ||
color: descriptionColor, | ||
}, | ||
]} | ||
> | ||
{description} | ||
</Text> | ||
)} | ||
</View> | ||
<View style={[styles.item, description && styles.multiline]}> | ||
<Icon | ||
name={ | ||
this.state.expanded | ||
? 'keyboard-arrow-up' | ||
: 'keyboard-arrow-down' | ||
} | ||
color={titleColor} | ||
size={24} | ||
/> | ||
</View> | ||
</View> | ||
</TouchableRipple> | ||
{this.state.expanded | ||
? React.Children.map(children, child => { | ||
if (icon && child && !child.props.icon && !child.props.avatar) { | ||
return React.cloneElement(child, { | ||
style: [styles.child, child.props.style], | ||
}); | ||
} | ||
|
||
return child; | ||
}) | ||
: null} | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
padding: 8, | ||
}, | ||
row: { | ||
flexDirection: 'row', | ||
}, | ||
icon: { | ||
width: 40, | ||
}, | ||
multiline: { | ||
height: 40, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}, | ||
title: { | ||
fontSize: 16, | ||
}, | ||
description: { | ||
fontSize: 14, | ||
}, | ||
item: { | ||
margin: 8, | ||
}, | ||
child: { | ||
paddingLeft: 64, | ||
}, | ||
content: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
}, | ||
}); | ||
|
||
export default withTheme(ListAccordion); |
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
Oops, something went wrong.