Skip to content

Commit

Permalink
Add tertiaryText Option [ListItem] (#67)
Browse files Browse the repository at this point in the history
* Added tertiaryText Option

* Removed logLines
  • Loading branch information
matthewfbenjamin authored and xotahal committed Jan 28, 2017
1 parent 094a90d commit dac2377
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/ListItem/ListItem.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const propTypes = {
PropTypes.shape({
primaryText: PropTypes.string.isRequired,
secondaryText: PropTypes.string,
tertiaryText: PropTypes.string,
}),
]),

Expand Down Expand Up @@ -65,7 +66,11 @@ function getNumberOfSecondaryTextLines(numberOfLines) {
function getNumberOfLines(props) {
const { numberOfLines, centerElement } = props;

if (centerElement && centerElement.secondaryText && (!numberOfLines || numberOfLines < 2)) {
if (centerElement && centerElement.secondaryText && centerElement.tertiaryText
&& (!numberOfLines || numberOfLines < 3)) {
return 3;
} else if (centerElement && centerElement.secondaryText &&
(!numberOfLines || numberOfLines < 2)) {
return 2;
}

Expand Down Expand Up @@ -160,6 +165,10 @@ function getStyles(props, context, state) {
listItem.secondaryText,
props.style.secondaryText,
],
tertiaryText: [
listItem.tertiaryText,
props.style.secondaryText,
],
rightElementContainer: [
listItem.rightElementContainer,
props.style.rightElementContainer,
Expand Down Expand Up @@ -244,23 +253,23 @@ class ListItem extends PureComponent {
renderCenterElement = (styles) => {
const { centerElement } = this.props;
const numberOfLines = getNumberOfSecondaryTextLines(this.state.numberOfLines);

let content = null;

if (React.isValidElement(centerElement)) {
content = centerElement;
} else if (centerElement) {
let primaryText = null;
let secondaryText = null;
let tertiaryText = null;

if (typeof centerElement === 'string') {
primaryText = centerElement;
} else {
primaryText = centerElement.primaryText;
secondaryText = centerElement.secondaryText;
tertiaryText = centerElement.tertiaryText;
}


const lineNumber = tertiaryText === undefined ? numberOfLines : 1;
content = (
<View style={styles.textViewContainer}>
<View style={styles.firstLine}>
Expand All @@ -272,16 +281,22 @@ class ListItem extends PureComponent {
</View>
{secondaryText &&
<View>
<Text numberOfLines={numberOfLines} style={styles.secondaryText}>
<Text numberOfLines={lineNumber} style={styles.secondaryText}>
{secondaryText}
</Text>
</View>
}
{tertiaryText &&
<View>
<Text numberOfLines={lineNumber} style={styles.secondaryText}>
{tertiaryText}
</Text>
</View>
}
</View>
);
}


return (
<View style={styles.centerElementContainer}>
{content}
Expand Down

0 comments on commit dac2377

Please sign in to comment.