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

ci(preview theme): allow gradient colors (2) #3427

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
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
14 changes: 8 additions & 6 deletions scripts/preview-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,14 +500,12 @@ export const run = async () => {
);
invalidColors = true;
} else if (
!isValidHexColor(colorValue) ||
!(
colorKey === "bg_color" &&
isValidGradient(colorValue.split(","))
)
!(colorKey === "bg_color" && colorValue.split(",").length > 1
? isValidGradient(colorValue.split(","))
: isValidHexColor(colorValue))
) {
errors.push(
`Theme color property \`${colorKey}\` is not a valid hex color: <code>#${colorValue}</code>`,
`Theme color property \`${colorKey}\` is not a valid hex color: <code>${colorValue}</code>`,
);
invalidColors = true;
}
Expand Down Expand Up @@ -548,6 +546,10 @@ export const run = async () => {
Object.keys(colorPairs).forEach((item) => {
let color1 = colorPairs[item][0];
let color2 = colorPairs[item][1];
const isGradientColor = color2.split(",").length > 1;
if (isGradientColor) {
return;
}
color1 = color1.length === 4 ? color1.slice(0, 3) : color1.slice(0, 6);
color2 = color2.length === 4 ? color2.slice(0, 3) : color2.slice(0, 6);
if (!ccc.isLevelAA(`#${color1}`, `#${color2}`)) {
Expand Down
5 changes: 4 additions & 1 deletion src/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,10 @@ const clampValue = (number, min, max) => {
* @returns {boolean} True if the given string is a valid gradient.
*/
const isValidGradient = (colors) => {
return colors.slice(1).every((color) => isValidHexColor(color));
return (
colors.length > 2 &&
colors.slice(1).every((color) => isValidHexColor(color))
);
};

/**
Expand Down