Skip to content

feat(ColorPicker): new component#378

Open
alberthovhannisyan1 wants to merge 17 commits intorelease/3.0.0from
feature/new-colorpicker-component
Open

feat(ColorPicker): new component#378
alberthovhannisyan1 wants to merge 17 commits intorelease/3.0.0from
feature/new-colorpicker-component

Conversation

@alberthovhannisyan1
Copy link
Collaborator

@alberthovhannisyan1 alberthovhannisyan1 commented Feb 16, 2026

width: 28.8rem;
padding: var(--guit-ref-spacing-large);

.react-colorful {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This approach is unacceptable; we should not be depended from third part library classname.

export const WithRecentColors: Story = {
render: (props) => {
return (
<div style={{ width: "100%" }}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove unnecessary <div>

Suggested change
<div style={{ width: "100%" }}>
return <ColorPicker {...props} />;

onOutsideClick?.();
}, [popoverRef.current.floatingElement, popoverRef.current.referenceElement]);

const ColorSquareIcon = useCallback(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This clickable item should be a <button> for proper semantics and accessibility, rather than a generic clickable element. Also, useCallback is unnecessary here since the callback is not expensive and does not provide a clear optimization benefit. Finally, this code would be more readable if rgba is destructured (e.g., const { r, g, b, a } = rgba) before building the rgba string/style.

}, [format]);

useClickOutside(() => {
if (!isOpenControlled) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The same controlled-state guard is duplicated in multiple places. Please extract it into a single handler (e.g., setOpenState(nextState: boolean)) and reuse it instead of repeating the conditional logic. This will reduce duplication and make future changes safer.

setProps={setPropsForPopover}
>
<PopoverBody withPadding={false}>
<div className="colorPicker__wrapper">
Copy link
Collaborator

Choose a reason for hiding this comment

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

The extra wrapper <div className="colorPicker__wrapper"> looks unnecessary. We can likely apply this class directly to PopoverBody and keep the same behavior, while removing redundant DOM nesting.
<PopoverBody withPadding={false} className="colorPicker__wrapper">

[emitChange]
);

const handlePickerChange = useCallback(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems like an overuse of useCallback. handlePickerChange is mostly local logic, and memoizing it here adds complexity without clear performance benefit. Unless this callback is required for referential stability in a memoized child, consider using a regular function instead.

const isColorControlled = value !== undefined;
const isOpenControlled = open !== undefined;

const [isOpen, setIsOpen] = useState<boolean>(open ?? false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need to explicitly annotate primitive state types here. TypeScript can infer this from the initial value, so useState(open ?? false) is cleaner and equivalent.
This can be simplified from open ?? false to !!open . The current expression is valid, but the simplified form is more concise.

const initialHex = value ?? defaultColor;
const rgb = initialHex ? hexToRgb(initialHex) : null;

return rgb ? { ...rgb, a: alphaValue / 100 } : { ...DEFAULT_RGBA };
Copy link
Collaborator

Choose a reason for hiding this comment

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

There are several hardcoded 100 values here, which read as magic numbers. Please extract them into well-named constants (e.g., PERCENT_MAX or ALPHA_SCALE_MAX) so the intent is clear and easier to maintain.

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.

[Feat]: New ColorPicker component

3 participants