2017-01-26 09:17:38 +01:00
|
|
|
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
2017-01-25 12:16:04 +01:00
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2017-07-17 18:37:33 +02:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2017-01-25 12:16:04 +01:00
|
|
|
|
2017-05-09 12:01:44 +02:00
|
|
|
import { arrayOrObjectProptype, nodeOrStringProptype } from '@parity/shared/util/proptypes';
|
2017-01-25 12:16:04 +01:00
|
|
|
|
2017-05-04 10:40:52 +02:00
|
|
|
import { chunkArray } from './array';
|
|
|
|
import Overlay from './Overlay';
|
2017-01-25 12:16:04 +01:00
|
|
|
import styles from './sectionList.css';
|
|
|
|
|
|
|
|
// TODO: We probably want this to be passed via props - additional work required in that case to
|
|
|
|
// support the styling for both the hover and no-hover CSS for the pre/post sizes. Future work only
|
|
|
|
// if/when required.
|
|
|
|
const ITEMS_PER_ROW = 3;
|
|
|
|
|
|
|
|
export default class SectionList extends Component {
|
|
|
|
static propTypes = {
|
|
|
|
className: PropTypes.string,
|
|
|
|
items: arrayOrObjectProptype().isRequired,
|
|
|
|
renderItem: PropTypes.func.isRequired,
|
2017-01-31 17:04:41 +01:00
|
|
|
noStretch: PropTypes.bool,
|
2017-01-25 12:16:04 +01:00
|
|
|
overlay: nodeOrStringProptype()
|
2017-01-31 17:04:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
noStretch: false
|
|
|
|
};
|
2017-01-25 12:16:04 +01:00
|
|
|
|
|
|
|
render () {
|
2017-05-04 10:40:52 +02:00
|
|
|
const { className, items, overlay } = this.props;
|
2017-01-25 12:16:04 +01:00
|
|
|
|
|
|
|
if (!items || !items.length) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-02-20 16:34:38 +01:00
|
|
|
const rendered = items
|
|
|
|
.map(this.renderItem)
|
|
|
|
.filter((item) => item);
|
|
|
|
|
|
|
|
if (!rendered.length) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-01-25 12:16:04 +01:00
|
|
|
return (
|
|
|
|
<section className={ [styles.section, className].join(' ') }>
|
2017-05-04 10:40:52 +02:00
|
|
|
<Overlay overlay={ overlay } />
|
2017-02-20 16:34:38 +01:00
|
|
|
{ chunkArray(rendered, ITEMS_PER_ROW).map(this.renderRow) }
|
2017-01-25 12:16:04 +01:00
|
|
|
</section>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderRow = (row, index) => {
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={ styles.row }
|
|
|
|
key={ `row_${index}` }
|
|
|
|
>
|
2017-02-20 16:34:38 +01:00
|
|
|
{ row }
|
2017-01-25 12:16:04 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderItem = (item, index) => {
|
2017-01-31 17:04:41 +01:00
|
|
|
const { noStretch, renderItem } = this.props;
|
2017-02-14 08:29:32 +01:00
|
|
|
const itemRendered = renderItem(item, index);
|
|
|
|
|
|
|
|
if (!itemRendered) {
|
|
|
|
return null;
|
|
|
|
}
|
2017-01-25 12:16:04 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
2017-01-31 17:04:41 +01:00
|
|
|
className={ [
|
|
|
|
styles.item,
|
2017-02-14 08:29:32 +01:00
|
|
|
noStretch
|
|
|
|
? styles.stretchOff
|
|
|
|
: styles.stretchOn
|
2017-01-31 17:04:41 +01:00
|
|
|
].join(' ') }
|
2017-01-25 12:16:04 +01:00
|
|
|
key={ `item_${index}` }
|
|
|
|
>
|
2017-02-14 08:29:32 +01:00
|
|
|
{ itemRendered }
|
2017-01-25 12:16:04 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|