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-03-26 14:48:06 +01:00
|
|
|
import { get } from 'lodash';
|
2020-03-16 13:37:10 +01:00
|
|
|
import { createMatrix } from '../../utils';
|
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-26 09:30:44 +01:00
|
|
|
import ListWrapper from '../ListWrapper';
|
2020-02-14 17:44:54 +01:00
|
|
|
|
2020-03-25 17:55:06 +01:00
|
|
|
const List = ({
|
|
|
|
clickable,
|
|
|
|
data,
|
|
|
|
onChange,
|
|
|
|
onCardClick,
|
|
|
|
selectedItems,
|
|
|
|
canSelect,
|
|
|
|
renderCardControl,
|
|
|
|
}) => {
|
2020-03-02 00:21:43 +01:00
|
|
|
const matrix = createMatrix(data);
|
|
|
|
|
2020-03-24 15:45:01 +01:00
|
|
|
const handleClick = e => {
|
|
|
|
e.stopPropagation();
|
|
|
|
};
|
|
|
|
|
2020-02-14 17:44:54 +01:00
|
|
|
return (
|
2020-03-26 09:30:44 +01:00
|
|
|
<ListWrapper>
|
2020-03-02 00:21:43 +01:00
|
|
|
{matrix.map(({ key, rowContent }) => {
|
|
|
|
return (
|
|
|
|
<div className="row" key={key}>
|
2020-03-02 14:33:16 +01:00
|
|
|
{rowContent.map(item => {
|
2020-03-26 14:48:06 +01:00
|
|
|
const { id } = item;
|
2020-03-26 16:11:42 +01:00
|
|
|
const url = get(item, ['formats', 'thumbnail', 'url'], item.url);
|
2020-03-23 16:24:26 +01:00
|
|
|
const checked = selectedItems.findIndex(file => file.id === id) !== -1;
|
|
|
|
const fileUrl = url.startsWith('/') ? `${strapi.backendURL}${url}` : url;
|
2020-03-06 17:19:20 +01:00
|
|
|
|
2020-03-02 14:33:16 +01:00
|
|
|
return (
|
2020-03-21 21:25:45 +01:00
|
|
|
<div className="col-xs-12 col-md-6 col-xl-3" key={id}>
|
2020-03-26 16:07:14 +01:00
|
|
|
<Card
|
|
|
|
checked={checked}
|
|
|
|
{...item}
|
|
|
|
hasIcon={clickable}
|
|
|
|
url={fileUrl}
|
2020-03-25 17:55:06 +01:00
|
|
|
onClick={onCardClick}
|
2020-03-26 16:07:14 +01:00
|
|
|
>
|
2020-03-09 16:49:12 +01:00
|
|
|
{(checked || canSelect) && (
|
2020-03-25 17:55:06 +01:00
|
|
|
<>
|
|
|
|
<CardControlsWrapper leftAlign className="card-control-wrapper">
|
|
|
|
<Checkbox
|
|
|
|
name={`${id}`}
|
|
|
|
onChange={onChange}
|
|
|
|
onClick={handleClick}
|
|
|
|
value={checked}
|
|
|
|
/>
|
|
|
|
</CardControlsWrapper>
|
|
|
|
{renderCardControl && (
|
|
|
|
<CardControlsWrapper className="card-control-wrapper">
|
|
|
|
{renderCardControl(id)}
|
|
|
|
</CardControlsWrapper>
|
|
|
|
)}
|
|
|
|
</>
|
2020-03-09 16:49:12 +01:00
|
|
|
)}
|
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>
|
|
|
|
);
|
|
|
|
})}
|
2020-03-26 09:30:44 +01:00
|
|
|
</ListWrapper>
|
2020-02-14 17:44:54 +01:00
|
|
|
);
|
2020-02-13 09:01:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
List.defaultProps = {
|
2020-03-26 16:07:14 +01:00
|
|
|
clickable: false,
|
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: () => {},
|
2020-03-25 17:55:06 +01:00
|
|
|
onCardClick: () => {},
|
|
|
|
renderCardControl: null,
|
2020-03-02 14:33:16 +01:00
|
|
|
selectedItems: [],
|
2020-02-13 09:01:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
List.propTypes = {
|
2020-03-26 16:07:14 +01:00
|
|
|
clickable: PropTypes.bool,
|
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,
|
2020-03-25 17:55:06 +01:00
|
|
|
onCardClick: PropTypes.func,
|
|
|
|
renderCardControl: PropTypes.func,
|
2020-03-02 14:33:16 +01:00
|
|
|
selectedItems: PropTypes.array,
|
2020-02-13 09:01:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export default List;
|