Skip to content

Commit

Permalink
feat: remove react-tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
d4rkr00t committed Feb 26, 2018
1 parent e254155 commit b05cc20
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 122 deletions.
14 changes: 0 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -35,12 +35,12 @@
"html": "^1.0.0",
"ie-array-find-polyfill": "^1.1.0",
"jsondiffpatch": "github:d4rkr00t/jsondiffpatch#d80390b4354befe55802e292122b8059462c1b7d",
"prop-types": "^15.6.0",
"prosemirror-model": ">=1.0.0",
"prosemirror-state": ">=1.0.0",
"react-dock": "^0.2.3",
"react-emotion": "^9.0.2",
"react-json-tree": "^0.11.0",
"react-tabs": "^2.1.1",
"unstated": "^1.0.3"
},
"peerDependencies": {
Expand Down
98 changes: 98 additions & 0 deletions src/components/tabs.js
@@ -0,0 +1,98 @@
import React from "react";
import styled from "react-emotion";
import PropTypes from "prop-types";
import theme from "../theme";

export const TabList = styled("div")({
display: "flex",
listStyle: "none",
borderBottom: `1px solid ${theme.main20}`
});
TabList.displayName = "TabList";

export const TabsStled = styled("div")({
height: "100%",
width: "100%"
});
TabsStled.displayName = "TabsStyled";

export const TabStyled = styled("div")(
{
color: theme.white,
textTransform: "uppercase",
fontSize: "13px",
padding: "16px 24px 14px",
boxSizing: "border-box",
userSelect: "none",

"&:hover": {
cursor: "pointer",
background: theme.white05
},

"&:focus": {
outline: "none"
}
},
props => ({
borderBottom: props.isSelected ? `2px solid ${theme.main}` : "none"
})
);
TabStyled.displayName = "TabStyled";

export class Tab extends React.Component {
render() {
return (
<TabStyled
isSelected={this.props.index === this.context.tabs.selectedIndex}
onClick={() => {
(this.context.tabs.onSelect || (() => {}))(this.props.index);
}}
>
{this.props.children}
</TabStyled>
);
}
}
Tab.contextTypes = {
tabs: PropTypes.object.isRequired
};

export const TabPanelStyled = styled("div")({
width: "100%",
height: "calc(100% - 48px)",
boxSizing: "border-box"
});
TabPanelStyled.displayName = "TabPanelStyled";

export class TabPanel extends React.Component {
render() {
return (
<TabPanelStyled>
{this.props.children({ index: this.context.tabs.selectedIndex })}
</TabPanelStyled>
);
}
}
TabPanel.contextTypes = {
tabs: PropTypes.object.isRequired
};

export class Tabs extends React.Component {
getChildContext() {
return {
tabs: {
onSelect: this.props.onSelect,
selectedIndex: this.props.selectedIndex
}
};
}

render() {
return <TabsStled>{this.props.children}</TabsStled>;
}
}

Tabs.childContextTypes = {
tabs: PropTypes.object
};
136 changes: 30 additions & 106 deletions src/dev-tools-expanded.js
@@ -1,7 +1,7 @@
import React from "react";
import Dock from "react-dock";
import styled from "react-emotion";
import { Tab, Tabs, TabList, TabPanel } from "react-tabs";
import { Tab, Tabs, TabList, TabPanel } from "./components/tabs";
import { Subscribe } from "unstated";
import GlobalStateContainer from "./state/global";
import EditorStateContainer from "./state/editor";
Expand All @@ -22,60 +22,10 @@ const DockContainer = styled("div")({
overflow: "hidden",
background: theme.mainBg,
fontFamily: "Helvetica Neue, Calibri Light, Roboto, sans-serif",
fontSize: "13px",

"& .tabs": {
height: "100%",
width: "100%",

"& ul": {
margin: 0,
padding: 0
},

"& .tabs__tablist": {
display: "flex",
listStyle: "none",
borderBottom: `1px solid ${theme.main20}`
},

"& .tabs_tab-panel--selected": {
height: "100%"
},

"& .tabs--selected": {
borderBottom: `2px solid ${theme.main}`
}
}
fontSize: "13px"
});
DockContainer.displayName = "DockContainer";

const TabLabel = styled("div")({
color: theme.white,
textTransform: "uppercase",
fontSize: "13px",
padding: "16px 24px 14px",
boxSizing: "border-box",
userSelect: "none",

"&:hover": {
cursor: "pointer",
background: theme.white05
},

"&:focus": {
outline: "none"
}
});
TabLabel.displayName = "TabLabel";

const TabPanelWrapper = styled("div")({
width: "100%",
height: "calc(100% - 48px)",
boxSizing: "border-box"
});
TabPanelWrapper.displayName = "TabPanelWrapper";

const CloseButton = styled("button")({
background: "none",
border: "none",
Expand Down Expand Up @@ -153,62 +103,36 @@ export default function DevToolsExpanded() {
</SaveSnapshotButton>
)}
</Subscribe>
<Tabs
className="tabs"
selectedTabClassName="tabs--selected"
selectedTabPanelClassName="tabs_tab-panel--selected"
selectedIndex={tabIndex}
onSelect={selectTab}
>
<TabList className="tabs__tablist">
<Tab>
<TabLabel>State</TabLabel>
</Tab>
<Tab>
<TabLabel>History</TabLabel>
</Tab>
<Tab>
<TabLabel>Plugins</TabLabel>
</Tab>
<Tab>
<TabLabel>Schema</TabLabel>
</Tab>
<Tab>
<TabLabel>Structure</TabLabel>
</Tab>
<Tab>
<TabLabel>Snapshots</TabLabel>
</Tab>

<Tabs onSelect={selectTab} selectedIndex={tabIndex}>
<TabList>
<Tab index="state">State</Tab>
<Tab index="history">History</Tab>
<Tab index="plugins">Plugins</Tab>
<Tab index="schema">Schema</Tab>
<Tab index="structure">Structure</Tab>
<Tab index="snapshots">Snapshots</Tab>
</TabList>

<TabPanel>
<TabPanelWrapper>
<StateTab />
</TabPanelWrapper>
</TabPanel>
<TabPanel>
<TabPanelWrapper>
<HistoryTab />
</TabPanelWrapper>
</TabPanel>
<TabPanel>
<TabPanelWrapper>
<PluginsTab />
</TabPanelWrapper>
</TabPanel>
<TabPanel>
<TabPanelWrapper>
<SchemaTab />
</TabPanelWrapper>
</TabPanel>
<TabPanel>
<TabPanelWrapper>
<StructureTab />
</TabPanelWrapper>
</TabPanel>
<TabPanel>
<TabPanelWrapper>
<SnapshotsTab />
</TabPanelWrapper>
{({ index }) => {
switch (index) {
case "state":
return <StateTab />;
case "history":
return <HistoryTab />;
case "plugins":
return <PluginsTab />;
case "schema":
return <SchemaTab />;
case "structure":
return <StructureTab />;
case "snapshots":
return <SnapshotsTab />;
default:
return <StateTab />;
}
}}
</TabPanel>
</Tabs>
</DockContainer>
Expand Down
2 changes: 1 addition & 1 deletion src/state/global.js
Expand Up @@ -3,7 +3,7 @@ import { Container } from "unstated";
export default class GlobalStateContainer extends Container {
state = {
opened: false,
tabIndex: 0,
tabIndex: "state",
defaultSize: 0.5
};

Expand Down

0 comments on commit b05cc20

Please sign in to comment.