-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
57 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,32 @@ | ||
import React from 'react'; | ||
import React, { useState } from 'react'; | ||
import 'bulma/css/bulma.css'; | ||
import '@fortawesome/fontawesome-free/css/all.css'; | ||
import './App.scss'; | ||
|
||
import { Tabs } from './components/Tabs'; | ||
|
||
export const tabs = [ | ||
{ id: 'tab-1', title: 'Tab 1', content: 'Some text 1' }, | ||
{ id: 'tab-2', title: 'Tab 2', content: 'Some text 2' }, | ||
{ id: 'tab-3', title: 'Tab 3', content: 'Some text 3' }, | ||
]; | ||
|
||
export const App = () => ( | ||
<div className="section"> | ||
<h1 className="title">Selected tab is Tab 1</h1> | ||
|
||
<div data-cy="TabsComponent"> | ||
<div className="tabs is-boxed"> | ||
<ul> | ||
<li className="is-active" data-cy="Tab"> | ||
<a href="#tab-1" data-cy="TabLink"> | ||
Tab 1 | ||
</a> | ||
</li> | ||
export const App = () => { | ||
const [activeTabId, setActiveTabId] = useState('tab-1'); | ||
|
||
<li data-cy="Tab"> | ||
<a href="#tab-2" data-cy="TabLink"> | ||
Tab 2 | ||
</a> | ||
</li> | ||
|
||
<li data-cy="Tab"> | ||
<a href="#tab-3" data-cy="TabLink"> | ||
Tab 3 | ||
</a> | ||
</li> | ||
</ul> | ||
</div> | ||
return ( | ||
<div className="section"> | ||
<h1 className="title"> | ||
Selected tab is {tabs.find(tab => tab.id === activeTabId).title} | ||
</h1> | ||
|
||
<div className="block" data-cy="TabContent"> | ||
Some text 1 | ||
<div data-cy="TabsComponent"> | ||
<Tabs | ||
tabs={tabs} | ||
activeTabId={activeTabId} | ||
onTabSelected={setActiveTabId} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,38 @@ | ||
export const Tabs = () => {}; | ||
import React from 'react'; | ||
|
||
export const Tabs = ({ tabs, activeTabId, onTabSelected }) => { | ||
const activeTab = tabs.find(tab => tab.id === activeTabId) || tabs[0]; | ||
|
||
return ( | ||
<div> | ||
<div className="tabs is-boxed"> | ||
<ul> | ||
{tabs.map(tab => ( | ||
<li | ||
key={tab.id} | ||
className={tab.id === activeTab.id ? 'is-active' : ''} | ||
data-cy="Tab" | ||
> | ||
<a | ||
href={`#${tab.id}`} | ||
data-cy="TabLink" | ||
onClick={e => { | ||
e.preventDefault(); | ||
if (tab.id !== activeTab.id) { | ||
onTabSelected(tab.id); | ||
} | ||
}} | ||
> | ||
{tab.title} | ||
</a> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
|
||
<div className="block" data-cy="TabContent"> | ||
{activeTab.content} | ||
</div> | ||
</div> | ||
); | ||
}; |