import React from "react"; import { Tab, Tabs, TabList, TabPanel } from "react-tabs"; import "react-tabs/style/react-tabs.css"; import styled from "styled-components"; import Icon, { IconName, IconSize } from "./Icon"; import { Classes } from "./common"; export type TabProp = { key: string; title: string; panelComponent: JSX.Element; icon: IconName; }; const TabsWrapper = styled.div<{ shouldOverflow?: boolean }>` user-select: none; border-radius: 0px; height: 100%; .${Classes.ICON} { margin-right: ${props => props.theme.spaces[3]}px; } .react-tabs { height: 100%; } .react-tabs__tab-panel { height: calc(100% - 32px); overflow: scroll; } .react-tabs__tab-list { display: flex; align-items: center; border-bottom: ${props => props.theme.spaces[1] - 2}px solid ${props => props.theme.colors.blackShades[3]}; color: ${props => props.theme.colors.blackShades[6]}; path { fill: ${props => props.theme.colors.blackShades[6]}; } ${props => props.shouldOverflow && ` overflow-y: hidden; overflow-x: auto; white-space: nowrap; `} } .react-tabs__tab { display: flex; align-items: center; justify-content: flex-start; padding: 0 0 ${props => props.theme.spaces[4]}px 0; margin-right: ${props => props.theme.spaces[12] - 3}px; text-align: center; display: inline-flex; align-items: center; justify-content: center; border-color: transparent; position: relative; } .react-tabs__tab:hover { color: ${props => props.theme.colors.blackShades[9]}; path { fill: ${props => props.theme.colors.blackShades[9]}; } } .react-tabs__tab--selected { color: ${props => props.theme.colors.blackShades[9]}; background-color: transparent; path { fill: ${props => props.theme.colors.blackShades[9]}; } &::after { content: ""; position: absolute; width: 100%; bottom: ${props => props.theme.spaces[0] - 1}px; left: ${props => props.theme.spaces[0]}px; height: ${props => props.theme.spaces[1] - 2}px; background-color: ${props => props.theme.colors.info.main}; } } .react-tabs__tab:focus { &::after { content: ""; position: absolute; width: 100%; bottom: ${props => props.theme.spaces[0] - 1}px; left: ${props => props.theme.spaces[0]}px; height: ${props => props.theme.spaces[1] - 2}px; background-color: ${props => props.theme.colors.info.main}; } box-shadow: none; border-color: transparent; path { fill: ${props => props.theme.colors.blackShades[9]}; } } `; const TabTitle = styled.span` font-size: ${props => props.theme.typography.h4.fontSize}px; font-weight: normal; line-height: ${props => props.theme.typography.h4.lineHeight}px; letter-spacing: ${props => props.theme.typography.h4.letterSpacing}px; `; type TabbedViewComponentType = { tabs: Array; selectedIndex?: number; onSelect?: Function; overflow?: boolean; }; export const TabComponent = (props: TabbedViewComponentType) => { return ( { props.onSelect && props.onSelect(index); }} > {props.tabs.map(tab => ( {tab.icon ? : null} {tab.title} ))} {props.tabs.map(tab => ( {tab.panelComponent} ))} ); };