Skip to content

Commit

Permalink
Feat: color placeholder text only (#208)
Browse files Browse the repository at this point in the history
feat: added color placeholders for interactive text
  • Loading branch information
annsch authored Jan 6, 2023
1 parent be865bb commit 58c8a10
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions scripts/color-placeholders-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
*/

const prefix = 'db';
const fileHeader = `
@use "variables" as *;
// Do not edit directly
// Generated on
// ${new Date().toString()}
`;

const generateInteractiveVariants = (currentColorObject, cssProp) => {
return `
Expand Down Expand Up @@ -39,6 +45,7 @@ const generateBGVariants = (
%${placeholderName}-ia-states {
${generateInteractiveVariants(currentColorObject, 'background-color')}
}
%${placeholderName} {
background-color: $${prefix}-${currentColorObject.enabled.name};
color: $${prefix}-${baseColorObject.enabled.name};
Expand All @@ -60,7 +67,6 @@ const generateBGVariants = (
a {
${generateInteractiveVariants(baseColorObject, 'color')}
}
`;
if (baseColorObject.weak) {
result += `
Expand All @@ -74,7 +80,8 @@ const generateBGVariants = (
`;
}

result += `}`;
result += `}
`;
return result;
};

Expand All @@ -86,15 +93,25 @@ const generateBGVariants = (
* @returns scss string
*/
exports.generateColorUtilitityPlaceholder = (colorToken) => {
let output = '@use "variables" as *;\n';
let output = fileHeader;

for (const [, value] of Object.keys(colorToken).entries()) {
output += `/**
output += `
/**
* ${value.toUpperCase()} - Placeholder Utilities
**/
`;
// Text colors with interactive variant, e.g. primary
if (colorToken[value].enabled) {
// Only text
output += `
%${prefix}-${value}-text-ia {
color: $${prefix}-${colorToken[value].enabled.name};
${generateInteractiveVariants(colorToken[value], 'color')}
}
`;

// Text and background colors
output += generateBGVariants(
value,
Expand Down

0 comments on commit 58c8a10

Please sign in to comment.