Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Colors): enable [token, newAlpha] format #543

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
ImCoolNowRight marked this conversation as resolved.
Show resolved Hide resolved
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
Loading