Skip to content

Commit 84c1e0b

Browse files
committed
feat(tabs): "justified" and "fill" options
1 parent 79fc3dc commit 84c1e0b

File tree

3 files changed

+65
-16
lines changed

3 files changed

+65
-16
lines changed

demo/TabsExamples.jsx

+53-13
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,62 @@ export function TabsExamples() {
1111
<h1 className="h4">Simple Tabs</h1>
1212
<Tabs
1313
tabs={[
14-
{ title: 'A', content: 'a' },
15-
{ title: 'B', content: 'b' },
16-
{ title: 'C', content: 'c' },
14+
{
15+
title: 'A',
16+
content: <Lorem header="Content A" />,
17+
},
18+
{ title: 'B', content: <Lorem header="Content B" /> },
19+
{ title: 'C', content: <Lorem header="Content C" /> },
1720
]}
1821
/>
1922
</div>
2023
<div className="col">
2124
<h1 className="h4">Bordered Tabs</h1>
2225
<Tabs
2326
tabs={[
24-
{ title: 'A', content: 'a' },
25-
{ title: 'B', content: 'b' },
26-
{ title: 'C', content: 'c' },
27+
{ title: 'A', content: <Lorem header="Content A" /> },
28+
{ title: 'B', content: <Lorem header="Content B" /> },
29+
{ title: 'C', content: <Lorem header="Content C" /> },
2730
]}
2831
bordered={true}
2932
activeTab={4}
3033
/>
3134
</div>
3235
</div>
33-
<div className="row mt-2">
36+
<div className="row mt-3">
37+
<div className="col">
38+
<h1 className="h4">Justified Tabs</h1>
39+
<Tabs
40+
tabs={[
41+
{ title: 'A', content: <Lorem header="Content A" /> },
42+
{ title: 'Bbbbbbbbbbbbbbbb', content: <Lorem header="Content B" /> },
43+
{ title: 'C', content: <Lorem header="Content C" /> },
44+
]}
45+
justified={true}
46+
activeTab={1}
47+
/>
48+
</div>
49+
<div className="col">
50+
<h1 className="h4">Fill Tabs</h1>
51+
<Tabs
52+
tabs={[
53+
{ title: 'A', content: <Lorem header="Content A" /> },
54+
{ title: 'Bbbbbbbbbbbbbbbb', content: <Lorem header="Content B" /> },
55+
{ title: 'C', content: <Lorem header="Content C" /> },
56+
]}
57+
fill={true}
58+
activeTab={1}
59+
/>
60+
</div>
61+
</div>
62+
<div className="row mt-3">
3463
<div className="col">
3564
<h1 className="h4">Vertical Tabs</h1>
3665
<Tabs
3766
tabs={[
38-
{ title: 'A', content: 'a' },
39-
{ title: 'B', content: 'b' },
40-
{ title: 'C', content: 'c' },
67+
{ title: 'A', content: <Lorem header="Content A" /> },
68+
{ title: 'B', content: <Lorem header="Content B" /> },
69+
{ title: 'C', content: <Lorem header="Content C" /> },
4170
]}
4271
vertical={true}
4372
onSelect={console.log}
@@ -47,9 +76,9 @@ export function TabsExamples() {
4776
<h1 className="h4">Stateful Tabs</h1>
4877
<StatefulTabs
4978
tabs={[
50-
{ title: 'A', content: 'a' },
51-
{ title: 'B', content: 'b' },
52-
{ title: 'C', content: 'c' },
79+
{ title: 'A', content: <Lorem header="Content A" /> },
80+
{ title: 'B', content: <Lorem header="Content B" /> },
81+
{ title: 'C', content: <Lorem header="Content C" /> },
5382
]}
5483
vertical={true}
5584
/>
@@ -58,3 +87,14 @@ export function TabsExamples() {
5887
</div>
5988
);
6089
}
90+
91+
function Lorem({ header }) {
92+
return (
93+
<p>
94+
<h3>{header}</h3>
95+
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Hic iusto dolores voluptatum sunt. Assumenda, vero esse?
96+
Numquam alias repellendus, quaerat beatae expedita inventore recusandae, molestiae earum vel illo provident
97+
ducimus?
98+
</p>
99+
);
100+
}

demo/demo.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ ReactDOM.render(
2222
<StatefulTabs
2323
vertical={true}
2424
onlyRenderActiveTab={true}
25-
initialTab={3}
25+
initialTab={7}
2626
tabs={[
2727
{
2828
title: 'Dialog',

src/tabs/Tabs.jsx

+11-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { formatClasses } from '../utils/attributes';
66
import { TabHeader } from './TabHeader';
77
import { TabContent } from './TabContent';
88

9-
export function Tabs({ vertical, tabs, activeTab, onlyRenderActiveTab, bordered, onSelect }) {
9+
export function Tabs({ vertical, tabs, activeTab, onlyRenderActiveTab, bordered, onSelect, justified, fill }) {
1010
if (activeTab >= tabs.length) {
1111
// eslint-disable-next-line no-console
1212
console.error(`Invalid tab selected: ${activeTab}. The first tab will be selected instead.`);
@@ -17,7 +17,12 @@ export function Tabs({ vertical, tabs, activeTab, onlyRenderActiveTab, bordered,
1717
<div className={formatClasses(['custom-tabs-container', vertical && 'd-flex'])}>
1818
<div className="tabs-navigation">
1919
<ul
20-
className={formatClasses(['nav', vertical ? 'nav-pills flex-column' : 'nav-tabs'])}
20+
className={formatClasses([
21+
'nav',
22+
vertical ? 'nav-pills flex-column' : 'nav-tabs',
23+
justified && 'nav-justified',
24+
fill && 'nav-fill',
25+
])}
2126
id="myTab"
2227
role="tablist"
2328
>
@@ -55,6 +60,8 @@ export function Tabs({ vertical, tabs, activeTab, onlyRenderActiveTab, bordered,
5560
Tabs.defaultProps = {
5661
activeTab: 0,
5762
bordered: false,
63+
fill: false,
64+
justified: false,
5865
onlyRenderActiveTab: false,
5966
onSelect: () => {},
6067
vertical: false,
@@ -63,6 +70,8 @@ Tabs.defaultProps = {
6370
Tabs.propTypes = {
6471
activeTab: PropTypes.number,
6572
bordered: PropTypes.bool,
73+
fill: PropTypes.bool,
74+
justified: PropTypes.bool,
6675
onlyRenderActiveTab: PropTypes.bool,
6776
onSelect: PropTypes.func,
6877
tabs: PropTypes.arrayOf(

0 commit comments

Comments
 (0)