Skip to content

Commit 1185a40

Browse files
author
evgenyantipin
committed
setup tailwind, add counter page
1 parent d0b9578 commit 1185a40

File tree

18 files changed

+397
-93
lines changed

18 files changed

+397
-93
lines changed

next.config.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
module.exports = {
2+
experimental: {
3+
legacyBrowsers: false,
4+
browsersListForSwc: true
5+
},
26
webpack: (config, { dev, isServer }) => {
37
if (!dev && !isServer) {
48
Object.assign(config.resolve.alias, {
5-
react: "preact/compat",
6-
"react-dom/test-utils": "preact/test-utils",
7-
"react-dom": "preact/compat",
9+
react: 'preact/compat',
10+
'react-dom/test-utils': 'preact/test-utils',
11+
'react-dom': 'preact/compat'
812
});
913
}
1014

1115
return config;
12-
},
16+
}
1317
};

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@
4444
"@types/redux": "^3.6.0",
4545
"@types/redux-logger": "^3.0.9",
4646
"@types/redux-thunk": "^2.1.0",
47+
"autoprefixer": "^10.4.12",
4748
"eslint": "^8.25.0",
4849
"eslint-config-next": "^12.3.1",
4950
"husky": "^4.2.5",
5051
"lint-staged": "10.2.13",
52+
"postcss": "^8.4.18",
5153
"prettier": "^2.7.1",
5254
"redux-logger": "^3.0.6",
55+
"tailwindcss": "^3.1.8",
5356
"typescript": "^4.8.4"
5457
},
5558
"engines": {

pages/_app.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { AppProps } from 'next/app';
33
import { Provider } from 'react-redux';
44
import { store } from 'store';
5-
import 'styles.global.scss';
5+
import 'styles.global.css';
66

77
export default function App({ Component, pageProps }: AppProps) {
88
return (

pages/_document.tsx

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
1-
import React from 'react'
2-
import Document, { Html, Head, Main, NextScript } from "next/document";
1+
import { Html, Head, Main, NextScript } from 'next/document';
32

4-
class MyDocument extends Document {
5-
render() {
6-
return (
7-
<Html>
8-
<Head>
9-
<link
10-
rel="stylesheet"
11-
type="text/css"
12-
href="https://cdnjs.cloudflare.com/ajax/libs/sanitize.css/2.0.0/sanitize.min.css"
13-
/>
14-
<link
15-
rel="stylesheet"
16-
type="text/css"
17-
href="https://cdnjs.cloudflare.com/ajax/libs/tachyons/4.7.4/tachyons.min.css"
18-
/>
19-
</Head>
20-
<body>
21-
<Main />
22-
<NextScript />
23-
</body>
24-
</Html>
25-
);
26-
}
27-
}
28-
29-
export default MyDocument;
3+
export default function Document() {
4+
return (
5+
<Html>
6+
<Head>
7+
<link
8+
rel="stylesheet"
9+
type="text/css"
10+
href="https://cdnjs.cloudflare.com/ajax/libs/tachyons/4.7.4/tachyons.min.css"
11+
/>
12+
</Head>
13+
<body>
14+
<Main />
15+
<NextScript />
16+
</body>
17+
</Html>
18+
);
19+
}

pages/counter.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React from 'react';
2+
import type { NextPage } from 'next';
3+
import { useSelector, useDispatch } from 'react-redux';
4+
import Layout from 'layouts/Main';
5+
import { decrement, increment } from 'store/reducers/counter';
6+
import type { RootState } from 'store';
7+
8+
const CounterPage: NextPage = () => {
9+
const dispatch = useDispatch();
10+
const count = useSelector((state: RootState) => state.counter.value);
11+
12+
return (
13+
<Layout>
14+
<div className="flex">
15+
<button
16+
className="pointer-events-auto ml-8 rounded-md bg-indigo-600 py-2 px-3 text-[0.8125rem] font-semibold leading-5 text-white hover:bg-indigo-500"
17+
aria-label="Increment value"
18+
onClick={() => dispatch(increment())}
19+
>
20+
Increment
21+
</button>
22+
<span className="pointer-events-auto ml-8 rounded-md py-2 px-3 font-semibold leading-5 text-black">{count}</span>
23+
<button
24+
className="pointer-events-auto ml-8 rounded-md bg-indigo-600 py-2 px-3 text-[0.8125rem] font-semibold leading-5 text-white hover:bg-indigo-500"
25+
aria-label="Decrement value"
26+
onClick={() => dispatch(decrement())}
27+
>
28+
Decrement
29+
</button>
30+
</div>
31+
</Layout>
32+
);
33+
};
34+
35+
export default CounterPage;

postcss.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
plugins: {
3+
tailwindcss: {},
4+
autoprefixer: {}
5+
}
6+
};

src/components/Nav/index.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,31 @@ import React from 'react';
22
import Image from 'next/image';
33
import Link from 'next/link';
44
import nextLogo from 'assets/nextjs.svg';
5-
import styles from './Nav.module.scss';
5+
import s from './styles.module.scss';
66

77
const Nav: React.FC = () => (
8-
<div className={styles.nav}>
8+
<div className={s.nav}>
99
<Link href="/">
1010
<a>
1111
<Image src={nextLogo} alt="nextjs" width="100" height="40" />
1212
</a>
1313
</Link>
14+
<Link href="/counter">
15+
<a className="font-normal text-gray-600 dark:text-gray-400 hidden md:inline-block p-1 sm:px-3 sm:py-2 rounded-lg hover:bg-gray-200 dark:hover:bg-gray-800 transition-all">
16+
Counter
17+
</a>
18+
</Link>
1419
|
1520
<Link href="/about">
16-
<a>About</a>
17-
</Link>{' '}
21+
<a className="font-normal text-gray-600 dark:text-gray-400 hidden md:inline-block p-1 sm:px-3 sm:py-2 rounded-lg hover:bg-gray-200 dark:hover:bg-gray-800 transition-all">
22+
About
23+
</a>
24+
</Link>
1825
|
1926
<Link href="/contact">
20-
<a>Contact</a>
27+
<a className="font-normal text-gray-600 dark:text-gray-400 hidden md:inline-block p-1 sm:px-3 sm:py-2 rounded-lg hover:bg-gray-200 dark:hover:bg-gray-800 transition-all">
28+
Contact
29+
</a>
2130
</Link>
2231
</div>
2332
);
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,12 @@
33
border-bottom: 1px solid #ddd;
44
display: flex;
55
align-items: center;
6-
background: var(--purple);
6+
background: palegreen;
77
img {
88
display: block;
99
height: 50px;
1010
width: 82px;
1111
}
12-
a {
13-
padding: 0 15px;
14-
color: #fff;
15-
}
1612
p {
1713
font-size: 1.2rem;
1814
line-height: 35px;

src/layouts/Main.module.scss

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/layouts/Main.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import Head from 'next/head';
33
import Nav from 'components/Nav';
4-
import styles from './Main.module.scss';
4+
import s from './styles.module.scss';
55

66
interface IProps {
77
children: React.ReactNode;
@@ -12,17 +12,15 @@ const MainLayout: React.FC<IProps> = ({
1212
children,
1313
title = 'default title'
1414
}) => (
15-
<div className={styles.layout}>
15+
<div className={s.layout}>
1616
<Head>
1717
<title>{title}</title>
1818
</Head>
1919
<header>
2020
<Nav />
2121
</header>
22-
23-
<main>{children}</main>
24-
25-
<div className={styles.footer}>Footer</div>
22+
<main className="mt-10">{children}</main>
23+
<div className="flex flex-col justify-center px-8 bg-gray-2000">Footer</div>
2624
</div>
2725
);
2826

0 commit comments

Comments
 (0)