Skip to content

Commit

Permalink
solution
Browse files Browse the repository at this point in the history
  • Loading branch information
vlad14982 committed Oct 10, 2024
1 parent fb270a1 commit 22a3bac
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 32 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ Follow the next requirements to pass the tests:
- Install the Prettier Extension and use these [VSCode settings](https://mate-academy.github.io/fe-program/tools/vscode/settings.json) to enable format on save.
- Implement a solution following the [React task guidelines](https://github.com/mate-academy/react_task-guideline#react-tasks-guideline).
- Open one more terminal and run tests with `npm test` to ensure your solution is correct.
- Replace `<your_account>` with your Github username in the [DEMO LINK](https://<your_account>.github.io/react_tabs-js/) and add it to the PR description.
- Replace `<your_account>` with your Github username in the [DEMO LINK](https://vlad14982.github.io/react_tabs-js/) and add it to the PR description.
48 changes: 18 additions & 30 deletions src/App.jsx
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>
);
);
};
39 changes: 38 additions & 1 deletion src/components/Tabs/Tabs.jsx
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>
);
};

0 comments on commit 22a3bac

Please sign in to comment.