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

[NOJIRA]: Migrate to sass-embedded #3103

Merged
merged 33 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
785b41b
[NOJIRA]: Prepare for sass-embedded
Nov 30, 2023
7d630db
[NO-JIRA]: Fixed dependencies
Nov 30, 2023
5547c9e
[NO-JIRA]: removed css files
Nov 30, 2023
435d2fc
[NOJIRA]: added scripts
Nov 30, 2023
48dec5c
[NOJIRA]: replace imports
Nov 30, 2023
a851513
[NOJIRA]: apply sass-migrator to examples
Nov 30, 2023
0d198be
[NOJIRA]: fix webpack
Nov 30, 2023
5758554
[NOJIRA]: fix lint
Nov 30, 2023
2adfccd
[NOJIRA]: fix lint 2
Nov 30, 2023
e580e92
[NOJIRA]: Granular imports
Dec 11, 2023
dc048b5
[NOJIRA]: base.css
Dec 11, 2023
70de8db
[NOJIRA]: icons.scss header
Dec 11, 2023
0ce10a6
[NOJIRA]: flatten mixins
Dec 11, 2023
265291b
[NOJIRA]: fix
Dec 11, 2023
acebbb6
[NOJIRA]: forwarding fix
Dec 11, 2023
ebfd03d
[NOJIRA]: Adapt to the changes in main
Jan 17, 2024
c14e325
[NOJIRA]: Rename unstable mixins folder
Jan 17, 2024
6becec7
[NOJIRA]: Post-rename cleanup
Jan 17, 2024
123a20b
[NOJIRA]: Add decision doc
Jan 17, 2024
9d17fd0
[NOJIRA]: Added linting rule and disabled it for allowed usages
Jan 17, 2024
b7f2c72
[NOJIRA]: fix
Jan 17, 2024
03141de
[NOJIRA]: fix stylesheets
Jan 17, 2024
ed9fce6
[NOJIRA]: fix normalize
Jan 17, 2024
5079cc9
[NOJIRA]: Fix transpile script
Jan 18, 2024
cdb3f30
[NOJIRA]: Fix and bump dependencies
Jan 18, 2024
62cdcc3
[NOJIRA]: Updated Contributing.md
Jan 18, 2024
04048bb
[NOJIRA]: SCSS Cleanup
Jan 22, 2024
b3effd0
[NOJIRA]: Fix storybook
Jan 22, 2024
7f0b42a
[NOJIRA]: Update naming
Feb 15, 2024
bb4bf4d
[NOJIRA]: fix
Feb 15, 2024
c202524
fix
Feb 15, 2024
6496f2d
fix math
Feb 15, 2024
10aa4e5
[NOJIRA]: Fix copy-utils
Feb 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ npm-debug.*
yarn.lock
/packages/*/changelog.md
.storybook/__image_snapshots__/__diff_output__

# Ignore css assets as these should be built on demand from sass
*.css
!packages/bpk-stylesheets/base.css
/packages/unstable__bpk-mixins
4 changes: 0 additions & 4 deletions .storybook/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const path = require('path');

const MiniCssExtractPlugin = require("mini-css-extract-plugin");

const sassFunctions = require('../packages/bpk-mixins/sass-functions');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

const postCssPlugins = require('../scripts/webpack/postCssPlugins');

const { BPK_TOKENS } = process.env;
Expand Down Expand Up @@ -120,9 +119,6 @@ module.exports = ({ config }) => {
),
)
: '',
sassOptions: {
functions: sassFunctions,
},
},
},
],
Expand Down
2 changes: 2 additions & 0 deletions .stylelintignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules
packages/unstable__bpk-mixins
**/*.css
1 change: 1 addition & 0 deletions .stylelintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"resolveNestedSelectors": true
}
],
"at-rule-disallowed-list": ["import"],
"unit-disallowed-list": [["px"], {
"ignoreProperties": {
"px": ["box-shadow"]
Expand Down
20 changes: 18 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,13 @@ git checkout -b {BRANCH_NAME}
npm install --registry="https://registry.npmjs.org/"
```

If you receive an error about `ValueError: invalid mode: 'rU' while trying to load binding.gyp`, try downgrading the default python version for your shell to python 3.9
3. Build a modern version of mixins for local development

3. Build SVGs
```sh
npm run build:unstable__bpk-mixins
```

4. Build SVGs

```sh
npm run build
Expand Down Expand Up @@ -105,6 +109,18 @@ We use [CSS Modules](https://github.com/css-modules/css-modules) along with [BEM

When creating (S)CSS files, follow the CSS Module naming convention by using the `.module.(s)css` extension.

When creating or modifying SCSS files, follow these rules

1. Use Modern SASS API
* Prefer `@use` instead of `@import`
* Prefer `math.div($a, $b)` instead of `$a / $b`. Add `@use sass:math` statement to the top of your file to make this function available
* Read more about [@use rule](https://sass-lang.com/documentation/at-rules/use/) and [SASS math functions](https://sass-lang.com/documentation/modules/math/)
2. Use only what you need
* Instead of blank import of all mixins, import them on demand. E.g. if you need only colour tokens, add `@use '../unstable__bpk-mixins/tokens'` statement only
3. Use `unstable__bpk-mixins` for Backpack components development
* If you need to add or modify a mixin, do it in `packages/bpk-mixins`, then execute `npm run unstable__bpk-mixins` command to make it available for Modern API
* Import mixins from `packages/unstable__bpk-mixins` only. Otherwise your code will break because Modern SASS API doesn't support `~` import syntax or slash division

#### Adding a new component

If you want to add a new component:
Expand Down
59 changes: 59 additions & 0 deletions decisions/modern-sass-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Transition to modern SASS API

## Decision
Backpack is transforming the way it works with SASS to align with modern SASS API used in
dart-sass and sass-embedded. Old API remains the default option, but at some point of time
in the future we will switch the default API to the new one

* Backpack is shipped with two versions of `bpk-mixins` package
* `packages/bpk-mixins` that remains the stable option. It uses old SASS API and `@import` syntax
* `packages/unstable__bpk-mixins` is a modern SASS API version compatible with `sass` and `sass-embedded` packages, but not with `node-sass`
* In the future the package using Old API will be deprecated and removed and the one using New API will be promoted to stable
* For our own components we use `unstable__bpk-mixins`
* These mixins must be imported with `@use` at-rule
* Mixins partials must be used in a granular way (use only those partials that you need to build a particular component, see "Wrong" and "Correct" examples below)
* If you need to add or modify a mixin, do it in `packages/bpk-mixins`. Then run `npm run unstable__bpk-mixins` to generate a new modern version of the package

## Examples

**Wrong (1)**
```
// BpkAwesomeComponent.module.scss

@use '../unstable__bpk-mixins' as mixins;

.bpk-awesome-component {
margin-right: mixins.bpk-spacing-md();
}
```

**Wrong (2)**
```
// BpkAwesomeComponent.module.scss

@import '../bpk-mixins';

.bpk-awesome-component {
margin-right: bpk-spacing-md();
}
```

**Correct**
```
// BpkAwesomeComponent.module.scss

@use '../unstable__bpk-mixins/tokens';

.bpk-awesome-component {
margin-right: tokens.bpk-spacing-md();
}
```

## Thinking

The main reason behind such a change is to deliver modern API to consumers in a non-breaking manner. Using `unstable` prefix
means that we can't guarantee that this package structure won't change before becoming stable.

## Anything Else

https://sass-lang.com/documentation/at-rules/use/#differences-from-import
18 changes: 0 additions & 18 deletions examples/bpk-component-aria-live/examples.module.css

This file was deleted.

28 changes: 15 additions & 13 deletions examples/bpk-component-aria-live/examples.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,25 @@
* limitations under the License.
*/

@import '../../packages/bpk-mixins/index.scss';
@use '../../packages/unstable__bpk-mixins/tokens';
@use '../../packages/unstable__bpk-mixins/borders';
@use '../../packages/unstable__bpk-mixins/radii';

.bpk-storybook-aria-live-demo {
padding: bpk-spacing-base();
background: $bpk-canvas-contrast-day;
color: $bpk-text-primary-day;
padding: tokens.bpk-spacing-base();
background: tokens.$bpk-canvas-contrast-day;
color: tokens.$bpk-text-primary-day;

@include bpk-border-sm($bpk-line-day);
@include bpk-border-radius-sm;
@include borders.bpk-border-sm(tokens.$bpk-line-day);
@include radii.bpk-border-radius-sm;

&__chips-wrapper {
margin-bottom: bpk-spacing-base();
margin-bottom: tokens.bpk-spacing-base();
}

&__select-wrapper {
display: flex;
margin-bottom: bpk-spacing-base();
margin-bottom: tokens.bpk-spacing-base();
justify-content: space-between;
align-items: center;
}
Expand All @@ -46,16 +48,16 @@
}

&__chip {
margin-right: bpk-spacing-base();
margin-bottom: bpk-spacing-base();
margin-right: tokens.bpk-spacing-base();
margin-bottom: tokens.bpk-spacing-base();
}

&__aria-live {
margin-top: bpk-spacing-base();
margin-top: tokens.bpk-spacing-base();
}

> p {
margin-top: $bpk-spacing-none;
margin-bottom: bpk-spacing-base();
margin-top: tokens.$bpk-spacing-none;
margin-bottom: tokens.bpk-spacing-base();
}
}
11 changes: 6 additions & 5 deletions examples/bpk-component-badge/BpkBadgeLayout.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@
* limitations under the License.
*/

@import '../../packages/bpk-mixins/index.scss';
@use '../../packages/unstable__bpk-mixins/tokens';
@use '../../packages/unstable__bpk-mixins/radii';

.bpk-badge-layout {
&__container {
position: relative;
display: flex;
min-height: bpk-spacing-xxl();
padding: bpk-spacing-lg();
min-height: tokens.bpk-spacing-xxl();
padding: tokens.bpk-spacing-lg();

&--light {
background-color: $bpk-canvas-contrast-day;
background-color: tokens.$bpk-canvas-contrast-day;

@include bpk-border-radius-xs;
@include radii.bpk-border-radius-xs;
}
}
}
18 changes: 0 additions & 18 deletions examples/bpk-component-banner-alert/examples.module.css

This file was deleted.

4 changes: 2 additions & 2 deletions examples/bpk-component-banner-alert/examples.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
* limitations under the License.
*/

@import '../../packages/bpk-mixins/index.scss';
@use '../../packages/unstable__bpk-mixins/tokens';

.bpk-banner-alert-examples {
&__component {
margin-top: bpk-spacing-base();
margin-top: tokens.bpk-spacing-base();
}
}
18 changes: 0 additions & 18 deletions examples/bpk-component-barchart/examples.module.css

This file was deleted.

11 changes: 6 additions & 5 deletions examples/bpk-component-barchart/examples.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,23 @@
* limitations under the License.
*/

@import '../../packages/bpk-mixins/index.scss';
@use '../../packages/unstable__bpk-mixins/tokens';
@use '../../packages/unstable__bpk-mixins/scroll-indicators';

.bpk-heading {
margin-bottom: bpk-spacing-base();
margin-bottom: tokens.bpk-spacing-base();
}

$custom-color: $bpk-canvas-contrast-day;
$custom-color: tokens.$bpk-canvas-contrast-day;

.bpk-barchart-custom-scrollers {
background: $custom-color;

&--leading {
@include bpk-scroll-indicator-left($custom-color);
@include scroll-indicators.bpk-scroll-indicator-left($custom-color);
}

&--trailing {
@include bpk-scroll-indicator-right($custom-color);
@include scroll-indicators.bpk-scroll-indicator-right($custom-color);
}
}
18 changes: 0 additions & 18 deletions examples/bpk-component-bottom-sheet/examples.module.css

This file was deleted.

4 changes: 2 additions & 2 deletions examples/bpk-component-bottom-sheet/examples.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* limitations under the License.
*/

@import '../../packages/bpk-mixins/index.scss';
@use '../../packages/unstable__bpk-mixins/tokens';

.bpk-bottom-sheet-paragraph {
margin-bottom: bpk-spacing-md();
margin-bottom: tokens.bpk-spacing-md();
}
18 changes: 0 additions & 18 deletions examples/bpk-component-breakpoint/examples.module.css

This file was deleted.

15 changes: 8 additions & 7 deletions examples/bpk-component-breakpoint/examples.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,22 @@
* limitations under the License.
*/

@import '../../packages/bpk-mixins/index.scss';
@use '../../packages/unstable__bpk-mixins/tokens';
@use '../../packages/unstable__bpk-mixins/utils';

.bpk-breakpoints-demo {
border-radius: $bpk-border-radius-xs;
border-radius: tokens.$bpk-border-radius-xs;
overflow: hidden;

&--active {
padding: bpk-spacing-lg();
color: $bpk-text-primary-inverse-day;
padding: tokens.bpk-spacing-lg();
color: tokens.$bpk-text-primary-inverse-day;

@include bpk-apply-primary-color-to(background-color);
@include utils.bpk-apply-primary-color-to(background-color);
}

&--inactive {
padding: bpk-spacing-lg();
background-color: $bpk-surface-highlight-day;
padding: tokens.bpk-spacing-lg();
background-color: tokens.$bpk-surface-highlight-day;
}
}
Loading
Loading