Skip to content

Commit

Permalink
fix(Colors): enable [token, newAlpha] format (#543)
Browse files Browse the repository at this point in the history
  • Loading branch information
ImCoolNowRight authored Oct 9, 2024
1 parent 7fb9dd8 commit 5823750
Showing 1 changed file with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -557,19 +557,30 @@ export const colorParser = (targetObject, styleObj) => {
// Process style object and remove unnecessary properties
const processedStyle = JSON.stringify(styleObj, (_, value) => {
if (-1 < ['tone', 'mode'].indexOf(_)) return value; // Remove any tone/mode or mode/tone properties as they have already been processed
if ('string' === typeof value && value.startsWith('theme.')) {
// Support theme strings example: theme.radius.md
return getValFromObjPath(targetObject, value); // If no theme value exists, the property will be removed from the object
} else if (

// Handle theme strings, e.g., 'theme.radius.md'
if (typeof value === 'string' && value.startsWith('theme.')) {
// Retrieve the value from the target object using the theme path
return getValFromObjPath(targetObject, value); // If no theme value exists, the property will be removed
}

function isValidColor(num) {
return num >= 0 && num <= 0xffffffff;
}

// Handle color arrays, e.g., ['#663399', 1] or [255, 0.5]
if (
Array.isArray(value) &&
value.length === 2 &&
typeof value[0] === 'string' &&
value[0].substr(0, 1) === '#' &&
((typeof value[0] === 'string' && value[0].startsWith('#')) ||
(typeof value[0] === 'number' && isValidColor(value[0]))) &&
typeof value[1] === 'number'
) {
// Process value as a color ['#663399', 1]
// Return processed hex color or the original value if processing fails
return getHexColor(value[0], value[1]) || value;
}

// Return all other values as-is
return value;
});

Expand Down

0 comments on commit 5823750

Please sign in to comment.