Skip to content

Conversation

@Estasie
Copy link
Contributor

@Estasie Estasie commented Aug 14, 2025

No description provided.

@gravity-ui
Copy link
Contributor

gravity-ui bot commented Aug 14, 2025

Preview is ready.

@gravity-ui
Copy link
Contributor

gravity-ui bot commented Aug 14, 2025

Visual Tests Report is ready.

@Estasie Estasie changed the title feat(ColorPicker): Add ColorPicker component with support for HEX, RGB and Alpha channel using react-color lib feat(ColorPicker): Add ColorPicker component with support for HEX, RGB and Alpha channel Aug 15, 2025
@Estasie Estasie changed the title feat(ColorPicker): Add ColorPicker component with support for HEX, RGB and Alpha channel feat(colorpicker): Add ColorPicker component with support for HEX, RGB and Alpha channel Aug 15, 2025
@amje
Copy link
Contributor

amje commented Aug 18, 2025

Снимок экрана 2025-08-18 в 20 18 47

Button has a strange appearance. It should be squared evenly and also chess-pattern should be white/gray, not transparent, background should be visible through.

@amje
Copy link
Contributor

amje commented Aug 18, 2025

Does this library has keyboard support? I can set the focus on the sliders but it seems not responding

@amje
Copy link
Contributor

amje commented Aug 18, 2025

Why mixing RGB and HEX controls. If HEX selected then it should be a single field of hex value including alpha part:
Снимок экрана 2025-08-18 в 20 38 34

package.json Outdated
Comment on lines 136 to 138
"i": "^0.3.7",
"lodash": "^4.17.21",
"npm": "^11.5.2",
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these deps added by mistake?

anchorElement={anchor}
onOpenChange={handleOpenChange}
>
<Flex direction={'column'} gap={2}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Flex component should not be used inside the other components, it's for user-only component as it follows spacing variables which can be overwriten and we want our components to be fixed spacing

<Popup
open={open}
className={b('popup')}
placement={'bottom-end'}
Copy link
Contributor

Choose a reason for hiding this comment

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

Only bottom-end value makes component look shifted when it rendered on the left side of the screen. Let's use 'bottom-start' | 'bottom-end' so the component could flip from side to side.

return (
<Card view={'outlined'} className={b('picker-wrapper')} ref={ref}>
<Flex alignItems={'center'} gap={2}>
<Button size={'s'} className={b('underlay')} onClick={onClick}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Button has complex styles and instead of overriding them it's easier to use native button, reset and apply only needed styles. It will be much cleaner

@Estasie
Copy link
Contributor Author

Estasie commented Aug 18, 2025

Why mixing RGB and HEX controls. If HEX selected then it should be a single field of hex value including alpha part: Снимок экрана 2025-08-18 в 20 38 34

I thought it would be more comfortable to use common instruments for setting opacity, percent just looks more human

@Estasie
Copy link
Contributor Author

Estasie commented Aug 18, 2025

Does this library has keyboard support? I can set the focus on the sliders but it seems not responding

seems not, but react-colorful does

@amje
Copy link
Contributor

amje commented Aug 19, 2025

I thought it would be more comfortable to use common instruments for setting opacity, percent just looks more human

Picker already has such instrument, the slider for opacity changing. Rest controls are specific for the format, and HEX should be a single input, so I can paste any valid color, inncluding alpha part and picker should accept it

@amje
Copy link
Contributor

amje commented Aug 19, 2025

Does this library has keyboard support? I can set the focus on the sliders but it seems not responding

seems not, but react-colorful does

It's sad...

package.json Outdated
"@gravity-ui/i18n": "^1.8.0",
"@gravity-ui/icons": "^2.13.0",
"@tanstack/react-virtual": "^3.13.9",
"@uiw/react-color": "^2.7.3",
Copy link
Contributor

Choose a reason for hiding this comment

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

Keyboard support has been added in 2.8.0. Let's update


export interface ColorPickerProps {
withAlpha?: boolean;
mode?: Modes;
Copy link
Contributor

Choose a reason for hiding this comment

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

mode seems not very usefull if it's only affect inputs in popup. I assume we can remove it without affecting ux/dx

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed it

mode?: Modes;
defaultColor?: HsvaColor;
onChange?: (color: HsvaColor) => void;
onClose?: () => void;
Copy link
Contributor

Choose a reason for hiding this comment

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

The component should have similar API to other inputs. Let's change API to the following:

interface ColorPickerProps {
    // Same size as in the `TextInput`
    size?: 's' | 'm' | 'l' | 'xl';
    // if controlled value
    value?: string;
    // if uncontrolled value
    defaultValue?: string;
    // onChange naming is reserved for native event handlers
    onUpdate?: (value: string) => void;
    // if controlled open state
    open?: boolean;
    // if uncontrolled open state
    defaultOpen?: boolean;
    onOpenChange?: (open: boolean) => void;
    // it should be false by default (common case)
    withAlpha?: boolean;
}

For controlled/uncontrolled state there is a hook useContolledState (see other components as an example)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added more props, also added 'onlyPicker' prop for button only render without value

withAlpha?: boolean;
mode?: Modes;
defaultColor?: HsvaColor;
onChange?: (color: HsvaColor) => void;
Copy link
Contributor

Choose a reason for hiding this comment

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

What about accepting more common format as value, like simple HEX?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed it to the hex, incoming as string and resolving it only for external usage, locally I use hsva for better precision

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.

3 participants