From 96f62f8d32d2e73374ee7d8b0269c5985517b838 Mon Sep 17 00:00:00 2001 From: John Tran Date: Wed, 22 Aug 2018 12:49:09 -0700 Subject: [PATCH] falcon-ui: Added initial Tabs to HomePage --- app/containers/HomePage.js | 14 +++++ packages/falcon-ui/src/components/HTMLTabs.js | 19 ++++++ packages/falcon-ui/src/components/Tabs/Tab.js | 13 ++++- .../falcon-ui/src/components/Tabs/TabList.js | 58 +++++++++++++++++-- .../falcon-ui/src/components/Tabs/Tabs.js | 38 ++++++++++-- 5 files changed, 129 insertions(+), 13 deletions(-) diff --git a/app/containers/HomePage.js b/app/containers/HomePage.js index 55cffe4..f2efe7f 100644 --- a/app/containers/HomePage.js +++ b/app/containers/HomePage.js @@ -4,6 +4,13 @@ import React, { Component } from 'react'; import { ResizableBox } from 'react-resizable'; import { ipcRenderer } from 'electron'; import { Switch, Route } from 'react-router'; +import { + Tabs, + Tab, + TabPanel, + TabList, + HTMLTabs +} from '@falcon-client/falcon-ui'; import Loadable from 'react-loadable'; import Header from '../components/Header'; import Footer from '../components/Footer'; @@ -358,6 +365,13 @@ export default class HomePage extends Component { activeConnections={this.state.activeConnections} /> + {/* */} + + + + + +
this.layoutTabs()); this.el.addEventListener('dblclick', event => { @@ -74,15 +79,18 @@ class ChromeTabs { /** Returns array of all tab elements */ get tabEls() { + console.log('In get tabEls'); return Array.from(this.el.querySelectorAll('.chrome-tab')); } get tabContentEl() { + console.log('In get tabContentEl'); return this.el.querySelector('.chrome-tabs-content'); } /** Gets width of tabs */ get tabWidth(): number { + console.log('In get tabWidth'); const tabsContentWidth = this.tabContentEl.clientWidth - this.options.tabOverlapDistance; const width = @@ -99,6 +107,7 @@ class ChromeTabs { /** Gets the positions of each tabs */ get tabPositions() { + console.log('In tabPositions'); const tabEffectiveWidth = this.tabEffectiveWidth; let left = 0; const positions = []; @@ -112,6 +121,7 @@ class ChromeTabs { /** Lays out all the current tabs */ layoutTabs() { + console.log('In layoutTabs'); const tabWidth = this.tabWidth; this.cleanUpPreviouslyDraggedTabs(); @@ -132,6 +142,7 @@ class ChromeTabs { } fixZIndexes() { + console.log('In fixZIndexes'); const bottomBarEl = this.el.querySelector('.chrome-tabs-bottom-bar'); const tabEls = this.tabEls; @@ -148,6 +159,7 @@ class ChromeTabs { /** Create a tab's HTML representation */ createNewTabEl() { + console.log('In createNewTabEl'); const div = document.createElement('div'); div.innerHTML = tabTemplate; return div.firstElementChild; @@ -155,6 +167,7 @@ class ChromeTabs { /** Adds additional tabs. Performs necessary HTML/CSS modifications */ addTab(tabProperties) { + console.log('In addTab'); const tabEl = this.createNewTabEl(); tabEl.classList.add('chrome-tab-just-added'); @@ -172,6 +185,7 @@ class ChromeTabs { /** Sets the selected tab. Performs necessary HTML/CSS modifications */ setCurrentTab(tabEl) { + console.log('In setCurrentTab'); const currentTab = this.el.querySelector('.chrome-tab-current'); if (currentTab) currentTab.classList.remove('chrome-tab-current'); tabEl.classList.add('chrome-tab-current'); @@ -180,6 +194,7 @@ class ChromeTabs { } removeTab(tabEl) { + console.log('In removeTab'); if (tabEl.classList.contains('chrome-tab-current')) { if (tabEl.previousElementSibling) { this.setCurrentTab(tabEl.previousElementSibling); @@ -196,6 +211,7 @@ class ChromeTabs { /** Updates the contents of a Tab (in the TabList) */ updateTab(tabEl, tabProperties) { + console.log('In updateTab'); tabEl.querySelector('.chrome-tab-title').textContent = tabProperties.title; tabEl.querySelector('.chrome-tab-favicon').style.backgroundImage = `url('${ tabProperties.favicon @@ -203,12 +219,14 @@ class ChromeTabs { } cleanUpPreviouslyDraggedTabs() { + console.log('In cleanUpPreviouslyDraggedTabs'); this.tabEls.forEach(tabEl => tabEl.classList.remove('chrome-tab-just-dragged') ); } setupDraggabilly() { + console.log('In setupDraggabilly'); const tabEls = this.tabEls; const tabEffectiveWidth = this.tabEffectiveWidth; const tabPositions = this.tabPositions; @@ -282,6 +300,7 @@ class ChromeTabs { } animateTabMove(tabEl, originIndex, destinationIndex) { + console.log('In animateTabMove'); if (destinationIndex < originIndex) { tabEl.parentNode.insertBefore(tabEl, this.tabEls[destinationIndex]); } else { diff --git a/packages/falcon-ui/src/components/Tabs/Tab.js b/packages/falcon-ui/src/components/Tabs/Tab.js index b6d16b6..242725e 100644 --- a/packages/falcon-ui/src/components/Tabs/Tab.js +++ b/packages/falcon-ui/src/components/Tabs/Tab.js @@ -6,12 +6,14 @@ type Props = { disabled?: boolean, tabIndex: string, disabledClassName?: string, + title: string, focus: boolean, // private id: string, // private panelId: string, // private selected: boolean, // private selectedClassName: string, - tabRef: Function // private + tabRef: Function, // private + left: number // private }; export default class Tab extends React.Component { @@ -45,6 +47,13 @@ export default class Tab extends React.Component { ...attributes } = this.props; - return
; + return ( +
+
+
+
{this.props.title}
+
+
+ ); } } diff --git a/packages/falcon-ui/src/components/Tabs/TabList.js b/packages/falcon-ui/src/components/Tabs/TabList.js index 7576f81..3740edb 100644 --- a/packages/falcon-ui/src/components/Tabs/TabList.js +++ b/packages/falcon-ui/src/components/Tabs/TabList.js @@ -2,13 +2,59 @@ import * as React from 'react'; type Props = { children: React.ReactNode, - className: string + className: string, + id: string, // private + selected: boolean, // private + selectedClassName: string, + clientWidth: number, + minTabWidth: number, + maxTabWidth: number, + tabOverlapDistance: number, + tabId: string // private }; export default class TabList extends React.Component { - render = () => ( -
- {children} -
- ); + getTabWidth = (): number => { + console.log('In get tabWidth'); + const tabsContentWidth = + this.props.clientWidth - this.props.tabOverlapDistance; + const width = + tabsContentWidth / this.tabEls.length + this.props.tabOverlapDistance; + return Math.max( + this.props.minTabWidth, + Math.min(this.props.maxTabWidth, width) + ); + }; + + getTabEffectiveWidth = () => + this.getTabWidth() - this.props.tabOverlapDistance; + + getTabPositions = () => { + console.log('In getTabPositions'); + const tabEffectiveWidth = this.getTabEffectiveWidth(); + let left = 0; + const positions = []; + + this.tabEls.forEach((tabEl, i) => { + positions.push(left); + left += tabEffectiveWidth; + }); + return positions; + }; + + renderChildren = () => + React.Children.map(this.props.children, child => { + console.log('In TabList.js'); + console.dir(child); + return React.cloneElement(child, {}); + }); + + render() { + return ( +
+
{this.renderChildren()}
+
+
+ ); + } } diff --git a/packages/falcon-ui/src/components/Tabs/Tabs.js b/packages/falcon-ui/src/components/Tabs/Tabs.js index ad1c51d..9090eeb 100644 --- a/packages/falcon-ui/src/components/Tabs/Tabs.js +++ b/packages/falcon-ui/src/components/Tabs/Tabs.js @@ -1,5 +1,5 @@ // @flow -import * as React from 'react'; +import React, { Children, Component } from 'react'; type Props = { children: React.ReactNode, @@ -7,14 +7,42 @@ type Props = { defaultFocus: boolean, defaultIndex: number, disabledTabClassName: string, - onSelect: (index: number, lastIndex: number, event: Event) => ?boolean, selectedIndex: number, selectedTabClassName: string, - selectedTabPanelClassName: string + selectedTabPanelClassName: string, + width: number, + onSelect: (index: number, lastIndex: number, event: Event) => ?boolean }; -export default class Tabs extends React.Component { +export default class Tabs extends Component { + renderChildren = () => + React.Children.map(this.props.children, child => + // console.log('In Tab.js'); + // console.dir(child); + React.cloneElement(child, {}) + ); + + 3; + + gettabWidth(): number { + const tabsContentWidth = + this.tabContentEl.clientWidth - this.options.tabOverlapDistance; + const width = + tabsContentWidth / this.tabEls.length + this.options.tabOverlapDistance; + return Math.max( + this.options.minWidth, + Math.min(this.options.maxWidth, width) + ); + } + + renderSelectedTab = (i: number) => {}; + render() { - return
; + return ( +
+
{this.renderChildren()}
+
+
+ ); } }