|
| 1 | +import React from 'react'; |
| 2 | +import PropTypes from 'prop-types'; |
| 3 | +import { TabHeader } from './TabHeader'; |
| 4 | +import { TabContent } from './TabContent'; |
| 5 | + |
| 6 | +export function Tabs({ vertical, tabs, activeTab, onlyRenderActiveTab, bordered, onSelect }) { |
| 7 | + if (activeTab >= tabs.length) { |
| 8 | + console.warn('Invalid tab selected:', activeTab); |
| 9 | + } |
| 10 | + |
| 11 | + return ( |
| 12 | + <div className={`custom-tabs-container ${vertical ? 'd-flex' : ''}`}> |
| 13 | + <div className="tabs-navigation"> |
| 14 | + <ul className={`nav ${vertical ? 'nav-pills flex-column' : 'nav-tabs'}`} id="myTab" role="tablist"> |
| 15 | + {tabs.map((tab, tabIndex) => ( |
| 16 | + <TabHeader |
| 17 | + key={tabIndex} |
| 18 | + index={tabIndex} |
| 19 | + isActive={tabIndex === activeTab} |
| 20 | + title={tab.title} |
| 21 | + onSelect={onSelect} |
| 22 | + /> |
| 23 | + ))} |
| 24 | + </ul> |
| 25 | + </div> |
| 26 | + |
| 27 | + <div |
| 28 | + className={`tab-content ${ |
| 29 | + vertical ? 'flex-fill ml-3' : `${bordered ? 'border-left border-right border-bottom p-2' : 'py-2'}` |
| 30 | + }`} |
| 31 | + // id="myTabContent" |
| 32 | + > |
| 33 | + {onlyRenderActiveTab ? ( |
| 34 | + <TabContent isActive={true} content={tabs[activeTab] && tabs[activeTab].content} /> |
| 35 | + ) : ( |
| 36 | + tabs.map((tab, tabIndex) => ( |
| 37 | + <TabContent key={tabIndex} isActive={tabIndex === activeTab} content={tab.content} /> |
| 38 | + )) |
| 39 | + )} |
| 40 | + </div> |
| 41 | + </div> |
| 42 | + ); |
| 43 | +} |
| 44 | + |
| 45 | +Tabs.defaultProps = { |
| 46 | + vertical: false, |
| 47 | + bordered: false, |
| 48 | + activeTab: 0, |
| 49 | + onlyRenderActiveTab: false, |
| 50 | + onSelect: () => {}, |
| 51 | +}; |
| 52 | + |
| 53 | +Tabs.propTypes = { |
| 54 | + vertical: PropTypes.bool, |
| 55 | + tabs: PropTypes.arrayOf(PropTypes.object), |
| 56 | + activeTab: PropTypes.number, |
| 57 | + onlyRenderActiveTab: PropTypes.bool, |
| 58 | + bordered: PropTypes.bool, |
| 59 | +}; |
0 commit comments