index.js 1012 B

12345678910111213141516171819202122232425262728293031
  1. import React from 'react';
  2. import { Link } from 'react-router-dom';
  3. import './index.less';
  4. function getItem(props, item, onChange) {
  5. const { width, space, active } = props;
  6. return (
  7. <div
  8. onClick={() => active !== item.key && onChange && onChange(item.key)}
  9. style={{ width: width || '', marginLeft: space || '', marginRight: space || '' }}
  10. className={`tab ${active === item.key ? 'active' : ''}`}
  11. >
  12. {item.name || item.title}
  13. </div>
  14. );
  15. }
  16. function Tabs(props) {
  17. const { tabs = [], type = 'line', theme = 'default', border, space, onChange } = props;
  18. return (
  19. <div className={`tabs ${type} ${theme} ${border ? 'border' : ''}`}>
  20. <div className="tabs-warpper" style={{ marginLeft: space * -1 || '', marginRight: space * -1 || '' }}>
  21. {tabs.map(item => {
  22. return item.path ? <Link to={item.path}>{getItem(props, item)}</Link> : getItem(props, item, onChange);
  23. })}
  24. </div>
  25. </div>
  26. );
  27. }
  28. Tabs.propTypes = {};
  29. export default Tabs;