index.js 835 B

1234567891011121314151617181920212223242526272829
  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}
  13. </div>
  14. );
  15. }
  16. function Tabs(props) {
  17. const { tabs = [], type = 'line', border, onChange } = props;
  18. return (
  19. <div className={`tabs ${type} ${border ? 'border' : ''}`}>
  20. {tabs.map(item => {
  21. return item.path ? <Link to={item.path}>{getItem(props, item)}</Link> : getItem(props, item, onChange);
  22. })}
  23. </div>
  24. );
  25. }
  26. Tabs.propTypes = {};
  27. export default Tabs;