2021-05-14 08:15:15 +00:00
|
|
|
import { Typography } from "@material-ui/core";
|
2022-11-24 12:16:51 +00:00
|
|
|
import { alpha } from "@material-ui/core/styles";
|
2021-07-21 08:59:52 +00:00
|
|
|
import { makeStyles } from "@saleor/macaw-ui";
|
2022-12-02 10:45:19 +00:00
|
|
|
import clsx from "clsx";
|
2019-08-09 10:26:22 +00:00
|
|
|
import React from "react";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2019-10-30 14:34:24 +00:00
|
|
|
const useStyles = makeStyles(
|
|
|
|
theme => ({
|
2019-09-10 16:23:59 +00:00
|
|
|
active: {
|
2022-06-21 09:36:55 +00:00
|
|
|
color: theme.palette.text.secondary,
|
2019-09-10 16:23:59 +00:00
|
|
|
},
|
2019-06-19 14:40:52 +00:00
|
|
|
root: {
|
|
|
|
"&$active": {
|
|
|
|
borderBottomColor: theme.palette.primary.main,
|
2022-06-21 09:36:55 +00:00
|
|
|
color: theme.typography.body1.color,
|
2019-06-19 14:40:52 +00:00
|
|
|
},
|
|
|
|
"&:focus": {
|
2022-06-21 09:36:55 +00:00
|
|
|
color: theme.palette.primary.main,
|
2019-06-19 14:40:52 +00:00
|
|
|
},
|
|
|
|
"&:hover": {
|
2022-06-21 09:36:55 +00:00
|
|
|
color: theme.palette.primary.main,
|
2019-06-19 14:40:52 +00:00
|
|
|
},
|
|
|
|
borderBottom: "1px solid transparent",
|
2022-11-24 12:16:51 +00:00
|
|
|
color: alpha(theme.palette.text.secondary, 0.6),
|
2019-06-19 14:40:52 +00:00
|
|
|
cursor: "pointer",
|
|
|
|
display: "inline-block",
|
|
|
|
fontWeight: theme.typography.fontWeightRegular,
|
2019-10-28 16:16:49 +00:00
|
|
|
marginRight: theme.spacing(2),
|
2019-06-19 14:40:52 +00:00
|
|
|
minWidth: 40,
|
2019-10-28 16:16:49 +00:00
|
|
|
padding: theme.spacing(1),
|
2022-06-21 09:36:55 +00:00
|
|
|
transition: theme.transitions.duration.short + "ms",
|
|
|
|
},
|
2019-10-30 14:34:24 +00:00
|
|
|
}),
|
2022-06-21 09:36:55 +00:00
|
|
|
{ name: "Tab" },
|
2019-10-30 14:34:24 +00:00
|
|
|
);
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2019-10-30 14:34:24 +00:00
|
|
|
interface TabProps<T> {
|
2019-06-19 14:40:52 +00:00
|
|
|
children?: React.ReactNode;
|
|
|
|
isActive: boolean;
|
|
|
|
changeTab: (index: T) => void;
|
2021-03-12 14:57:02 +00:00
|
|
|
testId?: string;
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function Tab<T>(value: T) {
|
2019-10-30 14:34:24 +00:00
|
|
|
const Component: React.FC<TabProps<T>> = props => {
|
2021-03-12 14:57:02 +00:00
|
|
|
const { children, isActive, changeTab, testId } = props;
|
2019-10-30 14:34:24 +00:00
|
|
|
|
|
|
|
const classes = useStyles(props);
|
|
|
|
|
|
|
|
return (
|
2019-06-19 14:40:52 +00:00
|
|
|
<Typography
|
|
|
|
component="span"
|
2021-03-12 14:57:02 +00:00
|
|
|
data-test-id={testId}
|
2022-12-02 10:45:19 +00:00
|
|
|
className={clsx({
|
2019-06-19 14:40:52 +00:00
|
|
|
[classes.root]: true,
|
2022-06-21 09:36:55 +00:00
|
|
|
[classes.active]: isActive,
|
2019-06-19 14:40:52 +00:00
|
|
|
})}
|
|
|
|
onClick={() => changeTab(value)}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</Typography>
|
2019-10-30 14:34:24 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
return Component;
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Tab;
|