Skip to content

Commit

Permalink
Add info link to color viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
andbas committed Oct 7, 2024
1 parent cd5226e commit 9016ddb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
19 changes: 15 additions & 4 deletions src/components/color-viewer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Pixel } from "@/types";
import { isLight, pixelToHex, pixelToX } from "@/utils";
import { isLight, pixelToHex, pixelToUrlSlug, pixelToX } from "@/utils";
import { useDebounce } from "@uidotdev/usehooks";
import { ClipboardCopy, Sparkle } from "lucide-react";
import { ClipboardCopy, Info, Sparkle } from "lucide-react";
import Link from "next/link";
import { useState } from "react";

interface ColorViewerProps {
Expand Down Expand Up @@ -33,8 +34,7 @@ export function ColorViewer({

return (
<div
onClick={handleClick}
className={`flex w-full justify-center items-center h-12 transition-colors duration-200 ${
className={`flex w-full justify-center items-center h-12 transition-colors duration-200 relative ${
isLight(pixelColor) ? "text-black" : "text-white"
}`}
style={{
Expand All @@ -60,6 +60,17 @@ export function ColorViewer({
{value}
</span>
</div>
<div
onClick={handleClick}
className="absolute left-0 top-0 w-5/6 h-full cursor-pointer"
></div>

<Link
href={`/colors/${pixelToUrlSlug(pixel)}`}
className="absolute right-0 top-0 w-1/6 h-full cursor-pointer flex items-center justify-center"
>
<Info className="w-6 h-6" />
</Link>
</div>
);
}
13 changes: 12 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,15 @@ const colorToUrlSlug = (colorName: string) => {
return colorName.toLowerCase().replace("/", "").replace(/ /g, "_");
};

export { isLight, closest, pixelToHex, pixelToX, colorToUrlSlug };
const pixelToUrlSlug = (pixel: Pixel) => {
return `${colorToUrlSlug(pixelToX(pixel, "name"))}`;
};

export {
isLight,
closest,
pixelToHex,
pixelToX,
colorToUrlSlug,
pixelToUrlSlug,
};

0 comments on commit 9016ddb

Please sign in to comment.