Skip to content

Commit

Permalink
refactor(styles): reorder imports to avoid config conflict (#10963)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and tay1orjones committed Mar 11, 2022
1 parent d5ebf7b commit 9dd28d7
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Snapshot Tests should match snapshots 1`] = `
exports[`@carbon/styles should have stable public scss entrypoints 1`] = `
Array [
"scss/compat/theme",
"scss/compat/themes",
Expand Down
61 changes: 38 additions & 23 deletions packages/styles/__tests__/styles-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,36 +91,51 @@ const filepaths = [
'scss/components/treeview',
'scss/components/ui-shell',
];
describe.each(filepaths)('%s', (filepath) => {
it('should be importable', async () => {
await expect(render(`@use '../${filepath}';`)).resolves.toBeDefined();

describe('@carbon/styles', () => {
describe.each(filepaths)('%s', (filepath) => {
it('should be importable', async () => {
await expect(render(`@use '../${filepath}';`)).resolves.toBeDefined();
});
});
});

describe('Snapshot Tests', () => {
it('should match snapshots', async () => {
it('should have stable public scss entrypoints', async () => {
expect(filepaths).toMatchSnapshot();
});
});

describe('@carbon/styles/scss/config', () => {
test('Config overrides', async () => {
const { get } = await render(`
@use 'sass:meta';
@use '../scss/config' with (
$prefix: 'custom-prefix',
$css--font-face: false,
);
describe('scss/config', () => {
test('config overrides', async () => {
const { get } = await render(`
@use 'sass:meta';
@use '../scss/config' with (
$prefix: 'custom-prefix',
$css--font-face: false,
);
$_: get('config', (
prefix: config.$prefix,
css--font-face: config.$css--font-face,
));
`);
$_: get('config', (
prefix: config.$prefix,
css--font-face: config.$css--font-face,
));
`);

expect(get('config').value).toEqual({
prefix: 'custom-prefix',
['css--font-face']: false,
});
});
});

expect(get('config').value).toEqual({
prefix: 'custom-prefix',
['css--font-face']: false,
describe('import order', () => {
it('should support bringing in stylesheets independently', async () => {
await expect(
render(`
@use '../scss/reset';
@use '../scss/grid';
@use '../scss/breakpoint';
@use '../scss/colors';
@use '../scss/components';
`)
).resolves.not.toThrow();
});
});
});
2 changes: 1 addition & 1 deletion packages/styles/scss/_reset.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

@use 'config';
@use 'type';
@use 'type/reset' as type;

@mixin reset {
/// http://meyerweb.com/eric/tools/css/reset/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// LICENSE file in the root directory of this source tree.
//

@use 'config';
@use '../config';
@forward '@carbon/type' show
// Mixins
reset,
Expand Down
8 changes: 8 additions & 0 deletions packages/styles/scss/type/_reset.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// Copyright IBM Corp. 2018, 2018
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//

@forward '@carbon/type/scss/modules/reset';
1 change: 1 addition & 0 deletions packages/type/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
@forward 'scss/modules/reset';
@forward 'scss/modules/scale';
@forward 'scss/modules/styles';
@forward 'scss/modules/default-type';
55 changes: 55 additions & 0 deletions packages/type/scss/modules/_default-type.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// Copyright IBM Corp. 2018, 2018
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//

@use 'styles' as *;

/// Include default type styles
/// @access public
/// @group @carbon/type
@mixin default-type {
h1 {
@include type-style('productive-heading-06');
}

h2 {
@include type-style('productive-heading-05');
}

h3 {
@include type-style('productive-heading-04');
}

h4 {
@include type-style('productive-heading-03');
}

h5 {
@include type-style('productive-heading-02');
}

h6 {
@include type-style('productive-heading-01');
}

p {
@include type-style('body-long-02');
}

a {
@if meta.global-variable-exists('carbon--theme') and
map.has-key($carbon--theme, 'link-01')
{
color: map.get($carbon--theme, 'link-01');
} @else {
color: #0062fe;
}
}

em {
font-style: italic;
}
}
48 changes: 0 additions & 48 deletions packages/type/scss/modules/_reset.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
@use 'sass:meta';
@use '@carbon/layout';
@use 'font-family' as *;
@use 'styles' as *;

/// Include a type reset for a given body and mono font family
/// @param {String} $body-font-family [font-family('sans')] - The font family used on the `<body>` element
Expand Down Expand Up @@ -43,50 +42,3 @@
@include font-weight('semibold');
}
}

/// Include default type styles
/// @access public
/// @group @carbon/type
@mixin default-type {
h1 {
@include type-style('productive-heading-06');
}

h2 {
@include type-style('productive-heading-05');
}

h3 {
@include type-style('productive-heading-04');
}

h4 {
@include type-style('productive-heading-03');
}

h5 {
@include type-style('productive-heading-02');
}

h6 {
@include type-style('productive-heading-01');
}

p {
@include type-style('body-long-02');
}

a {
@if meta.global-variable-exists('carbon--theme') and
map.has-key($carbon--theme, 'link-01')
{
color: map.get($carbon--theme, 'link-01');
} @else {
color: #0062fe;
}
}

em {
font-style: italic;
}
}

0 comments on commit 9dd28d7

Please sign in to comment.