Skip to content
This repository was archived by the owner on Aug 17, 2021. It is now read-only.
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
15 changes: 15 additions & 0 deletions base/code/src/components/Navbar.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter } from 'react-router-dom';

import { Navbar } from './Navbar';

it('renders without crashing', () => {
const div = document.createElement('div');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't something like const footer = create(<Footer />); also work instead of rendering into the DOM?

ReactDOM.render(
<BrowserRouter>
<Navbar />
</BrowserRouter>,
div);
ReactDOM.unmountComponentAtNode(div);
});
36 changes: 36 additions & 0 deletions base/code/src/components/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { css } from 'emotion';
import * as React from 'react';
import { NavLink } from 'react-router-dom'
import { LINK_COLOR } from '../consts/colors';

const navbarClass = css`
height: 100px;
display: flex;
justify-content: center;
align-items: center;
margin-bottom: 100px;
`;

const navigationLink = css`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class variables should be named consistently, so better to add the Class suffix here also

text-decoration: none;
color: white;
margin: 0 10px;

&:hover {
text-decoration: underline;
}
`;

const activeLink = css`
color: ${LINK_COLOR} !important;
`;

export const Navbar: React.FC<{}> = () => {

return (
<nav className={navbarClass}>
<NavLink exact to="/" className={navigationLink} activeClassName={activeLink}>HOME</NavLink>
<NavLink to="/about" className={navigationLink} activeClassName={activeLink}>ABOUT</NavLink>
</nav>
);
};
9 changes: 9 additions & 0 deletions base/code/src/containers/About.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom';
import About from './About';

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<About />, div);
ReactDOM.unmountComponentAtNode(div);
});
31 changes: 31 additions & 0 deletions base/code/src/containers/About.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as React from 'react';

import { getApiData } from '../services/api';

const About: React.FC<{}> = () => {
const [title, setTitle] = React.useState('');
const [content, setContent] = React.useState('');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also handle the loading and error states. That's quite simple with the useAsync hook from react-use


React.useEffect(() => {
const fetchData = async () => {
const aboutPageContent = await getApiData();
const { title, content } = aboutPageContent;

setTitle(title);
setContent(content);
}

fetchData();
}, [title]);

return (
<React.Fragment>
<div>
<h1>{title}</h1>
<p>{content}</p>
</div>
</React.Fragment>
);
}

export default About;
99 changes: 29 additions & 70 deletions base/code/src/containers/App.tsx
Original file line number Diff line number Diff line change
@@ -1,94 +1,53 @@
import { css, keyframes } from 'emotion';
import { css } from 'emotion';
import * as React from 'react';
import { BrowserRouter } from 'react-router-dom'
import { Switch, Route } from 'react-router'

import logo from '../assets/logo.svg';
import { Footer } from '../components/Footer';
import { BACKGROUND_PRIMARY, LINK_COLOR } from '../consts/colors';
import { Navbar } from '../components/Navbar';
import { BACKGROUND_PRIMARY } from '../consts/colors';

const logoSpinKeyframes = keyframes`
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
`;
const Home = React.lazy(() => import('./Home'));
const About = React.lazy(() => import('./About'));

const appClass = css`
display: flex;
flex-direction: column;
text-align: center;
`;

const logoClass = (animationSpeed: number) => css`
animation: ${logoSpinKeyframes} infinite ${animationSpeed}s linear;
height: 30vmin;
`;

const buttonClass = css`
padding: 10px;
margin: 5px;
`;

const stateContaninerClass = css`
margin: 40px 0;
`;

const headerClass = css`
background-color: ${BACKGROUND_PRIMARY};
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
`;

const linkClass = css`
color: ${LINK_COLOR};
`;

const footerClass = css`
margin-top: 100px;
font-size: 16px;
`;

