Skip to content

Commit fa7f540

Browse files
joshblacktw15egankodiakhq[bot]
authored
fix(colors): update classic sass file variable initialization (#8670)
Co-authored-by: TJ Egan <tw15egan@gmail.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 4a35ad5 commit fa7f540

File tree

1 file changed

+68
-65
lines changed

1 file changed

+68
-65
lines changed

packages/colors/tasks/build.js

Lines changed: 68 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,6 @@ async function build() {
5656
return acc.concat(...values);
5757
}, []);
5858

59-
const colorVariables = colorValues.map(({ grade, swatch, value }) =>
60-
t.Assignment({
61-
id: t.Identifier(`${swatch}-${grade}`),
62-
init: t.SassColor(value),
63-
default: true,
64-
})
65-
);
66-
const deprecatedColorVariables = colorValues.map(({ grade, swatch, value }) =>
67-
t.Assignment({
68-
id: t.Identifier(`ibm-color__${swatch}-${grade}`),
69-
init: t.SassColor(value),
70-
default: true,
71-
global: true,
72-
})
73-
);
7459
const colorMapProperties = t.SassMap({
7560
properties: Object.keys(colors).flatMap((swatch) => {
7661
const value = t.SassMap({
@@ -106,65 +91,83 @@ async function build() {
10691
];
10792
}),
10893
});
109-
const deprecatedColorMap = t.Assignment({
110-
id: t.Identifier('ibm-color-map'),
111-
init: colorMapProperties,
112-
default: true,
113-
global: true,
114-
});
115-
const colorMap = t.Assignment({
116-
id: t.Identifier('carbon--colors'),
117-
init: colorMapProperties,
118-
default: true,
94+
95+
const prefixes = ['ibm-color__', 'carbon--', ''];
96+
const variables = prefixes.flatMap((prefix) => {
97+
return colorValues.flatMap(({ swatch, grade, value }) => {
98+
return t.Assignment({
99+
id: t.Identifier(`${prefix}${swatch}-${grade}`),
100+
init: t.SassColor(value),
101+
default: true,
102+
});
103+
});
119104
});
120105

121-
const mixins = t.StyleSheet({
122-
children: [
123-
FILE_BANNER,
124-
t.Comment(`/ Define color variables
125-
/ @access public
126-
/ @group @carbon/colors
127-
/ @deprecated Use \`$${NAMESPACE}--colors\` going forward`),
128-
t.SassMixin({
129-
id: t.Identifier('ibm--colors'),
130-
body: t.BlockStatement([
131-
...deprecatedColorVariables,
132-
deprecatedColorMap,
133-
]),
106+
variables.push(
107+
t.Assignment({
108+
id: t.Identifier('ibm-color-map'),
109+
init: colorMapProperties,
110+
default: true,
111+
}),
112+
t.Assignment({
113+
id: t.Identifier('carbon--colors'),
114+
init: colorMapProperties,
115+
default: true,
116+
}),
117+
t.Newline()
118+
);
119+
120+
const ibmColorsMixin = t.SassMixin({
121+
id: t.Identifier('ibm--colors'),
122+
body: t.BlockStatement([
123+
...colorValues.flatMap(({ swatch, grade, value }) => {
124+
return t.Assignment({
125+
id: t.Identifier(`ibm-color__${swatch}-${grade}`),
126+
init: t.SassColor(value),
127+
global: true,
128+
});
129+
}),
130+
t.Assignment({
131+
id: t.Identifier('ibm-color-map'),
132+
init: colorMapProperties,
133+
global: true,
134134
}),
135+
]),
136+
});
135137

136-
t.Comment(`/ Define color variables
137-
/ @access public
138-
/ @group @carbon/colors`),
139-
...colorValues.map(({ grade, swatch, value }) =>
140-
t.Assignment({
138+
const carbonColorsMixin = t.SassMixin({
139+
id: t.Identifier('carbon--colors'),
140+
body: t.BlockStatement([
141+
...colorValues.flatMap(({ swatch, grade, value }) => {
142+
return t.Assignment({
141143
id: t.Identifier(`carbon--${swatch}-${grade}`),
142-
init: t.SassValue(value),
143-
})
144-
),
145-
...colorValues.map(({ grade, swatch, value }) =>
146-
t.Assignment({
147-
id: t.Identifier(`${swatch}-${grade}`),
148144
init: t.SassColor(value),
149-
})
150-
),
151-
t.SassMixin({
152-
id: t.Identifier(`${NAMESPACE}--colors`),
153-
body: t.BlockStatement([
154-
...colorValues.map(({ grade, swatch, value }) =>
155-
t.Assignment({
156-
id: t.Identifier(`carbon--${swatch}-${grade}`),
157-
init: t.SassColor(value),
158-
default: true,
159-
})
160-
),
161-
...colorVariables,
162-
colorMap,
163-
]),
145+
global: true,
146+
});
164147
}),
165-
],
148+
t.Assignment({
149+
id: t.Identifier('carbon--colors'),
150+
init: colorMapProperties,
151+
global: true,
152+
}),
153+
]),
166154
});
167155

156+
const mixins = t.StyleSheet([
157+
FILE_BANNER,
158+
...variables,
159+
t.Comment(`/ Define color variables
160+
/ @access public
161+
/ @group @carbon/colors
162+
/ @deprecated Use \`$carbon--colors\` going forward`),
163+
ibmColorsMixin,
164+
t.Newline(),
165+
t.Comment(`/ Define color variables
166+
/ @access public
167+
/ @group @carbon/colors`),
168+
carbonColorsMixin,
169+
]);
170+
168171
const entrypoint = t.StyleSheet([
169172
FILE_BANNER,
170173
t.SassImport('./mixins'),

0 commit comments

Comments
 (0)