Skip to content

Fix ColorPicker undo stack additions #494

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

KARM99
Copy link
Contributor

@KARM99 KARM99 commented Jun 14, 2025

No description provided.

Copy link

vercel bot commented Jun 14, 2025

@KARM99 is attempting to deploy a commit to the dottle's projects Team on Vercel.

A member of the Team first needs to authorize it.

@KARM99 KARM99 force-pushed the fix-colorpicker-undo-stack branch from 8e0a89c to 87df48d Compare June 14, 2025 08:09
@KARM99 KARM99 force-pushed the fix-colorpicker-undo-stack branch from 87df48d to 00074ad Compare June 14, 2025 08:16
Copy link

vercel bot commented Jun 14, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
drawdb ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 14, 2025 10:40am

Copy link
Member

@1ilit 1ilit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's unify and move this logic to a custom component that wraps ColorPicker from semi-ui

The component would roughly look like this

import { ColorPicker as SemiColorPicker } from "@douyinfe/semi-ui";
import { useState } from "react";

export default function ColorPicker({
  children,
  value,
  onBlur,
  onChange,
  ...props
}) {
  const [pickedColor, setPickedColor] = useState(null);

  const handleBlur = () => {
    if (pickedColor) onBlur(pickedColor);
    setPickedColor(null);
  };

  return (
    <div onPointerUp={handleBlur} onBlur={handleBlur}>
      <SemiColorPicker
        {...props}
        value={SemiColorPicker.colorStringToValue(value)}
        onChange={({ hex: color }) => {
          setPickedColor(color);
          onChange(color);
        }}
      >
        {children}
      </SemiColorPicker>
    </div>
  );
}

And it would be consumed like this:

<ColorPicker
  usePopover={true}
  value={data.color}
  onChange={(color) => updateArea(i, { color })}
  onBlur={(color) => handleColorPickerBlur(color)}
 >
  <div
     className="h-[32px] w-[32px] rounded-sm shrink-0"
     style={{ backgroundColor: data.color }}
   />
</ColorPicker>

@@ -217,10 +217,32 @@ export default function Area({

function EditPopoverContent({ data }) {
const [editField, setEditField] = useState({});
const [pickedColor, setPickedColor] = useState(undefined);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const [pickedColor, setPickedColor] = useState(undefined);
const [pickedColor, setPickedColor] = useState(null);

const { updateArea, deleteArea } = useAreas();
const { setUndoStack, setRedoStack } = useUndoRedo();
const { t } = useTranslation();

const handleColorPickerChange = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const handleColorPickerChange = () => {
const handleColorPickerBlur = () => {

},
]);
setRedoStack([]);
setPickedColor(undefined);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
setPickedColor(undefined);
setPickedColor(null);

const { updateArea, deleteArea } = useAreas();
const { setUndoStack, setRedoStack } = useUndoRedo();
const { t } = useTranslation();

const handleColorPickerChange = () => {
if (pickedColor !== undefined) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (pickedColor !== undefined) {
if (pickedColor) {

usePopover={true}
value={ColorPicker.colorStringToValue(data.color)}
>
<div
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Format please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants