2017-08-27 06:33:29 +08:00
|
|
|
import React from 'react';
|
2017-09-27 02:33:08 +08:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import fs from 'fs';
|
2016-04-01 06:52:03 +08:00
|
|
|
import classNames from 'classnames';
|
|
|
|
|
2017-09-27 02:33:08 +08:00
|
|
|
import { Flexbox, RetinaImg } from 'nylas-component-kit';
|
2017-09-27 02:42:18 +08:00
|
|
|
import { Actions, PreferencesUIStore, Utils } from 'mailspring-exports';
|
2016-04-01 06:52:03 +08:00
|
|
|
|
|
|
|
class PreferencesTabItem extends React.Component {
|
|
|
|
static displayName = 'PreferencesTabItem';
|
|
|
|
|
|
|
|
static propTypes = {
|
2017-07-12 06:42:18 +08:00
|
|
|
selection: PropTypes.shape({
|
|
|
|
accountId: PropTypes.string,
|
|
|
|
tabId: PropTypes.string,
|
|
|
|
}).isRequired,
|
|
|
|
tabItem: PropTypes.instanceOf(PreferencesUIStore.TabItem).isRequired,
|
2017-09-27 02:33:08 +08:00
|
|
|
};
|
2016-04-01 06:52:03 +08:00
|
|
|
|
|
|
|
_onClick = () => {
|
|
|
|
Actions.switchPreferencesTab(this.props.tabItem.tabId);
|
2017-09-27 02:33:08 +08:00
|
|
|
};
|
2016-04-01 06:52:03 +08:00
|
|
|
|
|
|
|
_onClickAccount = (event, accountId) => {
|
2017-09-27 02:33:08 +08:00
|
|
|
Actions.switchPreferencesTab(this.props.tabItem.tabId, { accountId });
|
2016-04-01 06:52:03 +08:00
|
|
|
event.stopPropagation();
|
2017-09-27 02:33:08 +08:00
|
|
|
};
|
2016-04-01 06:52:03 +08:00
|
|
|
|
|
|
|
render() {
|
2017-09-27 02:33:08 +08:00
|
|
|
const { selection, tabItem } = this.props;
|
|
|
|
const { tabId, displayName } = tabItem;
|
2016-04-01 06:52:03 +08:00
|
|
|
const classes = classNames({
|
2016-05-07 07:23:48 +08:00
|
|
|
item: true,
|
2017-07-12 06:42:18 +08:00
|
|
|
active: tabId === selection.tabId,
|
2016-04-01 06:52:03 +08:00
|
|
|
});
|
|
|
|
|
2017-09-27 02:33:08 +08:00
|
|
|
let path = `icon-preferences-${displayName.toLowerCase().replace(' ', '-')}.png`;
|
2016-04-01 06:52:03 +08:00
|
|
|
if (!fs.existsSync(Utils.imageNamed(path))) {
|
2017-09-27 02:33:08 +08:00
|
|
|
path = 'icon-preferences-general.png';
|
2016-04-01 06:52:03 +08:00
|
|
|
}
|
2016-05-07 07:23:48 +08:00
|
|
|
const icon = (
|
2017-09-27 02:33:08 +08:00
|
|
|
<RetinaImg className="tab-icon" name={path} mode={RetinaImg.Mode.ContentPreserve} />
|
2016-05-07 07:23:48 +08:00
|
|
|
);
|
2016-04-01 06:52:03 +08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={classes} onClick={this._onClick}>
|
|
|
|
{icon}
|
|
|
|
<div className="name">{displayName}</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class PreferencesTabsBar extends React.Component {
|
|
|
|
static displayName = 'PreferencesTabsBar';
|
|
|
|
|
|
|
|
static propTypes = {
|
2017-07-12 06:42:18 +08:00
|
|
|
tabs: PropTypes.array.isRequired,
|
|
|
|
selection: PropTypes.shape({
|
|
|
|
accountId: PropTypes.string,
|
|
|
|
tabId: PropTypes.string,
|
|
|
|
}).isRequired,
|
2017-09-27 02:33:08 +08:00
|
|
|
};
|
2016-04-01 06:52:03 +08:00
|
|
|
|
|
|
|
renderTabs() {
|
2017-09-27 02:33:08 +08:00
|
|
|
return this.props.tabs.map(tabItem => (
|
|
|
|
<PreferencesTabItem key={tabItem.tabId} tabItem={tabItem} selection={this.props.selection} />
|
|
|
|
));
|
2016-04-01 06:52:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div className="container-preference-tabs">
|
|
|
|
<Flexbox direction="row" className="preferences-tabs">
|
2017-09-27 02:33:08 +08:00
|
|
|
<div style={{ flex: 1 }} />
|
2016-04-01 06:52:03 +08:00
|
|
|
{this.renderTabs()}
|
2017-09-27 02:33:08 +08:00
|
|
|
<div style={{ flex: 1 }} />
|
2016-04-01 06:52:03 +08:00
|
|
|
</Flexbox>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default PreferencesTabsBar;
|