ui: Update rgbaToHex to optionally return alpha value or not

This commit is contained in:
blessedcoolant 2024-03-22 02:59:24 +05:30
parent 168b35f86d
commit 4687739319
2 changed files with 3 additions and 3 deletions

View File

@ -1,11 +1,11 @@
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 alphaHex = Math.round(color.a * 255)
.toString(16)
.padStart(2, '0');
return `#${hex}${alphaHex}`;
return alpha ? `#${hex}${alphaHex}` : `#${hex}`;
}
export function hexToRGBA(hex: string, alpha: number) {

View File

@ -61,7 +61,7 @@ const ColorFieldInputComponent = (props: FieldComponentProps<ColorFieldInputInst
outline: 'none',
}}
className="nodrag"
color={rgbaToHex(color)}
color={rgbaToHex(color, true)}
onChange={handleValueChanged}
prefixed
alpha