Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task completed #1757

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"devDependencies": {
"@cypress/react18": "^2.0.1",
"@mate-academy/scripts": "^1.8.5",
"@mate-academy/scripts": "^1.9.12",
"@mate-academy/students-ts-config": "*",
"@mate-academy/stylelint-config": "*",
"@types/node": "^20.14.10",
Expand Down
98 changes: 51 additions & 47 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,59 @@ import 'bulma/css/bulma.css';
import '@fortawesome/fontawesome-free/css/all.css';
import './App.scss';

// 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' },
// ];
import { Routes, Route, NavLink, Navigate } from 'react-router-dom';
import classNames from 'classnames';
import { TabsPage } from './components/TabsPage';

export const App = () => (
<>
{/* Also requires <html class="has-navbar-fixed-top"> */}
<nav
className="navbar is-light is-fixed-top is-mobile has-shadow"
data-cy="Nav"
>
<div className="container">
<div className="navbar-brand">
<a href="/" className="navbar-item is-active">
Home
</a>
<a href="/tabs" className="navbar-item">
Tabs
</a>
</div>
</div>
</nav>

<div className="section">
<div className="container">
<h1 className="title">Home page</h1>
<h1 className="title">Tabs page</h1>
<h1 className="title">Page not found</h1>

<div className="tabs is-boxed">
<ul>
<li data-cy="Tab" className="is-active">
<a href="#/">Tab 1</a>
</li>
<li data-cy="Tab">
<a href="#/">Tab 2</a>
</li>
<li data-cy="Tab">
<a href="#/">Tab 3</a>
</li>
</ul>
export const App = () => {
return (
<>
{/* Also requires <html class="has-navbar-fixed-top"> */}
<nav
className="navbar is-light is-fixed-top is-mobile has-shadow"
data-cy="Nav"
>
<div className="container">
<div className="navbar-brand">
<NavLink
to={'/'}
className={({ isActive }) => {
return classNames('navbar-item', {
'is-active': isActive,
});
}}
>
Home
</NavLink>
<NavLink
to={'/tabs'}
className={({ isActive }) => {
return classNames('navbar-item', {
'is-active': isActive,
});
}}
>
Tabs
</NavLink>
</div>
</div>
</nav>

<div className="block" data-cy="TabContent">
Please select a tab
<div className="section">
<div className="container">
<Routes>
<Route path="/" element={<h1 className="title">Home page</h1>} />
<Route path="/home" element={<Navigate to="/" replace />} />
<Route path="tabs" element={<TabsPage />}>
<Route path=":tabId" />
</Route>
<Route
path="*"
element={<h1 className="title">Page not found</h1>}
/>
</Routes>
</div>
</div>
</div>
</>
);
</>
);
};
39 changes: 39 additions & 0 deletions src/components/TabsPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Link, useParams } from 'react-router-dom';
import { Outlet } from 'react-router-dom';

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 TabsPage = () => {
const { tabId } = useParams();

const activeTab = tabs.find(tab => tab.id === tabId);

return (
<>
<h1 className="title">Tabs page</h1>
<div className="tabs is-boxed">
<ul>
{tabs.map(tab => {
return (
<li
key={tab.id}
data-cy="Tab"
className={tabId === tab.id ? 'is-active' : ''}
>
<Link to={tab.id}>{tab.title}</Link>
</li>
);
})}
</ul>
</div>
<div className="block" data-cy="TabContent">
{activeTab ? activeTab.content : 'Please select a tab'}
</div>
<Outlet />
</>
);
};
Loading