feat(app): add currentcolor picker option
This commit is contained in:
@@ -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;
|
||||||
@@ -46,4 +46,4 @@ input.color-input::-webkit-color-swatch {
|
|||||||
input.color-input:focus {
|
input.color-input:focus {
|
||||||
outline: none;
|
outline: none;
|
||||||
border: 2px solid white;
|
border: 2px solid white;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user