2020-02-13 09:01:32 +01:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2020-03-06 17:19:20 +01:00
|
|
|
import { Checkbox } from '@buffetjs/core';
|
2020-02-13 09:01:32 +01:00
|
|
|
|
2020-03-16 13:37:10 +01:00
|
|
|
import { createMatrix } from '../../utils';
|
2020-03-02 00:21:43 +01:00
|
|
|
|
2020-02-14 17:44:54 +01:00
|
|
|
import Card from '../Card';
|
2020-03-10 00:27:18 +01:00
|
|
|
import CardControlsWrapper from '../CardControlsWrapper';
|
2020-03-02 00:21:43 +01:00
|
|
|
import Wrapper from './Wrapper';
|
2020-02-14 17:44:54 +01:00
|
|
|
|
2020-03-09 16:49:12 +01:00
|
|
|
const List = ({ data, onChange, selectedItems, canSelect }) => {
|
2020-03-02 00:21:43 +01:00
|
|
|
const matrix = createMatrix(data);
|
|
|
|
|
2020-02-14 17:44:54 +01:00
|
|
|
return (
|
2020-03-02 00:21:43 +01:00
|
|
|
<Wrapper>
|
|
|
|
{matrix.map(({ key, rowContent }) => {
|
|
|
|
return (
|
|
|
|
<div className="row" key={key}>
|
2020-03-02 14:33:16 +01:00
|
|
|
{rowContent.map(item => {
|
2020-03-06 17:19:20 +01:00
|
|
|
const { id, url } = item;
|
2020-03-09 16:49:12 +01:00
|
|
|
const checked = selectedItems.some(selectedItem => selectedItem.id === id);
|
2020-03-06 17:19:20 +01:00
|
|
|
|
2020-03-02 14:33:16 +01:00
|
|
|
return (
|
2020-03-05 14:34:05 +01:00
|
|
|
<div className="col-xs-12 col-md-6 col-xl-3" key={JSON.stringify(item)}>
|
2020-03-06 17:19:20 +01:00
|
|
|
<Card small checked={checked} {...item} url={`${strapi.backendURL}${url}`}>
|
2020-03-09 16:49:12 +01:00
|
|
|
{(checked || canSelect) && (
|
|
|
|
<CardControlsWrapper leftAlign className="card-control-wrapper">
|
|
|
|
<Checkbox name={`${id}`} onChange={onChange} value={checked} />
|
|
|
|
</CardControlsWrapper>
|
|
|
|
)}
|
2020-03-06 17:19:20 +01:00
|
|
|
</Card>
|
2020-03-02 14:33:16 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})}
|
2020-03-02 00:21:43 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</Wrapper>
|
2020-02-14 17:44:54 +01:00
|
|
|
);
|
2020-02-13 09:01:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
List.defaultProps = {
|
2020-03-09 16:49:12 +01:00
|
|
|
canSelect: true,
|
2020-03-06 17:19:20 +01:00
|
|
|
data: [],
|
2020-03-02 14:33:16 +01:00
|
|
|
onChange: () => {},
|
|
|
|
selectedItems: [],
|
2020-02-13 09:01:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
List.propTypes = {
|
2020-03-09 16:49:12 +01:00
|
|
|
canSelect: PropTypes.bool,
|
2020-02-13 10:02:28 +01:00
|
|
|
data: PropTypes.array,
|
2020-03-02 14:33:16 +01:00
|
|
|
onChange: PropTypes.func,
|
|
|
|
selectedItems: PropTypes.array,
|
2020-02-13 09:01:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export default List;
|