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

Use math.div instead of slash for sass #9508

Merged
merged 8 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from 7 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
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,15 @@
"contributions": [
"doc"
]
},
{
"login": "egriff38",
"name": "Eshin Griffith",
"avatar_url": "https://avatars.githubusercontent.com/u/6627718?v=4",
"profile": "https://github.com/egriff38",
"contributions": [
"code"
]
}
],
"commitConvention": "none"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ check out our [Contributing Guide](/.github/CONTRIBUTING.md) and our
<td align="center"><a href="https://github.com/szymonbrandys"><img src="https://avatars.githubusercontent.com/u/79149899?v=4?s=100" width="100px;" alt=""/><br /><sub><b>szymonbrandys</b></sub></a><br /><a href="https://github.com/carbon-design-system/carbon/commits?author=szymonbrandys" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/adamalston"><img src="https://avatars.githubusercontent.com/u/18297826?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Adam Alston</b></sub></a><br /><a href="https://github.com/carbon-design-system/carbon/commits?author=adamalston" title="Documentation">📖</a></td>
<td align="center"><a href="https://github.com/Kiittyka"><img src="https://avatars.githubusercontent.com/u/41021851?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Krithika S Udupa</b></sub></a><br /><a href="https://github.com/carbon-design-system/carbon/commits?author=Kiittyka" title="Documentation">📖</a></td>
<td align="center"><a href="https://github.com/egriff38"><img src="https://avatars.githubusercontent.com/u/6627718?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Eshin Griffith</b></sub></a><br /><a href="https://github.com/carbon-design-system/carbon/commits?author=egriff38" title="Code">💻</a></td>
</tr>
</table>

Expand Down
5 changes: 2 additions & 3 deletions packages/carbon-react/src/components/Grid/Grid.stories.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@import '~carbon-components/scss/globals/scss/vars';
@import '~carbon-components/scss/globals/scss/colors';
@import '~carbon-components/scss/globals/scss/typography';
@use '@carbon/styles/scss/colors' as *;
@use '@carbon/styles/scss/type' as *;

// Grid modes
.bx--css-grid {
Expand Down
78 changes: 78 additions & 0 deletions packages/components/src/globals/scss/_typography.import.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//
// Copyright IBM Corp. 2016, 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.
//
//-------------------------------------------
// Compatibility notes (*.import.scss)
// ------------------------------------------
//
// This file is intended to be consumed and processed with dart-sass.
// It is incompatible with node-sass/libsass as it contains sass language features
// or functions that are unavailable in node-sass/libsass, such as `math.div`.
//
// The non-`.import` suffixed version of this file eg. `_filename.scss`
// is intended to be compatible with node-sass/libsass.
//
// Styles authored within this file must be duplicated to the corresponding
// compatibility file to ensure we continue to support node-sass and dart-sass
// in v10.

@use 'sass:math';
@import 'vars'; /* stylelint-disable-line no-invalid-position-at-import-rule */

/// Base font size in px
/// @access public
/// @group global-typography
/// @type Number
/// @deprecated (For v10) Superseded by `$carbon--base-font-size`
$base-font-size: 16px !default;

/// Convert px to rem
/// @access public
/// @param {Number} $px - Value of type in pixels
/// @returns {Number} In rem
/// @example rem(48px);
/// @group global-typography
/// @deprecated (For v10) Use `carbon--rem()`
@function rem($px) {
@if unit($px) != 'px' {
// TODO: update to @error in v11
@warn "Expected argument $px to be of type `px`, instead received: `#{unit($px)}`";
}

@return math.div($px, $base-font-size) * 1rem;
}

/// Convert px to em
/// @access public
/// @param {Number} $px - Value of type in pixels
/// @returns {Number} In em
/// @example em(48px);
/// @group global-typography
/// @deprecated (For v10) Use `carbon--em()`
@function em($px) {
@if unit($px) != 'px' {
// TODO: update to @error in v11
@warn "Expected argument $px to be of type `px`, instead received: `#{unit($px)}`";
}

@return math.div($px, $base-font-size) * 1em;
}

// 🔬 Experimental
// stylelint-disable-next-line no-invalid-position-at-import-rule
@import '../../globals/scss/vendor/@carbon/elements/scss/type/font-family';
// stylelint-disable-next-line no-invalid-position-at-import-rule
@import '../../globals/scss/vendor/@carbon/elements/scss/type/styles';

/// Different type styles per token
/// @access public
/// @param {String} $name - The name of the token to get the styles for
/// @param {Bool} $fluid [false] - Specify whether to include fluid styles
/// @example @include type-style('body-short-01');
/// @group global-typography
@mixin type-style($name, $fluid: false) {
@include carbon--type-style($name, $fluid);
}
14 changes: 14 additions & 0 deletions packages/components/src/globals/scss/_typography.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//
//-------------------------------------------
// Compatibility notes
// ------------------------------------------
//
// This file is intended to be consumed and processed with node-sass/libsass.
// Sass language features only available in dart-sass, such as `math.div`,
// should not be used.
//
// The `.import` suffixed version of this file eg. `_filename.import.scss`
// is intended to be compatible with dart-sass.
//
// Styles authored within this file must be duplicated to the corresponding
// compatibility file to ensure we continue to support node-sass and dart-sass
// in v10.

@import 'vars';

Expand Down
2 changes: 1 addition & 1 deletion packages/components/tests/styles-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const defaultOptions = {
const cwd = path.resolve(__dirname, '../src');
const files = glob.sync('**/*.scss', {
cwd,
ignore: ['**/vendor/@carbon/**'],
ignore: ['**/vendor/@carbon/**', '**/*.import.scss'],
});

const render = promisify(sass.render);
Expand Down
Loading