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

solution #1726

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
75 changes: 28 additions & 47 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,56 +1,37 @@
import 'bulma/css/bulma.css';
import '@fortawesome/fontawesome-free/css/all.css';
import './App.scss';
import React from 'react';
import { NavLink, Outlet } from 'react-router-dom';
import classNames from 'classnames';

// 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' },
// ];
const getLinkClass = ({ isActive }: { isActive: boolean }) =>
classNames(`navbar-item`, { 'is-active': isActive });

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>
export const App = () => {
return (
<html className="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={getLinkClass}>
Home
</NavLink>

<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>
<NavLink to="/tabs" className={getLinkClass}>
Tabs
</NavLink>
</div>
</div>

<div className="block" data-cy="TabContent">
Please select a tab
</nav>
<div className="section">
<div className="container">
<Outlet />
</div>
</div>
</div>
</>
);
</html>
);
};
7 changes: 7 additions & 0 deletions src/Data/tabs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Tab } from "../types/Tab";

export const tabs: Tab[] = [
{ 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' },
];
25 changes: 25 additions & 0 deletions src/Root.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {
HashRouter as Router,
Routes,
Route,
Navigate,
} from 'react-router-dom';
import { Home, PageNotFound, Tabs } from './pages';
import { App } from './App';
import React from 'react';

export const Root = () => (
<Router>
<Routes>
<Route path="/" element={<App />}>
<Route index element={<Home />} />
<Route path="*" element={<PageNotFound />} />
<Route path="tabs">
<Route index element={<Tabs />} />
<Route path=":selectedTabId" element={<Tabs />} />
</Route>
<Route path="/home" element={<Navigate to="/" replace />} />
</Route>
</Routes>
</Router>
);
10 changes: 3 additions & 7 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { createRoot } from 'react-dom/client';
import { HashRouter } from 'react-router-dom';
import { App } from './App';
import { Root } from './Root';
import React from 'react';

createRoot(document.getElementById('root') as HTMLElement).render(
<HashRouter>
<App />
</HashRouter>,
);
createRoot(document.getElementById('root') as HTMLElement).render(<Root />);
3 changes: 3 additions & 0 deletions src/pages/Home.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import React from 'react';

export const Home = () => <h1 className="title">Home page</h1>;
3 changes: 3 additions & 0 deletions src/pages/PageNotFound.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import React from 'react';

export const PageNotFound = () => <h1 className="title">Page not found</h1>;
34 changes: 34 additions & 0 deletions src/pages/Tabs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react';
import { tabs } from '../Data/tabs';
import { Link, useParams } from 'react-router-dom';
import classNames from 'classnames';

export const Tabs = () => {
const { selectedTabId } = useParams();
const selectedTab = tabs.find(tab => tab.id === selectedTabId);

return (
<>
<div className="container">
<h1 className="title">Tabs page</h1>
</div>
<div className="tabs is-boxed">
<ul>
{tabs.map(tab => (
<li
key={tab.id}
data-cy="Tab"
className={classNames({ 'is-active': selectedTabId === tab.id })}
>
<Link to={`/tabs/${tab.id}`}>{tab.title}</Link>
</li>
))}
</ul>
</div>

<div className="block" data-cy="TabContent">
{selectedTab ? selectedTab.content : 'Please select a tab'}
</div>
</>
);
};
3 changes: 3 additions & 0 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { Home } from './Home';
export { Tabs } from './Tabs';
export { PageNotFound } from './PageNotFound';
Loading