Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add tabs for tables

Lukasz Szewczyk37ba58d57f65
diff --git a/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsx b/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsx
index a5b817f563..067b98e846 100644
--- a/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsx
+++ b/saleor/static/dashboard-next/categories/components/CategoryUpdatePage/CategoryUpdatePage.tsx
@@ -19,6 +19,8 @@ import SaveButtonBar, {
SaveButtonBarState
} from "../../../components/SaveButtonBar/SaveButtonBar";
+import Tabs, { SingleTab } from "../../../components/Tab";
+
import { UserError } from "../../../";
// import Card from "@material-ui/core/Card";
import Button from "@material-ui/core/Button";
@@ -94,6 +96,9 @@ const decorate = withStyles(theme => ({
display: "grid",
marginTop: theme.spacing.unit * 2,
gridGap: theme.spacing.unit * 4 + "px"
+ },
+ tabsBorder: {
+ borderBottom: "1px solid #eeeeee"
}
}));
@@ -189,23 +194,57 @@ export const CategoryUpdatePage = decorate<CategoryUpdatePageProps>(
/>
</>
)}
- <CategoryList
- categories={subcategories}
- isRoot={isRoot}
- onAdd={onAddCategory}
- onRowClick={onCategoryClick}
- />
+ {isRoot && (
+ <CategoryList
+ categories={subcategories}
+ isRoot={isRoot}
+ onAdd={onAddCategory}
+ onRowClick={onCategoryClick}
+ />
+ )}
{!isRoot && (
<>
- <CategoryProductsCard
- products={products}
- disabled={disabled}
- pageInfo={pageInfo}
- onNextPage={onNextPage}
- onPreviousPage={onPreviousPage}
- onRowClick={onProductClick}
- onAdd={onAddProduct}
- />{" "}
+ <Tabs>
+ {({ changeTab, currentTab }) => (
+ <>
+ <div className={classes.tabsBorder}>
+ <SingleTab
+ isActive={currentTab === 0}
+ value={0}
+ changeTab={changeTab}
+ >
+ Subcategories
+ </SingleTab>
+ <SingleTab
+ isActive={currentTab === 1}
+ value={1}
+ changeTab={changeTab}
+ >
+ Products
+ </SingleTab>
+ </div>
+ {currentTab === 0 && (
+ <CategoryList
+ categories={subcategories}
+ isRoot={isRoot}
+ onAdd={onAddCategory}
+ onRowClick={onCategoryClick}
+ />
+ )}
+ {currentTab === 1 && (
+ <CategoryProductsCard
+ products={products}
+ disabled={disabled}
+ pageInfo={pageInfo}
+ onNextPage={onNextPage}
+ onPreviousPage={onPreviousPage}
+ onRowClick={onProductClick}
+ onAdd={onAddProduct}
+ />
+ )}
+ </>
+ )}
+ </Tabs>
<SaveButtonBar
onCancel={onBack}
onDelete={toggleDeleteDialog}
diff --git a/saleor/static/dashboard-next/components/Tab/SingleTab.tsx b/saleor/static/dashboard-next/components/Tab/SingleTab.tsx
new file mode 100644
index 0000000000..c86559b8e0
--- /dev/null
+++ b/saleor/static/dashboard-next/components/Tab/SingleTab.tsx
@@ -0,0 +1,55 @@
+import * as React from "react";
+import { withStyles } from "@material-ui/core/styles";
+import Typography from "@material-ui/core/Typography";
+import * as classNames from "classnames";
+
+interface TabProps {
+ isActive: boolean;
+ value: number;
+ changeTab: (index: number) => void;
+}
+
+const decorate = withStyles(theme => ({
+ active: {},
+ root: {
+ "&$active": {
+ borderBottomColor: theme.palette.primary.main
+ },
+ borderBottomWidth: 1,
+ borderBottomStyle: "solid" as "solid",
+ borderBottomColor: "transparent",
+ display: "inline-block" as "inline-block",
+ minWidth: 40,
+ fontWeight: theme.typography.fontWeightRegular,
+ marginRight: theme.spacing.unit * 4,
+ cursor: "pointer",
+ "&:hover": {
+ color: "#5AB378",
+ opacity: 1
+ },
+ "&$tabSelected": {
+ color: "#5AB378",
+ fontWeight: theme.typography.fontWeightMedium
+ },
+ "&:focus": {
+ color: "#5AB378"
+ }
+ }
+}));
+
+export const SingleTab = decorate<TabProps>(
+ ({ classes, children, isActive, value, changeTab }) => (
+ <Typography
+ component="span"
+ className={classNames({
+ [classes.root]: true,
+ [classes.active]: isActive
+ })}
+ onClick={() => changeTab(value)}
+ >
+ {children}
+ </Typography>
+ )
+);
+
+export default SingleTab;
diff --git a/saleor/static/dashboard-next/components/Tab/Tabs.tsx b/saleor/static/dashboard-next/components/Tab/Tabs.tsx
new file mode 100644
index 0000000000..5eb09a3ff6
--- /dev/null
+++ b/saleor/static/dashboard-next/components/Tab/Tabs.tsx
@@ -0,0 +1,31 @@
+import * as React from "react";
+
+export interface TabsProps {
+ children: (
+ props: {
+ changeTab: (index: number) => void;
+ currentTab: number;
+ }
+ ) => React.ReactNode;
+}
+
+interface TabsState {
+ currentTab: number;
+}
+
+class Tabs extends React.Component<TabsProps, TabsState> {
+ state: TabsState = {
+ currentTab: 0
+ };
+
+ changeTab = (index: number) => this.setState({ currentTab: index });
+
+ render() {
+ return this.props.children({
+ changeTab: this.changeTab,
+ currentTab: this.state.currentTab
+ });
+ }
+}
+
+export default Tabs;
diff --git a/saleor/static/dashboard-next/components/Tab/index.ts b/saleor/static/dashboard-next/components/Tab/index.ts
new file mode 100644
index 0000000000..6fad2c4fcb
--- /dev/null
+++ b/saleor/static/dashboard-next/components/Tab/index.ts
@@ -0,0 +1,3 @@
+export { default } from "./Tabs";
+export * from "./Tabs";
+export * from "./SingleTab";