Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 

105 wiersze
2.8 KiB

  1. import React from "react";
  2. // nodejs library that concatenates classes
  3. import classNames from "classnames";
  4. // nodejs library to set properties for components
  5. import PropTypes from "prop-types";
  6. // material-ui components
  7. import { makeStyles } from "@material-ui/core/styles";
  8. import Tabs from "@material-ui/core/Tabs";
  9. import Tab from "@material-ui/core/Tab";
  10. import Icon from "@material-ui/core/Icon";
  11. // core components
  12. import Card from "components/Card/Card.js";
  13. import CardBody from "components/Card/CardBody.js";
  14. import CardHeader from "components/Card/CardHeader.js";
  15. import styles from "assets/jss/nextjs-material-kit/components/customTabsStyle.js";
  16. const useStyles = makeStyles(styles);
  17. export default function CustomTabs(props) {
  18. const [value, setValue] = React.useState(0);
  19. const handleChange = (event, value) => {
  20. setValue(value);
  21. };
  22. const classes = useStyles();
  23. const { headerColor, plainTabs, tabs, title, rtlActive } = props;
  24. const cardTitle = classNames({
  25. [classes.cardTitle]: true,
  26. [classes.cardTitleRTL]: rtlActive
  27. });
  28. return (
  29. <Card plain={plainTabs}>
  30. <CardHeader color={headerColor} plain={plainTabs}>
  31. {title !== undefined ? <div className={cardTitle}>{title}</div> : null}
  32. <Tabs
  33. value={value}
  34. onChange={handleChange}
  35. classes={{
  36. root: classes.tabsRoot,
  37. indicator: classes.displayNone
  38. }}
  39. >
  40. {tabs.map((prop, key) => {
  41. var icon = {};
  42. if (prop.tabIcon) {
  43. icon = {
  44. icon:
  45. typeof prop.tabIcon === "string" ? (
  46. <Icon>{prop.tabIcon}</Icon>
  47. ) : (
  48. <prop.tabIcon />
  49. )
  50. };
  51. }
  52. return (
  53. <Tab
  54. classes={{
  55. root: classes.tabRootButton,
  56. label: classes.tabLabel,
  57. selected: classes.tabSelected,
  58. wrapper: classes.tabWrapper
  59. }}
  60. key={key}
  61. label={prop.tabName}
  62. {...icon}
  63. />
  64. );
  65. })}
  66. </Tabs>
  67. </CardHeader>
  68. <CardBody>
  69. {tabs.map((prop, key) => {
  70. if (key === value) {
  71. return <div key={key}>{prop.tabContent}</div>;
  72. }
  73. return null;
  74. })}
  75. </CardBody>
  76. </Card>
  77. );
  78. }
  79. CustomTabs.propTypes = {
  80. headerColor: PropTypes.oneOf([
  81. "warning",
  82. "success",
  83. "danger",
  84. "info",
  85. "primary",
  86. "rose"
  87. ]),
  88. title: PropTypes.string,
  89. tabs: PropTypes.arrayOf(
  90. PropTypes.shape({
  91. tabName: PropTypes.string.isRequired,
  92. tabIcon: PropTypes.object,
  93. tabContent: PropTypes.node.isRequired
  94. })
  95. ),
  96. rtlActive: PropTypes.bool,
  97. plainTabs: PropTypes.bool
  98. };