Skip to content

Commit

Permalink
refactor: remove some unuse js code and fix can not use styles-jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
Chau Duong committed Apr 9, 2019
1 parent 186e000 commit 0a331b5
Show file tree
Hide file tree
Showing 12 changed files with 278 additions and 1,003 deletions.
12 changes: 2 additions & 10 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
"env": {
"development": {
"presets": [
["next/babel", {
"styled-jsx": {
"plugins": ["styled-jsx-plugin-postcss"]
}
}],
["next/babel"],
"@zeit/next-typescript/babel"
],
"plugins": [
Expand All @@ -25,11 +21,7 @@
},
"production": {
"presets": [
["next/babel", {
"styled-jsx": {
"plugins": ["styled-jsx-plugin-postcss"]
}
}],
["next/babel"],
"@zeit/next-typescript/babel"
],
"plugins": [
Expand Down
173 changes: 49 additions & 124 deletions components/Nav.tsx
Original file line number Diff line number Diff line change
@@ -1,129 +1,54 @@
import React, { useState } from 'react';
import React from 'react';
import Link from 'next/link';

import { connect } from 'react-redux';
import { testRedux } from '@app/redux/test/actions';
import { getTest } from '@app/redux/test/selectors';

import { Button, Alert, Dropdown, Spinner } from '@app/components/Common';

const { DropdownTrigger, DropdownContent } = Dropdown;
const links = [
{ href: 'https://github.com/segmentio/create-next-app', label: 'Github' },
].map((link) => {
link.key = `nav-link-${link.href}-${link.label}`;
return link;
});

const Nav = (props) => {
const [state, setState] = useState({
isBusy: false,
count: 0,
});
return (
<>
<nav>
<ul>
<li>
<Link prefetch href="/">
<a onClick={() => props.testRedux(Math.random())}>test redux</a>
const Nav = () => (
<nav>
<ul>
<li>
<Link prefetch href="/">
<a>Home</a>
</Link>
</li>
<ul>
{links.map(({ key, href, label }) => (
<li key={key}>
<Link href={href}>
<a>{label}</a>
</Link>
</li>
<li>
{props.test}
</li>
</ul>
<Button
color="primary"
rounded
onClick={() =>
setState({
isBusy: true,
count: state.count + 1,
})}
isBusy={state.isBusy}
>
{state.count} count
</Button>

<Alert color="primary" solid>
<strong>Waring! </strong>
<span>Something seriously bad happened.</span>
</Alert>

<Dropdown>
<DropdownTrigger color="primary">
bottom
</DropdownTrigger>
<DropdownContent>
<div>
<Link href="/about">
<a>test redux</a>
</Link>
<div>2222</div>
<div>3333</div>
<div>4444</div>
<div>5555</div>
</div>
</DropdownContent>
</Dropdown>
<br />
<Dropdown direction="top">
<DropdownTrigger color="primary">
top
</DropdownTrigger>
<DropdownContent>
<div>
<Link href="/about">
<a>test redux</a>
</Link>
<div>2222</div>
<div>3333</div>
<div>4444</div>
<div>5555</div>
</div>
</DropdownContent>
</Dropdown>
<br />
<Dropdown direction="left">
<DropdownTrigger color="primary">
left
</DropdownTrigger>
<DropdownContent>
<div>
<Link href="/about">
<a>test redux</a>
</Link>
<div>2222</div>
<div>3333</div>
<div>4444</div>
<div>5555</div>
</div>
</DropdownContent>
</Dropdown>
<br/>
<Dropdown direction="right">
<DropdownTrigger color="primary">
right
</DropdownTrigger>
<DropdownContent>
<div>
<Link href="/about">
<a>test redux</a>
</Link>
<div>2222</div>
<div>3333</div>
<div>4444</div>
<div>5555</div>
</div>
</DropdownContent>
</Dropdown>
<Spinner />
</nav>
</>
);
};

const mapStateToProps = state => ({
test: getTest(state),
});

const mapDispatchToProps = {
testRedux,
};

export default connect(mapStateToProps, mapDispatchToProps)(Nav);
))}
</ul>
</ul>

<style jsx>{`
nav {
text-align: center;
}
ul {
display: flex;
justify-content: space-between;
}
nav > ul {
padding: 4px 16px;
}
li {
display: flex;
padding: 6px 8px;
}
a {
color: #067df7;
text-decoration: none;
font-size: 13px;
}
`}</style>
</nav>
);

export default Nav;
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"react-redux": "^6.0.0",
"redux": "^4.0.1",
"redux-thunk": "^2.3.0",
"styled-jsx-plugin-postcss": "^2.0.0",
"webpack": "^4.29.4"
},
"devDependencies": {
Expand Down
10 changes: 9 additions & 1 deletion pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,15 @@ class MyDocument extends Document<IMyDocumentProps> {

<body>
{/* {this.renderGTM(true)} */}

<style jsx>
{`
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, Avenir Next, Avenir,
Helvetica, sans-serif;
}
`}
</style>
<Main />

<NextScript />
Expand Down
81 changes: 81 additions & 0 deletions pages/components.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import React from 'react';
import css from 'styled-jsx/css';
import Link from 'next/link';

import { Button, Alert, Dropdown, Spinner } from '@app/components/Common';
const { DropdownTrigger, DropdownContent } = Dropdown;

const style = css`
.content {
padding: 2rem;
}
.content .wrap {
display: flex;
justify-content: space-around;
}
.content .component {
font-weight: bold;
color: black;
flex-direction: column;
display: flex;
}
:global(.primary),
:global(.btn-primary) {
background-color: blue;
color: white;
}
:global(.warning) {
background-color: yellow;
color: black;
}
`;

const Home = () => (
<div className="content">
<style jsx>{style}</style>
<Link href="/"><a>Back</a></Link>
<div className="wrap">
<div className="component">
DropDown
<Dropdown>
<DropdownTrigger color="primary">
For bottom
</DropdownTrigger>
<DropdownContent>
<div>
<Link href="/about">
<a>test 1</a>
</Link>
<div>2222</div>
<div>3333</div>
<div>4444</div>
<div>5555</div>
</div>
</DropdownContent>
</Dropdown>
</div>
<div className="component">
Alert
<Alert color="warning" solid>
<strong>Waring! </strong>
<span>Something seriously bad happened.</span>
</Alert>
<Alert color="primary" solid>
<strong>Opps! </strong>
<span>Hi</span>
</Alert>
</div>
<div className="component">
Button
<Button
color="primary"
rounded
>
Primary
</Button>
</div>
</div>
</div>
);

export default Home;
Loading

0 comments on commit 0a331b5

Please sign in to comment.