-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
226 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import Card from "../components/Card"; | ||
import Navbar from "../components/Navbar"; | ||
import { HomeStyled } from "../styles/HomeStyled"; | ||
import { useState, useEffect } from "react"; | ||
import { Link } from "react-router-dom"; | ||
import Meta from "../components/Meta"; | ||
import { Button } from "../styles/ButtonStyled"; | ||
import { useParams } from "react-router-dom"; | ||
import { greenGradients, redGradients, yellowGradients, blackGradients, blueGradients, whiteGradients } from "../utils/generateColors"; | ||
import Spinner from "../components/Spinner"; | ||
|
||
const SortedColors = () => { | ||
|
||
const [loading, setIsLoading] = useState(false); | ||
const { sortedName } = useParams() | ||
|
||
console.log(sortedName) | ||
|
||
useEffect(() => { | ||
setIsLoading(false) | ||
}, []) | ||
|
||
|
||
|
||
return ( | ||
<> | ||
<Meta /> | ||
<HomeStyled> | ||
<Navbar /> | ||
<div className="wrapper"> | ||
<div className="category"> | ||
<Link className="sorted-link" to="/sorted/red"> | ||
<Button border="none" background="#FF025E">Red</Button> | ||
</Link> | ||
<Link className="sorted-link" to="/sorted/yellow"> | ||
<Button border="none" background="#FFD000">Yellow</Button> | ||
</Link> | ||
<Link className="sorted-link" to="/sorted/green"> | ||
<Button border="none" background="#64F38C">Green</Button> | ||
</Link> | ||
<Link className="sorted-link" to="/sorted/blue"> | ||
<Button border="none" background="#019DF7">Blue</Button> | ||
</Link> | ||
<Link className="sorted-link" to="/sorted/black"> | ||
<Button border="none" background="#161A1D">Black</Button> | ||
</Link> | ||
</div> | ||
<section className="main"> | ||
|
||
{ | ||
<> | ||
{loading ? ( | ||
<Spinner /> | ||
) : | ||
( | ||
<> | ||
{sortedName === "red" | ||
? redGradients.map((gradient) => ( | ||
<Link style={{textDecoration:"none"}} to={`/indie-color/${gradient.name}`}> | ||
<Card color={gradient.colors} name={gradient.name} isSaved = {true} /> | ||
</Link> | ||
)) | ||
: sortedName === "green" | ||
? greenGradients.map((gradient) => ( | ||
<Link style={{textDecoration:"none"}} to={`/indie-color/${gradient.name}`}> | ||
<Card color={gradient.colors} name={gradient.name} isSaved = {true} /> | ||
</Link> | ||
)) | ||
: sortedName === "blue" | ||
? blueGradients.map((gradient) => ( | ||
<Link style={{textDecoration:"none"}} to={`/indie-color/${gradient.name}`}> | ||
<Card color={gradient.colors} name={gradient.name} isSaved = {true} /> | ||
</Link> | ||
)) | ||
: sortedName === "white" | ||
? whiteGradients.map((gradient) => ( | ||
<Link style={{textDecoration:"none"}} to={`/indie-color/${gradient.name}`}> | ||
<Card color={gradient.colors} name={gradient.name} isSaved = {true} /> | ||
</Link> | ||
)) | ||
: sortedName === "yellow" | ||
? yellowGradients.map((gradient) => ( | ||
<Link style={{textDecoration:"none"}} to={`/indie-color/${gradient.name}`}> | ||
<Card color={gradient.colors} name={gradient.name} isSaved = {true} /> | ||
</Link> | ||
)) | ||
: blackGradients.map((gradient) => ( | ||
<Link style={{textDecoration:"none"}} to={`/indie-color/${gradient.name}`}> | ||
<Card color={gradient.colors} name={gradient.name} isSaved = {true} /> | ||
</Link> | ||
))} | ||
</> | ||
)} | ||
</> | ||
} | ||
|
||
|
||
</section> | ||
</div> | ||
</HomeStyled> | ||
</> | ||
); | ||
} | ||
|
||
export default SortedColors; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TailSpin } from "react-loader-spinner"; | ||
import { HomeStyled } from "../styles/HomeStyled"; | ||
|
||
const Spinner = () => { | ||
return ( | ||
<> | ||
<HomeStyled> | ||
<div className="loader"> | ||
<TailSpin width="90" color="blue" /> | ||
</div> | ||
</HomeStyled> | ||
</> | ||
); | ||
} | ||
|
||
export default Spinner ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const hexToRGB = (hex) => { | ||
// Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF") | ||
var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; | ||
hex = hex.replace(shorthandRegex, function (m, r, g, b) { | ||
return r + r + g + g + b + b; | ||
}); | ||
|
||
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); | ||
return result | ||
? { | ||
r: parseInt(result[1], 16), | ||
g: parseInt(result[2], 16), | ||
b: parseInt(result[3], 16), | ||
} | ||
: null; | ||
}; | ||
|
||
export const generateCategory = (hex) => { | ||
const RGB = hexToRGB(hex); | ||
|
||
const { r, g, b } = RGB; | ||
|
||
if (r > 200 && g > 200 && b > 200) { | ||
return "white"; | ||
} else if (r > b && g > b && r > 200 && g > 100 && g < 200 && b < 100) { | ||
return "yellow"; | ||
} else if (r > g && r > b && r > 150 && g < 120) { | ||
return "red"; | ||
} else if (g > b && g > r && g > 150 && b < 150) { | ||
return "green"; | ||
} else if (b > r && b > g && b > 150) { | ||
return "blue"; | ||
} else if (r < 90 && g < 90 && b < 90) { | ||
return "black"; | ||
} else { | ||
return "none"; | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { generateCategory } from "../helpers/Sort"; | ||
import gradients from "../data/data.json"; | ||
|
||
|
||
export const whiteGradients = gradients.filter((gradient) => { | ||
return ( | ||
generateCategory(gradient.colors[0]) === "white" || | ||
generateCategory(gradient.colors[1]) === "white" | ||
); | ||
}); | ||
export const yellowGradients = gradients.filter((gradient) => { | ||
return ( | ||
generateCategory(gradient.colors[0]) === "yellow" || | ||
generateCategory(gradient.colors[1]) === "yellow" | ||
); | ||
}); | ||
export const redGradients = gradients.filter((gradient) => { | ||
return ( | ||
generateCategory(gradient.colors[0]) === "red" || | ||
generateCategory(gradient.colors[1]) === "red" | ||
); | ||
}); | ||
export const greenGradients = gradients.filter((gradient) => { | ||
return ( | ||
generateCategory(gradient.colors[0]) === "green" || | ||
generateCategory(gradient.colors[1]) === "green" | ||
); | ||
}); | ||
export const blueGradients = gradients.filter((gradient) => { | ||
return ( | ||
generateCategory(gradient.colors[0]) === "blue" || | ||
generateCategory(gradient.colors[1]) === "blue" | ||
); | ||
}); | ||
export const blackGradients = gradients.filter((gradient) => { | ||
return ( | ||
generateCategory(gradient.colors[0]) === "black" || | ||
generateCategory(gradient.colors[1]) === "black" | ||
); | ||
}); |
4c83515
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
gradients-ninja – ./
gradients-ninja-git-main-wahabdev12.vercel.app
gradients-ninja-wahabdev12.vercel.app
gradients-ninja.vercel.app