mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
ui: Update rgbaToHex to optionally return alpha value or not
This commit is contained in:
parent
168b35f86d
commit
4687739319
@ -1,11 +1,11 @@
|
|||||||
import type { RgbaColor } from 'react-colorful';
|
import type { RgbaColor } from 'react-colorful';
|
||||||
|
|
||||||
export function rgbaToHex(color: RgbaColor): string {
|
export function rgbaToHex(color: RgbaColor, alpha: boolean = false): string {
|
||||||
const hex = ((1 << 24) + (color.r << 16) + (color.g << 8) + color.b).toString(16).slice(1);
|
const hex = ((1 << 24) + (color.r << 16) + (color.g << 8) + color.b).toString(16).slice(1);
|
||||||
const alphaHex = Math.round(color.a * 255)
|
const alphaHex = Math.round(color.a * 255)
|
||||||
.toString(16)
|
.toString(16)
|
||||||
.padStart(2, '0');
|
.padStart(2, '0');
|
||||||
return `#${hex}${alphaHex}`;
|
return alpha ? `#${hex}${alphaHex}` : `#${hex}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function hexToRGBA(hex: string, alpha: number) {
|
export function hexToRGBA(hex: string, alpha: number) {
|
||||||
|
@ -61,7 +61,7 @@ const ColorFieldInputComponent = (props: FieldComponentProps<ColorFieldInputInst
|
|||||||
outline: 'none',
|
outline: 'none',
|
||||||
}}
|
}}
|
||||||
className="nodrag"
|
className="nodrag"
|
||||||
color={rgbaToHex(color)}
|
color={rgbaToHex(color, true)}
|
||||||
onChange={handleValueChanged}
|
onChange={handleValueChanged}
|
||||||
prefixed
|
prefixed
|
||||||
alpha
|
alpha
|
||||||
|
Loading…
x
Reference in New Issue
Block a user