feat(app): add currentcolor picker option

This commit is contained in:
rektdeckard
2023-04-20 21:23:14 -06:00
parent b1b9eadc35
commit 2fc3263cdc
2 changed files with 23 additions and 7 deletions

View File

@@ -6,16 +6,16 @@
flex: 1; flex: 1;
border: none; border: none;
outline: none; outline: none;
appearance: none;
-webkit-appearance: none; -webkit-appearance: none;
} }
.color-picker span { .color-picker span {
display: grid;
place-items: center;
position: absolute; position: absolute;
margin: 0; margin: 0;
top: 50%; inset: 0;
left: 50%;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
-moz-user-select: none; -moz-user-select: none;
-webkit-user-select: none; -webkit-user-select: none;
user-select: none; user-select: none;

View File

@@ -1,5 +1,6 @@
import { useCallback } from "react"; import { useCallback } from "react";
import { useRecoilState, useRecoilValue } from "recoil"; import { useRecoilState, useRecoilValue } from "recoil";
import { EyedropperSample } from "@phosphor-icons/react";
import { useThrottled } from "@/hooks"; import { useThrottled } from "@/hooks";
import { iconColorAtom, isDarkThemeSelector } from "@/state"; import { iconColorAtom, isDarkThemeSelector } from "@/state";
@@ -22,12 +23,21 @@ const ColorInput = (_: ColorInputProps) => {
[setColor] [setColor]
); );
const handleSetInheritedColor = (e: React.MouseEvent) => {
e.preventDefault();
setColor("currentColor");
};
const throttledColorChange = useThrottled(handleColorChange, 100, [ const throttledColorChange = useThrottled(handleColorChange, 100, [
handleColorChange, handleColorChange,
]); ]);
return ( return (
<div className="color-picker"> <div
className="color-picker"
title="Select a color, or right-click to use inherited color"
onContextMenu={handleSetInheritedColor}
>
<input <input
className="color-input" className="color-input"
aria-label="Icon Color" aria-label="Icon Color"
@@ -36,7 +46,13 @@ const ColorInput = (_: ColorInputProps) => {
onChange={throttledColorChange} onChange={throttledColorChange}
value={color} value={color}
/> />
<span style={{ color: isDark ? "black" : "white" }}>{color}</span> <span style={{ color: isDark ? "black" : "white" }}>
{color === "currentColor" ? (
<EyedropperSample size={28} weight="fill" />
) : (
color
)}
</span>
</div> </div>
); );
}; };