Skip to content

Color: class refactor and add types#33996

Open
vorobey wants to merge 3 commits into
DevExpress:26_1from
vorobey:26_1_color_refactor
Open

Color: class refactor and add types#33996
vorobey wants to merge 3 commits into
DevExpress:26_1from
vorobey:26_1_color_refactor

Conversation

@vorobey

@vorobey vorobey commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI review requested due to automatic review settings June 15, 2026 14:23
@vorobey vorobey requested review from a team as code owners June 15, 2026 14:23
@vorobey vorobey self-assigned this Jun 15, 2026
@vorobey vorobey added the 26_1 label Jun 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the internal Color implementation used across DevExtreme (via @ts/m_color and the deprecated @js/color re-export) into a TypeScript class with improved typing, and updates call sites to align with the refactor.

Changes:

  • Switched palette color extrapolation logic to use @ts/m_color and Color.fromHSL(...) static API.
  • Updated ColorBox’s ColorView validation logic to use Color.isValid* static methods instead of instance methods.
  • Refactored m_color.ts from a function/prototype pattern to a typed Color class, adding type annotations to parsing/conversion helpers.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/devextreme/js/__internal/viz/palette.ts Migrates palette extrapolation to @ts/m_color and the new fromHSL call style.
packages/devextreme/js/__internal/ui/color_box/color_view.ts Updates alpha/hex/rgb validation to use static Color.isValid* methods.
packages/devextreme/js/__internal/m_color.ts Reworks Color implementation into a typed class and updates parsing/conversion utilities.

Comment on lines +568 to +592
static isValidHex(hex: string): boolean {
return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(hex);
},
}

isValidRGB(r, g, b) {
if (!isIntegerBetweenMinAndMax(r) || !isIntegerBetweenMinAndMax(g) || !isIntegerBetweenMinAndMax(b)) {
static isValidRGB(
r: number | undefined,
g: number | undefined,
b: number | undefined,
): boolean {
if (
!isIntegerBetweenMinAndMax(r)
|| !isIntegerBetweenMinAndMax(g)
|| !isIntegerBetweenMinAndMax(b)
) {
return false;
}
return true;
},
}

isValidAlpha(a) {
static isValidAlpha(a: number): boolean {
if (isNaN(a) || a < 0 || a > 1 || typeof a !== 'number') {
return false;
}
return true;
},

colorIsInvalid: false,
}
Comment on lines 594 to +606
@@ -598,12 +603,9 @@ Color.prototype = {
color.b = rgb[2];

return color;
},
};

interface ColorConstructor {
prototype: ColorInstance;
new(value?: string): ColorInstance;
}
Copilot AI review requested due to automatic review settings June 16, 2026 06:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

{
re: /^#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/,
process(colorString) {
process(colorString):[number, number, number, number] {
@vorobey vorobey force-pushed the 26_1_color_refactor branch from bc312c2 to 8504c6a Compare June 16, 2026 06:51
@vorobey vorobey force-pushed the 26_1_color_refactor branch from 8504c6a to f607300 Compare June 16, 2026 07:07
Copilot AI review requested due to automatic review settings June 16, 2026 07:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comment on lines +476 to +480
function isIntegerBetweenMinAndMax(number: number | undefined, min = 0, max = 255): boolean {
if (typeof number !== 'number'
|| number % 1 !== 0
|| number < min
|| number > max
Comment on lines +576 to +580
static isValidRGB(
r: number | undefined,
g: number | undefined,
b: number | undefined,
): boolean {
{
re: /^#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/,
process(colorString) {
process(colorString):[number, number, number, number] {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants