Mailspring/app/internal_packages/thread-snooze/lib/snooze-buttons.tsx
Ben Gotow 149b389508
Replace Babel with TypeScript compiler, switch entire app to TypeScript 🎉 (#1404)
* Switch to using Typescript instead of Babel

* Switch all es6 / jsx file extensions to ts / tsx

* Convert Utils to a TS module from module.exports style module

* Move everything from module.exports to typescript exports

* Define .d.ts files for mailspring-exports and component kit… Yes it seems this is the best option :(

* Load up on those @types

* Synthesize TS types from PropTypes for standard components

* Add types to Model classes and move constructor constants to instance vars

* 9800 => 7700 TS errors

* 7700 => 5600 TS errors

* 5600 => 5330 TS errors

* 5330 => 4866 TS errors

* 4866 => 4426 TS errors

* 4426 => 2411 TS errors

* 2411 > 1598 TS errors

* 1598 > 769 TS errors

* 769 > 129 TS errors

* 129 > 22 TS errors

* Fix runtime errors

* More runtime error fixes

* Remove support for custom .es6 file extension

* Remove a few odd remaining references to Nylas

* Don’t ship Typescript support in the compiled app for now

* Fix issues in compiled app - module resolution in TS is case sensitive?

* README updates

* Fix a few more TS errors

* Make “No Signature” option clickable + selectable

* Remove flicker when saving file and reloading keymaps

* Fix mail rule item height in preferences

* Fix missing spacing in thread sharing popover

* Fix scrollbar ticks being nested incorrectly

* Add Japanese as a manually reviewed language

* Prevent the thread list from “sticking”

* Re-use Sheet when switching root tabs, prevent sidebar from resetting

* Ensure specs run

* Update package configuration to avoid shpping types

* Turn eslint back on - we will opt-in to the TS rules one by one
2019-03-04 11:03:12 -08:00

118 lines
3.2 KiB
TypeScript

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import ReactDOM from 'react-dom';
import { Actions, FocusedPerspectiveStore, Thread } from 'mailspring-exports';
import { RetinaImg, BindGlobalCommands } from 'mailspring-component-kit';
import SnoozePopover from './snooze-popover';
interface SnoozeButtonProps {
className: string;
threads: Thread[];
direction: string;
shouldRenderIconImg: boolean;
getBoundingClientRect: (inst: any) => ClientRect;
}
class SnoozeButton extends Component<SnoozeButtonProps> {
static propTypes = {
className: PropTypes.string,
threads: PropTypes.array,
direction: PropTypes.string,
shouldRenderIconImg: PropTypes.bool,
getBoundingClientRect: PropTypes.func,
};
static defaultProps = {
className: 'btn btn-toolbar',
direction: 'down',
shouldRenderIconImg: true,
getBoundingClientRect: inst =>
(ReactDOM.findDOMNode(inst) as HTMLElement).getBoundingClientRect(),
};
onClick = (event?: React.MouseEvent<any>) => {
if (event) {
event.stopPropagation();
}
const { threads, direction, getBoundingClientRect } = this.props;
const buttonRect = getBoundingClientRect(this);
Actions.openPopover(<SnoozePopover threads={threads} />, {
originRect: buttonRect,
direction: direction,
});
};
render() {
return (
<button
title="Snooze"
tabIndex={-1}
className={`snooze-button ${this.props.className}`}
onClick={this.onClick}
>
{this.props.shouldRenderIconImg ? (
<RetinaImg name="toolbar-snooze.png" mode={RetinaImg.Mode.ContentIsMask} />
) : null}
</button>
);
}
}
export class QuickActionSnooze extends Component<{ thread: Thread }> {
static displayName = 'QuickActionSnooze';
static propTypes = {
thread: PropTypes.object,
};
static containerRequired = false;
getBoundingClientRect = () => {
// Grab the parent node because of the zoom applied to this button. If we
// took this element directly, we'd have to divide everything by 2
const element = ReactDOM.findDOMNode(this).parentNode as HTMLElement;
const { height, width, top, bottom, left, right } = element.getBoundingClientRect();
// The parent node is a bit too much to the left, lets adjust this.
return { height, width, top, bottom, right, left: left + 5 };
};
render() {
if (!FocusedPerspectiveStore.current().isInbox()) {
return <span />;
}
return (
<SnoozeButton
direction="left"
threads={[this.props.thread]}
className="btn action action-snooze"
shouldRenderIconImg={false}
getBoundingClientRect={this.getBoundingClientRect}
/>
);
}
}
export class ToolbarSnooze extends Component<{ items: Thread[] }> {
static displayName = 'ToolbarSnooze';
static propTypes = {
items: PropTypes.array,
};
static containerRequired = false;
_btn: SnoozeButton;
render() {
if (!FocusedPerspectiveStore.current().isInbox()) {
return <span />;
}
return (
<BindGlobalCommands commands={{ 'core:snooze-item': () => this._btn.onClick() }}>
<SnoozeButton threads={this.props.items} ref={b => (this._btn = b)} />
</BindGlobalCommands>
);
}
}