Skip to content

Commit 6ed960b

Browse files
committed
chore: update color names
1 parent f997127 commit 6ed960b

File tree

1 file changed

+34
-45
lines changed

1 file changed

+34
-45
lines changed

color-import/src/my-command.js

Lines changed: 34 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ const expandHexColor = (hexColor) => {
3333
return hexColor;
3434
};
3535
const prefixOrder = {
36-
brand: 1,
37-
neutral: 2,
38-
critical: 3,
39-
informational: 4,
40-
successful: 5,
41-
warning: 6,
36+
"db-brand": 1,
37+
"db-neutral": 2,
38+
"db-critical": 3,
39+
"db-informational": 4,
40+
"db-successful": 5,
41+
"db-warning": 6,
4242
};
4343

4444
const createSwatch = (document, name, hexColor, alpha) => {
@@ -75,13 +75,11 @@ const generateColorName = (theme, colorName) => {
7575
let prefix, color, state;
7676
[prefix, color, state] = colorName.split("/");
7777

78-
const capitalizedTheme = capitalize(theme);
7978
const capitalizedColor = capitalize(color);
80-
const capitalizedState = capitalizeState(state);
8179

8280
function getFormattedCount(prefixOrder, prefix) {
8381
let count;
84-
if (prefixOrder.hasOwnProperty(prefix)) {
82+
if (prefixOrder.hasOwnProperty([prefix])) {
8583
count = prefixOrder[prefix];
8684
} else {
8785
count = Object.keys(prefixOrder).length + 1;
@@ -91,52 +89,43 @@ const generateColorName = (theme, colorName) => {
9189
}
9290
const formattedCount = getFormattedCount(prefixOrder, prefix);
9391

94-
const componentName = `${formattedCount}--${capitalize(prefix)}`;
92+
const componentName = `${formattedCount}--${prefix}`;
9593

96-
if (color.includes("On")) {
94+
if (color === "on") {
9795
const parts = colorName.split("/").slice(0);
9896
const on = parts[1];
9997
color = parts[2];
10098
if (parts.length > 2) {
101-
state = capitalizeState(parts[3]);
99+
state = parts[3];
102100
}
103-
if (parts[2].includes("01-Enabled")) {
104-
state = capitalizeState(parts[2]);
101+
if (colorName === "db-brand/on/enabled") {
102+
state = parts[2];
105103
}
106104
if (color === "bg-weak") {
107-
return `${capitalizedTheme}/${componentName}/${on}/Background/Weak--${state}`;
108-
} else if (color === "bg") {
109-
return `${capitalizedTheme}/${componentName}/${on}/Background/${state}`;
110-
} else if (color === "contrast") {
111-
return `${capitalizedTheme}/${componentName}/${on}/Contrast/${state}`;
112-
}
113-
return `${capitalizedTheme}/${componentName}/${on}/${state}`;
105+
return `${theme}/${componentName}/${on}/bg/weak-${state}`;
106+
} else if (color === "bg" || color === "contrast") {
107+
return `${theme}/${componentName}/${on}/${color}/${state}`;
108+
}
109+
return `${theme}/${componentName}/${on}/${state}`;
114110
}
115-
if (color.includes("bg")) {
116-
if (color === "bg-lvl-1") {
117-
return `${capitalizedTheme}/${componentName}/Background/Level-1--${capitalizedState}`;
118-
} else if (color === "bg-lvl-2") {
119-
return `${capitalizedTheme}/${componentName}/Background/Level-2--${capitalizedState}`;
120-
} else if (color === "bg-lvl-3") {
121-
return `${capitalizedTheme}/${componentName}/Background/Level-3--${capitalizedState}`;
122-
} else if (color.includes("bg-transparent")) {
123-
if (color === "bg-transparent-full") {
124-
return `${capitalizedTheme}/${componentName}/Background-Transparent/Full--${capitalizedState}`;
125-
} else {
126-
return `${capitalizedTheme}/${componentName}/Background-Transparent/Semi--${capitalizedState}`;
127-
}
111+
112+
if (color.includes("bg-lvl-")) {
113+
const extractedColor = color.split("bg-")[1];
114+
return `${theme}/${componentName}/bg/${extractedColor}-${state}`;
115+
} else if (color.includes("bg-transparent")) {
116+
if (color === "bg-transparent-full") {
117+
return `${theme}/${componentName}/bg-transparent/full-${state}`;
118+
} else if (color === "bg-transparent-semi"){
119+
return `${theme}/${componentName}/bg-transparent/semi-${state}`;
120+
} else {
121+
return `${theme}/${componentName}/bg-transparent/${state}`;
128122
}
129123
}
130-
if (color.includes("contrast")) {
131-
if (color === "contrast-high") {
132-
return `${capitalizedTheme}/${componentName}/Contrast-High/${capitalizedState}`;
133-
}
134-
if (color === "contrast-low") {
135-
return `${capitalizedTheme}/${componentName}/Contrast-Low/${capitalizedState}`;
136-
}
124+
125+
if (!state) {
126+
return `${theme}/${componentName}/${color}`;
137127
}
138-
139-
return `${capitalizedTheme}/${componentName}/${capitalizedColor}/${capitalizedState}`;
128+
return `${theme}/${componentName}/${color}/${state}`;
140129
};
141130

142131
const createArtboard = (
@@ -185,7 +174,7 @@ const importThemes = async () => {
185174
const response = await sketch.UI.getInputFromUser(
186175
"Select themes to import (Light/Dark/Both):",
187176
{
188-
initialValue: "Both",
177+
initialValue: "Light",
189178
},
190179
async (err, value) => {
191180
if (err) {
@@ -208,7 +197,7 @@ const importThemes = async () => {
208197
const alpha = 1 - transparencyPercentage / 100;
209198

210199
const newNames = generateColorName(theme, colorName);
211-
200+
//console.log(newNames);
212201
createSwatch(document, newNames, hexValue, alpha);
213202
}
214203
};

0 commit comments

Comments
 (0)