PromucFlow_constructor/app/client/src/components/ads/MultiSwitch.tsx
Satish Gandham 7f7f6f666b
Development: Add eslint rules for code consistency (#4083)
Co-authored-by: Satish Gandham <satish@appsmith.com>
Co-authored-by: Abhinav Jha <abhinav@appsmith.com>
2021-04-28 15:58:39 +05:30

71 lines
1.7 KiB
TypeScript

import React from "react";
import styled from "styled-components";
import { CommonComponentProps } from "./common";
import Text, { Case, TextType } from "./Text";
export type TabProp<T> = {
key: string;
title: T;
panelComponent: JSX.Element;
};
const TabList = styled.div`
margin-left: 30px;
display: flex;
align-items: center;
height: 24px;
background-color: ${(props) => props.theme.colors.multiSwitch.bg};
width: fit-content;
margin-bottom: 12px;
padding-left: 1px;
`;
const TabContent = styled.div`
height: calc(100% - 24px);
`;
const Tab = styled.div<{ selected: boolean }>`
display: flex;
align-items: center;
cursor: pointer;
height: 22px;
padding: 0 12px;
${(props) =>
props.selected
? `
background-color: ${props.theme.colors.multiSwitch.selectedBg};
`
: null};
border-right: 1px solid ${(props) => props.theme.colors.multiSwitch.border};
`;
type MultiSwitchProps<T> = CommonComponentProps & {
tabs: Array<TabProp<T>>;
selected: { title: T; value: string };
onSelect: (title: T) => void;
};
export default function MultiSwitch<T>(props: MultiSwitchProps<T>) {
const selectedTab = props.tabs.find(
(tab) => tab.key === props.selected.value,
);
return (
<div data-cy={props.cypressSelector}>
<TabList>
{props.tabs.map((tab) => (
<Tab
key={tab.key}
onClick={() => props.onSelect(tab.title)}
selected={props.selected.value === tab.key}
>
<Text case={Case.UPPERCASE} type={TextType.P3}>
{tab.title}
</Text>
</Tab>
))}
</TabList>
{selectedTab && <TabContent>{selectedTab.panelComponent}</TabContent>}
</div>
);
}