From 71c5c7c64fb242269f601e5817e7b0da90565d59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bel=C3=A9n=20Curcio?= Date: Mon, 10 Sep 2018 11:13:13 -0300 Subject: [PATCH] Basic Tab usage --- src/core/client/ui/components/Tabs/Tab.css | 42 ++++++++++++ src/core/client/ui/components/Tabs/Tab.tsx | 43 ++++++++++++ src/core/client/ui/components/Tabs/TabBar.css | 13 ++++ src/core/client/ui/components/Tabs/TabBar.mdx | 52 +++++++++++++++ src/core/client/ui/components/Tabs/TabBar.tsx | 66 +++++++++++++++++++ .../client/ui/components/Tabs/TabContent.tsx | 0 .../client/ui/components/Tabs/TabPane.tsx | 0 src/core/client/ui/components/Tabs/index.ts | 1 + 8 files changed, 217 insertions(+) create mode 100644 src/core/client/ui/components/Tabs/Tab.css create mode 100644 src/core/client/ui/components/Tabs/Tab.tsx create mode 100644 src/core/client/ui/components/Tabs/TabBar.css create mode 100644 src/core/client/ui/components/Tabs/TabBar.mdx create mode 100644 src/core/client/ui/components/Tabs/TabBar.tsx create mode 100644 src/core/client/ui/components/Tabs/TabContent.tsx create mode 100644 src/core/client/ui/components/Tabs/TabPane.tsx create mode 100644 src/core/client/ui/components/Tabs/index.ts diff --git a/src/core/client/ui/components/Tabs/Tab.css b/src/core/client/ui/components/Tabs/Tab.css new file mode 100644 index 000000000..1a25fcc1c --- /dev/null +++ b/src/core/client/ui/components/Tabs/Tab.css @@ -0,0 +1,42 @@ +.root { + box-sizing: border-box; + list-style: none; + padding: var(--spacing-unit); + display: inline-flex; + margin-bottom: -1px; +} + +.root.primary { + background: #f2f2f2; + color: #787d80; + border: 1px solid #979797; + border-left-width: 0; + padding: calc(0.5 * var(--spacing-unit)) calc(var(--spacing-unit) * 2); + + &:first-child { + border-left-width: 1px; + border-top-left-radius: var(--round-corners); + } + + &:last-child { + border-top-right-radius: var(--round-corners); + } + + &.active { + background-color: var(--palette-common-white); + color: var(--palette-common-black); + border-bottom-color: white; + border-top-width: 5px; + border-top-color: #3498db; + } +} + +.secondary { + border-bottom: 1px solid #e0e0e0; + padding: calc(0.5 * var(--spacing-unit)) calc(var(--spacing-unit) * 2); + + &.active { + font-weight: bold; + border-bottom: 3px solid #0277bd; + } +} diff --git a/src/core/client/ui/components/Tabs/Tab.tsx b/src/core/client/ui/components/Tabs/Tab.tsx new file mode 100644 index 000000000..32509b75f --- /dev/null +++ b/src/core/client/ui/components/Tabs/Tab.tsx @@ -0,0 +1,43 @@ +import cn from "classnames"; +import React, { StatelessComponent } from "react"; +import { withStyles } from "talk-ui/hocs"; +import * as styles from "./Tab.css"; + +export interface TabBarProps { + /** + * Convenient prop to override the root styling. + */ + className?: string; + /** + * Override or extend the styles applied to the component. + */ + classes: typeof styles; + + tabId: number; + active: boolean; + color: string; + onTabClick?: () => void; +} + +const TabBar: StatelessComponent = props => { + const { className, classes, children, tabId, active, color } = props; + + const rootClassName = cn( + classes.root, + { + [classes.primary]: color === "primary", + [classes.secondary]: color === "secondary", + [classes.active]: active, + }, + className + ); + + return ( +
  • + {children} +
  • + ); +}; + +const enhanced = withStyles(styles)(TabBar); +export default enhanced; diff --git a/src/core/client/ui/components/Tabs/TabBar.css b/src/core/client/ui/components/Tabs/TabBar.css new file mode 100644 index 000000000..8d076ee0a --- /dev/null +++ b/src/core/client/ui/components/Tabs/TabBar.css @@ -0,0 +1,13 @@ +.root { + display: flex; + padding: 0; + margin: 0; +} + +.primary { + border-bottom: 1px solid #787d80; +} + +.secondary { + border-bottom: 1px solid #e0e0e0; +} diff --git a/src/core/client/ui/components/Tabs/TabBar.mdx b/src/core/client/ui/components/Tabs/TabBar.mdx new file mode 100644 index 000000000..5b7e47727 --- /dev/null +++ b/src/core/client/ui/components/Tabs/TabBar.mdx @@ -0,0 +1,52 @@ +--- +name: TabBar +menu: UI Kit +--- + +import { Playground, PropsTable } from 'docz' +import HorizontalGutter from '../HorizontalGutter' + + +import TabBar from './TabBar' +import Tab from './Tab' + + +# TabBar + +## Basic Use + + + + + Tab one + Active Tab + Tab Three + + + + Tab one + Active Tab + Tab Three + + + + Tab one + Active Tab + Tab Three + + + + + +## Secondary Color + + + + + Tab one + Active Tab + Tab Three + + + + diff --git a/src/core/client/ui/components/Tabs/TabBar.tsx b/src/core/client/ui/components/Tabs/TabBar.tsx new file mode 100644 index 000000000..6aef2e6a8 --- /dev/null +++ b/src/core/client/ui/components/Tabs/TabBar.tsx @@ -0,0 +1,66 @@ +import cn from "classnames"; +import React, { StatelessComponent } from "react"; +import { withStyles } from "talk-ui/hocs"; +import * as styles from "./TabBar.css"; + +export interface TabBarProps { + /** + * Convenient prop to override the root styling. + */ + className?: string; + /** + * Override or extend the styles applied to the component. + */ + classes: typeof styles; + + color: "primary" | "secondary"; + activeId?: string; + defaultActiveId?: string; + onChange?: (activeId: string) => void; + onTabClick?: () => void; +} + +const TabBar: StatelessComponent = props => { + const { + className, + classes, + children, + onTabClick, + activeId, + color, + defaultActiveId, + } = props; + + const rootClassName = cn( + classes.root, + [ + { + [classes.primary]: color === "primary", + [classes.secondary]: color === "secondary", + }, + ], + className + ); + + const tabs = React.Children.toArray(children).map( + (child: React.ReactElement, index: number) => + React.cloneElement(child, { + tabId: index, + active: + defaultActiveId && !activeId + ? child.props.tabId === defaultActiveId + : child.props.tabId === activeId, + color, + onTabClick, + }) + ); + + return
      {tabs}
    ; +}; + +TabBar.defaultProps = { + color: "primary", +}; + +const enhanced = withStyles(styles)(TabBar); +export default enhanced; diff --git a/src/core/client/ui/components/Tabs/TabContent.tsx b/src/core/client/ui/components/Tabs/TabContent.tsx new file mode 100644 index 000000000..e69de29bb diff --git a/src/core/client/ui/components/Tabs/TabPane.tsx b/src/core/client/ui/components/Tabs/TabPane.tsx new file mode 100644 index 000000000..e69de29bb diff --git a/src/core/client/ui/components/Tabs/index.ts b/src/core/client/ui/components/Tabs/index.ts new file mode 100644 index 000000000..58ecee89f --- /dev/null +++ b/src/core/client/ui/components/Tabs/index.ts @@ -0,0 +1 @@ +export { default } from "./TabBar";