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): initialize color vars with default values #8440

Merged
merged 4 commits into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions packages/colors/__tests__/scss-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ const { createSassRenderer, types } = require('@carbon/test-utils/scss');
const render = createSassRenderer(__dirname);

describe('colors.scss', () => {
it('should emit no side-effects if mixins are included', async () => {
it('should emit default variable initializations when mixins are included', async () => {
const { calls } = await render(`
@import '../scss/mixins';

$test: test(mixin-exists(carbon--colors));
$test: test(global-variable-exists(carbon--blue-50));
`);
expect(calls[0][0].getValue()).toBe(true);
expect(calls[1][0].getValue()).toBe(false);
expect(calls[1][0].getValue()).toBe(true);
});

it('should include color variables as globals if the mixin is called', async () => {
Expand Down
15 changes: 12 additions & 3 deletions packages/colors/tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ async function build() {
id: t.Identifier(`${swatch}-${grade}`),
init: t.SassColor(value),
default: true,
global: true,
})
);
const deprecatedColorVariables = colorValues.map(({ grade, swatch, value }) =>
Expand Down Expand Up @@ -117,7 +116,6 @@ async function build() {
id: t.Identifier('carbon--colors'),
init: colorMapProperties,
default: true,
global: true,
});

const mixins = t.StyleSheet({
Expand All @@ -138,6 +136,18 @@ async function build() {
t.Comment(`/ Define color variables
/ @access public
/ @group @carbon/colors`),
...colorValues.map(({ grade, swatch, value }) =>
t.Assignment({
id: t.Identifier(`carbon--${swatch}-${grade}`),
init: t.SassValue(value),
})
),
...colorValues.map(({ grade, swatch, value }) =>
t.Assignment({
id: t.Identifier(`${swatch}-${grade}`),
init: t.SassColor(value),
})
),
t.SassMixin({
id: t.Identifier(`${NAMESPACE}--colors`),
body: t.BlockStatement([
Expand All @@ -146,7 +156,6 @@ async function build() {
id: t.Identifier(`carbon--${swatch}-${grade}`),
init: t.SassColor(value),
default: true,
global: true,
})
),
...colorVariables,
Expand Down