Skip to content

Commit 065e64c

Browse files
author
Nirmalya Ghosh
authored
Merge pull request #355 from ahmadbilaldev/main
📦 NEW: Random Color Palette Generator
2 parents f3b1be8 + 667fa43 commit 065e64c

File tree

10 files changed

+237
-0
lines changed

10 files changed

+237
-0
lines changed

random-color-palette-app/.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# local env files
28+
.env.local
29+
.env.development.local
30+
.env.test.local
31+
.env.production.local
32+
33+
# vercel
34+
.vercel

random-color-palette-app/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
![cover](assets/cover.png)
2+
3+
<div align="center">
4+
<h2>Random Color Palette App</h2>
5+
</div>
6+
7+
> [Live Preview](https://rapidapi-example-color-palette-app.vercel.app/)
8+
9+
### ⚡️ Features
10+
11+
- Generate random color palettes with every click.
12+
- Responsive design.
13+
14+
## Guide
15+
16+
[Read a step-by-step guide to build this application.](https://rapidapi.com/guides/build-color-palette-app)
17+
18+
### 🛠️ Installation Steps
19+
20+
1. Download the `random-color-palette-app` directory. Click [here](https://download-directory.github.io/?url=https://github.com/RapidAPI/DevRel-Examples-External/tree/main/random-color-palette-app) to download it.
21+
22+
2. Unzip the downloaded file and navigate to the working directory.
23+
24+
```bash
25+
cd RapidAPI\ DevRel-Examples-External\ main\ random-color-palette-app/
26+
```
27+
28+
3. Install dependencies
29+
30+
```bash
31+
npm install
32+
```
33+
34+
4. Create `.env.local` file in root and add your RapidAPI key.
35+
36+
```bash
37+
NEXT_PUBLIC_RAPIDAPI_KEY=YOUR_RAPID_API_KEY
38+
```
39+
40+
5. Run the app
41+
42+
```bash
43+
npm run dev
44+
```
45+
46+
You are all set! Open [localhost:3000](http://localhost:3000/) to see the app.
170 KB
Loading

random-color-palette-app/package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"private": true,
3+
"scripts": {
4+
"dev": "next dev",
5+
"build": "next build",
6+
"start": "next start"
7+
},
8+
"dependencies": {
9+
"axios": "^0.24.0",
10+
"next": "latest",
11+
"react": "^17.0.2",
12+
"react-dom": "^17.0.2"
13+
},
14+
"devDependencies": {
15+
"autoprefixer": "^10.4.0",
16+
"postcss": "^8.4.4",
17+
"tailwindcss": "^3.0.0"
18+
}
19+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import Head from "next/head";
2+
import "tailwindcss/tailwind.css";
3+
4+
function MyApp({ Component, pageProps }) {
5+
return (
6+
<>
7+
<Head>
8+
<title>RapidAPI - Random Color Palette App</title>
9+
<link rel="icon" href="/favicon.ico" />
10+
<link
11+
href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap"
12+
rel="stylesheet"
13+
/>
14+
</Head>
15+
<Component {...pageProps} />
16+
</>
17+
);
18+
}
19+
20+
export default MyApp;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import axios from "axios";
2+
3+
export default async function handler(req, res) {
4+
const options = {
5+
method: "GET",
6+
url: "https://random-palette-generator.p.rapidapi.com/palette/Monochromatic/1/4",
7+
headers: {
8+
"X-RapidAPI-Host": "random-palette-generator.p.rapidapi.com",
9+
"X-RapidAPI-Key": process.env.NEXT_PUBLIC_RAPIDAPI_KEY,
10+
},
11+
};
12+
try {
13+
let response = await axios(options);
14+
res.status(200).json(response.data);
15+
} catch (error) {
16+
console.error(error.response);
17+
}
18+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import axios from "axios";
2+
import { useState, useEffect } from "react";
3+
4+
export default function Home() {
5+
const [colors, setColors] = useState(null);
6+
const [loading, setLoading] = useState(false);
7+
8+
const getColors = async () => {
9+
try {
10+
setLoading(true);
11+
const res = await axios.get("api/generate/");
12+
setColors(res.data.data[0].palette);
13+
setLoading(false);
14+
} catch (error) {
15+
setLoading(false);
16+
}
17+
};
18+
19+
useEffect(() => {
20+
getColors();
21+
}, []);
22+
23+
return (
24+
<div className="flex flex-col md:px-12 px-4 bg-background font-poppins items-center min-h-screen">
25+
<h1 className="md:text-6xl text-4xl font-bold text-primary mt-10">
26+
Random <span className="text-active">Color Pallete</span> Generator
27+
</h1>
28+
<h2 className="text-primary text-2xl font-light mt-6 font-ebas">
29+
Click change to get a random color pallete
30+
</h2>
31+
32+
{colors && (
33+
<div className="mt-20 grid grid-cols-4 rounded-lg">
34+
{colors.map((color, index) => {
35+
return (
36+
<div
37+
key={index}
38+
className="text-primary font-bold sm:text-xl text-sm sm:px-12 px-2 py-36"
39+
style={{ backgroundColor: color }}
40+
>
41+
{color}
42+
</div>
43+
);
44+
})}
45+
</div>
46+
)}
47+
48+
<button
49+
className="mt-10 font-bold text-primary text-xl hover:text-active"
50+
onClick={getColors}
51+
>
52+
{loading ? (
53+
<span className="animate-pulse">Loading..</span>
54+
) : (
55+
<>Change &rarr;</>
56+
)}
57+
</button>
58+
59+
<div className="mt-20 mb-10 opacity-70 text-center">
60+
<p className="text-primary text-xs">
61+
Made by RapidAPI DevRel Team -{" "}
62+
<a
63+
className="hover:text-active"
64+
href="https://github.com/RapidAPI/DevRel-Examples-External"
65+
>
66+
See more examples like this
67+
</a>
68+
</p>
69+
</div>
70+
</div>
71+
);
72+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// If you want to use other PostCSS plugins, see the following:
2+
// https://tailwindcss.com/docs/using-with-preprocessors
3+
module.exports = {
4+
plugins: {
5+
tailwindcss: {},
6+
autoprefixer: {},
7+
},
8+
}
4.39 KB
Binary file not shown.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = {
2+
mode: "jit",
3+
purge: ["./pages/**/*.{js,ts,jsx,tsx}", "./components/**/*.{js,ts,jsx,tsx}"],
4+
darkMode: false, // or 'media' or 'class'
5+
theme: {
6+
fontFamily: {
7+
poppins: ["Poppins", "sans-serif"],
8+
},
9+
colors: {
10+
background: "#000000",
11+
primary: "#FFFFFF",
12+
active: "#FFCF00",
13+
},
14+
},
15+
16+
variants: {
17+
extend: {},
18+
},
19+
plugins: [],
20+
};

0 commit comments

Comments
 (0)