export const App: React.FC<{}> = () => {
const [animationSpeed, setAnimationSpeed] = React.useState(40);
const mainClass = css`
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
`;

const onButtonClick = (action: string) => {
return () => {
if (action === '+' && animationSpeed > 5) {
setAnimationSpeed(animationSpeed - 5);
} else if (action === '-') {
setAnimationSpeed(animationSpeed + 5);
}
}
}
export const App: React.FC<{}> = () => {

return (
<div className={appClass}>
<main className={headerClass}>
<img src={logo} className={logoClass(animationSpeed)} alt="logo" />
<p>
Edit <code>src/containers/App.tsx</code> and save to reload.
</p>
<div className={stateContaninerClass}>
<span>ANIMATION SPEED</span>
<div>
<button className={buttonClass} onClick={onButtonClick('+')}>+</button>
<button className={buttonClass} onClick={onButtonClick('-')}>-</button>
</div>
</div>
<a
className={linkClass}
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
<BrowserRouter>
<div className={appClass}>
<Navbar />
<main className={mainClass}>
<React.Suspense fallback={<div>Loading...</div>}>
<Switch>
<Route exact path="/" component={Home}/>
<Route path="/about" component={About}/>
</Switch>
</React.Suspense>
</main>
<Footer className={footerClass} />
</main>
</div>
</div>
</BrowserRouter>
);
}
9 changes: 9 additions & 0 deletions base/code/src/containers/Home.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom';
import Home from './Home';

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<Home />, div);
ReactDOM.unmountComponentAtNode(div);
});
72 changes: 72 additions & 0 deletions base/code/src/containers/Home.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { css, keyframes } from 'emotion';
import * as React from 'react';

import logo from '../assets/logo.svg';
import { LINK_COLOR } from '../consts/colors';

const logoSpinKeyframes = keyframes`
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
`;

const logoClass = (animationSpeed: number) => css`
animation: ${logoSpinKeyframes} infinite ${animationSpeed}s linear;
height: 30vmin;
`;

const buttonClass = css`
padding: 10px;
margin: 5px;
`;

const stateContaninerClass = css`
margin: 40px 0;
`;

const linkClass = css`
color: ${LINK_COLOR};
`;

const Home: React.FC<{}> = () => {
const [animationSpeed, setAnimationSpeed] = React.useState(40);

const onButtonClick = (action: string) => {
return () => {
if (action === '+' && animationSpeed > 5) {
setAnimationSpeed(animationSpeed - 5);
} else if (action === '-') {
setAnimationSpeed(animationSpeed + 5);
}
}
}

return (
<React.Fragment>
<img src={logo} className={logoClass(animationSpeed)} alt="logo" />
<p>
Edit <code>src/containers/App.tsx</code> and save to reload.
</p>
<div className={stateContaninerClass}>
<span>ANIMATION SPEED</span>
<div>
<button className={buttonClass} onClick={onButtonClick('+')}>+</button>
<button className={buttonClass} onClick={onButtonClick('-')}>-</button>
</div>
</div>
<a
className={linkClass}
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</React.Fragment>
);
}

export default Home;
4 changes: 4 additions & 0 deletions base/code/src/interfaces/IAbout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface IAbout {
title: string;
content: string;
}
12 changes: 12 additions & 0 deletions base/code/src/services/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { IAbout } from '../interfaces/IAbout';

export function getApiData(): Promise<IAbout> {
return new Promise((resolve) => {
setTimeout(() => {
resolve({
title: 'JS-CRA-STARTER',
content: 'Some text, since someone said lorem ipsum is deprecated.'
})
}, 500);
})
}
7 changes: 5 additions & 2 deletions base/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
"datx",
"decko",
"emotion",
"react-use"
"react-use",
"react-router-dom"
],
"devDependencies": [
"husky",
"prettier",
"eslint-config-prettier"
"eslint-config-prettier",
"@types/react-router-dom",
"@types/react-router"
],
"files": {
"move": {
Expand Down
3 changes: 0 additions & 3 deletions sample-project/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,3 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*


.cache
4 changes: 0 additions & 4 deletions sample-project/.storybook/addons.js

This file was deleted.

13 changes: 0 additions & 13 deletions sample-project/.storybook/config.js

This file was deleted.

11 changes: 0 additions & 11 deletions sample-project/.storybook/webpack.config.js

This file was deleted.

9 changes: 0 additions & 9 deletions sample-project/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,3 @@ If you aren’t satisfied with the build tool and configuration choices, you can
Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.


### `npm run storybook`

Run the storybook app on port 9009

### `npm run build-storybook`

Build the storybook app into the `public` folder (ready to be deployed to a static file server)
Loading