diff --git a/lib/components/header.js b/lib/components/header.tsx similarity index 96% rename from lib/components/header.js rename to lib/components/header.tsx index 919bc67e..faa131fb 100644 --- a/lib/components/header.js +++ b/lib/components/header.tsx @@ -3,11 +3,15 @@ import React from 'react'; import {decorate, getTabsProps} from '../utils/plugins'; import Tabs_ from './tabs'; +import {HeaderProps} from '../hyper'; const Tabs = decorate(Tabs_, 'Tabs'); -export default class Header extends React.PureComponent { - onChangeIntent = active => { +export default class Header extends React.PureComponent { + headerMouseDownWindowX!: number; + headerMouseDownWindowY!: number; + + onChangeIntent = (active: string) => { // we ignore clicks if they're a byproduct of a drag // motion to move the window if (window.screenX !== this.headerMouseDownWindowX || window.screenY !== this.headerMouseDownWindowY) { @@ -30,7 +34,7 @@ export default class Header extends React.PureComponent { this.headerMouseDownWindowY = window.screenY; }; - handleHamburgerMenuClick = event => { + handleHamburgerMenuClick = (event: React.MouseEvent) => { let {right: x, bottom: y} = event.currentTarget.getBoundingClientRect(); x -= 15; // to compensate padding y -= 12; // ^ same diff --git a/lib/components/style-sheet.js b/lib/components/style-sheet.tsx similarity index 96% rename from lib/components/style-sheet.js rename to lib/components/style-sheet.tsx index 1dc02b72..a20af4c4 100644 --- a/lib/components/style-sheet.js +++ b/lib/components/style-sheet.tsx @@ -1,6 +1,7 @@ import React from 'react'; +import {StyleSheetProps} from '../hyper'; -export default class StyleSheet extends React.PureComponent { +export default class StyleSheet extends React.PureComponent { render() { const {backgroundColor, fontFamily, foregroundColor, borderColor} = this.props; diff --git a/lib/components/tab.js b/lib/components/tab.tsx similarity index 94% rename from lib/components/tab.js rename to lib/components/tab.tsx index 9d3509db..4c666034 100644 --- a/lib/components/tab.js +++ b/lib/components/tab.tsx @@ -1,8 +1,9 @@ import React from 'react'; +import {TabProps} from '../hyper'; -export default class Tab extends React.PureComponent { - constructor() { - super(); +export default class Tab extends React.PureComponent { + constructor(props: TabProps) { + super(props); this.state = { hovered: false @@ -21,7 +22,7 @@ export default class Tab extends React.PureComponent { }); }; - handleClick = event => { + handleClick = (event: React.MouseEvent) => { const isLeftClick = event.nativeEvent.which === 1; if (isLeftClick && !this.props.isActive) { @@ -29,7 +30,7 @@ export default class Tab extends React.PureComponent { } }; - handleMouseUp = event => { + handleMouseUp = (event: React.MouseEvent) => { const isMiddleClick = event.nativeEvent.which === 2; if (isMiddleClick) { diff --git a/lib/components/tabs.js b/lib/components/tabs.tsx similarity index 96% rename from lib/components/tabs.js rename to lib/components/tabs.tsx index 3b521619..6055469e 100644 --- a/lib/components/tabs.js +++ b/lib/components/tabs.tsx @@ -3,11 +3,12 @@ import React from 'react'; import {decorate, getTabProps} from '../utils/plugins'; import Tab_ from './tab'; +import {TabsProps} from '../hyper'; const Tab = decorate(Tab_, 'Tab'); const isMac = /Mac/.test(navigator.userAgent); -export default class Tabs extends React.PureComponent { +export default class Tabs extends React.PureComponent { render() { const {tabs = [], borderColor, onChange, onClose, fullScreen} = this.props; diff --git a/lib/containers/header.ts b/lib/containers/header.ts index ba1feaf6..6e0c5f2e 100644 --- a/lib/containers/header.ts +++ b/lib/containers/header.ts @@ -4,7 +4,7 @@ import Header from '../components/header'; import {closeTab, changeTab, maximize, openHamburgerMenu, unmaximize, minimize, close} from '../actions/header'; import {connect} from '../utils/plugins'; import {getRootGroups} from '../selectors'; -import {HyperState, HyperDispatch} from '../hyper'; +import {HyperState, HyperDispatch, ITab} from '../hyper'; const isMac = /Mac/.test(navigator.userAgent); @@ -15,16 +15,18 @@ const getActivityMarkers = ({ui}: HyperState) => ui.activityMarkers; const getTabs = createSelector( [getSessions, getRootGroups, getActiveSessions, getActiveRootGroup, getActivityMarkers], (sessions, rootGroups, activeSessions, activeRootGroup, activityMarkers) => - rootGroups.map(t => { - const activeSessionUid = activeSessions[t.uid]; - const session = sessions[activeSessionUid]; - return { - uid: t.uid, - title: session.title, - isActive: t.uid === activeRootGroup, - hasActivity: activityMarkers[session.uid] - }; - }) + rootGroups.map( + (t): ITab => { + const activeSessionUid = activeSessions[t.uid]; + const session = sessions[activeSessionUid]; + return { + uid: t.uid, + title: session.title, + isActive: t.uid === activeRootGroup, + hasActivity: activityMarkers[session.uid] + }; + } + ) ); const mapStateToProps = (state: HyperState) => { diff --git a/lib/hyper.d.ts b/lib/hyper.d.ts index ada18f85..22b3c271 100644 --- a/lib/hyper.d.ts +++ b/lib/hyper.d.ts @@ -207,3 +207,37 @@ export type NotificationsProps = NotificationsConnectedProps & extensionProps; import {TermsConnectedProps} from './containers/terms'; export type TermsProps = TermsConnectedProps & extensionProps & {ref_: any}; + +export type StyleSheetProps = { + backgroundColor: string; + borderColor: string; + fontFamily: string; + foregroundColor: string; +} & extensionProps; + +export type TabProps = { + borderColor: string; + hasActivity: boolean; + isActive: boolean; + isFirst: boolean; + isLast: boolean; + onClick: (event: React.MouseEvent) => void; + onClose: () => void; + onSelect: () => void; + text: string; +} & extensionProps; + +export type ITab = { + uid: string; + title: string; + isActive: boolean; + hasActivity: boolean; +}; + +export type TabsProps = { + tabs: ITab[]; + borderColor: string; + onChange: () => void; + onClose: () => void; + fullScreen: boolean; +} & extensionProps;