Skip to content

Commit 0394964

Browse files
Add default CSS modules solution
1 parent ed8bec9 commit 0394964

15 files changed

+145
-232
lines changed

README.md

+1-26
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,9 @@
1-
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
1+
This is a [Next.js](https://nextjs.org/) project.
22

33
## Getting Started
44

55
First, run the development server:
66

77
```bash
8-
npm run dev
9-
# or
108
yarn dev
119
```
12-
13-
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
14-
15-
You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file.
16-
17-
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.js`.
18-
19-
The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.
20-
21-
## Learn More
22-
23-
To learn more about Next.js, take a look at the following resources:
24-
25-
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
26-
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
27-
28-
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
29-
30-
## Deploy on Vercel
31-
32-
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/import?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
33-
34-
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.

components/button.module.css

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
.button {
2+
color: dodgerblue;
3+
border: 0;
4+
height: 3em;
5+
padding: 0 2em;
6+
border-radius: 1.5em;
7+
cursor: pointer;
8+
font-weight: bold;
9+
width: 100vw;
10+
display: block;
11+
outline: 0;
12+
background-color: currentColor;
13+
margin: 1em auto;
14+
}
15+
16+
.button span {
17+
color: white;
18+
}
19+
20+
.button:hover {
21+
animation-name: button-animation;
22+
animation-fill-mode: forwards;
23+
animation-duration: 0.5s;
24+
}
25+
26+
@media only screen and (min-width: 640px) {
27+
.button {
28+
width: 100%;
29+
}
30+
}
31+
32+
@keyframes button-animation {
33+
from {
34+
transform: translateY(0);
35+
box-shadow: none;
36+
}
37+
to {
38+
transform: translateY(-0.5em);
39+
box-shadow: 0 0.5em 0 0 #ddd;
40+
}
41+
}

components/button.tsx

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import styles from "./button.module.css";
2+
3+
type Props = {
4+
children: string;
5+
color?: string;
6+
};
7+
8+
export function Button(props: Props) {
9+
const { children, color = "dodgerblue" } = props;
10+
11+
return (
12+
<button className={styles.button} style={{ color }}>
13+
<span>{children}</span>
14+
</button>
15+
);
16+
}

next-env.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/// <reference types="next" />
2+
/// <reference types="next/types/global" />

package.json

+5
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,10 @@
1111
"next": "10.0.5",
1212
"react": "17.0.1",
1313
"react-dom": "17.0.1"
14+
},
15+
"devDependencies": {
16+
"@types/node": "^14.14.20",
17+
"@types/react": "^17.0.0",
18+
"typescript": "^4.1.3"
1419
}
1520
}

pages/_app.js

-7
This file was deleted.

pages/_app.tsx

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { AppProps /*, AppContext */ } from "next/app";
2+
3+
import "../styles/globals.css";
4+
5+
function MyApp({ Component, pageProps }: AppProps) {
6+
return <Component {...pageProps} />;
7+
}
8+
9+
export default MyApp;

pages/api/hello.js

-6
This file was deleted.

pages/index.js

-65
This file was deleted.

pages/index.tsx

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Button } from "../components/button";
2+
3+
export default function Home() {
4+
return (
5+
<main>
6+
<Button>Default color</Button>
7+
<Button color="#e3b307">Yellow color</Button>
8+
<Button color="#57b004">Green color</Button>
9+
</main>
10+
);
11+
}

public/vercel.svg

-4
This file was deleted.

styles/Home.module.css

-122
This file was deleted.

styles/globals.css

+13-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,19 @@ html,
22
body {
33
padding: 0;
44
margin: 0;
5-
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
6-
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
5+
min-height: 100vh;
6+
display: flex;
7+
align-items: center;
8+
justify-content: center;
9+
text-align: center;
10+
}
11+
12+
html,
13+
body,
14+
button,
15+
input {
16+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
17+
Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
718
}
819

920
a {

tsconfig.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"lib": ["dom", "dom.iterable", "esnext"],
5+
"allowJs": false,
6+
"skipLibCheck": true,
7+
"strict": true,
8+
"forceConsistentCasingInFileNames": true,
9+
"noEmit": true,
10+
"esModuleInterop": true,
11+
"module": "esnext",
12+
"moduleResolution": "node",
13+
"resolveJsonModule": true,
14+
"isolatedModules": true,
15+
"jsx": "preserve"
16+
},
17+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
18+
"exclude": ["node_modules"]
19+
}

0 commit comments

Comments
 (0)