mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(ui): add number inputs for canvas brush color picker (#5067)
* drop-down for the color picker * fixed the bug in alpha value * designing done --------- Co-authored-by: psychedelicious <4822129+psychedelicious@users.noreply.github.com>
This commit is contained in:
parent
90a038c685
commit
89a039460d
@ -1,9 +1,12 @@
|
|||||||
import { Box, ChakraProps } from '@chakra-ui/react';
|
import { ChakraProps, Flex } from '@chakra-ui/react';
|
||||||
import { memo } from 'react';
|
import { memo, useCallback } from 'react';
|
||||||
import { RgbaColorPicker } from 'react-colorful';
|
import { RgbaColorPicker } from 'react-colorful';
|
||||||
import { ColorPickerBaseProps, RgbaColor } from 'react-colorful/dist/types';
|
import { ColorPickerBaseProps, RgbaColor } from 'react-colorful/dist/types';
|
||||||
|
import IAINumberInput from './IAINumberInput';
|
||||||
|
|
||||||
type IAIColorPickerProps = ColorPickerBaseProps<RgbaColor>;
|
type IAIColorPickerProps = ColorPickerBaseProps<RgbaColor> & {
|
||||||
|
withNumberInput?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
const colorPickerStyles: NonNullable<ChakraProps['sx']> = {
|
const colorPickerStyles: NonNullable<ChakraProps['sx']> = {
|
||||||
width: 6,
|
width: 6,
|
||||||
@ -11,17 +14,84 @@ const colorPickerStyles: NonNullable<ChakraProps['sx']> = {
|
|||||||
borderColor: 'base.100',
|
borderColor: 'base.100',
|
||||||
};
|
};
|
||||||
|
|
||||||
const sx = {
|
const sx: ChakraProps['sx'] = {
|
||||||
'.react-colorful__hue-pointer': colorPickerStyles,
|
'.react-colorful__hue-pointer': colorPickerStyles,
|
||||||
'.react-colorful__saturation-pointer': colorPickerStyles,
|
'.react-colorful__saturation-pointer': colorPickerStyles,
|
||||||
'.react-colorful__alpha-pointer': colorPickerStyles,
|
'.react-colorful__alpha-pointer': colorPickerStyles,
|
||||||
|
gap: 2,
|
||||||
|
flexDir: 'column',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const numberInputWidth: ChakraProps['w'] = '4.2rem';
|
||||||
|
|
||||||
const IAIColorPicker = (props: IAIColorPickerProps) => {
|
const IAIColorPicker = (props: IAIColorPickerProps) => {
|
||||||
|
const { color, onChange, withNumberInput, ...rest } = props;
|
||||||
|
const handleChangeR = useCallback(
|
||||||
|
(r: number) => onChange({ ...color, r }),
|
||||||
|
[color, onChange]
|
||||||
|
);
|
||||||
|
const handleChangeG = useCallback(
|
||||||
|
(g: number) => onChange({ ...color, g }),
|
||||||
|
[color, onChange]
|
||||||
|
);
|
||||||
|
const handleChangeB = useCallback(
|
||||||
|
(b: number) => onChange({ ...color, b }),
|
||||||
|
[color, onChange]
|
||||||
|
);
|
||||||
|
const handleChangeA = useCallback(
|
||||||
|
(a: number) => onChange({ ...color, a }),
|
||||||
|
[color, onChange]
|
||||||
|
);
|
||||||
return (
|
return (
|
||||||
<Box sx={sx}>
|
<Flex sx={sx}>
|
||||||
<RgbaColorPicker {...props} />
|
<RgbaColorPicker
|
||||||
</Box>
|
color={color}
|
||||||
|
onChange={onChange}
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
{...rest}
|
||||||
|
/>
|
||||||
|
{withNumberInput && (
|
||||||
|
<Flex>
|
||||||
|
<IAINumberInput
|
||||||
|
value={color.r}
|
||||||
|
onChange={handleChangeR}
|
||||||
|
min={0}
|
||||||
|
max={255}
|
||||||
|
step={1}
|
||||||
|
label="Red"
|
||||||
|
w={numberInputWidth}
|
||||||
|
/>
|
||||||
|
<IAINumberInput
|
||||||
|
value={color.g}
|
||||||
|
onChange={handleChangeG}
|
||||||
|
min={0}
|
||||||
|
max={255}
|
||||||
|
step={1}
|
||||||
|
label="Green"
|
||||||
|
w={numberInputWidth}
|
||||||
|
/>
|
||||||
|
<IAINumberInput
|
||||||
|
value={color.b}
|
||||||
|
onChange={handleChangeB}
|
||||||
|
min={0}
|
||||||
|
max={255}
|
||||||
|
step={1}
|
||||||
|
label="Blue"
|
||||||
|
w={numberInputWidth}
|
||||||
|
/>
|
||||||
|
<IAINumberInput
|
||||||
|
value={color.a}
|
||||||
|
onChange={handleChangeA}
|
||||||
|
step={0.1}
|
||||||
|
min={0}
|
||||||
|
max={1}
|
||||||
|
label="Alpha"
|
||||||
|
w={numberInputWidth}
|
||||||
|
isInteger={false}
|
||||||
|
/>
|
||||||
|
</Flex>
|
||||||
|
)}
|
||||||
|
</Flex>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -245,6 +245,7 @@ const IAICanvasToolChooserOptions = () => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<IAIColorPicker
|
<IAIColorPicker
|
||||||
|
withNumberInput={true}
|
||||||
color={brushColor}
|
color={brushColor}
|
||||||
onChange={(newColor) => dispatch(setBrushColor(newColor))}
|
onChange={(newColor) => dispatch(setBrushColor(newColor))}
|
||||||
/>
|
/>
|
||||||
|
Loading…
Reference in New Issue
Block a user