Skip to content

Commit

Permalink
ui: Update rgbaToHex to optionally return alpha value or not
Browse files Browse the repository at this point in the history
  • Loading branch information
blessedcoolant committed Mar 21, 2024
1 parent 5e01c46 commit 8ca21ab
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const ColorFieldInputComponent = (props: FieldComponentProps<ColorFieldInputInst
outline: 'none',
}}
className="nodrag"
color={rgbaToHex(color)}
color={rgbaToHex(color, true)}
onChange={handleValueChanged}
prefixed
alpha
Expand Down

0 comments on commit 8ca21ab

Please sign in to comment.