-
Notifications
You must be signed in to change notification settings - Fork 139
feat(colorpicker): Add ColorPicker component with support for HEX, RGB and Alpha channel #2386
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
base: main
Are you sure you want to change the base?
Conversation
|
Preview is ready. |
|
Visual Tests Report is ready. |
|
Does this library has keyboard support? I can set the focus on the sliders but it seems not responding |
package.json
Outdated
| "i": "^0.3.7", | ||
| "lodash": "^4.17.21", | ||
| "npm": "^11.5.2", |
There was a problem hiding this comment.
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}> |
There was a problem hiding this comment.
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'} |
There was a problem hiding this comment.
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}> |
There was a problem hiding this comment.
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
seems not, but react-colorful does |
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 |
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", |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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



No description provided.