Mailspring/app/internal_packages/thread-list/lib/selected-items-stack.jsx

79 lines
2.3 KiB
React
Raw Normal View History

2017-09-27 02:33:08 +08:00
import _ from 'underscore';
import React, { Component } from 'react';
import PropTypes from 'prop-types';
2017-09-27 02:46:00 +08:00
import { ListensToObservable } from 'mailspring-component-kit';
2017-09-27 02:33:08 +08:00
import ThreadListStore from './thread-list-store';
function getObservable() {
2017-09-27 02:33:08 +08:00
return ThreadListStore.selectionObservable().map(items => items.length);
}
function getStateFromObservable(selectionCount) {
if (!selectionCount) {
2017-09-27 02:33:08 +08:00
return { selectionCount: 0 };
}
2017-09-27 02:33:08 +08:00
return { selectionCount };
}
class SelectedItemsStack extends Component {
2017-09-27 02:33:08 +08:00
static displayName = 'SelectedItemsStack';
static propTypes = {
selectionCount: PropTypes.number,
};
2016-05-07 07:06:16 +08:00
static containerRequired = false;
2016-05-06 13:30:34 +08:00
onClearSelection = () => {
2017-09-27 02:33:08 +08:00
ThreadListStore.dataSource().selection.clear();
};
render() {
2017-09-27 02:33:08 +08:00
const { selectionCount } = this.props;
if (selectionCount <= 1) {
2017-09-27 02:33:08 +08:00
return <span />;
}
2017-09-27 02:33:08 +08:00
const cardCount = Math.min(5, selectionCount);
return (
<div className="selected-items-stack">
<div className="selected-items-stack-content">
<div className="stack">
2017-09-27 02:33:08 +08:00
{_.times(cardCount, idx => {
let deg = idx * 0.9;
if (idx === 1) {
2017-09-27 02:33:08 +08:00
deg += 0.5;
}
2017-09-27 02:33:08 +08:00
let transform = `rotate(${deg}deg)`;
if (idx === cardCount - 1) {
2017-09-27 02:33:08 +08:00
transform += ' translate3d(2px, 3px, 0)';
}
const style = {
transform,
zIndex: 5 - idx,
2017-09-27 02:33:08 +08:00
};
return (
<div key={`card-${idx}`} style={style} className="card">
<svg width="100%" height="100%" viewBox="0 0 390 527" version="1.1">
<rect strokeWidth="2.5" x="0" y="0" width="390" height="527" rx="15" />
</svg>
</div>
);
})}
</div>
<div className="count-info">
<div className="count">{selectionCount}</div>
<div className="count-message">messages selected</div>
2017-09-27 02:33:08 +08:00
<div className="clear btn" onClick={this.onClearSelection}>
Clear Selection
</div>
</div>
</div>
</div>
2017-09-27 02:33:08 +08:00
);
}
}
2017-09-27 02:33:08 +08:00
export default ListensToObservable(SelectedItemsStack, { getObservable, getStateFromObservable });