Skip to content

Commit

Permalink
fix: 🐛 color picker file classname code refactor using className library
Browse files Browse the repository at this point in the history
  • Loading branch information
padmanathan10 committed Dec 28, 2023
1 parent 6832715 commit f0e0307
Showing 1 changed file with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions src/components/colorPicker.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import classNames from "classnames";

import { colorPickerColors } from "../utils/constants";

type ColorPickerProps = {
Expand All @@ -6,25 +8,48 @@ type ColorPickerProps = {
selectedColor: string;
};

const colorBlockWrapper = classNames(
"flex",
"cursor-pointer",
"items-center",
"space-x-1",
);

const colorBlockSelected = ({
colorItem,
selectedColor,
}: {
colorItem: string;
selectedColor: string;
}) =>
classNames("rounded-md", "p-1", "hover:bg-custom-gray-7", {
"bg-custom-gray-7": colorItem === selectedColor,
});

const colorBlockItemBorder = (colorItem: string) =>
classNames(
"h-4",
"w-4",
"rounded-full",
"border-[1px]",
"p-1",
{ "border-gray-900": colorItem === colorPickerColors[0] },
{ "border-transparent": colorItem !== colorPickerColors[0] },
);

const ColorPicker = ({
colorsList,
onChange,
selectedColor,
}: ColorPickerProps) => (
<div className="flex cursor-pointer items-center space-x-1">
<div className={colorBlockWrapper}>
{colorsList?.map((colorItem) => (
<div
className={`rounded-md p-1 hover:bg-custom-gray-7 ${
colorItem === selectedColor ? "bg-custom-gray-7" : ""
}`}
className={colorBlockSelected({ colorItem, selectedColor })}
key={colorItem}
>
<div
className={`h-4 w-4 rounded-full border-[1px] p-1 ${
colorItem === colorPickerColors[0]
? "border-gray-900"
: "border-transparent"
}`}
className={colorBlockItemBorder(colorItem)}
onClick={() => onChange(colorItem)}
onKeyDown={() => {}}
role="button"
Expand Down

0 comments on commit f0e0307

Please sign in to comment.