Spaces:
Running
Running
File size: 4,083 Bytes
6bcb42f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
import PropTypes from 'prop-types';
import React from 'react';
import classNames from 'classnames';
import SpriteSelectorItem from '../../containers/sprite-selector-item.jsx';
import Box from '../box/box.jsx';
import ActionMenu from '../action-menu/action-menu.jsx';
import SortableAsset from './sortable-asset.jsx';
import SortableHOC from '../../lib/sortable-hoc.jsx';
import DragConstants from '../../lib/drag-constants';
import styles from './selector.css';
const Selector = props => {
const {
buttons,
containerRef,
dragType,
isRtl,
items,
selectedItemIndex,
draggingIndex,
draggingType,
ordering,
onAddSortable,
onRemoveSortable,
onDeleteClick,
onDuplicateClick,
onExportClick,
onItemClick
} = props;
const isRelevantDrag = draggingType === dragType;
let newButtonSection = null;
if (buttons.length > 0) {
const {img, title, onClick} = buttons[0];
const moreButtons = buttons.slice(1);
newButtonSection = (
<Box className={styles.newButtons}>
<ActionMenu
img={img}
moreButtons={moreButtons}
title={title}
tooltipPlace={isRtl ? 'left' : 'right'}
onClick={onClick}
/>
</Box>
);
}
return (
<Box
className={styles.wrapper}
componentRef={containerRef}
>
<Box className={styles.listArea}>
{items.map((item, index) => (
<SortableAsset
id={item.name}
index={isRelevantDrag ? ordering.indexOf(index) : index}
key={item.name}
onAddSortable={onAddSortable}
onRemoveSortable={onRemoveSortable}
>
<SpriteSelectorItem
asset={item.asset}
className={classNames(styles.listItem, {
[styles.placeholder]: isRelevantDrag && index === draggingIndex
})}
costumeURL={item.url}
details={item.details}
dragPayload={item.dragPayload}
dragType={dragType}
id={index}
index={index}
name={item.name}
number={index + 1 /* 1-indexed */}
selected={index === selectedItemIndex}
onClick={onItemClick}
onDeleteButtonClick={onDeleteClick}
onDuplicateButtonClick={onDuplicateClick}
onExportButtonClick={onExportClick}
/>
</SortableAsset>
))}
</Box>
{newButtonSection}
</Box>
);
};
Selector.propTypes = {
buttons: PropTypes.arrayOf(PropTypes.shape({
title: PropTypes.string.isRequired,
img: PropTypes.string.isRequired,
onClick: PropTypes.func
})),
containerRef: PropTypes.func,
dragType: PropTypes.oneOf(Object.keys(DragConstants)),
draggingIndex: PropTypes.number,
draggingType: PropTypes.oneOf(Object.keys(DragConstants)),
isRtl: PropTypes.bool,
items: PropTypes.arrayOf(PropTypes.shape({
url: PropTypes.string,
// eslint-disable-next-line react/forbid-prop-types
name: PropTypes.any
})),
onAddSortable: PropTypes.func,
onDeleteClick: PropTypes.func,
onDuplicateClick: PropTypes.func,
onExportClick: PropTypes.func,
onItemClick: PropTypes.func.isRequired,
onRemoveSortable: PropTypes.func,
ordering: PropTypes.arrayOf(PropTypes.number),
selectedItemIndex: PropTypes.number.isRequired
};
export default SortableHOC(Selector);
|